parser

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2020 License: Apache-2.0 Imports: 6 Imported by: 55

README

Parser

GoDoc

The Parser package provides support for parsing Rosetta blocks. This includes things like calculating all the balance changes that occurred in a block and grouping related operations.

Installation

go get github.com/coinbase/rosetta-sdk-go/parser

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 ExemptOperation added in v0.1.10

type ExemptOperation func(*types.Operation) bool

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 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL