sdk

package
v1.99.99 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: Apache-2.0 Imports: 23 Imported by: 1

README

Ndau API SDK

Right now, it's easier for go code to interact directly with the blockchain than to indirect through the REST API. That's because the tool package is, in effect, a lean SDK.

However, it is desirable for as many services as possible to indirect through the REST API[Citation Needed]. To make this practical, it needs to be as easy as possible to use the API.

To that end, this package is designed to have largely the same interface that the tool package does. It's not a drop-in replacement, but conversion should be simple.

Documentation

Index

Constants

View Source
const JSON = "application/json"

JSON is the expected data format of requests and responses

Variables

This section is empty.

Functions

func GetAccount

func GetAccount(node *Client, addr address.Address) (*backing.AccountData, error)

GetAccount gets the account data associated with a given address

func GetAccountHistory

func GetAccountHistory(node *Client, params search.AccountHistoryParams) (*search.AccountHistoryResponse, error)

GetAccountHistory gets account data history associated with a given address.

func GetAccountList

func GetAccountList(node *Client, after string, limit int) (*query.AccountListQueryResponse, error)

GetAccountList gets a list of account names, paged according to the params Pass in after = "" (which is less than all nonempty strings) and limit = 0 to get all results. (Note that the ndauapi will enforce a limit of 100 items.)

func GetAccountListBatch

func GetAccountListBatch(node *Client) ([]address.Address, error)

GetAccountListBatch abstracts over the process of repeatedly calling GetAccountList in order to get a complete list of all known addresses.

This function makes a best-effort attempt to return a complete and current list of accounts known to the node, but true consistency is impossible using a sequential paged API; as we cannot lock the node, there may be updates during paging which cause addresses to appear in pages we have already visited. This is unavoidable.

func GetCurrencySeats

func GetCurrencySeats(node *Client) ([]address.Address, error)

GetCurrencySeats gets a list of ndau currency seats

func GetDelegates

func GetDelegates(node *Client) (map[address.Address][]address.Address, error)

GetDelegates gets the set of nodes with delegates, and the list of accounts delegated to each

func GetSIB

func GetSIB(node *Client) (*routes.PriceInfo, error)

GetSIB exists for compatibility; it delegates to node.PriceInfo()

func GetSequence

func GetSequence(node *Client, addr address.Address) (uint64, error)

GetSequence gets the current sequence number of a particular account

func GetSummary

func GetSummary(node *Client) (*routes.PriceInfo, error)

GetSummary exists for compatibility; it delegates to node.PriceInfo()

func Info

func Info(node *Client) (status *rpctypes.ResultStatus, err error)

Info gets the node's current status

func Prevalidate

func Prevalidate(node *Client, tx metatx.Transactable) (fee math.Ndau, sib math.Ndau, err error)

Prevalidate prevalidates the provided transactable

func SendCommit

func SendCommit(node *Client, tx metatx.Transactable) (result *routes.SubmitResult, err error)

SendCommit broadcasts and commits a transaction

func Sysvar

func Sysvar(node *Client, name string, example msgp.Unmarshaler) error

Sysvar gets a single system variable given its name and an example of its type

The example is populated with the appropriate data

func SysvarHistory

func SysvarHistory(node *Client, name string, after uint64, limit int) (*query.SysvarHistoryResponse, error)

SysvarHistory gets the value history of the given sysvar.

Pass in 0,0 for the paging params to get the entire history.

func Sysvars

func Sysvars(node *Client, vars ...string) (map[string][]byte, error)

Sysvars gets the list of requested system variables, marshaled

func Version

func Version(node *Client) (*routes.VersionResult, error)

Version delivers version information

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client is a client for the ndau REST API.

func NewClient

func NewClient(node string) (*Client, error)

NewClient creates a SDKClient.

func TestClient

func TestClient(t *testing.T, port uint) *Client

TestClient creates an SDKClient suitable for testing

func (*Client) ABCIInfo

func (c *Client) ABCIInfo() (abci *rpctypes.ResultABCIInfo, err error)

ABCIInfo returns the node's ABCI data

func (*Client) Consensus

func (c *Client) Consensus() (cs *rpctypes.ResultConsensusState, err error)

Consensus return's the node's current Tendermint consensus state

func (*Client) EAIRate

func (c *Client) EAIRate(query ...routes.EAIRateRequest) (response []routes.EAIRateResponse, err error)

EAIRate returns EAI rates given certain account states

The address field is just to correlate request fields with response fields; account data is not checked.

func (*Client) Genesis

func (c *Client) Genesis() (g *rpctypes.ResultGenesis, err error)

Genesis returns the genesis document of the node

func (*Client) GetAccount

func (c *Client) GetAccount(addr address.Address) (*backing.AccountData, error)

GetAccount gets the account data associated with a given address

func (*Client) GetAccountHistory

func (c *Client) GetAccountHistory(ahparams search.AccountHistoryParams) (*search.AccountHistoryResponse, error)

GetAccountHistory gets account data history associated with a given address.

func (*Client) GetAccountList

func (c *Client) GetAccountList(after string, limit int) (*query.AccountListQueryResponse, error)

GetAccountList gets a list of account names, paged according to the params Pass in after = "" (which is less than all nonempty strings) and limit = 0 to get all results. (Note that the ndauapi will enforce a limit of 100 items.)

func (*Client) GetAccountListBatch

func (c *Client) GetAccountListBatch() ([]address.Address, error)

GetAccountListBatch abstracts over the process of repeatedly calling GetAccountList in order to get a complete list of all known addresses.

This function makes a best-effort attempt to return a complete and current list of accounts known to the node, but true consistency is impossible using a sequential paged API; as we cannot lock the node, there may be updates during paging which cause addresses to appear in pages we have already visited. This is unavoidable.

func (*Client) GetBlock

func (c *Client) GetBlock(hash string) (block *rpctypes.ResultBlock, err error)

GetBlock returns a block with a particular hash

func (*Client) GetBlockAt

func (c *Client) GetBlockAt(height uint64) (block *rpctypes.ResultBlock, err error)

GetBlockAt returns a block at a given height

If height is 0, get the current block

func (*Client) GetBlocksByDaterange

func (c *Client) GetBlocksByDaterange(first, last time.Time, noempty bool, after time.Time, limit int) (blocks *rpctypes.ResultBlockchainInfo, err error)

GetBlocksByDaterange returns a sequence of block metadata for blocks with block times in the specified range.

If noempty is set, exclude blocks containing no transactions. after should be the last value from the previous page, or a zero value to exclude

func (*Client) GetBlocksByHeight

func (c *Client) GetBlocksByHeight(before, after uint64, noempty bool) (blocks *rpctypes.ResultBlockchainInfo, err error)

GetBlocksByHeight returns a sequence of block metadata for blocks with heights in the specified range.

If noempty is set, exclude blocks containing no transactions

func (*Client) GetBlocksByRange

func (c *Client) GetBlocksByRange(before, after uint64, noempty bool) (blocks *rpctypes.ResultBlockchainInfo, err error)

GetBlocksByRange returns a sequence of block metadata for blocks with heights in the specified range.

If noempty is set, exclude blocks containing no transactions

func (*Client) GetCurrencySeats

func (c *Client) GetCurrencySeats() (seats []address.Address, err error)

GetCurrencySeats gets a list of ndau currency seats

func (*Client) GetCurrentBlock

func (c *Client) GetCurrentBlock() (*rpctypes.ResultBlock, error)

GetCurrentBlock returns the current block

func (*Client) GetDelegates

func (c *Client) GetDelegates() (delegates map[address.Address][]address.Address, err error)

GetDelegates gets the set of nodes with delegates, and the list of accounts delegated to each

func (*Client) GetSequence

func (c *Client) GetSequence(addr address.Address) (uint64, error)

GetSequence gets the current sequence number of a particular account

func (*Client) Health

func (c *Client) Health() (resp *routes.HealthResponse, err error)

Health is a simple check of a node's health

func (*Client) Info

func (c *Client) Info() (status *rpctypes.ResultStatus, err error)

Info gets the node's current status

func (*Client) MarketPriceHistory

func (c *Client) MarketPriceHistory(params srch.PriceQueryParams) ([]srch.PriceQueryResult, error)

MarketPriceHistory returns historical market price data

func (*Client) NetInfo

func (c *Client) NetInfo() (ni *rpctypes.ResultNetInfo, err error)

NetInfo returns the network information of the node

func (*Client) Prevalidate

func (c *Client) Prevalidate(tx metatx.Transactable) (fee math.Ndau, sib math.Ndau, err error)

Prevalidate prevalidates the provided transactable

func (*Client) PriceInfo

func (c *Client) PriceInfo() (info *routes.PriceInfo, err error)

PriceInfo returns current price data for key parameters

func (*Client) Send

func (c *Client) Send(tx metatx.Transactable) (result *routes.SubmitResult, err error)

Send broadcasts and commits a transaction

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration)

SetTimeout updates the node's http timeout

The default is 5 seconds

func (*Client) Sysvar

func (c *Client) Sysvar(name string, example msgp.Unmarshaler) error

Sysvar gets a single system variable given its name and an example of its type

The example is populated with the appropriate data

func (*Client) SysvarHistory

func (c *Client) SysvarHistory(name string, after uint64, limit int) (resp *query.SysvarHistoryResponse, err error)

SysvarHistory gets the value history of the given sysvar.

Pass in 0,0 for the paging params to get the entire history.

func (*Client) Sysvars

func (c *Client) Sysvars(vars ...string) (svs map[string][]byte, err error)

Sysvars gets the list of requested system variables, marshaled

func (*Client) TargetPriceHistory

func (c *Client) TargetPriceHistory(params srch.PriceQueryParams) ([]srch.PriceQueryResult, error)

TargetPriceHistory returns historical target price data

func (*Client) URL

func (c *Client) URL(path string, args ...interface{}) string

URL constructs a URL from a path

It constructs the path from the supplied path and arguments using fmt.Sprintf.

func (*Client) URLP

func (c *Client) URLP(params params, path string, args ...interface{}) string

URLP constructs a URL from a path and adds some query parameters

func (*Client) Version

func (c *Client) Version() (version *routes.VersionResult, err error)

Version delivers version information

Jump to

Keyboard shortcuts

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