asserter

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: Apache-2.0 Imports: 8 Imported by: 137

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

View Source
const (
	// MinUnixEpoch is the unix epoch time in milliseconds of
	// 01/01/2000 at 12:00:00 AM.
	MinUnixEpoch = 946713600000

	// MaxUnixEpoch is the unix epoch time in milliseconds of
	// 01/01/2040 at 12:00:00 AM.
	MaxUnixEpoch = 2209017600000
)

Variables

View Source
var (
	ErrReturnedBlockHashMismatch = errors.New(
		"request block hash does not match response block hash",
	)
	ErrReturnedBlockIndexMismatch = errors.New(
		"request block index does not match response block index",
	)

	AccountBalanceErrs = []error{
		ErrReturnedBlockHashMismatch,
		ErrReturnedBlockIndexMismatch,
	}

	ErrAmountValueMissing            = errors.New("Amount.Value is missing")
	ErrAmountIsNotInt                = errors.New("Amount.Value is not an integer")
	ErrAmountCurrencyIsNil           = errors.New("Amount.Currency is nil")
	ErrAmountCurrencySymbolEmpty     = errors.New("Amount.Currency.Symbol is empty")
	ErrAmountCurrencyHasNegDecimals  = errors.New("Amount.Currency.Decimals must be >= 0")
	ErrOperationIdentifierIndexIsNil = errors.New(
		"Operation.OperationIdentifier.Index is invalid",
	)
	ErrOperationIdentifierIndexOutOfOrder = errors.New(
		"Operation.OperationIdentifier.Index is out of order",
	)
	ErrOperationIdentifierNetworkIndexInvalid = errors.New(
		"Operation.OperationIdentifier.NetworkIndex is invalid",
	)
	ErrAccountIsNil                           = errors.New("Account is nil")
	ErrAccountAddrMissing                     = errors.New("Account.Address is missing")
	ErrAccountSubAccountAddrMissing           = errors.New("Account.SubAccount.Address is missing")
	ErrOperationStatusMissing                 = errors.New("Operation.Status is missing")
	ErrOperationStatusInvalid                 = errors.New("Operation.Status is invalid")
	ErrOperationTypeInvalid                   = errors.New("Operation.Type is invalid")
	ErrOperationIsNil                         = errors.New("Operation is nil")
	ErrOperationStatusNotEmptyForConstruction = errors.New(
		"Operation.Status must be empty for construction",
	)
	ErrRelatedOperationIndexOutOfOrder = errors.New(
		"related operation has index greater than operation",
	)
	ErrRelatedOperationIndexDuplicate     = errors.New("found duplicate related operation index")
	ErrBlockIdentifierIsNil               = errors.New("BlockIdentifier is nil")
	ErrBlockIdentifierHashMissing         = errors.New("BlockIdentifier.Hash is missing")
	ErrBlockIdentifierIndexIsNeg          = errors.New("BlockIdentifier.Index is negative")
	ErrPartialBlockIdentifierIsNil        = errors.New("PartialBlockIdentifier is nil")
	ErrPartialBlockIdentifierFieldsNotSet = errors.New(
		"neither PartialBlockIdentifier.Hash nor PartialBlockIdentifier.Index is set",
	)
	ErrTxIdentifierIsNil              = errors.New("TransactionIdentifier is nil")
	ErrTxIdentifierHashMissing        = errors.New("TransactionIdentifier.Hash is missing")
	ErrNoOperationsForConstruction    = errors.New("operations cannot be empty for construction")
	ErrTxIsNil                        = errors.New("Transaction is nil")
	ErrTimestampBeforeMin             = errors.New("timestamp is before 01/01/2000")
	ErrTimestampAfterMax              = errors.New("timestamp is after 01/01/2040")
	ErrBlockIsNil                     = errors.New("Block is nil")
	ErrBlockHashEqualsParentBlockHash = errors.New(
		"BlockIdentifier.Hash == ParentBlockIdentifier.Hash",
	)
	ErrBlockIndexPrecedesParentBlockIndex = errors.New(
		"BlockIdentifier.Index <= ParentBlockIdentifier.Index",
	)

	BlockErrs = []error{
		ErrAmountValueMissing,
		ErrAmountIsNotInt,
		ErrAmountCurrencyIsNil,
		ErrAmountCurrencySymbolEmpty,
		ErrAmountCurrencyHasNegDecimals,
		ErrOperationIdentifierIndexIsNil,
		ErrOperationIdentifierIndexOutOfOrder,
		ErrOperationIdentifierNetworkIndexInvalid,
		ErrAccountIsNil,
		ErrAccountAddrMissing,
		ErrAccountSubAccountAddrMissing,
		ErrOperationStatusMissing,
		ErrOperationStatusInvalid,
		ErrOperationTypeInvalid,
		ErrOperationIsNil,
		ErrOperationStatusNotEmptyForConstruction,
		ErrRelatedOperationIndexOutOfOrder,
		ErrRelatedOperationIndexDuplicate,
		ErrBlockIdentifierIsNil,
		ErrBlockIdentifierHashMissing,
		ErrBlockIdentifierIndexIsNeg,
		ErrPartialBlockIdentifierIsNil,
		ErrPartialBlockIdentifierFieldsNotSet,
		ErrTxIdentifierIsNil,
		ErrTxIdentifierHashMissing,
		ErrNoOperationsForConstruction,
		ErrTxIsNil,
		ErrTimestampBeforeMin,
		ErrTimestampAfterMax,
		ErrBlockIsNil,
		ErrBlockHashEqualsParentBlockHash,
		ErrBlockIndexPrecedesParentBlockIndex,
	}

	ErrCoinIsNil            = errors.New("coin cannot be nil")
	ErrCoinDuplicate        = errors.New("duplicate coin identifier detected")
	ErrCoinIdentifierIsNil  = errors.New("coin identifier cannot be nil")
	ErrCoinIdentifierNotSet = errors.New("coin identifier cannot be empty")
	ErrCoinChangeIsNil      = errors.New("coin change cannot be nil")
	ErrCoinActionInvalid    = errors.New("not a valid coin action")

	CoinErrs = []error{
		ErrCoinIsNil,
		ErrCoinDuplicate,
		ErrCoinIdentifierIsNil,
		ErrCoinIdentifierNotSet,
		ErrCoinChangeIsNil,
		ErrCoinActionInvalid,
	}

	ErrConstructionPreprocessResponseIsNil = errors.New(
		"ConstructionPreprocessResponse cannot be nil",
	)
	ErrConstructionMetadataResponseIsNil = errors.New(
		"ConstructionMetadataResponse cannot be nil",
	)
	ErrConstructionMetadataResponseMetadataMissing = errors.New("Metadata is nil")
	ErrTxIdentifierResponseIsNil                   = errors.New(
		"TransactionIdentifierResponse cannot be nil",
	)
	ErrConstructionCombineResponseIsNil = errors.New(
		"construction combine response cannot be nil",
	)
	ErrSignedTxEmpty = errors.New(
		"signed transaction cannot be empty",
	)
	ErrConstructionDeriveResponseIsNil = errors.New(
		"construction derive response cannot be nil",
	)
	ErrConstructionDeriveResponseAddrEmpty = errors.New("address cannot be empty")
	ErrConstructionParseResponseIsNil      = errors.New(
		"construction parse response cannot be nil",
	)
	ErrConstructionParseResponseOperationsEmpty        = errors.New("operations cannot be empty")
	ErrConstructionParseResponseSignersEmptyOnSignedTx = errors.New(
		"signers cannot be empty on signed transaction",
	)
	ErrConstructionParseResponseSignersNonEmptyOnUnsignedTx = errors.New(
		"signers should be empty for unsigned txs",
	)
	ErrConstructionParseResponseSignerEmpty     = errors.New("signer cannot be empty string")
	ErrConstructionParseResponseDuplicateSigner = errors.New("found duplicate signer")
	ErrConstructionPayloadsResponseIsNil        = errors.New(
		"construction payloads response cannot be nil",
	)
	ErrConstructionPayloadsResponseUnsignedTxEmpty = errors.New(
		"unsigned transaction cannot be empty",
	)
	ErrConstructionPayloadsResponsePayloadsEmpty = errors.New("signing payloads cannot be empty")
	ErrPublicKeyIsNil                            = errors.New("PublicKey cannot be nil")
	ErrPublicKeyBytesEmpty                       = errors.New("public key bytes cannot be empty")
	ErrCurveTypeNotSupported                     = errors.New("not a supported CurveType")
	ErrSigningPayloadIsNil                       = errors.New("signing payload cannot be nil")
	ErrSigningPayloadAddrEmpty                   = errors.New(
		"signing payload address cannot be empty",
	)
	ErrSigningPayloadBytesEmpty = errors.New(
		"signing payload bytes cannot be empty",
	)
	ErrSignaturesEmpty               = errors.New("signatures cannot be empty")
	ErrSignaturesReturnedSigMismatch = errors.New(
		"requested signature type does not match returned signature type",
	)
	ErrSignatureBytesEmpty       = errors.New("signature bytes cannot be empty")
	ErrSignatureTypeNotSupported = errors.New("not a supported SignatureType")

	ConstructionErrs = []error{
		ErrConstructionPreprocessResponseIsNil,
		ErrConstructionMetadataResponseIsNil,
		ErrConstructionMetadataResponseMetadataMissing,
		ErrTxIdentifierResponseIsNil,
		ErrConstructionCombineResponseIsNil,
		ErrSignedTxEmpty,
		ErrConstructionDeriveResponseIsNil,
		ErrConstructionDeriveResponseAddrEmpty,
		ErrConstructionParseResponseIsNil,
		ErrConstructionParseResponseOperationsEmpty,
		ErrConstructionParseResponseSignersEmptyOnSignedTx,
		ErrConstructionParseResponseSignersNonEmptyOnUnsignedTx,
		ErrConstructionParseResponseSignerEmpty,
		ErrConstructionPayloadsResponseIsNil,
		ErrConstructionPayloadsResponseUnsignedTxEmpty,
		ErrConstructionPayloadsResponsePayloadsEmpty,
		ErrPublicKeyIsNil,
		ErrPublicKeyBytesEmpty,
		ErrCurveTypeNotSupported,
		ErrSigningPayloadIsNil,
		ErrSigningPayloadAddrEmpty,
		ErrSigningPayloadBytesEmpty,
		ErrSignaturesEmpty,
		ErrSignaturesReturnedSigMismatch,
		ErrSignatureBytesEmpty,
		ErrSignatureTypeNotSupported,
	}

	ErrSubNetworkIdentifierInvalid = errors.New(
		"NetworkIdentifier.SubNetworkIdentifier.Network is missing",
	)
	ErrNetworkIdentifierIsNil               = errors.New("NetworkIdentifier is nil")
	ErrNetworkIdentifierBlockchainMissing   = errors.New("NetworkIdentifier.Blockchain is missing")
	ErrNetworkIdentifierNetworkMissing      = errors.New("NetworkIdentifier.Network is missing")
	ErrPeerIDMissing                        = errors.New("Peer.PeerID is missing")
	ErrVersionIsNil                         = errors.New("version is nil")
	ErrVersionNodeVersionMissing            = errors.New("Version.NodeVersion is missing")
	ErrVersionMiddlewareVersionMissing      = errors.New("Version.MiddlewareVersion is missing")
	ErrNetworkStatusResponseIsNil           = errors.New("network status response is nil")
	ErrNoAllowedOperationStatuses           = errors.New("no Allow.OperationStatuses found")
	ErrNoSuccessfulAllowedOperationStatuses = errors.New(
		"no successful Allow.OperationStatuses found",
	)
	ErrErrorIsNil                                   = errors.New("Error is nil")
	ErrErrorCodeIsNeg                               = errors.New("Error.Code is negative")
	ErrErrorMessageMissing                          = errors.New("Error.Message is missing")
	ErrErrorCodeUsedMultipleTimes                   = errors.New("error code used multiple times")
	ErrAllowIsNil                                   = errors.New("Allow is nil")
	ErrNetworkOptionsResponseIsNil                  = errors.New("options is nil")
	ErrNetworkListResponseIsNil                     = errors.New("NetworkListResponse is nil")
	ErrNetworkListResponseNetworksContinsDuplicates = errors.New(
		"NetworkListResponse.Networks contains duplicates",
	)

	NetworkErrs = []error{
		ErrSubNetworkIdentifierInvalid,
		ErrNetworkIdentifierIsNil,
		ErrNetworkIdentifierBlockchainMissing,
		ErrNetworkIdentifierNetworkMissing,
		ErrPeerIDMissing,
		ErrVersionIsNil,
		ErrVersionNodeVersionMissing,
		ErrVersionMiddlewareVersionMissing,
		ErrNetworkStatusResponseIsNil,
		ErrNoAllowedOperationStatuses,
		ErrNoSuccessfulAllowedOperationStatuses,
		ErrErrorIsNil,
		ErrErrorCodeIsNeg,
		ErrErrorMessageMissing,
		ErrErrorCodeUsedMultipleTimes,
		ErrAllowIsNil,
		ErrNetworkOptionsResponseIsNil,
		ErrNetworkListResponseIsNil,
		ErrNetworkListResponseNetworksContinsDuplicates,
	}

	ErrNoSupportedNetworks = errors.New(
		"no supported networks",
	)
	ErrSupportedNetworksDuplicate = errors.New(
		"supported network duplicate",
	)
	ErrRequestedNetworkNotSupported = errors.New(
		"requestNetwork not supported",
	)
	ErrAccountBalanceRequestIsNil = errors.New(
		"AccountBalanceRequest is nil",
	)
	ErrAccountBalanceRequestHistoricalBalanceLookupNotSupported = errors.New(
		"historical balance lookup is not supported",
	)
	ErrBlockRequestIsNil                       = errors.New("BlockRequest is nil")
	ErrBlockTransactionRequestIsNil            = errors.New("BlockTransactionRequest is nil")
	ErrConstructionMetadataRequestIsNil        = errors.New("ConstructionMetadataRequest is nil")
	ErrConstructionMetadataRequestOptionsIsNil = errors.New(
		"ConstructionMetadataRequest.Options is nil",
	)
	ErrConstructionSubmitRequestIsNil         = errors.New("ConstructionSubmitRequest is nil")
	ErrConstructionSubmitRequestSignedTxEmpty = errors.New(
		"ConstructionSubmitRequest.SignedTransaction is empty",
	)
	ErrMempoolTransactionRequestIsNil = errors.New(
		"MempoolTransactionRequest is nil",
	)
	ErrMetadataRequestIsNil = errors.New(
		"MetadataRequest is nil",
	)
	ErrNetworkRequestIsNil = errors.New(
		"NetworkRequest is nil",
	)
	ErrConstructionDeriveRequestIsNil = errors.New(
		"ConstructionDeriveRequest is nil",
	)
	ErrConstructionPreprocessRequestIsNil = errors.New(
		"ConstructionPreprocessRequest is nil",
	)
	ErrConstructionPreprocessRequestSuggestedFeeMultiplierIsNeg = errors.New(
		"suggested fee multiplier cannot be less than 0",
	)
	ErrConstructionPayloadsRequestIsNil          = errors.New("ConstructionPayloadsRequest is nil")
	ErrConstructionCombineRequestIsNil           = errors.New("ConstructionCombineRequest is nil")
	ErrConstructionCombineRequestUnsignedTxEmpty = errors.New("UnsignedTransaction cannot be empty")
	ErrConstructionHashRequestIsNil              = errors.New("ConstructionHashRequest is nil")
	ErrConstructionHashRequestSignedTxEmpty      = errors.New("SignedTransaction cannot be empty")
	ErrConstructionParseRequestIsNil             = errors.New("ConstructionParseRequest is nil")
	ErrConstructionParseRequestEmpty             = errors.New("Transaction cannot be empty")

	ServerErrs = []error{
		ErrNoSupportedNetworks,
		ErrSupportedNetworksDuplicate,
		ErrRequestedNetworkNotSupported,
		ErrAccountBalanceRequestIsNil,
		ErrAccountBalanceRequestHistoricalBalanceLookupNotSupported,
		ErrBlockRequestIsNil,
		ErrBlockTransactionRequestIsNil,
		ErrConstructionMetadataRequestIsNil,
		ErrConstructionMetadataRequestOptionsIsNil,
		ErrConstructionSubmitRequestIsNil,
		ErrConstructionSubmitRequestSignedTxEmpty,
		ErrMempoolTransactionRequestIsNil,
		ErrMetadataRequestIsNil,
		ErrNetworkRequestIsNil,
		ErrConstructionDeriveRequestIsNil,
		ErrConstructionPreprocessRequestIsNil,
		ErrConstructionPreprocessRequestSuggestedFeeMultiplierIsNeg,
		ErrConstructionPayloadsRequestIsNil,
		ErrConstructionCombineRequestIsNil,
		ErrConstructionCombineRequestUnsignedTxEmpty,
		ErrConstructionHashRequestIsNil,
		ErrConstructionHashRequestSignedTxEmpty,
		ErrConstructionParseRequestIsNil,
		ErrConstructionParseRequestEmpty,
	}
)

Named error types for Asserter errors

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 AccountArray added in v0.4.1

func AccountArray(arrName string, arr []*types.AccountIdentifier) error

AccountArray ensures all *types.AccountIdentifier in an array are valid and not duplicates.

func AccountBalanceResponse added in v0.1.5

func AccountBalanceResponse(
	requestBlock *types.PartialBlockIdentifier,
	response *types.AccountBalanceResponse,
) error

AccountBalanceResponse returns an error if the provided types.BlockIdentifier is invalid, if the requestBlock is not nil and not equal to the response block, or if the same currency is present in multiple amounts.

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 AssertUniqueAmounts added in v0.4.1

func AssertUniqueAmounts(amounts []*types.Amount) error

AssertUniqueAmounts returns an error if a slice of types.Amount is invalid. It is considered invalid if the same currency is returned multiple times (these shoould be consolidated) or if a types.Amount is considered invalid.

func BlockIdentifier

func BlockIdentifier(blockIdentifier *types.BlockIdentifier) error

BlockIdentifier ensures a types.BlockIdentifier is well-formatted.

func Coin added in v0.3.3

func Coin(coin *types.Coin) error

Coin returns an error if the provided *types.Coin is invalid.

func CoinAction added in v0.3.3

func CoinAction(action types.CoinAction) error

CoinAction returns an error if the provided types.CoinAction is invalid.

func CoinChange added in v0.3.3

func CoinChange(change *types.CoinChange) error

CoinChange returns an error if the provided *types.CoinChange is invalid.

func CoinIdentifier added in v0.3.3

func CoinIdentifier(coinIdentifier *types.CoinIdentifier) error

CoinIdentifier returns an error if the provided *types.CoinIdentifier is invalid.

func Coins added in v0.3.3

func Coins(coins []*types.Coin) error

Coins returns an error if the provided []*types.Coin is invalid. If there are any duplicate identifiers, this function will also return an error.

func ConstructionCombineResponse added in v0.3.0

func ConstructionCombineResponse(
	response *types.ConstructionCombineResponse,
) error

ConstructionCombineResponse returns an error if a *types.ConstructionCombineResponse does not have a populated SignedTransaction.

func ConstructionDeriveResponse added in v0.3.0

func ConstructionDeriveResponse(
	response *types.ConstructionDeriveResponse,
) error

ConstructionDeriveResponse returns an error if a *types.ConstructionDeriveResponse does not have a populated Address.

func ConstructionMetadataResponse added in v0.3.0

func ConstructionMetadataResponse(
	response *types.ConstructionMetadataResponse,
) error

ConstructionMetadataResponse returns an error if the metadata is not a JSON object.

func ConstructionPayloadsResponse added in v0.3.0

func ConstructionPayloadsResponse(
	response *types.ConstructionPayloadsResponse,
) error

ConstructionPayloadsResponse returns an error if a *types.ConstructionPayloadsResponse does not have an UnsignedTransaction or has no valid *SigningPaylod.

func ConstructionPreprocessResponse added in v0.4.1

func ConstructionPreprocessResponse(
	response *types.ConstructionPreprocessResponse,
) error

ConstructionPreprocessResponse returns an error if the request public keys are not valid AccountIdentifiers.

func ContainsCurrency added in v0.2.0

func ContainsCurrency(currencies []*types.Currency, currency *types.Currency) bool

ContainsCurrency returns a boolean indicating if a *types.Currency is contained within a slice of *types.Currency. The check for equality takes into account everything within the types.Currency struct (including currency.Metadata).

func Currency added in v0.4.1

func Currency(currency *types.Currency) error

Currency ensures a *types.Currency is valid.

func CurveType added in v0.3.0

func CurveType(
	curve types.CurveType,
) error

CurveType returns an error if the curve is not a valid types.CurveType.

func Err added in v0.4.1

func Err(err error) (bool, string)

Err takes an error as an argument and returns whether or not the error is one thrown by the asserter along with the specific source of the error

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 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 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 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.Allow.OperationStatuses are valid and that there exists at least 1 successful status.

func OperationTypes added in v0.1.6

func OperationTypes(types []string) error

OperationTypes ensures all items in Options.Allow.OperationStatuses are valid and that there are no repeats.

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 PublicKey added in v0.3.0

func PublicKey(
	publicKey *types.PublicKey,
) error

PublicKey returns an error if the *types.PublicKey is nil, is not valid hex, or has an undefined CurveType.

func SignatureType added in v0.3.0

func SignatureType(
	signature types.SignatureType,
) error

SignatureType returns an error if signature is not a valid types.SignatureType.

func Signatures added in v0.3.0

func Signatures(
	signatures []*types.Signature,
) error

Signatures returns an error if any *types.Signature is invalid.

func SigningPayload added in v0.3.0

func SigningPayload(
	signingPayload *types.SigningPayload,
) error

SigningPayload returns an error if a *types.SigningPayload is nil, has an empty address, has invlaid hex, or has an invalid SignatureType (if populated).

func StringArray

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

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

func SubNetworkIdentifier

func SubNetworkIdentifier(subNetworkIdentifier *types.SubNetworkIdentifier) error

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

func SupportedNetworks added in v0.1.6

func SupportedNetworks(supportedNetworks []*types.NetworkIdentifier) error

SupportedNetworks returns an error if there is an invalid types.NetworkIdentifier or there is a duplicate.

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 TransactionIdentifierResponse added in v0.3.3

func TransactionIdentifierResponse(
	response *types.TransactionIdentifierResponse,
) error

TransactionIdentifierResponse returns an error if the types.TransactionIdentifier in the response is not valid.

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 NewClientWithFile added in v0.1.6

func NewClientWithFile(
	filePath string,
) (*Asserter, error)

NewClientWithFile constructs a new Asserter using a specification file instead of responses. This can be useful for running reliable systems that error when updates to the server (more error types, more operations, etc.) significantly change how to parse the chain. The filePath provided is parsed relative to the current directory.

func NewClientWithOptions added in v0.1.6

func NewClientWithOptions(
	network *types.NetworkIdentifier,
	genesisBlockIdentifier *types.BlockIdentifier,
	operationTypes []string,
	operationStatuses []*types.OperationStatus,
	errors []*types.Error,
) (*Asserter, error)

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

func NewClientWithResponses added in v0.1.6

func NewClientWithResponses(
	network *types.NetworkIdentifier,
	networkStatus *types.NetworkStatusResponse,
	networkOptions *types.NetworkOptionsResponse,
) (*Asserter, error)

NewClientWithResponses constructs a new Asserter from a NetworkStatusResponse and NetworkOptionsResponse.

func NewServer added in v0.1.6

func NewServer(
	supportedOperationTypes []string,
	historicalBalanceLookup bool,
	supportedNetworks []*types.NetworkIdentifier,
) (*Asserter, error)

NewServer constructs a new Asserter for use in the server package.

func (*Asserter) AccountBalanceRequest added in v0.1.6

func (a *Asserter) AccountBalanceRequest(request *types.AccountBalanceRequest) error

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

func (*Asserter) Block

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

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

func (*Asserter) BlockRequest added in v0.1.6

func (a *Asserter) BlockRequest(request *types.BlockRequest) error

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

func (*Asserter) BlockTransactionRequest added in v0.1.6

func (a *Asserter) BlockTransactionRequest(request *types.BlockTransactionRequest) error

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

func (*Asserter) ClientConfiguration added in v0.1.6

func (a *Asserter) ClientConfiguration() (*Configuration, error)

ClientConfiguration returns all variables currently set in an Asserter. This function will error if it is called on an uninitialized asserter.

func (*Asserter) ConstructionCombineRequest added in v0.3.0

func (a *Asserter) ConstructionCombineRequest(request *types.ConstructionCombineRequest) error

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

func (*Asserter) ConstructionDeriveRequest added in v0.3.0

func (a *Asserter) ConstructionDeriveRequest(request *types.ConstructionDeriveRequest) error

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

func (*Asserter) ConstructionHashRequest added in v0.3.0

func (a *Asserter) ConstructionHashRequest(request *types.ConstructionHashRequest) error

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

func (*Asserter) ConstructionMetadataRequest added in v0.1.6

func (a *Asserter) ConstructionMetadataRequest(request *types.ConstructionMetadataRequest) error

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

func (*Asserter) ConstructionParseRequest added in v0.3.0

func (a *Asserter) ConstructionParseRequest(request *types.ConstructionParseRequest) error

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

func (*Asserter) ConstructionParseResponse added in v0.3.0

func (a *Asserter) ConstructionParseResponse(
	response *types.ConstructionParseResponse,
	signed bool,
) error

ConstructionParseResponse returns an error if a *types.ConstructionParseResponse does not have a valid set of operations or if the signers is empty.

func (*Asserter) ConstructionPayloadsRequest added in v0.3.0

func (a *Asserter) ConstructionPayloadsRequest(request *types.ConstructionPayloadsRequest) error

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

func (*Asserter) ConstructionPreprocessRequest added in v0.3.0

func (a *Asserter) ConstructionPreprocessRequest(
	request *types.ConstructionPreprocessRequest,
) error

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

func (*Asserter) ConstructionSubmitRequest added in v0.1.6

func (a *Asserter) ConstructionSubmitRequest(request *types.ConstructionSubmitRequest) error

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

func (*Asserter) MempoolTransactionRequest added in v0.1.6

func (a *Asserter) MempoolTransactionRequest(request *types.MempoolTransactionRequest) error

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

func (*Asserter) MetadataRequest added in v0.1.6

func (a *Asserter) MetadataRequest(request *types.MetadataRequest) error

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

func (*Asserter) NetworkRequest added in v0.1.6

func (a *Asserter) NetworkRequest(request *types.NetworkRequest) error

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

func (*Asserter) Operation

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

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

func (*Asserter) OperationStatus added in v0.1.6

func (a *Asserter) OperationStatus(status string) error

OperationStatus returns an error if an operation.Status is not valid.

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) OperationType added in v0.1.6

func (a *Asserter) OperationType(t string) error

OperationType returns an error if an operation.Type is not valid.

func (*Asserter) Operations added in v0.3.0

func (a *Asserter) Operations(
	operations []*types.Operation,
	construction bool,
) error

Operations returns an error if any *types.Operation in a []*types.Operation is invalid.

func (*Asserter) SupportedNetwork added in v0.1.6

func (a *Asserter) SupportedNetwork(
	requestNetwork *types.NetworkIdentifier,
) error

SupportedNetwork returns a boolean indicating if the requestNetwork is allowed. This should be called after the requestNetwork is asserted.

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.

func (*Asserter) ValidSupportedNetwork added in v0.3.0

func (a *Asserter) ValidSupportedNetwork(
	requestNetwork *types.NetworkIdentifier,
) error

ValidSupportedNetwork returns an error if a types.NetworkIdentifier is not valid or not supported.

type Configuration added in v0.1.7

type Configuration struct {
	NetworkIdentifier        *types.NetworkIdentifier `json:"network_identifier"`
	GenesisBlockIdentifier   *types.BlockIdentifier   `json:"genesis_block_identifier"`
	AllowedOperationTypes    []string                 `json:"allowed_operation_types"`
	AllowedOperationStatuses []*types.OperationStatus `json:"allowed_operation_statuses"`
	AllowedErrors            []*types.Error           `json:"allowed_errors"`
}

Configuration is the static configuration of an Asserter. This configuration can be exported by the Asserter and used to instantiate an Asserter.

Jump to

Keyboard shortcuts

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