Documentation ¶
Index ¶
- Variables
- func StreamChanges(changeProcessor ChangeProcessor, reader ChangeReader) error
- func StreamLedgerTransactions(txProcessor LedgerTransactionProcessor, reader LedgerReader) error
- type Change
- type ChangeProcessor
- type ChangeReader
- type DBLedgerReader
- type GenesisLedgerStateReader
- type LedgerChangeReader
- type LedgerEntryChangeCache
- type LedgerReader
- type LedgerTransaction
- type LedgerTransactionProcessor
- type MockChangeProcessor
- type MockChangeReader
- type MockLedgerReader
- func (m *MockLedgerReader) Close() error
- func (m *MockLedgerReader) GetHeader() xdr.LedgerHeaderHistoryEntry
- func (m *MockLedgerReader) GetSequence() uint32
- func (m *MockLedgerReader) GetUpgradeChanges() []Change
- func (m *MockLedgerReader) IgnoreUpgradeChanges()
- func (m *MockLedgerReader) Read() (LedgerTransaction, error)
- func (m *MockLedgerReader) ReadUpgradeChange() (Change, error)
- type MockLedgerTransactionProcessor
- type SingleLedgerStateReader
- type StatsChangeProcessor
- type StatsChangeProcessorResults
- type StatsLedgerTransactionProcessor
- type StatsLedgerTransactionProcessorResults
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("ledger not found")
Functions ¶
func StreamChanges ¶
func StreamChanges( changeProcessor ChangeProcessor, reader ChangeReader, ) error
func StreamLedgerTransactions ¶
func StreamLedgerTransactions( txProcessor LedgerTransactionProcessor, reader LedgerReader, ) 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 (*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 DBLedgerReader ¶
type DBLedgerReader struct {
// contains filtered or unexported fields
}
DBLedgerReader is a database-backed implementation of the io.LedgerReader interface. Use NewDBLedgerReader to create a new instance.
func NewDBLedgerReader ¶
func NewDBLedgerReader( ctx context.Context, sequence uint32, backend ledgerbackend.LedgerBackend, ) (*DBLedgerReader, error)
NewDBLedgerReader creates a new DBLedgerReader instance. Note that DBLedgerReader is not thread safe and should not be shared by multiple goroutines
func (*DBLedgerReader) Close ¶
func (dblrc *DBLedgerReader) Close() error
func (*DBLedgerReader) GetHeader ¶
func (dblrc *DBLedgerReader) GetHeader() xdr.LedgerHeaderHistoryEntry
GetHeader returns the XDR Header data associated with the stored ledger.
func (*DBLedgerReader) GetSequence ¶
func (dblrc *DBLedgerReader) GetSequence() uint32
GetSequence returns the sequence number of the ledger data stored by this object.
func (*DBLedgerReader) Read ¶
func (dblrc *DBLedgerReader) 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.
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 {
// contains filtered or unexported fields
}
LedgerChangeReader is a ChangeReader which returns Changes from Stellar Core for a single ledger
func NewLedgerChangeReader ¶
func NewLedgerChangeReader( ctx context.Context, sequence uint32, backend ledgerbackend.LedgerBackend, ) (*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
func (*LedgerChangeReader) GetHeader ¶
func (r *LedgerChangeReader) GetHeader() xdr.LedgerHeaderHistoryEntry
GetHeader returns the ledger header for the reader
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 LedgerReader ¶
type LedgerReader interface { GetSequence() uint32 GetHeader() xdr.LedgerHeaderHistoryEntry // Read should return the next transaction. If there are no more // transactions it should return `io.EOF` error. Read() (LedgerTransaction, 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. Close() error }
LedgerReader provides convenient, streaming access to the transactions within a ledger.
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 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 MockLedgerReader ¶
func (*MockLedgerReader) Close ¶
func (m *MockLedgerReader) Close() error
func (*MockLedgerReader) GetHeader ¶
func (m *MockLedgerReader) GetHeader() xdr.LedgerHeaderHistoryEntry
func (*MockLedgerReader) GetSequence ¶
func (m *MockLedgerReader) GetSequence() uint32
func (*MockLedgerReader) GetUpgradeChanges ¶
func (m *MockLedgerReader) GetUpgradeChanges() []Change
func (*MockLedgerReader) IgnoreUpgradeChanges ¶
func (m *MockLedgerReader) IgnoreUpgradeChanges()
func (*MockLedgerReader) Read ¶
func (m *MockLedgerReader) Read() (LedgerTransaction, error)
func (*MockLedgerReader) ReadUpgradeChange ¶
func (m *MockLedgerReader) ReadUpgradeChange() (Change, error)
type MockLedgerTransactionProcessor ¶
func (*MockLedgerTransactionProcessor) ProcessTransaction ¶
func (m *MockLedgerTransactionProcessor) ProcessTransaction(transaction LedgerTransaction) 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, maxStreamRetries int, ) (*SingleLedgerStateReader, error)
MakeSingleLedgerStateReader is a factory method for SingleLedgerStateReader. `maxStreamRetries` determines how many times the reader will retry when encountering errors while streaming xdr bucket entries from the history archive. Set `maxStreamRetries` to 0 if there should be no retry attempts
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 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 }
StatsLedgerTransactionProcessorResults contains results after running StatsLedgerTransactionProcessor.
func (*StatsLedgerTransactionProcessorResults) Map ¶
func (stats *StatsLedgerTransactionProcessorResults) Map() map[string]interface{}
Source Files ¶
- change.go
- change_reader.go
- errors.go
- genesis_ledger_state_reader.go
- ledger_entry_change_cache.go
- ledger_reader.go
- ledger_transaction.go
- memory_temp_set.go
- mock_change_processor.go
- mock_change_reader.go
- mock_ledger_reader.go
- mock_ledger_transaction_processor.go
- processors.go
- single_ledger_state_reader.go
- stats_change_processor.go
- stats_ledger_transaction_processor.go