asserter

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: Apache-2.0 Imports: 6 Imported by: 138

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccountBalance

func AccountBalance(
	block *rosetta.BlockIdentifier,
	balances []*rosetta.Balance,
) error

AccountBalance returns an error if the provided rosetta.BlockIdentifier is invalid, if the same rosetta.AccountIdentifier appears in multiple rosetta.Balance structs (should be consolidated), or if a rosetta.Balance is considered invalid.

func AccountIdentifier

func AccountIdentifier(account *rosetta.AccountIdentifier) error

AccountIdentifier returns an error if a rosetta.AccountIdentifier is missing an address or a provided SubAccount is missing an identifier.

func Amount

func Amount(amount *rosetta.Amount) error

Amount ensures a rosetta.Amount has an integer value, specified precision, and symbol.

func BlockIdentifier

func BlockIdentifier(blockIdentifier *rosetta.BlockIdentifier) error

BlockIdentifier ensures a rosetta.BlockIdentifier is well-formatted.

func Error added in v0.0.4

func Error(err *rosetta.Error) error

Error ensures a rosetta.Error is valid.

func Errors added in v0.0.4

func Errors(rosettaErrors []*rosetta.Error) error

Errors ensures each rosetta.Error in a slice is valid and that there is no error code collision.

func MempoolTransactions

func MempoolTransactions(
	transactions []*rosetta.TransactionIdentifier,
) error

MempoolTransactions returns an error if any rosetta.TransactionIdentifier returns is missing a hash. The correctness of each populated MempoolTransaction is asserted by Transaction.

func NetworkIdentifier

func NetworkIdentifier(network *rosetta.NetworkIdentifier) error

NetworkIdentifier ensures a rosetta.NetworkIdentifier has a valid blockchain and network.

func NetworkInformation

func NetworkInformation(networkInformation *rosetta.NetworkInformation) error

NetworkInformation ensures any rosetta.NetworkInformation included in rosetta.NetworkStatus or rosetta.SubNetworkStatus is valid.

func NetworkOptions

func NetworkOptions(options *rosetta.Options) error

NetworkOptions ensures a rosetta.Options object is valid.

func NetworkStatus

func NetworkStatus(networkStatus *rosetta.NetworkStatus) error

NetworkStatus ensures a rosetta.NetworkStatus object is valid.

func NetworkStatusResponse

func NetworkStatusResponse(response *rosetta.NetworkStatusResponse) error

NetworkStatusResponse orchestrates assertions for all components of a rosetta.NetworkStatus.

func OperationIdentifier

func OperationIdentifier(
	identifier *rosetta.OperationIdentifier,
	index int64,
) error

OperationIdentifier returns an error if index of the rosetta.Operation is out-of-order or if the NetworkIndex is invalid.

func OperationStatuses

func OperationStatuses(statuses []*rosetta.OperationStatus) error

OperationStatuses ensures all items in Options.OperationStatuses are valid and that there exists at least 1 successful status.

func Peer

func Peer(peer *rosetta.Peer) error

Peer ensures a rosetta.Peer has a valid peer_id.

func StringArray

func StringArray(arrName string, arr []string) error

StringArray ensures all strings in an array are non-empty strings.

func SubNetworkIdentifier

func SubNetworkIdentifier(subNetworkIdentifier *rosetta.SubNetworkIdentifier) error

SubNetworkIdentifier asserts a rosetta.SubNetworkIdentifer is valid (if not nil).

func Timestamp

func Timestamp(timestamp int64) error

Timestamp returns an error if the timestamp on a block is less than or equal to 0.

func TransactionConstruction

func TransactionConstruction(
	response *rosetta.TransactionConstructionResponse,
) error

TransactionConstruction returns an error if the NetworkFee is not a valid rosetta.Amount.

func TransactionIdentifier

func TransactionIdentifier(
	transactionIdentifier *rosetta.TransactionIdentifier,
) error

TransactionIdentifier returns an error if a rosetta.TransactionIdentifier has an invalid hash.

func Version

func Version(version *rosetta.Version) error

Version ensures the version of the node is returned.

Types

type Asserter

type Asserter struct {
	// contains filtered or unexported fields
}

Asserter contains all logic to perform static validation on Rosetta Server responses.

func New

func New(
	ctx context.Context,
	networkResponse *rosetta.NetworkStatusResponse,
) (*Asserter, error)

New constructs a new Asserter.

func NewOptions added in v0.0.4

func NewOptions(
	ctx context.Context,
	genesisBlockIdentifier *rosetta.BlockIdentifier,
	operationTypes []string,
	operationStatuses []*rosetta.OperationStatus,
	errors []*rosetta.Error,
) *Asserter

NewOptions constructs a new Asserter using the provided arguments instead of using a rosetta.NetworkStatusResponse.

func (*Asserter) Block

func (a *Asserter) Block(
	ctx context.Context,
	block *rosetta.Block,
) error

Block runs a basic set of assertions for each returned block.

func (*Asserter) Operation

func (a *Asserter) Operation(
	operation *rosetta.Operation,
	index int64,
) error

Operation ensures a rosetta.Operation has a valid type, status, and amount.

func (*Asserter) OperationSuccessful

func (a *Asserter) OperationSuccessful(operation *rosetta.Operation) (bool, error)

OperationSuccessful returns a boolean indicating if a rosetta.Operation is successful and should be applied in a transaction. This should only be called AFTER an operation has been validated.

func (*Asserter) Transaction

func (a *Asserter) Transaction(
	transaction *rosetta.Transaction,
) error

Transaction returns an error if the rosetta.TransactionIdentifier is invalid, if any rosetta.Operation within the rosetta.Transaction is invalid, or if any operation index is reused within a transaction.

func (*Asserter) TransactionSubmit

func (a *Asserter) TransactionSubmit(
	response *rosetta.TransactionSubmitResponse,
) error

TransactionSubmit returns an error if the rosetta.TransactionIdentifier in the response is not valid or if the Submission.Status is not contained within the provided validStatuses slice.

Jump to

Keyboard shortcuts

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