Documentation ¶
Index ¶
- Constants
- Variables
- func AccountBalanceResponse(requestBlock *types.PartialBlockIdentifier, ...) error
- func AccountIdentifier(account *types.AccountIdentifier) error
- func Allow(allowed *types.Allow) error
- func Amount(amount *types.Amount) error
- func BlockIdentifier(blockIdentifier *types.BlockIdentifier) error
- func ConstructionMetadata(response *types.ConstructionMetadataResponse) error
- func ConstructionSubmit(response *types.ConstructionSubmitResponse) error
- func Error(err *types.Error) error
- func Errors(rosettaErrors []*types.Error) error
- func MempoolTransactions(transactions []*types.TransactionIdentifier) error
- func NetworkIdentifier(network *types.NetworkIdentifier) error
- func NetworkListResponse(response *types.NetworkListResponse) error
- func NetworkOptionsResponse(options *types.NetworkOptionsResponse) error
- func NetworkStatusResponse(response *types.NetworkStatusResponse) error
- func OperationIdentifier(identifier *types.OperationIdentifier, index int64) error
- func OperationStatuses(statuses []*types.OperationStatus) error
- func OperationTypes(types []string) error
- func PartialBlockIdentifier(blockIdentifier *types.PartialBlockIdentifier) error
- func Peer(peer *types.Peer) error
- func StringArray(arrName string, arr []string) error
- func SubNetworkIdentifier(subNetworkIdentifier *types.SubNetworkIdentifier) error
- func SupportedNetworks(supportedNetworks []*types.NetworkIdentifier) error
- func Timestamp(timestamp int64) error
- func TransactionIdentifier(transactionIdentifier *types.TransactionIdentifier) error
- func Version(version *types.Version) error
- type Asserter
- func NewClientWithFile(filePath string) (*Asserter, error)
- func NewClientWithOptions(network *types.NetworkIdentifier, ...) (*Asserter, error)
- func NewClientWithResponses(network *types.NetworkIdentifier, networkStatus *types.NetworkStatusResponse, ...) (*Asserter, error)
- func NewServer(supportedNetworks []*types.NetworkIdentifier) (*Asserter, error)
- func (a *Asserter) AccountBalanceRequest(request *types.AccountBalanceRequest) error
- func (a *Asserter) Block(block *types.Block) error
- func (a *Asserter) BlockRequest(request *types.BlockRequest) error
- func (a *Asserter) BlockTransactionRequest(request *types.BlockTransactionRequest) error
- func (a *Asserter) ClientConfiguration() (*Configuration, error)
- func (a *Asserter) ConstructionMetadataRequest(request *types.ConstructionMetadataRequest) error
- func (a *Asserter) ConstructionSubmitRequest(request *types.ConstructionSubmitRequest) error
- func (a *Asserter) MempoolRequest(request *types.MempoolRequest) error
- func (a *Asserter) MempoolTransactionRequest(request *types.MempoolTransactionRequest) error
- func (a *Asserter) MetadataRequest(request *types.MetadataRequest) error
- func (a *Asserter) NetworkRequest(request *types.NetworkRequest) error
- func (a *Asserter) Operation(operation *types.Operation, index int64) error
- func (a *Asserter) OperationStatus(status string) error
- func (a *Asserter) OperationSuccessful(operation *types.Operation) (bool, error)
- func (a *Asserter) OperationType(t string) error
- func (a *Asserter) SupportedNetwork(requestNetwork *types.NetworkIdentifier) error
- func (a *Asserter) Transaction(transaction *types.Transaction) error
- type Configuration
Constants ¶
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 ¶
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 AccountBalanceResponse ¶ added in v0.1.5
func AccountBalanceResponse( requestBlock *types.PartialBlockIdentifier, responseBlock *types.BlockIdentifier, balances []*types.Amount, ) 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 BlockIdentifier ¶
func BlockIdentifier(blockIdentifier *types.BlockIdentifier) error
BlockIdentifier ensures a types.BlockIdentifier is well-formatted.
func ConstructionMetadata ¶ added in v0.1.2
func ConstructionMetadata( response *types.ConstructionMetadataResponse, ) error
ConstructionMetadata returns an error if the metadata is not a JSON object.
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 Errors ¶ added in v0.0.4
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
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 StringArray ¶
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 TransactionIdentifier ¶
func TransactionIdentifier( transactionIdentifier *types.TransactionIdentifier, ) error
TransactionIdentifier returns an error if a types.TransactionIdentifier has an invalid hash.
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
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( 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) 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) 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) 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) MempoolRequest ¶ added in v0.1.6
func (a *Asserter) MempoolRequest(request *types.MempoolRequest) error
MempoolRequest ensures that a types.MempoolRequest 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 ¶
Operation ensures a types.Operation has a valid type, status, and amount.
func (*Asserter) OperationStatus ¶ added in v0.1.6
OperationStatus returns an error if an operation.Status is not valid.
func (*Asserter) OperationSuccessful ¶
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
OperationType returns an error if an operation.Type is not valid.
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.
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.