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

Use TransactionInfo within GetTransactionResponse #251

Merged
merged 3 commits into from
Jul 19, 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
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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could still keep the Status field to show what actually happened with Txn. Any strong motive to remove this field? or is it rarely used by users?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it's still part of TransactionInfo. It can take on one additional value (TransactionNotFound) for this endpoint, but since it's a string regardless this doesn't impact the code.

// 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
Loading