asserter

package
v0.1.3 Latest Latest
Warning

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

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

README

Asserter

GoDoc

The Asserter package is used to validate the correctness of Rosetta types. It is important to note that this validation only ensures that required fields are populated, fields are in the correct format, and transaction operations only contain types and statuses specified in the /network/status endpoint.

If you want more intensive validation, try running the Rosetta Validator.

Installation

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAsserterNotInitialized is returned when some call in the asserter
	// package requires the asserter to be initialized first.
	ErrAsserterNotInitialized = errors.New("asserter not initialized")
)

Functions

func AccountBalance

func AccountBalance(
	block *types.BlockIdentifier,
	balances []*types.Amount,
) error

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

func AccountBalanceRequest added in v0.1.0

func AccountBalanceRequest(request *types.AccountBalanceRequest) error

AccountBalanceRequest ensures that a types.AccountBalanceRequest is well-formatted.

func AccountIdentifier

func AccountIdentifier(account *types.AccountIdentifier) error

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

func Allow added in v0.1.2

func Allow(allowed *types.Allow) error

Allow ensures a types.Allow object is valid.

func Amount

func Amount(amount *types.Amount) error

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

func BlockIdentifier

func BlockIdentifier(blockIdentifier *types.BlockIdentifier) error

BlockIdentifier ensures a types.BlockIdentifier is well-formatted.

func BlockRequest added in v0.1.0

func BlockRequest(request *types.BlockRequest) error

BlockRequest ensures that a types.BlockRequest is well-formatted.

func BlockTransactionRequest added in v0.1.0

func BlockTransactionRequest(request *types.BlockTransactionRequest) error

BlockTransactionRequest ensures that a types.BlockTransactionRequest is well-formatted.

func ConstructionMetadata added in v0.1.2

func ConstructionMetadata(
	response *types.ConstructionMetadataResponse,
) error

ConstructionMetadata returns an error if the NetworkFee is not a valid types.Amount.

func ConstructionMetadataRequest added in v0.1.2

func ConstructionMetadataRequest(request *types.ConstructionMetadataRequest) error

ConstructionMetadataRequest ensures that a types.ConstructionMetadataRequest is well-formatted.

func ConstructionSubmit added in v0.1.3

func ConstructionSubmit(
	response *types.ConstructionSubmitResponse,
) error

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

func ConstructionSubmitRequest added in v0.1.2

func ConstructionSubmitRequest(request *types.ConstructionSubmitRequest) error

ConstructionSubmitRequest ensures that a types.ConstructionSubmitRequest is well-formatted.

func Error added in v0.0.4

func Error(err *types.Error) error

Error ensures a types.Error is valid.

func Errors added in v0.0.4

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

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

func MempoolRequest added in v0.1.0

func MempoolRequest(request *types.MempoolRequest) error

MempoolRequest ensures that a types.MempoolRequest is well-formatted.

func MempoolTransactionRequest added in v0.1.0

func MempoolTransactionRequest(request *types.MempoolTransactionRequest) error

MempoolTransactionRequest ensures that a types.MempoolTransactionRequest is well-formatted.

func MempoolTransactions

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

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

func MetadataRequest added in v0.1.2

func MetadataRequest(request *types.MetadataRequest) error

MetadataRequest ensures that a types.MetadataRequest is well-formatted.

func NetworkIdentifier

func NetworkIdentifier(network *types.NetworkIdentifier) error

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

func NetworkListResponse added in v0.1.2

func NetworkListResponse(response *types.NetworkListResponse) error

NetworkListResponse ensures a types.NetworkListResponse object is valid.

func NetworkOptionsResponse added in v0.1.2

func NetworkOptionsResponse(options *types.NetworkOptionsResponse) error

NetworkOptionsResponse ensures a types.NetworkOptionsResponse object is valid.

func NetworkRequest added in v0.1.2

func NetworkRequest(request *types.NetworkRequest) error

NetworkRequest ensures that a types.NetworkRequest is well-formatted.

func NetworkStatusResponse

func NetworkStatusResponse(response *types.NetworkStatusResponse) error

NetworkStatusResponse ensures any types.NetworkStatusResponse is valid.

func OperationIdentifier

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

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

func OperationStatuses

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

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

func PartialBlockIdentifier added in v0.1.0

func PartialBlockIdentifier(blockIdentifier *types.PartialBlockIdentifier) error

PartialBlockIdentifier ensures a types.PartialBlockIdentifier is well-formatted.

func Peer

func Peer(peer *types.Peer) error

Peer ensures a types.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 *types.SubNetworkIdentifier) error

SubNetworkIdentifier asserts a types.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 TransactionIdentifier

func TransactionIdentifier(
	transactionIdentifier *types.TransactionIdentifier,
) error

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

func Version

func Version(version *types.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 NewWithOptions added in v0.1.2

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

NewWithOptions constructs a new Asserter using the provided arguments instead of using a NetworkStatusResponse and a NetworkOptionsResponse.

func NewWithResponses added in v0.1.2

func NewWithResponses(
	ctx context.Context,
	networkStatus *types.NetworkStatusResponse,
	networkOptions *types.NetworkOptionsResponse,
) (*Asserter, error)

NewWithResponses constructs a new Asserter from a NetworkStatusResponse and NetworkOptionsResponse.

func (*Asserter) Block

func (a *Asserter) Block(
	block *types.Block,
) error

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

func (*Asserter) Operation

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

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

func (*Asserter) OperationSuccessful

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

OperationSuccessful returns a boolean indicating if a types.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 *types.Transaction,
) error

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

Jump to

Keyboard shortcuts

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