Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hash to getTransactions response #299

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/soroban-rpc/internal/db/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
var ErrNoTransaction = errors.New("no transaction with this hash exists")

type Transaction struct {
TransactionHash string
Result []byte // XDR encoded xdr.TransactionResult
Meta []byte // XDR encoded xdr.TransactionMeta
Envelope []byte // XDR encoded xdr.TransactionEnvelope
Expand Down Expand Up @@ -223,6 +224,7 @@ func ParseTransaction(lcm xdr.LedgerCloseMeta, ingestTx ingest.LedgerTransaction
Sequence: lcm.LedgerSequence(),
CloseTime: lcm.LedgerCloseTime(),
}
tx.TransactionHash = ingestTx.Result.TransactionHash.HexString()
aditya1702 marked this conversation as resolved.
Show resolved Hide resolved

if tx.Result, err = ingestTx.Result.Result.MarshalBinary(); err != nil {
return tx, fmt.Errorf("couldn't encode transaction Result: %w", err)
Expand Down
4 changes: 4 additions & 0 deletions cmd/soroban-rpc/internal/methods/get_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func (req GetTransactionsRequest) isValid(maxLimit uint, ledgerRange ledgerbucke
type TransactionInfo struct {
// Status is one of: TransactionSuccess, TransactionFailed.
Status string `json:"status"`
// TransactionHash is the hex encoded hash of the transaction. Note that for fee-bump transaction
// this will be the hash of the fee-bump transaction instead of the inner transaction hash.
TransactionHash string `json:"txHash"`
aditya1702 marked this conversation as resolved.
Show resolved Hide resolved
// ApplicationOrder is the index of the transaction among all the transactions
// for that ledger.
ApplicationOrder int32 `json:"applicationOrder"`
Expand Down Expand Up @@ -194,6 +197,7 @@ func (h transactionsRPCHandler) processTransactionsInLedger(
}

txInfo := TransactionInfo{
TransactionHash: tx.TransactionHash,
ApplicationOrder: tx.ApplicationOrder,
FeeBump: tx.FeeBump,
Ledger: tx.Ledger.Sequence,
Expand Down
22 changes: 22 additions & 0 deletions cmd/soroban-rpc/internal/methods/get_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ const (
NetworkPassphrase string = "passphrase"
)

var expectedTransactionInfo = TransactionInfo{
Status: "SUCCESS",
TransactionHash: "b0d0b35dcaed0152d62fbbaa28ed3fa4991c87e7e169a8fca2687b17ee26ca2d",
ApplicationOrder: 1,
FeeBump: false,
Ledger: 1,
LedgerCloseTime: 125,
EnvelopeXDR: "AAAAAgAAAQCAAAAAAAAAAD8MNL+TrQ2ZcdBMzJD3BVEcg4qtlzSkovsNegP8f+iaAAAAAQAAAAD///+dAAAAAAAAAAAAAAAAAAAAAAAAAAA=", //nolint:lll
ResultMetaXDR: "AAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAA",
ResultXDR: "AAAAAAAAAGQAAAAAAAAAAAAAAAA=",
DiagnosticEventsXDR: []string{},
}

// createTestLedger Creates a test ledger with 2 transactions
func createTestLedger(sequence uint32) xdr.LedgerCloseMeta {
sequence -= 100
Expand Down Expand Up @@ -70,6 +83,9 @@ func TestGetTransactions_DefaultLimit(t *testing.T) {

// assert transactions result
assert.Len(t, response.Transactions, 10)

// assert the transaction structure. We will match only 1 tx for sanity purposes.
assert.Equal(t, expectedTransactionInfo, response.Transactions[0])
}

func TestGetTransactions_DefaultLimitExceedsLatestLedger(t *testing.T) {
Expand Down Expand Up @@ -104,6 +120,9 @@ func TestGetTransactions_DefaultLimitExceedsLatestLedger(t *testing.T) {

// assert transactions result
assert.Len(t, response.Transactions, 6)

// assert the transaction structure. We will match only 1 tx for sanity purposes.
assert.Equal(t, expectedTransactionInfo, response.Transactions[0])
}

func TestGetTransactions_CustomLimit(t *testing.T) {
Expand Down Expand Up @@ -143,6 +162,9 @@ func TestGetTransactions_CustomLimit(t *testing.T) {
assert.Len(t, response.Transactions, 2)
assert.Equal(t, uint32(1), response.Transactions[0].Ledger)
assert.Equal(t, uint32(1), response.Transactions[1].Ledger)

// assert the transaction structure. We will match only 1 tx for sanity purposes.
assert.Equal(t, expectedTransactionInfo, response.Transactions[0])
}

func TestGetTransactions_CustomLimitAndCursor(t *testing.T) {
Expand Down
Loading