From e04483ad41545c0fda607d08a9601ef485707774 Mon Sep 17 00:00:00 2001 From: George Date: Thu, 24 Oct 2024 12:12:11 -0700 Subject: [PATCH] Make createdAt properly non-breaking --- .../internal/methods/get_transaction.go | 10 ++++-- .../internal/methods/get_transaction_test.go | 18 +++++------ .../internal/methods/get_transactions.go | 31 ++++++++++++------- .../internal/methods/get_transactions_test.go | 22 +++++++------ 4 files changed, 49 insertions(+), 32 deletions(-) diff --git a/cmd/soroban-rpc/internal/methods/get_transaction.go b/cmd/soroban-rpc/internal/methods/get_transaction.go index e6882b96..f08c89f6 100644 --- a/cmd/soroban-rpc/internal/methods/get_transaction.go +++ b/cmd/soroban-rpc/internal/methods/get_transaction.go @@ -38,8 +38,14 @@ type GetTransactionResponse struct { // LatestLedgerCloseTime is the unix timestamp of when the oldest ledger was closed. OldestLedgerCloseTime int64 `json:"oldestLedgerCloseTime,string"` - // Many of the fields below are only present if Status is not TransactionNotFound. - TransactionInfo + // Many of the fields below are only present if Status is not + // TransactionNotFound. + TransactionDetails + // LedgerCloseTime is the unix timestamp of when the transaction was + // included in the ledger. It isn't part of `TransactionInfo` because of a + // bug in which `createdAt` in getTransactions is encoded as a number + // whereas in getTransaction (singular) it's encoded as a string. + LedgerCloseTime int64 `json:"createdAt,string"` } type GetTransactionRequest struct { diff --git a/cmd/soroban-rpc/internal/methods/get_transaction_test.go b/cmd/soroban-rpc/internal/methods/get_transaction_test.go index 38e6d5a3..847b2e6e 100644 --- a/cmd/soroban-rpc/internal/methods/get_transaction_test.go +++ b/cmd/soroban-rpc/internal/methods/get_transaction_test.go @@ -36,7 +36,7 @@ func TestGetTransaction(t *testing.T) { tx, err := GetTransaction(ctx, log, store, ledgerReader, GetTransactionRequest{hash, ""}) require.NoError(t, err) require.Equal(t, GetTransactionResponse{ - TransactionInfo: TransactionInfo{ + TransactionDetails: TransactionDetails{ Status: TransactionStatusNotFound, }, }, tx) @@ -60,7 +60,7 @@ func TestGetTransaction(t *testing.T) { LatestLedgerCloseTime: 2625, OldestLedger: 101, OldestLedgerCloseTime: 2625, - TransactionInfo: TransactionInfo{ + TransactionDetails: TransactionDetails{ Status: TransactionStatusSuccess, ApplicationOrder: 1, FeeBump: false, @@ -68,9 +68,9 @@ func TestGetTransaction(t *testing.T) { ResultXDR: expectedTxResult, ResultMetaXDR: expectedTxMeta, Ledger: 101, - LedgerCloseTime: 2625, DiagnosticEventsXDR: []string{}, }, + LedgerCloseTime: 2625, }, tx) // ingest another (failed) transaction @@ -85,7 +85,7 @@ func TestGetTransaction(t *testing.T) { LatestLedgerCloseTime: 2650, OldestLedger: 101, OldestLedgerCloseTime: 2625, - TransactionInfo: TransactionInfo{ + TransactionDetails: TransactionDetails{ Status: TransactionStatusSuccess, ApplicationOrder: 1, FeeBump: false, @@ -93,9 +93,9 @@ func TestGetTransaction(t *testing.T) { ResultXDR: expectedTxResult, ResultMetaXDR: expectedTxMeta, Ledger: 101, - LedgerCloseTime: 2625, DiagnosticEventsXDR: []string{}, }, + LedgerCloseTime: 2625, }, tx) // the new transaction should also be there @@ -116,7 +116,7 @@ func TestGetTransaction(t *testing.T) { LatestLedgerCloseTime: 2650, OldestLedger: 101, OldestLedgerCloseTime: 2625, - TransactionInfo: TransactionInfo{ + TransactionDetails: TransactionDetails{ Status: TransactionStatusFailed, ApplicationOrder: 1, FeeBump: false, @@ -124,9 +124,9 @@ func TestGetTransaction(t *testing.T) { ResultXDR: expectedTxResult, ResultMetaXDR: expectedTxMeta, Ledger: 102, - LedgerCloseTime: 2650, DiagnosticEventsXDR: []string{}, }, + LedgerCloseTime: 2650, }, tx) // Test Txn with events @@ -151,7 +151,7 @@ func TestGetTransaction(t *testing.T) { tx, err = GetTransaction(ctx, log, store, ledgerReader, GetTransactionRequest{hash, ""}) require.NoError(t, err) require.Equal(t, GetTransactionResponse{ - TransactionInfo: TransactionInfo{ + TransactionDetails: TransactionDetails{ Status: TransactionStatusSuccess, ApplicationOrder: 1, FeeBump: false, @@ -159,9 +159,9 @@ func TestGetTransaction(t *testing.T) { ResultXDR: expectedTxResult, ResultMetaXDR: expectedTxMeta, Ledger: 103, - LedgerCloseTime: 2675, DiagnosticEventsXDR: []string{expectedEventsMeta}, }, + LedgerCloseTime: 2675, LatestLedger: 103, LatestLedgerCloseTime: 2675, OldestLedger: 101, diff --git a/cmd/soroban-rpc/internal/methods/get_transactions.go b/cmd/soroban-rpc/internal/methods/get_transactions.go index e98598d1..3d1d7efe 100644 --- a/cmd/soroban-rpc/internal/methods/get_transactions.go +++ b/cmd/soroban-rpc/internal/methods/get_transactions.go @@ -55,14 +55,15 @@ func (req GetTransactionsRequest) isValid(maxLimit uint, ledgerRange ledgerbucke return IsValidFormat(req.Format) } -type TransactionInfo struct { +type TransactionDetails struct { // Status is one of: TransactionSuccess, TransactionFailed, TransactionNotFound. 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 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"` - // ApplicationOrder is the index of the transaction among all the transactions - // for that ledger. + // ApplicationOrder is the index of the transaction among all the + // transactions for that ledger. ApplicationOrder int32 `json:"applicationOrder"` // FeeBump indicates whether the transaction is a feebump transaction FeeBump bool `json:"feeBump"` @@ -81,7 +82,13 @@ type TransactionInfo struct { DiagnosticEventsJSON []json.RawMessage `json:"diagnosticEventsJson,omitempty"` // 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. +} + +type TransactionInfo struct { + TransactionDetails + + // LedgerCloseTime is the unix timestamp of when the transaction was + // included in the ledger. LedgerCloseTime int64 `json:"createdAt"` } @@ -197,11 +204,13 @@ func (h transactionsRPCHandler) processTransactionsInLedger( } txInfo := TransactionInfo{ - TransactionHash: tx.TransactionHash, - ApplicationOrder: tx.ApplicationOrder, - FeeBump: tx.FeeBump, - Ledger: tx.Ledger.Sequence, - LedgerCloseTime: tx.Ledger.CloseTime, + TransactionDetails: TransactionDetails{ + TransactionHash: tx.TransactionHash, + ApplicationOrder: tx.ApplicationOrder, + FeeBump: tx.FeeBump, + Ledger: tx.Ledger.Sequence, + }, + LedgerCloseTime: tx.Ledger.CloseTime, } switch format { diff --git a/cmd/soroban-rpc/internal/methods/get_transactions_test.go b/cmd/soroban-rpc/internal/methods/get_transactions_test.go index 24e3f429..531ed9de 100644 --- a/cmd/soroban-rpc/internal/methods/get_transactions_test.go +++ b/cmd/soroban-rpc/internal/methods/get_transactions_test.go @@ -21,16 +21,18 @@ const ( ) 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{}, + TransactionDetails{ + Status: "SUCCESS", + TransactionHash: "b0d0b35dcaed0152d62fbbaa28ed3fa4991c87e7e169a8fca2687b17ee26ca2d", + ApplicationOrder: 1, + FeeBump: false, + Ledger: 1, + EnvelopeXDR: "AAAAAgAAAQCAAAAAAAAAAD8MNL+TrQ2ZcdBMzJD3BVEcg4qtlzSkovsNegP8f+iaAAAAAQAAAAD///+dAAAAAAAAAAAAAAAAAAAAAAAAAAA=", //nolint:lll + ResultMetaXDR: "AAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAA", + ResultXDR: "AAAAAAAAAGQAAAAAAAAAAAAAAAA=", + DiagnosticEventsXDR: []string{}, + }, + 125, } // createTestLedger Creates a test ledger with 2 transactions