blockatlas

package
v1.1.13 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2020 License: MIT Imports: 24 Imported by: 18

Documentation

Index

Constants

View Source
const (
	DelegationStatusActive  DelegationStatus = "active"
	DelegationStatusPending DelegationStatus = "pending"

	DelegationTypeAuto     DelegationType = "auto"
	DelegationTypeDelegate DelegationType = "delegate"

	DefaultAnnualReward = 0
)
View Source
const (
	StatusCompleted Status = "completed"
	StatusPending   Status = "pending"
	StatusError     Status = "error"

	DirectionOutgoing Direction = "outgoing"
	DirectionIncoming Direction = "incoming"
	DirectionSelf     Direction = "yourself"

	TokenTypeERC20 TokenType = "ERC20"
	TokenTypeBEP2  TokenType = "BEP2"
	TokenTypeBEP8  TokenType = "BEP8"
	TokenTypeBEP20 TokenType = "BEP20"
	TokenTypeTRC10 TokenType = "TRC10"
	TokenTypeETC20 TokenType = "ETC20"
	TokenTypePOA20 TokenType = "POA20"
	TokenTypeTRC20 TokenType = "TRC20"
	TokenTypeTRC21 TokenType = "TRC21"
	TokenTypeCLO20 TokenType = "CLO20"
	TokenTypeGO20  TokenType = "G020"
	TokenTypeWAN20 TokenType = "WAN20"
	TokenTypeTT20  TokenType = "TT20"

	TxTransfer              TransactionType = "transfer"
	TxNativeTokenTransfer   TransactionType = "native_token_transfer"
	TxTokenTransfer         TransactionType = "token_transfer"
	TxCollectibleTransfer   TransactionType = "collectible_transfer"
	TxTokenSwap             TransactionType = "token_swap"
	TxContractCall          TransactionType = "contract_call"
	TxAnyAction             TransactionType = "any_action"
	TxMultiCurrencyTransfer TransactionType = "multi_currency_transfer"

	KeyPlaceOrder        KeyType = "place_order"
	KeyCancelOrder       KeyType = "cancel_order"
	KeyIssueToken        KeyType = "issue_token"
	KeyBurnToken         KeyType = "burn_token"
	KeyMintToken         KeyType = "mint_token"
	KeyApproveToken      KeyType = "approve_token"
	KeyStakeDelegate     KeyType = "stake_delegate"
	KeyStakeClaimRewards KeyType = "stake_claim_rewards"

	KeyTitlePlaceOrder    KeyTitle = "Place Order"
	KeyTitleCancelOrder   KeyTitle = "Cancel Order"
	AnyActionDelegation   KeyTitle = "Delegation"
	AnyActionUndelegation KeyTitle = "Undelegation"
	AnyActionClaimRewards KeyTitle = "Claim Rewards"

	// TxPerPage says how many transactions to return per page
	TxPerPage = 25
)
View Source
const (
	JsonRpcVersion = "2.0"
)

Variables

View Source
var (
	// ErrSourceConn signals that the connection to the source API failed
	ErrSourceConn = errors.New("connection to servers failed")

	// ErrInvalidAddr signals that the requested address is invalid
	ErrInvalidAddr = errors.New("invalid address")

	// ErrNotFound signals that the resource has not been found
	ErrNotFound = errors.New("not found")

	// ErrInvalidKey signals that the requested key is invalid
	ErrInvalidKey = errors.New("invalid key")
)
View Source
var DefaultClient = &http.Client{
	Timeout: time.Second * 15,
}
View Source
var DefaultErrorHandler = func(res *http.Response, uri string) error {
	return nil
}

Functions

func GetBody

func GetBody(body interface{}) (buf io.ReadWriter, err error)

func GetValidParameter

func GetValidParameter(first, second string) string

Types

type Amount

type Amount string

Amount is a positive decimal integer string. It is written in the smallest possible unit (e.g. Wei, Satoshis)

func InferValue added in v1.1.0

func InferValue(tx *Tx, direction Direction, addressSet mapset.Set) Amount

func (*Amount) MarshalJSON

func (a *Amount) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON string representing the amount

func (*Amount) UnmarshalJSON

func (a *Amount) UnmarshalJSON(data []byte) error

UnmarshalJSON reads an amount from a JSON string or number. Comma separators get dropped with address.DecimalToSatoshis.

type AnyAction

type AnyAction struct {
	Coin     uint     `json:"coin"`
	Title    KeyTitle `json:"title"`
	Key      KeyType  `json:"key"`
	TokenID  string   `json:"token_id"`
	Name     string   `json:"name"`
	Symbol   string   `json:"symbol"`
	Decimals uint     `json:"decimals"`
	Value    Amount   `json:"value"`
}

AnyAction describes all other types

type Block

type Block struct {
	Number int64  `json:"number"`
	ID     string `json:"id,omitempty"`
	Txs    []Tx   `json:"txs"`
}

type BlockAPI

type BlockAPI interface {
	Platform
	CurrentBlockNumber() (int64, error)
	GetBlockByNumber(num int64) (*Block, error)
}

BlockAPI provides block information and lookups

type CoinStatus

type CoinStatus struct {
	Height int64  `json:"height"`
	Error  string `json:"error,omitempty"`
}

type Collectible

type Collectible struct {
	ID              string `json:"id"`
	CollectionID    string `json:"collection_id"`
	TokenID         string `json:"token_id"`
	ContractAddress string `json:"contract_address"`
	Category        string `json:"category"`
	ImageUrl        string `json:"image_url"`
	ExternalLink    string `json:"external_link"`
	ProviderLink    string `json:"provider_link"`
	Type            string `json:"type"`
	Description     string `json:"description"`
	Coin            uint   `json:"coin"`
	Name            string `json:"name"`
	Version         string `json:"nft_version"`
}

type CollectiblePage

type CollectiblePage []Collectible

func (CollectiblePage) MarshalJSON

func (r CollectiblePage) MarshalJSON() ([]byte, error)

MarshalJSON returns a wrapped list of collectibles in JSON

type CollectiblePageV3 added in v1.1.0

type CollectiblePageV3 []CollectibleV3

func (CollectiblePageV3) MarshalJSON added in v1.1.0

func (r CollectiblePageV3) MarshalJSON() ([]byte, error)

MarshalJSON returns a wrapped list of collectibles in JSON

type CollectibleTransfer

type CollectibleTransfer struct {
	Name     string `json:"name"`
	Contract string `json:"contract"`
	ImageURL string `json:"image_url"`
}

CollectibleTransfer describes the transfer of a "collectible", unique token.

type CollectibleV3 added in v1.1.0

type CollectibleV3 struct {
	ID               string `json:"id"`
	CollectionID     string `json:"collection_id"`
	TokenID          string `json:"token_id"`
	CategoryContract string `json:"category_contract"`
	ContractAddress  string `json:"contract_address"`
	Category         string `json:"category"`
	ImageUrl         string `json:"image_url"`
	ExternalLink     string `json:"external_link"`
	ProviderLink     string `json:"provider_link"`
	Type             string `json:"type"`
	Description      string `json:"description"`
	Coin             uint   `json:"coin"`
	Name             string `json:"name"`
	Version          string `json:"nft_version"`
}

type Collection

type Collection struct {
	Id           string `json:"id"`
	Name         string `json:"name"`
	ImageUrl     string `json:"image_url"`
	Description  string `json:"description"`
	ExternalLink string `json:"external_link"`
	Total        int    `json:"total"`
	Address      string `json:"address"`
	Coin         uint   `json:"coin"`
	Type         string `json:"-"`
}

type CollectionPage

type CollectionPage []Collection

func (CollectionPage) MarshalJSON

func (r CollectionPage) MarshalJSON() ([]byte, error)

MarshalJSON returns a wrapped list of collections in JSON

type CollectionPageV3 added in v1.1.0

type CollectionPageV3 []CollectionV3

func (CollectionPageV3) MarshalJSON added in v1.1.0

func (r CollectionPageV3) MarshalJSON() ([]byte, error)

MarshalJSON returns a wrapped list of collections in JSON

type CollectionV3 added in v1.1.0

type CollectionV3 struct {
	Id              string `json:"id"`
	Name            string `json:"name"`
	Symbol          string `json:"symbol"`
	Slug            string `json:"slug"`
	ImageUrl        string `json:"image_url"`
	Description     string `json:"description"`
	ExternalLink    string `json:"external_link"`
	Total           int    `json:"total"`
	CategoryAddress string `json:"category_address"`
	Address         string `json:"address"`
	Coin            uint   `json:"coin"`
	// Delete in the future version, as it's now part of Collectible
	Version string `json:"nft_version"`
	Type    string `json:"type"`
}

type CollectionsAPI added in v1.1.0

type CollectionsAPI interface {
	Platform
	GetCollections(owner string) (CollectionPage, error)
	GetCollectibles(owner, collectibleID string) (CollectiblePage, error)

	GetCollectionsV3(owner string) (CollectionPageV3, error)
	GetCollectiblesV3(owner, collectibleID string) (CollectiblePageV3, error)
}

type CollectionsAPIs added in v1.1.0

type CollectionsAPIs map[uint]CollectionsAPI

type ContractCall

type ContractCall struct {
	Input string `json:"input"`
	Value string `json:"value"`
}

ContractCall describes a

type Currency

type Currency struct {
	Token Token  `json:"token"`
	Value Amount `json:"value"`
}

Currency describes currency information with its amount

type Delegation

type Delegation struct {
	Delegator StakeValidator   `json:"delegator"`
	Value     string           `json:"value"`
	Status    DelegationStatus `json:"status"`
	Metadata  interface{}      `json:"metadata,omitempty"`
}

type DelegationMetaDataPending

type DelegationMetaDataPending struct {
	AvailableDate uint `json:"available_date"`
}

type DelegationResponse

type DelegationResponse struct {
	Delegations DelegationsPage `json:"delegations"`
	Balance     string          `json:"balance"`
	Address     string          `json:"address"`
	StakingResponse
}

type DelegationStatus

type DelegationStatus string

type DelegationType

type DelegationType string

type DelegationsBatchPage

type DelegationsBatchPage []DelegationResponse

type DelegationsPage

type DelegationsPage []Delegation

type Direction

type Direction string

Types of transaction statuses

func InferDirection added in v1.1.0

func InferDirection(tx *Tx, addressSet mapset.Set) Direction

type DocsResponse

type DocsResponse struct {
	Docs interface{} `json:"docs"`
}

type KeyTitle

type KeyTitle string

type KeyType

type KeyType string

type MultiCurrencyTransfer

type MultiCurrencyTransfer struct {
	Currencies []Currency `json:"currencies"`
	Fees       []Currency `json:"fees"`
}

MultiCurrencyTransfer describes the transfer of multiple currency native to the platform

type NamingServiceAPI

type NamingServiceAPI interface {
	CanHandle(name string) bool
	Lookup(coins []uint64, name string) ([]Resolved, error)
}

type NativeTokenTransfer

type NativeTokenTransfer struct {
	Name     string `json:"name"`
	Symbol   string `json:"symbol"`
	TokenID  string `json:"token_id"`
	Decimals uint   `json:"decimals"`
	Value    Amount `json:"value"`
	From     string `json:"from"`
	To       string `json:"to"`
}

NativeTokenTransfer describes the transfer of native tokens. Example: Stellar Tokens, TRC10

type Observer

type Observer struct {
	Status  bool   `json:"status"`
	Message string `json:"message"`
}

type Platform

type Platform interface {
	Coin() coin.Coin
}

Platform can be used to access a crypto service

type Platforms added in v1.1.0

type Platforms map[string]Platform

func (Platforms) GetPlatformList added in v1.1.0

func (ps Platforms) GetPlatformList() []Platform

type Request

type Request struct {
	BaseUrl      string
	Headers      map[string]string
	HttpClient   *http.Client
	ErrorHandler func(res *http.Response, uri string) error
}

func InitClient

func InitClient(baseUrl string) Request

func InitJSONClient added in v1.1.0

func InitJSONClient(baseUrl string) Request

func (*Request) Execute

func (r *Request) Execute(method string, url string, body io.Reader, result interface{}, ctx context.Context) error

func (*Request) Get

func (r *Request) Get(result interface{}, path string, query url.Values) error

func (*Request) GetBase

func (r *Request) GetBase(path string) string

func (*Request) GetWithCache

func (r *Request) GetWithCache(result interface{}, path string, query url.Values, cache time.Duration) error

func (*Request) GetWithCacheAndContext added in v1.1.4

func (r *Request) GetWithCacheAndContext(result interface{}, path string, query url.Values, cache time.Duration, ctx context.Context) error

func (*Request) GetWithContext added in v1.1.4

func (r *Request) GetWithContext(result interface{}, path string, query url.Values, ctx context.Context) error

func (*Request) Post

func (r *Request) Post(result interface{}, path string, body interface{}) error

func (*Request) PostWithCache

func (r *Request) PostWithCache(result interface{}, path string, body interface{}, cache time.Duration) error

func (*Request) PostWithCacheAndContext added in v1.1.4

func (r *Request) PostWithCacheAndContext(result interface{}, path string, body interface{}, cache time.Duration, ctx context.Context) error

func (*Request) PostWithContext added in v1.1.4

func (r *Request) PostWithContext(result interface{}, path string, body interface{}, ctx context.Context) error

func (*Request) RpcBatchCall added in v1.1.0

func (r *Request) RpcBatchCall(requests RpcRequests) ([]RpcResponse, error)

func (*Request) RpcBatchCallWithContext added in v1.1.4

func (r *Request) RpcBatchCallWithContext(requests RpcRequests, ctx context.Context) ([]RpcResponse, error)

func (*Request) RpcCall

func (r *Request) RpcCall(result interface{}, method string, params interface{}) error

func (*Request) RpcCallWithContext added in v1.1.4

func (r *Request) RpcCallWithContext(result interface{}, method string, params interface{}, ctx context.Context) error

func (*Request) SetTimeout

func (r *Request) SetTimeout(seconds time.Duration)

type Resolved

type Resolved struct {
	Result string `json:"result"`
	Coin   uint64 `json:"coin"`
}

type ResultsResponse

type ResultsResponse struct {
	Total   int         `json:"total"`
	Results interface{} `json:"docs"`
}

type RpcError

type RpcError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type RpcRequest

type RpcRequest struct {
	JsonRpc string      `json:"jsonrpc"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params,omitempty"`
	Id      int64       `json:"id,omitempty"`
}

type RpcRequests added in v1.1.0

type RpcRequests []*RpcRequest

type RpcResponse

type RpcResponse struct {
	JsonRpc string      `json:"jsonrpc"`
	Error   *RpcError   `json:"error,omitempty"`
	Result  interface{} `json:"result,omitempty"`
	Id      int64       `json:"id,omitempty"`
}

func (*RpcResponse) GetObject

func (r *RpcResponse) GetObject(toType interface{}) error

type StakeAPI

type StakeAPI interface {
	Platform
	UndelegatedBalance(address string) (string, error)
	GetDetails() StakingDetails
	GetValidators() (ValidatorPage, error)
	GetDelegations(address string) (DelegationsPage, error)
	GetActiveValidators() (StakeValidators, error)
}

StakingAPI provides staking information

type StakeValidator

type StakeValidator struct {
	ID      string             `json:"id"`
	Status  bool               `json:"status"`
	Info    StakeValidatorInfo `json:"info,omitempty"`
	Details StakingDetails     `json:"details,omitempty"`
}

type StakeValidatorInfo

type StakeValidatorInfo struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Image       string `json:"image"`
	Website     string `json:"website"`
}

type StakeValidators added in v1.1.0

type StakeValidators []StakeValidator

func (StakeValidators) ToMap added in v1.1.0

func (sv StakeValidators) ToMap() ValidatorMap

type StakingBatchPage

type StakingBatchPage []StakingResponse

type StakingDetails

type StakingDetails struct {
	Reward        StakingReward  `json:"reward"`
	LockTime      int            `json:"locktime"`
	MinimumAmount Amount         `json:"minimum_amount"`
	Type          DelegationType `json:"type"`
}

type StakingResponse

type StakingResponse struct {
	Coin    *coin.ExternalCoin `json:"coin"`
	Details StakingDetails     `json:"details"`
}

type StakingReward

type StakingReward struct {
	Annual float64 `json:"annual"`
}

type Status

type Status string

type Subscription

type Subscription struct {
	Coin    uint   `json:"coin"`
	Address string `json:"address"`
}

type SubscriptionEvent added in v1.1.0

type SubscriptionEvent struct {
	Subscriptions Subscriptions         `json:"subscriptions"`
	Operation     SubscriptionOperation `json:"operation"`
}

func (*SubscriptionEvent) ParseSubscriptions added in v1.1.0

func (e *SubscriptionEvent) ParseSubscriptions(s Subscriptions) []Subscription

type SubscriptionOperation added in v1.1.0

type SubscriptionOperation string

type Subscriptions added in v1.1.0

type Subscriptions map[string][]string

type Token

type Token struct {
	Name     string    `json:"name"`
	Symbol   string    `json:"symbol"`
	Decimals uint      `json:"decimals"`
	TokenID  string    `json:"token_id"`
	Coin     uint      `json:"coin"`
	Type     TokenType `json:"type"`
}

Token describes the non-native tokens. Examples: ERC-20, TRC-20, BEP-2

type TokenPage

type TokenPage []Token

TokenPage is a page of transactions.

type TokenSwap

type TokenSwap struct {
	Input  TokenTransfer `json:"input"`
	Output TokenTransfer `json:"output"`
}

TokenSwap describes the exchange of two different tokens

type TokenTransfer

type TokenTransfer struct {
	Name     string `json:"name"`
	Symbol   string `json:"symbol"`
	TokenID  string `json:"token_id"`
	Decimals uint   `json:"decimals"`
	Value    Amount `json:"value"`
	From     string `json:"from"`
	To       string `json:"to"`
}

TokenTransfer describes the transfer of non-native tokens. Examples: ERC-20, TRC20

type TokenTxAPI

type TokenTxAPI interface {
	Platform
	GetTokenTxsByAddress(address, token string) (TxPage, error)
}

TokenTxAPI provides token transaction lookups

type TokenType

type TokenType string

func GetEthereumTokenTypeByIndex added in v1.1.9

func GetEthereumTokenTypeByIndex(coinIndex uint) TokenType

type TokensAPI added in v1.1.0

type TokensAPI interface {
	Platform
	GetTokenListByAddress(address string) (TokenPage, error)
}

TokensAPI provides token lookups

type TransactionType

type TransactionType string

type Transfer

type Transfer struct {
	Value    Amount `json:"value"`
	Symbol   string `json:"symbol"`
	Decimals uint   `json:"decimals"`
}

Transfer describes the transfer of currency native to the platform

type Tx

type Tx struct {
	// Unique identifier
	ID string `json:"id"`
	// SLIP-44 coin index of the platform
	Coin uint `json:"coin"`
	// Address of the transaction sender
	From string `json:"from"`
	// Address of the transaction recipient
	To string `json:"to"`
	// Transaction fee (native currency)
	Fee Amount `json:"fee"`
	// Unix timestamp of the block the transaction was included in
	Date int64 `json:"date"`
	// Height of the block the transaction was included in
	Block uint64 `json:"block"`
	// Status of the transaction e.g: "completed", "pending", "error"
	Status Status `json:"status"`
	// Empty if the transaction "completed" or "pending", else error explaining why the transaction failed (optional)
	Error string `json:"error,omitempty"`
	// Transaction nonce or sequence
	Sequence uint64 `json:"sequence"`
	// Type of metadata
	Type TransactionType `json:"type"`
	// Input addresses
	Inputs []TxOutput `json:"inputs,omitempty"`
	// Output addresses
	Outputs []TxOutput `json:"outputs,omitempty"`
	// Transaction Direction
	Direction Direction `json:"direction,omitempty"`
	// Meta data object
	Memo string      `json:"memo"`
	Meta interface{} `json:"metadata"`
}

Tx describes an on-chain transaction generically

func (*Tx) GetAddresses

func (t *Tx) GetAddresses() []string

func (*Tx) GetTransactionDirection added in v1.1.0

func (t *Tx) GetTransactionDirection(address string) Direction

func (*Tx) GetUtxoAddresses

func (t *Tx) GetUtxoAddresses() (addresses []string)

func (*Tx) InferUtxoValue added in v1.1.0

func (t *Tx) InferUtxoValue(address string, coinIndex uint)

func (*Tx) MarshalJSON

func (t *Tx) MarshalJSON() ([]byte, error)

MarshalJSON creates a JSON object from a transaction. Sets the Type field to the currect value based on the Meta type.

func (*Tx) TokenID added in v1.1.9

func (t *Tx) TokenID() (string, bool)

func (*Tx) UnmarshalJSON

func (t *Tx) UnmarshalJSON(data []byte) error

UnmarshalJSON creates a transaction along with metadata from a JSON object. Fails if the meta object can't be read.

type TxAPI

type TxAPI interface {
	Platform
	GetTxsByAddress(address string) (TxPage, error)
}

TxAPI provides transaction lookups based on address

type TxOutput

type TxOutput struct {
	Address string `json:"address"`
	Value   Amount `json:"value"`
}

type TxPage

type TxPage []Tx

TxPage is a page of transactions

func (TxPage) Len added in v1.1.0

func (txs TxPage) Len() int

Sort sorts the response by date, descending

func (TxPage) Less added in v1.1.0

func (txs TxPage) Less(i, j int) bool

func (*TxPage) MarshalJSON

func (r *TxPage) MarshalJSON() ([]byte, error)

MarshalJSON returns a wrapped list of transactions in JSON

func (TxPage) Swap added in v1.1.0

func (txs TxPage) Swap(i, j int)

type TxUtxoAPI added in v1.1.0

type TxUtxoAPI interface {
	TxAPI
	GetTxsByXpub(xpub string) (TxPage, error)
}

TxUtxoAPI provides transaction lookup based on address and XPUB (Bitcoin-style)

type Txs added in v1.1.0

type Txs []Tx

func (Txs) FilterUniqueID added in v1.1.0

func (t Txs) FilterUniqueID() Txs

func (Txs) SortByDate added in v1.1.0

func (t Txs) SortByDate() Txs

type Validator

type Validator struct {
	ID      string         `json:"id"`
	Status  bool           `json:"status"`
	Details StakingDetails `json:"details"`
}

type ValidatorMap

type ValidatorMap map[string]StakeValidator

type ValidatorPage

type ValidatorPage []Validator

Jump to

Keyboard shortcuts

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