Skip to content

Commit

Permalink
feat: Add the success attribute to a transaction (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Apr 18, 2024
1 parent f026544 commit d8d65c4
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 1 deletion.
70 changes: 69 additions & 1 deletion serve/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions serve/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions serve/graph/model/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func (t *Transaction) BlockHeight() int {
return int(t.txResult.Height)
}

func (t *Transaction) Success() bool {
return t.txResult.Response.IsOK()
}

func (t *Transaction) GasWanted() int {
return int(t.txResult.Response.GasWanted)
}
Expand Down
6 changes: 6 additions & 0 deletions serve/graph/schema/filter/transaction_filter.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ input TransactionFilter {
For example, when trading a specific exchange, you would utilize the memo field of the transaction.
"""
memo: String

"""
`success` is whether the transaction was successful or not.
`success` enables you to filter between successful and unsuccessful transactions.
"""
success: Boolean
}

"""
Expand Down
5 changes: 5 additions & 0 deletions serve/graph/schema/types/transaction.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ type Transaction {
"""
hash: String!

"""
The success can determine whether the transaction succeeded or failed.
"""
success: Boolean!

"""
The height of the Block in which this Transaction is included. Links the Transaction to its containing Block.
"""
Expand Down
13 changes: 13 additions & 0 deletions serve/graph/transaction_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
// `FilteredTransactionBy` checks for conditions in GasUsed, GasWanted, Memo, and Message.
// By default, the condition is only checked if the input parameter exists.
func FilteredTransactionBy(tx *model.Transaction, filter model.TransactionFilter) bool {
if !filteredTransactionBySuccess(tx, filter.Success) {
return false
}

if !filteredTransactionByGasUsed(tx, filter.FromGasUsed, filter.ToGasUsed) {
return false
}
Expand Down Expand Up @@ -39,6 +43,15 @@ func FilteredTransactionBy(tx *model.Transaction, filter model.TransactionFilter
return true
}

// `filteredTransactionBySuccess` will check the success or failure results of the transaction.
func filteredTransactionBySuccess(tx *model.Transaction, success *bool) bool {
if success == nil {
return true
}

return deref(success) == tx.Success()
}

// `filteredAmountBy` checks a token represented as a string(<value><denomination>)
// against a range of amount and a denomination.
func filteredAmountBy(amountStr string, amountInput *model.AmountInput) bool {
Expand Down

0 comments on commit d8d65c4

Please sign in to comment.