client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: Apache-2.0 Imports: 22 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const BroadcastTxSyncDefaultTimeOut = 15 * time.Second

BroadcastTxSyncDefaultTimeOut timeout for sync tx broadcasting

View Source
const KeyPerm = 0600

KeyPerm is the file permissions for saved private keys

Variables

View Source
var (
	// ErrNoMatch is returned when two compared values does not match
	ErrNoMatch = errors.Register(121, "no match")
	// ErrInvalid is returned when a value is invalid
	ErrInvalid = errors.Register(122, "invalid")
	// ErrPermission is returned when an action is not permitted
	ErrPermission = errors.Register(123, "not permitted")
)
View Source
var QueryNewBlockHeader = tmtypes.EventQueryNewBlockHeader

Functions

func BuildSendTx

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

BuildSendTx will create an unsigned tx to move tokens

func DecodePrivateKey

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

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

func DecodePrivateKeyFromSeed

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

DecodePrivateKeyFromSeed decodes private key from seed string

func EncodePrivateKey

func EncodePrivateKey(key *crypto.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)

FindCoinByTicker returns coins with equal tickers

func GenPrivateKey

func GenPrivateKey() *crypto.PrivateKey

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

func KeysByAddress

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

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

func LoadPrivateKey

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

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

func LoadPrivateKeys

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

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

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 ParseBlogTx

func ParseBlogTx(data []byte) (*blog.Tx, error)

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

func SavePrivateKey

func SavePrivateKey(key *crypto.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 []*crypto.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

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

SetValidatorTx will create an unsigned tx to replace current validator set

func SignTx

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

SignTx modifies the tx in-place, adding signatures

func ToJsonString

func ToJsonString(d interface{}) (string, error)

ToJsonString is a generic stringer which outputs a struct in its equivalent (indented) json representation If json marshalling not sucessful returns error

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 BlogClient

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

BlogClient is a tendermint client wrapped to provide simple access to the data structures used in blog module.

func NewClient

func NewClient(conn client.Client) *BlogClient

NewClient wraps a BlogClient around an existing tendermint client connection.

func (*BlogClient) AbciQuery

func (cc *BlogClient) 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 (*BlogClient) BroadcastTx

func (cc *BlogClient) 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 (*BlogClient) BroadcastTxAsync

func (cc *BlogClient) 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 (*BlogClient) BroadcastTxSync

func (cc *BlogClient) BroadcastTxSync(tx weave.Tx, timeout time.Duration) BroadcastTxResponse

BroadcastTxSync brodcasts transactions synchronously

func (*BlogClient) ChainID

func (cc *BlogClient) ChainID() (string, error)

ChainID will parse out the chainID from the status result

func (*BlogClient) Genesis

func (cc *BlogClient) Genesis() (*tmtypes.GenesisDoc, error)

Genesis will return the genesis directly from the node

func (*BlogClient) GetUser

func (cc *BlogClient) 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 (*BlogClient) GetWallet

func (cc *BlogClient) 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 (*BlogClient) Height

func (cc *BlogClient) Height() (int64, error)

Height will parse out the Height from the status result

func (*BlogClient) NextNonce

func (cc *BlogClient) NextNonce(addr weave.Address) (int64, error)

NextNonce queries the blockchain for the next nonce returns 0 if the address never used

func (*BlogClient) Status

func (cc *BlogClient) Status() (*ctypes.ResultStatus, error)

Status will return the raw status from the node

func (*BlogClient) Subscribe

func (cc *BlogClient) 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 (*BlogClient) SubscribeHeaders

func (cc *BlogClient) SubscribeHeaders(out chan<- *tmtypes.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 (*BlogClient) TendermintClient

func (cc *BlogClient) TendermintClient() client.Client

TendermintClient returns underlying tendermint client

func (*BlogClient) TxSearch

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

TxSearch searches transactions using underlying tendermint client

func (*BlogClient) UnsubscribeAll

func (cc *BlogClient) UnsubscribeAll() error

UnsubscribeAll cancels all subscriptions

func (*BlogClient) WaitForTxEvent

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

WaitForTxEvent listens for and particular event type of evtTyp to be fired

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 returns the underlying tendermint client
	TendermintClient() client.Client
	// GetUser will return nonce and public key registered
	// for a given address if it was ever used.
	GetUser(addr weave.Address) (*UserResponse, error)
	// GetWallet will return a wallet given an address
	GetWallet(addr weave.Address) (*WalletResponse, error)
	// BroadcastTx serializes a signed transaction and writes to the
	// blockchain. It returns when the tx is committed to the blockchain.
	BroadcastTx(tx weave.Tx) BroadcastTxResponse
	// BroadcastTxAsync can be run in a goroutine and will output the
	// result or error to the given channel.
	BroadcastTxAsync(tx weave.Tx, out chan<- BroadcastTxResponse)
	// BroadcastTxSync brodcasts transactions synchronously
	BroadcastTxSync(tx weave.Tx, timeout time.Duration) BroadcastTxResponse
	// AbciQuery calls abci query on tendermint rpc.
	AbciQuery(path string, data []byte) (AbciResponse, error)
	// NextNonce queries the blockchain for the next nonce
	NextNonce(client Client, addr weave.Address) (int64, error)
}

Client is an interface to interact with weave apps

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   coin.Coins    `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, *crypto.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    []*crypto.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