-
Notifications
You must be signed in to change notification settings - Fork 81
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
Add events data to GetTransaction rpc #1192
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
|
@@ -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() | ||||||
if err != nil { | ||||||
return Transaction{}, false, storeRange | ||||||
} | ||||||
|
||||||
var events [][]byte | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. preallocate since we know the size?
Suggested change
|
||||||
|
||||||
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, | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. length check (easier) or content check (harder) would be good here besides not-nil |
||
} | ||
|
||
func stableHeapInUse() int64 { | ||
var ( | ||
m = runtime.MemStats{} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: style consistency so let's use
camelCase