Skip to content

Commit

Permalink
Add events data to GetTransaction rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
psheth9 committed Feb 6, 2024
1 parent 0c77361 commit 8dcb16a
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cmd/soroban-rpc/internal/methods/get_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ type GetTransactionResponse struct {
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"`
}

type GetTransactionRequest struct {
Expand Down Expand Up @@ -108,6 +112,7 @@ func GetTransaction(getter transactionGetter, request GetTransactionRequest) (Ge
response.Status = TransactionStatusSuccess
} else {
response.Status = TransactionStatusFailed
response.DiagnosticEventsXDR = base64EncodeSlice(tx.Events)
}
return response, nil
}
Expand Down
30 changes: 27 additions & 3 deletions cmd/soroban-rpc/internal/transactions/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ type LedgerInfo struct {
}

type Transaction struct {
Result []byte // XDR encoded xdr.TransactionResult
Meta []byte // XDR encoded xdr.TransactionMeta
Envelope []byte // XDR encoded xdr.TransactionEnvelope
Result []byte // XDR encoded xdr.TransactionResult
Meta []byte // XDR encoded xdr.TransactionMeta
Envelope []byte // XDR encoded xdr.TransactionEnvelope
Events [][]byte // XDR encoded xdr.DiagnosticEvent
FeeBump bool
ApplicationOrder int32
Successful bool
Expand Down Expand Up @@ -198,10 +199,33 @@ func (m *MemoryStore) GetTransaction(hash xdr.Hash) (Transaction, bool, StoreRan
if !ok {
return Transaction{}, false, storeRange
}

var tx_meta xdr.TransactionMeta
err := tx_meta.UnmarshalBinary(internalTx.meta)
if err != nil {
return Transaction{}, false, storeRange
}

txEvents, err := tx_meta.GetDiagnosticEvents()

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu, amd64)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-gnu, arm64)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu-20.04, 1.21)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu-22.04, 1.21)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-20.04, 1.21, ^Test(([^C])|(C[^L])|(CL[^I])).*$)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-20.04, 1.21, .*CLI.*)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-22.04, 1.21, ^Test(([^C])|(C[^L])|(CL[^I])).*$)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-22.04, 1.21, .*CLI.*)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu, amd64)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu-20.04, 1.21)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Unit tests (ubuntu-22.04, 1.21)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-20.04, 1.21, ^Test(([^C])|(C[^L])|(CL[^I])).*$)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-22.04, 1.21, .*CLI.*)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-20.04, 1.21, .*CLI.*)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)

Check failure on line 209 in cmd/soroban-rpc/internal/transactions/transactions.go

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-22.04, 1.21, ^Test(([^C])|(C[^L])|(CL[^I])).*$)

tx_meta.GetDiagnosticEvents undefined (type "github.com/stellar/go/xdr".TransactionMeta has no field or method GetDiagnosticEvents)
if err != nil {
return Transaction{}, false, storeRange
}

var events [][]byte

for _, e := range txEvents {
diagnosticEventXDR, err := e.MarshalBinary()
if err != nil {
return Transaction{}, false, storeRange
}
events = append(events, diagnosticEventXDR)
}

tx := Transaction{
Result: internalTx.result,
Meta: internalTx.meta,
Envelope: internalTx.envelope,
Events: events,
FeeBump: internalTx.feeBump,
Successful: internalTx.successful,
ApplicationOrder: internalTx.applicationOrder,
Expand Down
51 changes: 51 additions & 0 deletions cmd/soroban-rpc/internal/transactions/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,42 @@ func txMeta(ledgerSequence uint32, feeBump bool) xdr.LedgerCloseMeta {
}
}

func txMetaWithEvents(ledgerSequence uint32, feeBump bool) xdr.LedgerCloseMeta {
tx := txMeta(ledgerSequence, feeBump)
contractIDBytes, _ := hex.DecodeString("df06d62447fd25da07c0135eed7557e5a5497ee7d15b7fe345bd47e191d8f577")
var contractID xdr.Hash
copy(contractID[:], contractIDBytes)
counter := xdr.ScSymbol("COUNTER")

tx.V1.TxProcessing[0].TxApplyProcessing.V3 = &xdr.TransactionMetaV3{
SorobanMeta: &xdr.SorobanTransactionMeta{
Events: []xdr.ContractEvent{{
ContractId: &contractID,
Type: xdr.ContractEventTypeContract,
Body: xdr.ContractEventBody{
V: 0,
V0: &xdr.ContractEventV0{
Topics: []xdr.ScVal{{
Type: xdr.ScValTypeScvSymbol,
Sym: &counter,
}},
Data: xdr.ScVal{
Type: xdr.ScValTypeScvSymbol,
Sym: &counter,
},
},
},
}},
ReturnValue: xdr.ScVal{
Type: xdr.ScValTypeScvSymbol,
Sym: &counter,
},
},
}

return tx
}

func txEnvelope(ledgerSequence uint32, feeBump bool) xdr.TransactionEnvelope {
var envelope xdr.TransactionEnvelope
var err error
Expand Down Expand Up @@ -311,6 +347,21 @@ func TestIngestTransactions(t *testing.T) {
require.Len(t, store.transactions, 3)
}

func TestGetTransactionsWithEventData(t *testing.T) {
store := NewMemoryStore(interfaces.MakeNoOpDeamon(), "passphrase", 100)

// Insert ledger 1
metaWithEvents := txMetaWithEvents(1, false)
require.NoError(t, store.IngestTransactions(metaWithEvents))
require.Len(t, store.transactions, 1)

// check events data
tx, ok, _ := store.GetTransaction(txHash(1, false))
require.True(t, ok)
require.NotNil(t, tx.Events)

}

func stableHeapInUse() int64 {
var (
m = runtime.MemStats{}
Expand Down

0 comments on commit 8dcb16a

Please sign in to comment.