Skip to content

Commit e7debbe

Browse files
authored
Add hash to getTransactions response (#299)
Add transaction hash in the transaction object in the getTransactions response
1 parent cae1740 commit e7debbe

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

cmd/soroban-rpc/internal/db/transaction.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
var ErrNoTransaction = errors.New("no transaction with this hash exists")
2626

2727
type Transaction struct {
28+
TransactionHash string
2829
Result []byte // XDR encoded xdr.TransactionResult
2930
Meta []byte // XDR encoded xdr.TransactionMeta
3031
Envelope []byte // XDR encoded xdr.TransactionEnvelope
@@ -223,6 +224,7 @@ func ParseTransaction(lcm xdr.LedgerCloseMeta, ingestTx ingest.LedgerTransaction
223224
Sequence: lcm.LedgerSequence(),
224225
CloseTime: lcm.LedgerCloseTime(),
225226
}
227+
tx.TransactionHash = ingestTx.Result.TransactionHash.HexString()
226228

227229
if tx.Result, err = ingestTx.Result.Result.MarshalBinary(); err != nil {
228230
return tx, fmt.Errorf("couldn't encode transaction Result: %w", err)

cmd/soroban-rpc/internal/methods/get_transactions.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ func (req GetTransactionsRequest) isValid(maxLimit uint, ledgerRange ledgerbucke
5858
type TransactionInfo struct {
5959
// Status is one of: TransactionSuccess, TransactionFailed.
6060
Status string `json:"status"`
61+
// TransactionHash is the hex encoded hash of the transaction. Note that for fee-bump transaction
62+
// this will be the hash of the fee-bump transaction instead of the inner transaction hash.
63+
TransactionHash string `json:"txHash"`
6164
// ApplicationOrder is the index of the transaction among all the transactions
6265
// for that ledger.
6366
ApplicationOrder int32 `json:"applicationOrder"`
@@ -194,6 +197,7 @@ func (h transactionsRPCHandler) processTransactionsInLedger(
194197
}
195198

196199
txInfo := TransactionInfo{
200+
TransactionHash: tx.TransactionHash,
197201
ApplicationOrder: tx.ApplicationOrder,
198202
FeeBump: tx.FeeBump,
199203
Ledger: tx.Ledger.Sequence,

cmd/soroban-rpc/internal/methods/get_transactions_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ const (
2020
NetworkPassphrase string = "passphrase"
2121
)
2222

23+
var expectedTransactionInfo = TransactionInfo{
24+
Status: "SUCCESS",
25+
TransactionHash: "b0d0b35dcaed0152d62fbbaa28ed3fa4991c87e7e169a8fca2687b17ee26ca2d",
26+
ApplicationOrder: 1,
27+
FeeBump: false,
28+
Ledger: 1,
29+
LedgerCloseTime: 125,
30+
EnvelopeXDR: "AAAAAgAAAQCAAAAAAAAAAD8MNL+TrQ2ZcdBMzJD3BVEcg4qtlzSkovsNegP8f+iaAAAAAQAAAAD///+dAAAAAAAAAAAAAAAAAAAAAAAAAAA=", //nolint:lll
31+
ResultMetaXDR: "AAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAA",
32+
ResultXDR: "AAAAAAAAAGQAAAAAAAAAAAAAAAA=",
33+
DiagnosticEventsXDR: []string{},
34+
}
35+
2336
// createTestLedger Creates a test ledger with 2 transactions
2437
func createTestLedger(sequence uint32) xdr.LedgerCloseMeta {
2538
sequence -= 100
@@ -70,6 +83,9 @@ func TestGetTransactions_DefaultLimit(t *testing.T) {
7083

7184
// assert transactions result
7285
assert.Len(t, response.Transactions, 10)
86+
87+
// assert the transaction structure. We will match only 1 tx for sanity purposes.
88+
assert.Equal(t, expectedTransactionInfo, response.Transactions[0])
7389
}
7490

7591
func TestGetTransactions_DefaultLimitExceedsLatestLedger(t *testing.T) {
@@ -104,6 +120,9 @@ func TestGetTransactions_DefaultLimitExceedsLatestLedger(t *testing.T) {
104120

105121
// assert transactions result
106122
assert.Len(t, response.Transactions, 6)
123+
124+
// assert the transaction structure. We will match only 1 tx for sanity purposes.
125+
assert.Equal(t, expectedTransactionInfo, response.Transactions[0])
107126
}
108127

109128
func TestGetTransactions_CustomLimit(t *testing.T) {
@@ -143,6 +162,9 @@ func TestGetTransactions_CustomLimit(t *testing.T) {
143162
assert.Len(t, response.Transactions, 2)
144163
assert.Equal(t, uint32(1), response.Transactions[0].Ledger)
145164
assert.Equal(t, uint32(1), response.Transactions[1].Ledger)
165+
166+
// assert the transaction structure. We will match only 1 tx for sanity purposes.
167+
assert.Equal(t, expectedTransactionInfo, response.Transactions[0])
146168
}
147169

148170
func TestGetTransactions_CustomLimitAndCursor(t *testing.T) {

0 commit comments

Comments
 (0)