Skip to content

Commit

Permalink
Use TransactionInfo within GetTransactionResponse (#251)
Browse files Browse the repository at this point in the history
* Encode createdAt as a string for JS support
  • Loading branch information
Shaptic authored Jul 19, 2024
1 parent c8965d0 commit 2c74888
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 61 deletions.
24 changes: 1 addition & 23 deletions cmd/soroban-rpc/internal/methods/get_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ const (

// GetTransactionResponse is the response for the Soroban-RPC getTransaction() endpoint
type GetTransactionResponse struct {
// Status is one of: TransactionSuccess, TransactionNotFound, or TransactionFailed.
Status string `json:"status"`
// LatestLedger is the latest ledger stored in Soroban-RPC.
LatestLedger uint32 `json:"latestLedger"`
// LatestLedgerCloseTime is the unix timestamp of when the latest ledger was closed.
Expand All @@ -41,27 +39,7 @@ type GetTransactionResponse struct {
OldestLedgerCloseTime int64 `json:"oldestLedgerCloseTime,string"`

// The fields below are only present if Status is not TransactionNotFound.

// ApplicationOrder is the index of the transaction among all the transactions
// for that ledger.
ApplicationOrder int32 `json:"applicationOrder,omitempty"`
// FeeBump indicates whether the transaction is a feebump transaction
FeeBump bool `json:"feeBump,omitempty"`
// EnvelopeXdr is the TransactionEnvelope XDR value.
EnvelopeXdr string `json:"envelopeXdr,omitempty"`
// ResultXdr is the TransactionResult XDR value.
ResultXdr string `json:"resultXdr,omitempty"`
// ResultMetaXdr is the TransactionMeta XDR value.
ResultMetaXdr string `json:"resultMetaXdr,omitempty"`

// Ledger is the sequence of the ledger which included the transaction.
Ledger uint32 `json:"ledger,omitempty"`
// LedgerCloseTime is the unix timestamp of when the transaction was included in the ledger.
LedgerCloseTime int64 `json:"createdAt,string,omitempty"`

// DiagnosticEventsXDR is present only if Status is equal to TransactionFailed.
// DiagnosticEventsXDR is a base64-encoded slice of xdr.DiagnosticEvent
DiagnosticEventsXDR []string `json:"diagnosticEventsXdr,omitempty"`
TransactionInfo
}

type GetTransactionRequest struct {
Expand Down
86 changes: 49 additions & 37 deletions cmd/soroban-rpc/internal/methods/get_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ func TestGetTransaction(t *testing.T) {
hash := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
tx, err := GetTransaction(ctx, log, store, ledgerReader, GetTransactionRequest{hash})
require.NoError(t, err)
require.Equal(t, GetTransactionResponse{Status: TransactionStatusNotFound}, tx)
require.Equal(t, GetTransactionResponse{
TransactionInfo: TransactionInfo{
Status: TransactionStatusNotFound,
},
}, tx)

meta := txMeta(1, true)
require.NoError(t, store.InsertTransactions(meta))
Expand All @@ -50,19 +54,21 @@ func TestGetTransaction(t *testing.T) {
expectedTxMeta, err := xdr.MarshalBase64(meta.V1.TxProcessing[0].TxApplyProcessing)
require.NoError(t, err)
require.Equal(t, GetTransactionResponse{
Status: TransactionStatusSuccess,
LatestLedger: 101,
LatestLedgerCloseTime: 2625,
OldestLedger: 101,
OldestLedgerCloseTime: 2625,
ApplicationOrder: 1,
FeeBump: false,
EnvelopeXdr: expectedEnvelope,
ResultXdr: expectedTxResult,
ResultMetaXdr: expectedTxMeta,
Ledger: 101,
LedgerCloseTime: 2625,
DiagnosticEventsXDR: []string{},
TransactionInfo: TransactionInfo{
Status: TransactionStatusSuccess,
ApplicationOrder: 1,
FeeBump: false,
EnvelopeXdr: expectedEnvelope,
ResultXdr: expectedTxResult,
ResultMetaXdr: expectedTxMeta,
Ledger: 101,
LedgerCloseTime: 2625,
DiagnosticEventsXDR: []string{},
},
}, tx)

// ingest another (failed) transaction
Expand All @@ -73,19 +79,21 @@ func TestGetTransaction(t *testing.T) {
tx, err = GetTransaction(ctx, log, store, ledgerReader, GetTransactionRequest{hash})
require.NoError(t, err)
require.Equal(t, GetTransactionResponse{
Status: TransactionStatusSuccess,
LatestLedger: 102,
LatestLedgerCloseTime: 2650,
OldestLedger: 101,
OldestLedgerCloseTime: 2625,
ApplicationOrder: 1,
FeeBump: false,
EnvelopeXdr: expectedEnvelope,
ResultXdr: expectedTxResult,
ResultMetaXdr: expectedTxMeta,
Ledger: 101,
LedgerCloseTime: 2625,
DiagnosticEventsXDR: []string{},
TransactionInfo: TransactionInfo{
Status: TransactionStatusSuccess,
ApplicationOrder: 1,
FeeBump: false,
EnvelopeXdr: expectedEnvelope,
ResultXdr: expectedTxResult,
ResultMetaXdr: expectedTxMeta,
Ledger: 101,
LedgerCloseTime: 2625,
DiagnosticEventsXDR: []string{},
},
}, tx)

// the new transaction should also be there
Expand All @@ -102,19 +110,21 @@ func TestGetTransaction(t *testing.T) {
tx, err = GetTransaction(ctx, log, store, ledgerReader, GetTransactionRequest{hash})
require.NoError(t, err)
require.Equal(t, GetTransactionResponse{
Status: TransactionStatusFailed,
LatestLedger: 102,
LatestLedgerCloseTime: 2650,
OldestLedger: 101,
OldestLedgerCloseTime: 2625,
ApplicationOrder: 1,
FeeBump: false,
EnvelopeXdr: expectedEnvelope,
ResultXdr: expectedTxResult,
ResultMetaXdr: expectedTxMeta,
Ledger: 102,
LedgerCloseTime: 2650,
DiagnosticEventsXDR: []string{},
TransactionInfo: TransactionInfo{
Status: TransactionStatusFailed,
ApplicationOrder: 1,
FeeBump: false,
EnvelopeXdr: expectedEnvelope,
ResultXdr: expectedTxResult,
ResultMetaXdr: expectedTxMeta,
Ledger: 102,
LedgerCloseTime: 2650,
DiagnosticEventsXDR: []string{},
},
}, tx)

// Test Txn with events
Expand All @@ -139,19 +149,21 @@ func TestGetTransaction(t *testing.T) {
tx, err = GetTransaction(ctx, log, store, ledgerReader, GetTransactionRequest{hash})
require.NoError(t, err)
require.Equal(t, GetTransactionResponse{
Status: TransactionStatusSuccess,
TransactionInfo: TransactionInfo{
Status: TransactionStatusSuccess,
ApplicationOrder: 1,
FeeBump: false,
EnvelopeXdr: expectedEnvelope,
ResultXdr: expectedTxResult,
ResultMetaXdr: expectedTxMeta,
Ledger: 103,
LedgerCloseTime: 2675,
DiagnosticEventsXDR: []string{expectedEventsMeta},
},
LatestLedger: 103,
LatestLedgerCloseTime: 2675,
OldestLedger: 101,
OldestLedgerCloseTime: 2625,
ApplicationOrder: 1,
FeeBump: false,
EnvelopeXdr: expectedEnvelope,
ResultXdr: expectedTxResult,
ResultMetaXdr: expectedTxMeta,
Ledger: 103,
LedgerCloseTime: 2675,
DiagnosticEventsXDR: []string{expectedEventsMeta},
}, tx)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-rpc/internal/methods/get_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type TransactionInfo struct {
// Ledger is the sequence of the ledger which included the transaction.
Ledger uint32 `json:"ledger"`
// LedgerCloseTime is the unix timestamp of when the transaction was included in the ledger.
LedgerCloseTime int64 `json:"createdAt"`
LedgerCloseTime int64 `json:"createdAt,string"`
}

// GetTransactionsResponse encapsulates the response structure for getTransactions queries.
Expand Down

0 comments on commit 2c74888

Please sign in to comment.