client

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2020 License: Apache-2.0 Imports: 25 Imported by: 1

Documentation

Index

Constants

View Source
const BroadcastTxSyncDefaultTimeOut = 15 * time.Second
View Source
const (
	CurrentHeight int64 = -1
)
View Source
const KeyPerm = 0600

KeyPerm is the file permissions for saved private keys

Variables

View Source
var QueryNewBlockHeader = tmtypes.EventQueryNewBlockHeader

Functions

func Admin added in v0.10.2

func Admin(c *BnsClient) *admin

func BuildSendTx

func BuildSendTx(source, destination weave.Address, amount coin.Coin, memo string) *bnsd.Tx

BuildSendTx will create an unsigned tx to move tokens

func EncodePrivateKey

func EncodePrivateKey(key *PrivateKey) (string, error)

EncodePrivateKey stores the private key as a hex string that can be saved and later loaded

func FindCoinByTicker

func FindCoinByTicker(coins coin.Coins, ticker string) (*coin.Coin, bool)

func KeysByAddress

func KeysByAddress(keys []*PrivateKey) map[string]*PrivateKey

KeysByAddress takes a list of keys and creates a map to look up private keys by their (hex-encoded) address

func NewHTTPConnection

func NewHTTPConnection(remote string) client.Client

NewHTTPConnection takes a URL and sends all requests to the remote node

func NewLocalConnection

func NewLocalConnection(node *nm.Node) client.Client

NewLocalConnection wraps an in-process node with a client, useful for tests

func ParseBnsTx added in v0.21.0

func ParseBnsTx(data []byte) (*bnsd.Tx, error)

ParseBnsTx will load a serialize tx into a format we can read

func SavePrivateKey

func SavePrivateKey(key *PrivateKey, filename string, force bool) error

SavePrivateKey will encode the private key in hex and write to the named file

Refuses to overwrite a file unless force is true

func SavePrivateKeys

func SavePrivateKeys(keys []*PrivateKey, filename string, force bool) error

SavePrivateKeys will encode an array of private keys as a json array of hex strings and write to the named file

Refuses to overwrite a file unless force is true

func SetValidatorTx added in v0.10.2

func SetValidatorTx(u ...weave.ValidatorUpdate) *bnsd.Tx

SetValidatorTx will create an unsigned tx to replace current validator set

func SignTx

func SignTx(tx *bnsd.Tx, signer *PrivateKey, chainID string, nonce int64) error

SignTx modifies the tx in-place, adding signatures

func ToString

func ToString(d interface{}) string

ToString is a generic stringer which outputs a struct in its equivalent (indented) json representation

Types

type AbciResponse

type AbciResponse struct {
	// a list of key/value pairs
	Models []weave.Model
	Height int64
}

AbciResponse contains a query result: a (possibly empty) list of key-value pairs, and the height at which it queried

type BnsClient

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

BnsClient is a tendermint client wrapped to provide simple access to the data structures used in bns.

func NewClient

func NewClient(conn client.Client) *BnsClient

NewClient wraps a BnsClient around an existing tendermint client connection.

func (*BnsClient) AbciQuery

func (b *BnsClient) AbciQuery(path string, data []byte) (AbciResponse, error)

AbciQuery calls abci query on tendermint rpc, verifies if it is an error or empty, and if there is data pulls out the ResultSets from keys and values into a useful AbciResponse struct

func (*BnsClient) BroadcastTx

func (b *BnsClient) BroadcastTx(tx weave.Tx) BroadcastTxResponse

BroadcastTx serializes a signed transaction and writes to the blockchain. It returns when the tx is committed to the blockchain.

If you want high-performance, parallel sending, use BroadcastTxAsync

func (*BnsClient) BroadcastTxAsync

func (b *BnsClient) BroadcastTxAsync(tx weave.Tx, out chan<- BroadcastTxResponse)

BroadcastTxAsync can be run in a goroutine and will output the result or error to the given channel. Useful if you want to send many tx in parallel

func (*BnsClient) BroadcastTxSync

func (b *BnsClient) BroadcastTxSync(tx weave.Tx, timeout time.Duration) BroadcastTxResponse

func (*BnsClient) ChainID

func (b *BnsClient) ChainID() (string, error)

ChainID will parse out the chainID from the status result

func (*BnsClient) Currencies added in v0.12.0

func (b *BnsClient) Currencies() (CurrenciesResponse, error)

Currencies will returns all currencies configured for the blockchain with their token details.

func (*BnsClient) Genesis

func (b *BnsClient) Genesis() (*GenesisDoc, error)

Genesis will return the genesis directly from the node

func (*BnsClient) GetUser

func (b *BnsClient) GetUser(addr weave.Address) (*UserResponse, error)

GetUser will return nonce and public key registered for a given address if it was ever used. If it returns (nil, nil), then this address never signed a transaction before (and can use nonce = 0)

func (*BnsClient) GetWallet

func (b *BnsClient) GetWallet(addr weave.Address) (*WalletResponse, error)

GetWallet will return a wallet given an address If non wallet is present, it will return (nil, nil) Error codes are used when the query failed on the server

func (*BnsClient) Height

func (b *BnsClient) Height() (int64, error)

Height will parse out the Height from the status result

func (*BnsClient) Status

func (b *BnsClient) Status() (*Status, error)

Status will return the raw status from the node

func (*BnsClient) Subscribe

func (b *BnsClient) Subscribe(query tmpubsub.Query) (<-chan ctypes.ResultEvent, func(), error)

Subscribe will take an arbitrary query and push all events to the given channel. If there is no error, returns a cancel function that can be called to cancel the subscription

func (*BnsClient) SubscribeHeaders

func (b *BnsClient) SubscribeHeaders(out chan<- *Header) (func(), error)

SubscribeHeaders queries for headers and starts a goroutine to typecase the events into Headers. Returns a cancel function. If you don't want the automatic goroutine, use Subscribe(QueryNewBlockHeader, out)

func (*BnsClient) TendermintClient added in v0.16.0

func (bc *BnsClient) TendermintClient() client.Client

func (*BnsClient) TxSearch

func (b *BnsClient) TxSearch(query string, prove bool, page, perPage int) (*ctypes.ResultTxSearch, error)

func (*BnsClient) UnsubscribeAll

func (b *BnsClient) UnsubscribeAll() error

UnsubscribeAll cancels all subscriptions

func (*BnsClient) WaitForTxEvent

func (b *BnsClient) WaitForTxEvent(tx tmtypes.Tx, evtTyp string, timeout time.Duration) (tmtypes.TMEventData, error)

type BroadcastTxResponse

type BroadcastTxResponse struct {
	Error    error                           // not-nil if there was an error sending
	Response *ctypes.ResultBroadcastTxCommit // not-nil if we got response from node
}

BroadcastTxResponse is the result of submitting a transaction.

func (BroadcastTxResponse) IsError

func (b BroadcastTxResponse) IsError() error

IsError returns the error for failure if it failed, or null if it succeeded

type Client

type Client interface {
	TendermintClient() client.Client
	GetUser(addr weave.Address) (*UserResponse, error)
	GetWallet(addr weave.Address) (*WalletResponse, error)
	BroadcastTx(tx weave.Tx) BroadcastTxResponse
	BroadcastTxAsync(tx weave.Tx, out chan<- BroadcastTxResponse)
	BroadcastTxSync(tx weave.Tx, timeout time.Duration) BroadcastTxResponse
	AbciQuery(path string, data []byte) (AbciResponse, error)
}

Client is an interface to interact with bcp

type CurrenciesResponse added in v0.12.0

type CurrenciesResponse struct {
	Height     int64
	Currencies map[string]currency.TokenInfo
}

type GenesisDoc

type GenesisDoc = tmtypes.GenesisDoc
type Header = tmtypes.Header

type MaybeCoin

type MaybeCoin struct {
	Whole      *int64  `json:"whole,omitempty"`
	Fractional *int64  `json:"fractional,omitempty"`
	Ticker     *string `json:"ticker,omitempty"`
}

MaybeCoin is like coin.Coin, but with pointers instead This allows to distinguish between set values and missing ones

func (MaybeCoin) WithDefaults

func (m MaybeCoin) WithDefaults(defaults coin.Coin) coin.Coin

WithDefaults fills the gaps in a maybe coin by replacing missing values with default ones

type MaybeCoins

type MaybeCoins []*MaybeCoin

type Nonce

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

Nonce has a client/address pair, queries for the nonce and caches recent nonce locally to quickly sign

func NewNonce

func NewNonce(client Client, addr weave.Address) *Nonce

NewNonce creates a nonce for a client / address pair. Call Query to force a query, Next to use cache if possible

func (*Nonce) Next

func (n *Nonce) Next() (int64, error)

Next will use a cached value if present, otherwise Query It will always increment by 1, assuming last nonce was properly used. This is designed for cases where you want to rapidly generate many tranasactions without querying the blockchain each time

func (*Nonce) Query

func (n *Nonce) Query() (int64, error)

Query always queries the blockchain for the next nonce

type PrivateKey

type PrivateKey = crypto.PrivateKey

func DecodePrivateKey

func DecodePrivateKey(hexKey string) (*PrivateKey, error)

DecodePrivateKey reads a hex string created by EncodePrivateKey and returns the original PrivateKey

func DecodePrivateKeyFromSeed added in v0.11.1

func DecodePrivateKeyFromSeed(hexSeed string) (*PrivateKey, error)

func GenPrivateKey

func GenPrivateKey() *PrivateKey

GenPrivateKey creates a new random key. Alias to simplify usage.

func LoadPrivateKey

func LoadPrivateKey(filename string) (*PrivateKey, error)

LoadPrivateKey will load a private key from a file, Which was previously written by SavePrivateKey

func LoadPrivateKeys

func LoadPrivateKeys(filename string) ([]*PrivateKey, error)

LoadPrivateKeys will load an array of private keys from a file, Which was previously written by SavePrivateKeys

type Status

type Status = ctypes.ResultStatus

type Tx

type Tx interface {
	weave.Tx
	sigs.SignedTx
}

Tx is all the interfaces we need rolled into one

type UserResponse

type UserResponse struct {
	Address  weave.Address
	UserData sigs.UserData
	Height   int64
}

UserResponse is a response on a query for a User

type WalletRequest

type WalletRequest struct {
	Address weave.Address `json:"address"`
	Coins   MaybeCoins    `json:"coins,omitempty"`
}

WalletRequest is like GenesisAccount, but using pointers To differentiate between 0 and missing

func (WalletRequest) Normalize

func (w WalletRequest) Normalize(defaults coin.Coin) (cash.GenesisAccount, *PrivateKey)

Normalize returns corresponding cash.GenesisAccount with default values. It will generate private keys when there is no Address

type WalletRequests

type WalletRequests struct {
	Wallets []WalletRequest `json:"cash"`
}

WalletRequests contains a collection of MaybeWalletRequest

func (WalletRequests) Normalize

func (w WalletRequests) Normalize(defaults coin.Coin) WalletStore

Normalize Creates a WalletStore with defaulted Wallets and Generated Keys

type WalletResponse

type WalletResponse struct {
	Address weave.Address
	Wallet  cash.Set
	Height  int64
}

WalletResponse is a response on a query for a wallet

type WalletStore

type WalletStore struct {
	Wallets []cash.GenesisAccount `json:"wallets"`
	Keys    []*PrivateKey         `json:"-"`
}

WalletStore represents a list of wallets from a tendermint genesis file It also contains private keys generated for wallets without an Address

func MergeWalletStore

func MergeWalletStore(w1, w2 WalletStore) WalletStore

MergeWalletStore merges two WalletStore

func (*WalletStore) LoadFromFile

func (w *WalletStore) LoadFromFile(file string, defaults coin.Coin) error

LoadFromFile loads a wallet from a file It will generate private keys for wallets without an Address

func (*WalletStore) LoadFromGenesisFile

func (w *WalletStore) LoadFromGenesisFile(file string, defaults coin.Coin) error

LoadFromGenesisFile loads a wallet from a tendermint genesis file It will generate private keys for wallets without an Address

func (*WalletStore) LoadFromJSON

func (w *WalletStore) LoadFromJSON(msg json.RawMessage, defaults coin.Coin) error

LoadFromJSON loads a wallet from a json stream It will generate private keys for wallets without an Address

Jump to

Keyboard shortcuts

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