Documentation
¶
Index ¶
Constants ¶
const ( // AnyAmountSign is a positive or negative amount. AnyAmountSign = iota // NegativeAmountSign is a negative amount. NegativeAmountSign // PositiveAmountSign is a positive amount. PositiveAmountSign )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountDescription ¶ added in v0.3.0
type AccountDescription struct {
Exists bool
SubAccountExists bool
SubAccountAddress string
SubAccountMetadataKeys []*MetadataDescription
}
AccountDescription is used to describe a *types.AccountIdentifier.
type AmountDescription ¶ added in v0.3.0
type AmountDescription struct {
Exists bool
Sign AmountSign
Currency *types.Currency
}
AmountDescription is used to describe a *types.Amount.
type AmountSign ¶ added in v0.3.0
type AmountSign int
AmountSign is used to represent possible signedness of an amount.
func (AmountSign) Match ¶ added in v0.3.0
func (s AmountSign) Match(amount *types.Amount) bool
Match returns a boolean indicating if a *types.Amount has an AmountSign.
func (AmountSign) String ¶ added in v0.3.0
func (s AmountSign) String() string
String returns a description of an AmountSign.
type BalanceChange ¶
type BalanceChange struct {
Account *types.AccountIdentifier `json:"account_identifier,omitempty"`
Currency *types.Currency `json:"currency,omitempty"`
Block *types.BlockIdentifier `json:"block_identifier,omitempty"`
Difference string `json:"difference,omitempty"`
}
BalanceChange represents a balance change that affected a *types.AccountIdentifier and a *types.Currency.
type Descriptions ¶ added in v0.3.0
type Descriptions struct {
OperationDescriptions []*OperationDescription
// EqualAmounts are specified using the operation indicies of
// OperationDescriptions to handle out of order matches. MatchOperations
// will error if all groups of operations aren't equal.
EqualAmounts [][]int
// OppositeAmounts are specified using the operation indicies of
// OperationDescriptions to handle out of order matches. MatchOperations
// will error if all groups of operations aren't opposites.
OppositeAmounts [][]int
// EqualAddresses are specified using the operation indicies of
// OperationDescriptions to handle out of order matches. MatchOperations
// will error if all groups of operations addresses aren't equal.
EqualAddresses [][]int
// ErrUnmatched indicates that an error should be returned
// if all operations cannot be matched to a description.
ErrUnmatched bool
}
Descriptions contains a slice of OperationDescriptions and high-level requirements enforced across multiple *types.Operations.
type ExemptOperation ¶ added in v0.1.10
ExemptOperation is a function that returns a boolean indicating if the operation should be skipped eventhough it passes other checks indiciating it should be considered a balance change.
type Match ¶ added in v0.3.0
type Match struct {
Operations []*types.Operation
// Amounts has the same length as Operations. If an operation has
// a populate Amount, its corresponding *big.Int will be non-nil.
Amounts []*big.Int
}
Match contains all *types.Operation matching a given OperationDescription and their parsed *big.Int amounts (if populated).
func MatchOperations ¶ added in v0.3.0
func MatchOperations( descriptions *Descriptions, operations []*types.Operation, ) ([]*Match, error)
MatchOperations attempts to match a slice of operations with a slice of OperationDescriptions (high-level descriptions of what operations are desired). If matching succeeds, a slice of matching operations in the mapped to the order of the descriptions is returned.
type MetadataDescription ¶ added in v0.3.0
MetadataDescription is used to check if a map[string]interface{} has certain keys and values of a certain kind.
type OperationDescription ¶ added in v0.3.0
type OperationDescription struct {
Account *AccountDescription
Amount *AmountDescription
Metadata []*MetadataDescription
// Type is the operation.Type that must match. If this is left empty,
// any type is considered a match.
Type string
// AllowRepeats indicates that multiple operations can be matched
// to a particular description.
AllowRepeats bool
// Optional indicates that not finding any operations that meet
// the description should not trigger an error.
Optional bool
}
OperationDescription is used to describe a *types.Operation.
type OperationGroup ¶
type OperationGroup struct {
Type string
Operations []*types.Operation
Currencies []*types.Currency
NilAmountPresent bool
}
OperationGroup is a group of related operations If all operations in a group have the same operation.Type, the Type is also populated.
func GroupOperations ¶
func GroupOperations(transaction *types.Transaction) []*OperationGroup
GroupOperations parses all of a transaction's opertations and returns a slice of each group of related operations (assuming transitive relatedness). This should ONLY be called on operations that have already been asserted for correctness. Assertion ensures there are no duplicate operation indexes, operations are sorted, and that operations only reference operations with an index less than theirs.
OperationGroups are returned in ascending order based on the lowest OperationIdentifier.Index in the group. The operations in each OperationGroup are also sorted.
type Parser ¶
type Parser struct {
Asserter *asserter.Asserter
ExemptFunc ExemptOperation
}
Parser provides support for parsing Rosetta blocks.
func New ¶
func New(asserter *asserter.Asserter, exemptFunc ExemptOperation) *Parser
New creates a new Parser.
func (*Parser) BalanceChanges ¶
func (p *Parser) BalanceChanges( ctx context.Context, block *types.Block, blockRemoved bool, ) ([]*BalanceChange, error)
BalanceChanges returns all balance changes for a particular block. All balance changes for a particular account are summed into a single BalanceChanges struct. If a block is being orphaned, the opposite of each balance change is returned.