Documentation ¶
Index ¶
- Constants
- Variables
- func Admin(c *BnsClient) *admin
- func BuildSendTx(source, destination weave.Address, amount coin.Coin, memo string) *bnsd.Tx
- func EncodePrivateKey(key *PrivateKey) (string, error)
- func FindCoinByTicker(coins coin.Coins, ticker string) (*coin.Coin, bool)
- func KeysByAddress(keys []*PrivateKey) map[string]*PrivateKey
- func NewHTTPConnection(remote string) client.Client
- func NewLocalConnection(node *nm.Node) client.Client
- func ParseBnsTx(data []byte) (*bnsd.Tx, error)
- func SavePrivateKey(key *PrivateKey, filename string, force bool) error
- func SavePrivateKeys(keys []*PrivateKey, filename string, force bool) error
- func SetValidatorTx(u ...weave.ValidatorUpdate) *bnsd.Tx
- func SignTx(tx *bnsd.Tx, signer *PrivateKey, chainID string, nonce int64) error
- func ToString(d interface{}) string
- type AbciResponse
- type BnsClient
- func (b *BnsClient) AbciQuery(path string, data []byte) (AbciResponse, error)
- func (b *BnsClient) BroadcastTx(tx weave.Tx) BroadcastTxResponse
- func (b *BnsClient) BroadcastTxAsync(tx weave.Tx, out chan<- BroadcastTxResponse)
- func (b *BnsClient) BroadcastTxSync(tx weave.Tx, timeout time.Duration) BroadcastTxResponse
- func (b *BnsClient) ChainID() (string, error)
- func (b *BnsClient) Currencies() (CurrenciesResponse, error)
- func (b *BnsClient) Genesis() (*GenesisDoc, error)
- func (b *BnsClient) GetUser(addr weave.Address) (*UserResponse, error)
- func (b *BnsClient) GetWallet(addr weave.Address) (*WalletResponse, error)
- func (b *BnsClient) Height() (int64, error)
- func (b *BnsClient) Status() (*Status, error)
- func (b *BnsClient) Subscribe(query tmpubsub.Query) (<-chan ctypes.ResultEvent, func(), error)
- func (b *BnsClient) SubscribeHeaders(out chan<- *Header) (func(), error)
- func (bc *BnsClient) TendermintClient() client.Client
- func (b *BnsClient) TxSearch(query string, prove bool, page, perPage int) (*ctypes.ResultTxSearch, error)
- func (b *BnsClient) UnsubscribeAll() error
- func (b *BnsClient) WaitForTxEvent(tx tmtypes.Tx, evtTyp string, timeout time.Duration) (tmtypes.TMEventData, error)
- type BroadcastTxResponse
- type Client
- type CurrenciesResponse
- type GenesisDoc
- type Header
- type MaybeCoin
- type MaybeCoins
- type Nonce
- type PrivateKey
- type Status
- type Tx
- type UserResponse
- type WalletRequest
- type WalletRequests
- type WalletResponse
- type WalletStore
Constants ¶
const BroadcastTxSyncDefaultTimeOut = 15 * time.Second
const (
CurrentHeight int64 = -1
)
const KeyPerm = 0600
KeyPerm is the file permissions for saved private keys
Variables ¶
var QueryNewBlockHeader = tmtypes.EventQueryNewBlockHeader
Functions ¶
func BuildSendTx ¶
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 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 ¶
NewHTTPConnection takes a URL and sends all requests to the remote node
func NewLocalConnection ¶
NewLocalConnection wraps an in-process node with a client, useful for tests
func ParseBnsTx ¶ added in v0.21.0
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
Types ¶
type AbciResponse ¶
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 (*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 (*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) Subscribe ¶
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 ¶
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 (*BnsClient) UnsubscribeAll ¶
UnsubscribeAll cancels all subscriptions
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 GenesisDoc ¶
type GenesisDoc = tmtypes.GenesisDoc
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
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 ¶
NewNonce creates a nonce for a client / address pair. Call Query to force a query, Next to use cache if possible
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 UserResponse ¶
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 ¶
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