Documentation ¶
Index ¶
- Variables
- func StreamChanges(changeProcessor ChangeProcessor, reader ChangeReader) error
- func StreamLedgerTransactions(txProcessor LedgerTransactionProcessor, reader *LedgerTransactionReader) error
- type Change
- type ChangeProcessor
- type ChangeReader
- type GenesisLedgerStateReader
- type LedgerChangeReader
- type LedgerEntryChangeCache
- type LedgerTransaction
- type LedgerTransactionProcessor
- type LedgerTransactionReader
- func (reader *LedgerTransactionReader) Close() error
- func (reader *LedgerTransactionReader) GetHeader() xdr.LedgerHeaderHistoryEntry
- func (reader *LedgerTransactionReader) GetSequence() uint32
- func (reader *LedgerTransactionReader) Read() (LedgerTransaction, error)
- func (reader *LedgerTransactionReader) Rewind()
- type MockChangeProcessor
- type MockChangeReader
- type SingleLedgerStateReader
- type StatsChangeProcessor
- type StatsChangeProcessorResults
- type StatsLedgerTransactionProcessor
- type StatsLedgerTransactionProcessorResults
Constants ¶
This section is empty.
Variables ¶
var EOF = stdio.EOF
EOF represents end of stream and equals standard io.EOF.
var ErrNotFound = errors.New("ledger not found")
Functions ¶
func StreamChanges ¶
func StreamChanges( changeProcessor ChangeProcessor, reader ChangeReader, ) error
func StreamLedgerTransactions ¶
func StreamLedgerTransactions( txProcessor LedgerTransactionProcessor, reader *LedgerTransactionReader, ) error
Types ¶
type Change ¶
type Change struct { Type xdr.LedgerEntryType Pre *xdr.LedgerEntry Post *xdr.LedgerEntry }
Change is a developer friendly representation of LedgerEntryChanges. It also provides some helper functions to quickly check if a given change has occured in an entry.
If an entry is created: Pre is nil and Post is not nil. If an entry is updated: Pre is not nil and Post is not nil. If an entry is removed: Pre is not nil and Post is nil.
func GetChangesFromLedgerEntryChanges ¶
func GetChangesFromLedgerEntryChanges(ledgerEntryChanges xdr.LedgerEntryChanges) []Change
GetChangesFromLedgerEntryChanges transforms LedgerEntryChanges to []Change. Each `update` and `removed` is preceded with `state` and `create` changes are alone, without `state`. The transformation we're doing is to move each change (state/update, state/removed or create) to an array of pre/post pairs. Then: - for create, pre is null and post is a new entry, - for update, pre is previous state and post is the current state, - for removed, pre is previous state and post is null.
aiblocks-core source: https://github.com/aiblocks/aiblocks-core/blob/e584b43/src/ledger/LedgerTxn.cpp#L582
func (*Change) AccountChangedExceptSigners ¶
AccountChangedExceptSigners returns true if account has changed WITHOUT checking the signers (except master key weight!). In other words, if the only change is connected to signers, this function will return false.
func (*Change) AccountSignersChanged ¶
AccountSignersChanged returns true if account signers have changed. Notice: this will return true on master key changes too!
func (*Change) LedgerEntryChangeType ¶
func (c *Change) LedgerEntryChangeType() xdr.LedgerEntryChangeType
LedgerEntryChangeType returns type in terms of LedgerEntryChangeType.
type ChangeProcessor ¶
type ChangeReader ¶
type ChangeReader interface { // Read should return the next `Change` in the leader. If there are no more // changes left it should return an `io.EOF` error. Read() (Change, error) // Close should be called when reading is finished. This is especially // helpful when there are still some changes available so reader can stop // streaming them. Close() error }
ChangeReader provides convenient, streaming access to a sequence of Changes.
type GenesisLedgerStateReader ¶
type GenesisLedgerStateReader struct { NetworkPassphrase string // contains filtered or unexported fields }
GenesisLedgerStateReader is a streaming ledger entries for genesis ledger (ledgerseq = 1) for of the network with the given passphrase.
func (*GenesisLedgerStateReader) Close ¶
func (r *GenesisLedgerStateReader) Close() error
Close should be called when reading is finished.
func (*GenesisLedgerStateReader) Read ¶
func (r *GenesisLedgerStateReader) Read() (Change, error)
Read returns a new ledger entry change on each call, returning io.EOF when the stream ends.
type LedgerChangeReader ¶
type LedgerChangeReader struct { *LedgerTransactionReader // contains filtered or unexported fields }
LedgerChangeReader is a ChangeReader which returns Changes from AiBlocks Core for a single ledger
func NewLedgerChangeReader ¶
func NewLedgerChangeReader(backend ledgerbackend.LedgerBackend, networkPassphrase string, sequence uint32) (*LedgerChangeReader, error)
NewLedgerChangeReader constructs a new LedgerChangeReader instance bound to the given ledger. Note that the returned LedgerChangeReader is not thread safe and should not be shared by multiple goroutines.
func (*LedgerChangeReader) Close ¶
func (r *LedgerChangeReader) Close() error
Close should be called when reading is finished.
func (*LedgerChangeReader) Read ¶
func (r *LedgerChangeReader) Read() (Change, error)
Read returns the next change in the stream. If there are no changes remaining io.EOF is returned as an error.
type LedgerEntryChangeCache ¶
type LedgerEntryChangeCache struct {
// contains filtered or unexported fields
}
LedgerEntryChangeCache is a cache of ledger entry changes that squashes all changes within a single ledger. By doing this, it decreases number of DB queries sent to a DB to update the current state of the ledger. It has integrity checks built in so ex. removing an account that was previously removed returns an error. In such case verify.StateError is returned.
It applies changes to the cache using the following algorithm:
- If the change is CREATED it checks if any change connected to given entry is already in the cache. If not, it adds CREATED change. Otherwise, if existing change is: a. CREATED it returns error because we can't add an entry that already exists. b. UPDATED it returns error because we can't add an entry that already exists. c. REMOVED it means that due to previous transitions we want to remove this from a DB what means that it already exists in a DB so we need to update the type of change to UPDATED.
- If the change is UPDATE it checks if any change connected to given entry is already in the cache. If not, it adds UPDATE change. Otherwise, if existing change is: a. CREATED it means that due to previous transitions we want to create this in a DB what means that it doesn't exist in a DB so we need to update the entry but stay with CREATED type. b. UPDATED we simply update it with the new value. c. REMOVED it means that at this point in the ledger the entry is removed so updating it returns an error.
- If the change is REMOVE it checks if any change connected to given entry is already in the cache. If not, it adds REMOVE change. Otherwise, if existing change is: a. CREATED it means that due to previous transitions we want to create this in a DB what means that it doesn't exist in a DB. If it was created and removed in the same ledger it's a noop so we remove entry from the cache. b. UPDATED we simply update it to be a REMOVE change because the UPDATE change means the entry exists in a DB. c. REMOVED it returns error because we can't remove an entry that was already removed.
func NewLedgerEntryChangeCache ¶
func NewLedgerEntryChangeCache() *LedgerEntryChangeCache
NewLedgerEntryChangeCache returns a new LedgerEntryChangeCache.
func (*LedgerEntryChangeCache) AddChange ¶
func (c *LedgerEntryChangeCache) AddChange(change Change) error
AddChange adds a change to LedgerEntryChangeCache. All changes are stored in memory. To get the final, squashed changes call GetChanges.
Please note that the current ledger capacity in pubnet (max 1000 ops/ledger) makes LedgerEntryChangeCache safe to use in terms of memory usage. If the cache takes too much memory, you apply changes returned by GetChanges and create a new LedgerEntryChangeCache object to continue ingestion.
func (*LedgerEntryChangeCache) GetChanges ¶
func (c *LedgerEntryChangeCache) GetChanges() []Change
GetChanges returns a slice of Changes in the cache. The order of changes is random but each change is connected to a separate entry.
func (*LedgerEntryChangeCache) Size ¶
func (c *LedgerEntryChangeCache) Size() int
Size returns number of ledger entries in the cache.
type LedgerTransaction ¶
type LedgerTransaction struct { Index uint32 Envelope xdr.TransactionEnvelope Result xdr.TransactionResultPair // FeeChanges and Meta are low level values. // Use LedgerTransaction.GetChanges() for higher level access to ledger // entry changes. FeeChanges xdr.LedgerEntryChanges Meta xdr.TransactionMeta }
LedgerTransaction represents the data for a single transaction within a ledger.
func (*LedgerTransaction) GetChanges ¶
func (t *LedgerTransaction) GetChanges() ([]Change, error)
GetChanges returns a developer friendly representation of LedgerEntryChanges. It contains transaction changes and operation changes in that order. If the transaction failed with TxInternalError, operations and txChangesAfter are omitted. It doesn't support legacy TransactionMeta.V=0.
func (*LedgerTransaction) GetFeeChanges ¶
func (t *LedgerTransaction) GetFeeChanges() []Change
GetFeeChanges returns a developer friendly representation of LedgerEntryChanges connected to fees.
func (*LedgerTransaction) GetOperationChanges ¶
func (t *LedgerTransaction) GetOperationChanges(operationIndex uint32) ([]Change, error)
GetOperationChanges returns a developer friendly representation of LedgerEntryChanges. It contains only operation changes.
type LedgerTransactionProcessor ¶
type LedgerTransactionProcessor interface {
ProcessTransaction(transaction LedgerTransaction) error
}
type LedgerTransactionReader ¶
type LedgerTransactionReader struct {
// contains filtered or unexported fields
}
LedgerTransactionReader reads transactions for a given ledger sequence from a backend. Use NewTransactionReader to create a new instance.
func NewLedgerTransactionReader ¶
func NewLedgerTransactionReader(backend ledgerbackend.LedgerBackend, networkPassphrase string, sequence uint32) (*LedgerTransactionReader, error)
NewLedgerTransactionReader creates a new TransactionReader instance. Note that TransactionReader is not thread safe and should not be shared by multiple goroutines
func (*LedgerTransactionReader) Close ¶
func (reader *LedgerTransactionReader) Close() error
Close should be called when reading is finished. This is especially helpful when there are still some transactions available so reader can stop streaming them.
func (*LedgerTransactionReader) GetHeader ¶
func (reader *LedgerTransactionReader) GetHeader() xdr.LedgerHeaderHistoryEntry
GetHeader returns the XDR Header data associated with the stored ledger.
func (*LedgerTransactionReader) GetSequence ¶
func (reader *LedgerTransactionReader) GetSequence() uint32
GetSequence returns the sequence number of the ledger data stored by this object.
func (*LedgerTransactionReader) Read ¶
func (reader *LedgerTransactionReader) Read() (LedgerTransaction, error)
Read returns the next transaction in the ledger, ordered by tx number, each time it is called. When there are no more transactions to return, an EOF error is returned.
func (*LedgerTransactionReader) Rewind ¶
func (reader *LedgerTransactionReader) Rewind()
Rewind resets the reader back to the first transaction in the ledger
type MockChangeProcessor ¶
func (*MockChangeProcessor) ProcessChange ¶
func (m *MockChangeProcessor) ProcessChange(change Change) error
type MockChangeReader ¶
func (*MockChangeReader) Close ¶
func (m *MockChangeReader) Close() error
func (*MockChangeReader) Read ¶
func (m *MockChangeReader) Read() (Change, error)
type SingleLedgerStateReader ¶
type SingleLedgerStateReader struct {
// contains filtered or unexported fields
}
SingleLedgerStateReader is a streaming implementation that reads ledger entries from buckets for a given HistoryArchiveState (single ledger/checkpoint). SingleLedgerStateReader hides internal structure of buckets from the user so entries returned by `Read()` are exactly the ledger entries present at the given ledger.
func MakeSingleLedgerStateReader ¶
func MakeSingleLedgerStateReader( ctx context.Context, archive historyarchive.ArchiveInterface, sequence uint32, ) (*SingleLedgerStateReader, error)
MakeSingleLedgerStateReader is a factory method for SingleLedgerStateReader.
func (*SingleLedgerStateReader) Close ¶
func (msr *SingleLedgerStateReader) Close() error
Close should be called when reading is finished.
func (*SingleLedgerStateReader) Read ¶
func (msr *SingleLedgerStateReader) Read() (Change, error)
Read returns a new ledger entry change on each call, returning io.EOF when the stream ends.
type StatsChangeProcessor ¶
type StatsChangeProcessor struct {
// contains filtered or unexported fields
}
StatsChangeProcessor is a state processors that counts number of changes types and entry types.
func (*StatsChangeProcessor) GetResults ¶
func (p *StatsChangeProcessor) GetResults() StatsChangeProcessorResults
func (*StatsChangeProcessor) ProcessChange ¶
func (p *StatsChangeProcessor) ProcessChange(change Change) error
type StatsChangeProcessorResults ¶
type StatsChangeProcessorResults struct { AccountsCreated int64 AccountsUpdated int64 AccountsRemoved int64 ClaimableBalancesCreated int64 ClaimableBalancesUpdated int64 ClaimableBalancesRemoved int64 DataCreated int64 DataUpdated int64 DataRemoved int64 OffersCreated int64 OffersUpdated int64 OffersRemoved int64 TrustLinesCreated int64 TrustLinesUpdated int64 TrustLinesRemoved int64 }
StatsChangeProcessorResults contains results after running StatsChangeProcessor.
func (*StatsChangeProcessorResults) Map ¶
func (stats *StatsChangeProcessorResults) Map() map[string]interface{}
type StatsLedgerTransactionProcessor ¶
type StatsLedgerTransactionProcessor struct {
// contains filtered or unexported fields
}
StatsLedgerTransactionProcessor is a state processors that counts number of changes types and entry types.
func (*StatsLedgerTransactionProcessor) GetResults ¶
func (p *StatsLedgerTransactionProcessor) GetResults() StatsLedgerTransactionProcessorResults
func (*StatsLedgerTransactionProcessor) ProcessTransaction ¶
func (p *StatsLedgerTransactionProcessor) ProcessTransaction(transaction LedgerTransaction) error
type StatsLedgerTransactionProcessorResults ¶
type StatsLedgerTransactionProcessorResults struct { Transactions int64 TransactionsSuccessful int64 TransactionsFailed int64 Operations int64 OperationsInSuccessful int64 OperationsInFailed int64 OperationsCreateAccount int64 OperationsPayment int64 OperationsPathPaymentStrictReceive int64 OperationsManageSellOffer int64 OperationsCreatePassiveSellOffer int64 OperationsSetOptions int64 OperationsChangeTrust int64 OperationsAllowTrust int64 OperationsAccountMerge int64 OperationsInflation int64 OperationsManageData int64 OperationsBumpSequence int64 OperationsManageBuyOffer int64 OperationsPathPaymentStrictSend int64 OperationsCreateClaimableBalance int64 OperationsClaimClaimableBalance int64 OperationsBeginSponsoringFutureReserves int64 OperationsEndSponsoringFutureReserves int64 OperationsRevokeSponsorship int64 }
StatsLedgerTransactionProcessorResults contains results after running StatsLedgerTransactionProcessor.
func (*StatsLedgerTransactionProcessorResults) Map ¶
func (stats *StatsLedgerTransactionProcessorResults) Map() map[string]interface{}
Source Files ¶
- change.go
- errors.go
- genesis_ledger_state_reader.go
- ledger_change_reader.go
- ledger_entry_change_cache.go
- ledger_transaction.go
- ledger_transaction_reader.go
- main.go
- memory_temp_set.go
- mock_change_processor.go
- mock_change_reader.go
- processors.go
- single_ledger_state_reader.go
- stats_change_processor.go
- stats_ledger_transaction_processor.go