client

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 9, 2018 License: MIT Imports: 21 Imported by: 26

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeError

func DecodeError(resp *http.Response) error

DecodeError returns the api.Error from a API response. This method should only be called if the response's status code is non-2xx. The error returned may not be of type api.Error in the event of an error unmarshalling the JSON.

func DefaultCLIClient

func DefaultCLIClient(cfg Config)

DefaultCLIClient creates a new client using the given params as the default config, and an optional flag-based system to overrride some.

func Die

func Die(args ...interface{})

Die prints its arguments to stderr, then exits the program with the default error code.

func EstimatedHeightAt

func EstimatedHeightAt(t time.Time) types.BlockHeight

EstimatedHeightAt returns the estimated block height for the given time. Block height is estimated by calculating the minutes since a known block in the past and dividing by 10 minutes (the block time).

func Non2xx

func Non2xx(code int) bool

Non2xx returns true for non-success HTTP status codes.

func ParsePeriod

func ParsePeriod(period string) (string, error)

ParsePeriod converts a number of weeks to a number of blocks.

func PeriodUnits

func PeriodUnits(blocks types.BlockHeight) string

PeriodUnits turns a period in terms of blocks to a number of weeks.

func Wrap

func Wrap(fn interface{}) func(*cobra.Command, []string)

Wrap wraps a generic command with a check that the command has been passed the correct number of arguments. The command must take only strings as arguments.

func YesNo

func YesNo(b bool) string

YesNo returns "Yes" if b is true, and "No" if b is false.

Types

type Config

type Config struct {
	Address               string
	Name                  string
	Version               build.ProtocolVersion // blockchain version (is NOT Rivine Protocol Version)
	CurrencyCoinUnit      string
	CurrencyUnits         types.CurrencyUnits
	MinimumTransactionFee types.Currency

	// version used to create new transactions
	DefaultTransactionVersion types.TransactionVersion
}

Config defines the configuration for the default (CLI) client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig creates the default configuration for the default (CLI) client.

type CurrencyConvertor

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

CurrencyConvertor is used to parse a currency in it's default unit, and turn it into its in-memory smallest unit. Simiarly it allow you to turn the in-memory smallest unit into a string version of the default init.

func NewCurrencyConvertor

func NewCurrencyConvertor(units types.CurrencyUnits) (CurrencyConvertor, error)

NewCurrencyConvertor creates a new currency convertor using the given currency units.

See CurrencyConvertor for more information.

func (CurrencyConvertor) CoinArgDescription

func (cc CurrencyConvertor) CoinArgDescription(argName string) string

CoinArgDescription is used to print a helpful arg description message, for this convertor.

func (CurrencyConvertor) CoinHelp

func (cc CurrencyConvertor) CoinHelp() string

CoinHelp is used to print a help message, for this convertor.

func (CurrencyConvertor) ParseCoinString

func (cc CurrencyConvertor) ParseCoinString(str string) (types.Currency, error)

ParseCoinString parses the given string assumed to be in the default unit, and parses it into an in-memory currency unit of the smallest unit. It will fail if the given string is invalid or too precise.

func (CurrencyConvertor) ToCoinString

func (cc CurrencyConvertor) ToCoinString(c types.Currency) string

ToCoinString turns the in-memory currency unit, into a string version of the default currency unit. This can never fail, as the only thing it can do is make a number smaller.

func (CurrencyConvertor) ToCoinStringWithUnit

func (cc CurrencyConvertor) ToCoinStringWithUnit(c types.Currency) string

ToCoinStringWithUnit turns the in-memory currency unit, into a string version of the default currency unit. This can never fail, as the only thing it can do is make a number smaller. It also adds the unit of the coin behind the coin.

type HTTPClient

type HTTPClient struct {
	RootURL string
}

HTTPClient is used to communicate with the Rivine-based daemon, using the exposed (local) REST API over HTTP.

func (*HTTPClient) Get

func (c *HTTPClient) Get(call string) error

Get makes an API call and discards the response. An error is returned if the response status is not 2xx.

func (*HTTPClient) GetAPI

func (c *HTTPClient) GetAPI(call string, obj interface{}) error

GetAPI makes a GET API call and decodes the response. An error is returned if the response status is not 2xx.

func (*HTTPClient) Post

func (c *HTTPClient) Post(call, data string) error

Post makes an API call and discards the response. An error is returned if the response status is not 2xx.

func (*HTTPClient) PostResp

func (c *HTTPClient) PostResp(call, data string, reply interface{}) error

PostResp makes a POST API call and decodes the response. An error is returned if the response status is not 2xx.

Jump to

Keyboard shortcuts

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