types

package
v0.1.10 Latest Latest
Warning

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

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

README

Types

GoDoc

Types contains a collection of auto-generated Rosetta types. Using this package ensures that you don't need to automatically generate code on your own.

Installation

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccountString added in v0.1.7

func AccountString(account *AccountIdentifier) string

AccountString returns a human-readable representation of a *types.AccountIdentifier.

func AddValues added in v0.1.7

func AddValues(
	a string,
	b string,
) (string, error)

AddValues adds string amounts using big.Int.

func CurrencyString added in v0.1.7

func CurrencyString(currency *Currency) string

CurrencyString returns a human-readable representation of a *types.Currency.

func Hash added in v0.1.7

func Hash(i interface{}) string

Hash returns a deterministic hash for any interface. This works because Golang's JSON marshaler sorts all map keys, recursively. Source: https://golang.org/pkg/encoding/json/#Marshal Inspiration: https://github.com/onsi/gomega/blob/c0be49994280db30b6b68390f67126d773bc5558/matchers/match_json_matcher.go#L16

It is important to note that any interface that is a slice or contains slices will not be equal if the slice ordering is different.

func MarshalMap added in v0.1.8

func MarshalMap(input interface{}) (map[string]interface{}, error)

MarshalMap attempts to marshal an interface into a map[string]interface{}. This function is used similarly to json.Marshal.

func NegateValue added in v0.1.9

func NegateValue(
	val string,
) (string, error)

NegateValue flips the sign of a value.

func PrettyPrintStruct added in v0.1.7

func PrettyPrintStruct(val interface{}) string

PrettyPrintStruct marshals a struct to JSON and returns it as a string.

func SubtractValues added in v0.1.7

func SubtractValues(
	a string,
	b string,
) (string, error)

SubtractValues subtracts a-b using big.Int.

func UnmarshalMap added in v0.1.8

func UnmarshalMap(metadata map[string]interface{}, output interface{}) error

UnmarshalMap attempts to unmarshal a map[string]interface{} into an interface. This function is used similarly to json.Unmarshal.

Types

type AccountBalanceRequest

type AccountBalanceRequest struct {
	NetworkIdentifier *NetworkIdentifier      `json:"network_identifier"`
	AccountIdentifier *AccountIdentifier      `json:"account_identifier"`
	BlockIdentifier   *PartialBlockIdentifier `json:"block_identifier,omitempty"`
}

AccountBalanceRequest An AccountBalanceRequest is utilized to make a balance request on the /account/balance endpoint. If the block_identifier is populated, a historical balance query should be performed.

type AccountBalanceResponse

type AccountBalanceResponse struct {
	BlockIdentifier *BlockIdentifier `json:"block_identifier"`
	// A single account may have a balance in multiple currencies.
	Balances []*Amount `json:"balances"`
	// Account-based blockchains that utilize a nonce or sequence number should include that number
	// in the metadata. This number could be unique to the identifier or global across the account
	// address.
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

AccountBalanceResponse An AccountBalanceResponse is returned on the /account/balance endpoint. If an account has a balance for each AccountIdentifier describing it (ex: an ERC-20 token balance on a few smart contracts), an account balance request must be made with each AccountIdentifier.

type AccountIdentifier

type AccountIdentifier struct {
	// The address may be a cryptographic public key (or some encoding of it) or a provided
	// username.
	Address    string                `json:"address"`
	SubAccount *SubAccountIdentifier `json:"sub_account,omitempty"`
	// Blockchains that utilize a username model (where the address is not a derivative of a
	// cryptographic public key) should specify the public key(s) owned by the address in metadata.
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

AccountIdentifier The account_identifier uniquely identifies an account within a network. All fields in the account_identifier are utilized to determine this uniqueness (including the metadata field, if populated).

type Allow added in v0.1.2

type Allow struct {
	// All Operation.Status this implementation supports. Any status that is returned during parsing
	// that is not listed here will cause client validation to error.
	OperationStatuses []*OperationStatus `json:"operation_statuses"`
	// All Operation.Type this implementation supports. Any type that is returned during parsing
	// that is not listed here will cause client validation to error.
	OperationTypes []string `json:"operation_types"`
	// All Errors that this implementation could return. Any error that is returned during parsing
	// that is not listed here will cause client validation to error.
	Errors []*Error `json:"errors"`
}

Allow Allow specifies supported Operation status, Operation types, and all possible error statuses. This Allow object is used by clients to validate the correctness of a Rosetta Server implementation. It is expected that these clients will error if they receive some response that contains any of the above information that is not specified here.

type Amount

type Amount struct {
	// Value of the transaction in atomic units represented as an arbitrary-sized signed integer.
	// For example, 1 BTC would be represented by a value of 100000000.
	Value    string                 `json:"value"`
	Currency *Currency              `json:"currency"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

Amount Amount is some Value of a Currency. It is considered invalid to specify a Value without a Currency.

type Block

type Block struct {
	BlockIdentifier       *BlockIdentifier `json:"block_identifier"`
	ParentBlockIdentifier *BlockIdentifier `json:"parent_block_identifier"`
	// The timestamp of the block in milliseconds since the Unix Epoch. The timestamp is stored in
	// milliseconds because some blockchains produce blocks more often than once a second.
	Timestamp    int64                  `json:"timestamp"`
	Transactions []*Transaction         `json:"transactions"`
	Metadata     map[string]interface{} `json:"metadata,omitempty"`
}

Block Blocks contain an array of Transactions that occurred at a particular BlockIdentifier.

type BlockIdentifier

type BlockIdentifier struct {
	// This is also known as the block height.
	Index int64  `json:"index"`
	Hash  string `json:"hash"`
}

BlockIdentifier The block_identifier uniquely identifies a block in a particular network.

type BlockRequest

type BlockRequest struct {
	NetworkIdentifier *NetworkIdentifier      `json:"network_identifier"`
	BlockIdentifier   *PartialBlockIdentifier `json:"block_identifier"`
}

BlockRequest A BlockRequest is utilized to make a block request on the /block endpoint.

type BlockResponse

type BlockResponse struct {
	Block *Block `json:"block"`
	// Some blockchains may require additional transactions to be fetched that weren't returned in
	// the block response (ex: block only returns transaction hashes). For blockchains with a lot of
	// transactions in each block, this can be very useful as consumers can concurrently fetch all
	// transactions returned.
	OtherTransactions []*TransactionIdentifier `json:"other_transactions,omitempty"`
}

BlockResponse A BlockResponse includes a fully-populated block or a partially-populated block with a list of other transactions to fetch (other_transactions).

type BlockTransactionRequest

type BlockTransactionRequest struct {
	NetworkIdentifier     *NetworkIdentifier     `json:"network_identifier"`
	BlockIdentifier       *BlockIdentifier       `json:"block_identifier"`
	TransactionIdentifier *TransactionIdentifier `json:"transaction_identifier"`
}

BlockTransactionRequest A BlockTransactionRequest is used to fetch a Transaction included in a block that is not returned in a BlockResponse.

type BlockTransactionResponse

type BlockTransactionResponse struct {
	Transaction *Transaction `json:"transaction"`
}

BlockTransactionResponse A BlockTransactionResponse contains information about a block transaction.

type ConstructionMetadataRequest added in v0.1.2

type ConstructionMetadataRequest struct {
	NetworkIdentifier *NetworkIdentifier `json:"network_identifier"`
	// Some blockchains require different metadata for different types of transaction construction
	// (ex: delegation versus a transfer). Instead of requiring a blockchain node to return all
	// possible types of metadata for construction (which may require multiple node fetches), the
	// client can populate an options object to limit the metadata returned to only the subset
	// required.
	Options map[string]interface{} `json:"options"`
}

ConstructionMetadataRequest A ConstructionMetadataRequest is utilized to get information required to construct a transaction. The Options object used to specify which metadata to return is left purposely unstructured to allow flexibility for implementers.

type ConstructionMetadataResponse added in v0.1.2

type ConstructionMetadataResponse struct {
	Metadata map[string]interface{} `json:"metadata"`
}

ConstructionMetadataResponse The ConstructionMetadataResponse returns network-specific metadata used for transaction construction. It is likely that the client will not inspect this metadata before passing it to a client SDK that uses it for construction.

type ConstructionSubmitRequest added in v0.1.2

type ConstructionSubmitRequest struct {
	NetworkIdentifier *NetworkIdentifier `json:"network_identifier"`
	SignedTransaction string             `json:"signed_transaction"`
}

ConstructionSubmitRequest The transaction submission request includes a signed transaction.

type ConstructionSubmitResponse added in v0.1.2

type ConstructionSubmitResponse struct {
	TransactionIdentifier *TransactionIdentifier `json:"transaction_identifier"`
	Metadata              map[string]interface{} `json:"metadata,omitempty"`
}

ConstructionSubmitResponse A TransactionSubmitResponse contains the transaction_identifier of a submitted transaction that was accepted into the mempool.

type Currency

type Currency struct {
	// Canonical symbol associated with a currency.
	Symbol string `json:"symbol"`
	// Number of decimal places in the standard unit representation of the amount.  For example, BTC
	// has 8 decimals. Note that it is not possible to represent the value of some currency in
	// atomic units that is not base 10.
	Decimals int32 `json:"decimals"`
	// Any additional information related to the currency itself.  For example, it would be useful
	// to populate this object with the contract address of an ERC-20 token.
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

Currency Currency is composed of a canonical Symbol and Decimals. This Decimals value is used to convert an Amount.Value from atomic units (Satoshis) to standard units (Bitcoins).

type Error

type Error struct {
	// Code is a network-specific error code. If desired, this code can be equivalent to an HTTP
	// status code.
	Code int32 `json:"code"`
	// Message is a network-specific error message.
	Message string `json:"message"`
	// An error is retriable if the same request may succeed if submitted again.
	Retriable bool `json:"retriable"`
}

Error Instead of utilizing HTTP status codes to describe node errors (which often do not have a good analog), rich errors are returned using this object.

type MempoolRequest

type MempoolRequest struct {
	NetworkIdentifier *NetworkIdentifier `json:"network_identifier"`
}

MempoolRequest A MempoolRequest is utilized to retrieve all transaction identifiers in the mempool for a particular network_identifier.

type MempoolResponse

type MempoolResponse struct {
	TransactionIdentifiers []*TransactionIdentifier `json:"transaction_identifiers"`
}

MempoolResponse A MempoolResponse contains all transaction identifiers in the mempool for a particular network_identifier.

type MempoolTransactionRequest

type MempoolTransactionRequest struct {
	NetworkIdentifier     *NetworkIdentifier     `json:"network_identifier"`
	TransactionIdentifier *TransactionIdentifier `json:"transaction_identifier"`
}

MempoolTransactionRequest A MempoolTransactionRequest is utilized to retrieve a transaction from the mempool.

type MempoolTransactionResponse

type MempoolTransactionResponse struct {
	Transaction *Transaction           `json:"transaction"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

MempoolTransactionResponse A MempoolTransactionResponse contains an estimate of a mempool transaction. It may not be possible to know the full impact of a transaction in the mempool (ex: fee paid).

type MetadataRequest added in v0.1.2

type MetadataRequest struct {
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

MetadataRequest A MetadataRequest is utilized in any request where the only argument is optional metadata.

type NetworkIdentifier

type NetworkIdentifier struct {
	Blockchain string `json:"blockchain"`
	// If a blockchain has a specific chain-id or network identifier, it should go in this field. It
	// is up to the client to determine which network-specific identifier is mainnet or testnet.
	Network              string                `json:"network"`
	SubNetworkIdentifier *SubNetworkIdentifier `json:"sub_network_identifier,omitempty"`
}

NetworkIdentifier The network_identifier specifies which network a particular object is associated with.

type NetworkListResponse added in v0.1.2

type NetworkListResponse struct {
	NetworkIdentifiers []*NetworkIdentifier `json:"network_identifiers"`
}

NetworkListResponse A NetworkListResponse contains all NetworkIdentifiers that the node can serve information for.

type NetworkOptionsResponse added in v0.1.2

type NetworkOptionsResponse struct {
	Version *Version `json:"version"`
	Allow   *Allow   `json:"allow"`
}

NetworkOptionsResponse NetworkOptionsResponse contains information about the versioning of the node and the allowed operation statuses, operation types, and errors.

type NetworkRequest added in v0.1.2

type NetworkRequest struct {
	NetworkIdentifier *NetworkIdentifier     `json:"network_identifier"`
	Metadata          map[string]interface{} `json:"metadata,omitempty"`
}

NetworkRequest A NetworkRequest is utilized to retrieve some data specific exclusively to a NetworkIdentifier.

type NetworkStatusResponse

type NetworkStatusResponse struct {
	CurrentBlockIdentifier *BlockIdentifier `json:"current_block_identifier"`
	// The timestamp of the block in milliseconds since the Unix Epoch. The timestamp is stored in
	// milliseconds because some blockchains produce blocks more often than once a second.
	CurrentBlockTimestamp  int64            `json:"current_block_timestamp"`
	GenesisBlockIdentifier *BlockIdentifier `json:"genesis_block_identifier"`
	Peers                  []*Peer          `json:"peers"`
}

NetworkStatusResponse NetworkStatusResponse contains basic information about the node's view of a blockchain network.

type Operation

type Operation struct {
	OperationIdentifier *OperationIdentifier `json:"operation_identifier"`
	// Restrict referenced related_operations to identifier indexes < the current
	// operation_identifier.index. This ensures there exists a clear DAG-structure of relations.
	// Since operations are one-sided, one could imagine relating operations in a single transfer or
	// linking operations in a call tree.
	RelatedOperations []*OperationIdentifier `json:"related_operations,omitempty"`
	// The network-specific type of the operation. Ensure that any type that can be returned here is
	// also specified in the NetowrkStatus. This can be very useful to downstream consumers that
	// parse all block data.
	Type string `json:"type"`
	// The network-specific status of the operation. Status is not defined on the transaction object
	// because blockchains with smart contracts may have transactions that partially apply.
	// Blockchains with atomic transactions (all operations succeed or all operations fail) will
	// have the same status for each operation.
	Status   string                 `json:"status"`
	Account  *AccountIdentifier     `json:"account,omitempty"`
	Amount   *Amount                `json:"amount,omitempty"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

Operation Operations contain all balance-changing information within a transaction. They are always one-sided (only affect 1 AccountIdentifier) and can succeed or fail independently from a Transaction.

type OperationIdentifier

type OperationIdentifier struct {
	// The operation index is used to ensure each operation has a unique identifier within a
	// transaction.  To clarify, there may not be any notion of an operation index in the blockchain
	// being described.
	Index int64 `json:"index"`
	// Some blockchains specify an operation index that is essential for client use. For example,
	// Bitcoin uses a network_index to identify which UTXO was used in a transaction.  network_index
	// should not be populated if there is no notion of an operation index in a blockchain
	// (typically most account-based blockchains).
	NetworkIndex *int64 `json:"network_index,omitempty"`
}

OperationIdentifier The operation_identifier uniquely identifies an operation within a transaction.

type OperationStatus

type OperationStatus struct {
	// The status is the network-specific status of the operation.
	Status string `json:"status"`
	// An Operation is considered successful if the Operation.Amount should affect the
	// Operation.Account. Some blockchains (like Bitcoin) only include successful operations in
	// blocks but other blockchains (like Ethereum) include unsuccessful operations that incur a
	// fee.  To reconcile the computed balance from the stream of Operations, it is critical to
	// understand which Operation.Status indicate an Operation is successful and should affect an
	// Account.
	Successful bool `json:"successful"`
}

OperationStatus OperationStatus is utilized to indicate which Operation status are considered successful.

type PartialBlockIdentifier

type PartialBlockIdentifier struct {
	Index *int64  `json:"index,omitempty"`
	Hash  *string `json:"hash,omitempty"`
}

PartialBlockIdentifier When fetching data by BlockIdentifier, it may be possible to only specify the index or hash. If neither property is specified, it is assumed that the client is making a request at the current block.

func ConstructPartialBlockIdentifier added in v0.1.2

func ConstructPartialBlockIdentifier(
	blockIdentifier *BlockIdentifier,
) *PartialBlockIdentifier

ConstructPartialBlockIdentifier constructs a *PartialBlockIdentifier from a *BlockIdentifier.

It is useful to have this helper when making block requests with the fetcher.

type Peer

type Peer struct {
	PeerID   string                 `json:"peer_id"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

Peer A Peer is a representation of a node's peer.

type SubAccountIdentifier

type SubAccountIdentifier struct {
	// The SubAccount address may be a cryptographic value or some other identifier (ex: bonded)
	// that uniquely specifies a SubAccount.
	Address string `json:"address"`
	// If the SubAccount address is not sufficient to uniquely specify a SubAccount, any other
	// identifying information can be stored here.  It is important to note that two SubAccounts
	// with identical addresses but differing metadata will not be considered equal by clients.
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

SubAccountIdentifier An account may have state specific to a contract address (ERC-20 token) and/or a stake (delegated balance). The sub_account_identifier should specify which state (if applicable) an account instantiation refers to.

type SubNetworkIdentifier

type SubNetworkIdentifier struct {
	Network  string                 `json:"network"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

SubNetworkIdentifier In blockchains with sharded state, the SubNetworkIdentifier is required to query some object on a specific shard. This identifier is optional for all non-sharded blockchains.

type Transaction

type Transaction struct {
	TransactionIdentifier *TransactionIdentifier `json:"transaction_identifier"`
	Operations            []*Operation           `json:"operations"`
	// Transactions that are related to other transactions (like a cross-shard transactioin) should
	// include the tranaction_identifier of these transactions in the metadata.
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

Transaction Transactions contain an array of Operations that are attributable to the same TransactionIdentifier.

type TransactionIdentifier

type TransactionIdentifier struct {
	// Any transactions that are attributable only to a block (ex: a block event) should use the
	// hash of the block as the identifier.
	Hash string `json:"hash"`
}

TransactionIdentifier The transaction_identifier uniquely identifies a transaction in a particular network and block or in the mempool.

type Version

type Version struct {
	// The rosetta_version is the version of the Rosetta interface the implementation adheres to.
	// This can be useful for clients looking to reliably parse responses.
	RosettaVersion string `json:"rosetta_version"`
	// The node_version is the canonical version of the node runtime. This can help clients manage
	// deployments.
	NodeVersion string `json:"node_version"`
	// When a middleware server is used to adhere to the Rosetta interface, it should return its
	// version here. This can help clients manage deployments.
	MiddlewareVersion *string `json:"middleware_version,omitempty"`
	// Any other information that may be useful about versioning of dependent services should be
	// returned here.
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

Version The Version object is utilized to inform the client of the versions of different components of the Rosetta implementation.

Jump to

Keyboard shortcuts

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