Skip to content

Commit

Permalink
Make createdAt properly non-breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Oct 24, 2024
1 parent 54e3360 commit e04483a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 32 deletions.
10 changes: 8 additions & 2 deletions cmd/soroban-rpc/internal/methods/get_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions cmd/soroban-rpc/internal/methods/get_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -60,17 +60,17 @@ func TestGetTransaction(t *testing.T) {
LatestLedgerCloseTime: 2625,
OldestLedger: 101,
OldestLedgerCloseTime: 2625,
TransactionInfo: TransactionInfo{
TransactionDetails: TransactionDetails{
Status: TransactionStatusSuccess,
ApplicationOrder: 1,
FeeBump: false,
EnvelopeXDR: expectedEnvelope,
ResultXDR: expectedTxResult,
ResultMetaXDR: expectedTxMeta,
Ledger: 101,
LedgerCloseTime: 2625,
DiagnosticEventsXDR: []string{},
},
LedgerCloseTime: 2625,
}, tx)

// ingest another (failed) transaction
Expand All @@ -85,17 +85,17 @@ func TestGetTransaction(t *testing.T) {
LatestLedgerCloseTime: 2650,
OldestLedger: 101,
OldestLedgerCloseTime: 2625,
TransactionInfo: TransactionInfo{
TransactionDetails: TransactionDetails{
Status: TransactionStatusSuccess,
ApplicationOrder: 1,
FeeBump: false,
EnvelopeXDR: expectedEnvelope,
ResultXDR: expectedTxResult,
ResultMetaXDR: expectedTxMeta,
Ledger: 101,
LedgerCloseTime: 2625,
DiagnosticEventsXDR: []string{},
},
LedgerCloseTime: 2625,
}, tx)

// the new transaction should also be there
Expand All @@ -116,17 +116,17 @@ func TestGetTransaction(t *testing.T) {
LatestLedgerCloseTime: 2650,
OldestLedger: 101,
OldestLedgerCloseTime: 2625,
TransactionInfo: TransactionInfo{
TransactionDetails: TransactionDetails{
Status: TransactionStatusFailed,
ApplicationOrder: 1,
FeeBump: false,
EnvelopeXDR: expectedEnvelope,
ResultXDR: expectedTxResult,
ResultMetaXDR: expectedTxMeta,
Ledger: 102,
LedgerCloseTime: 2650,
DiagnosticEventsXDR: []string{},
},
LedgerCloseTime: 2650,
}, tx)

// Test Txn with events
Expand All @@ -151,17 +151,17 @@ 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,
EnvelopeXDR: expectedEnvelope,
ResultXDR: expectedTxResult,
ResultMetaXDR: expectedTxMeta,
Ledger: 103,
LedgerCloseTime: 2675,
DiagnosticEventsXDR: []string{expectedEventsMeta},
},
LedgerCloseTime: 2675,
LatestLedger: 103,
LatestLedgerCloseTime: 2675,
OldestLedger: 101,
Expand Down
31 changes: 20 additions & 11 deletions cmd/soroban-rpc/internal/methods/get_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
}

Expand Down Expand Up @@ -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 {
Expand Down
22 changes: 12 additions & 10 deletions cmd/soroban-rpc/internal/methods/get_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e04483a

Please sign in to comment.