client

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2018 License: MIT Imports: 26 Imported by: 27

Documentation

Index

Constants

View Source
const (
	ExitCodeGeneral        = 1 // Not in sysexits.h, but is standard practice.
	ExitCodeNotFound       = 2
	ExitCodeCancelled      = 3
	ExitCodeForbidden      = 4
	ExitCodeTemporaryError = 5
	ExitCodeUsage          = 64 // EX_USAGE in sysexits.h
)

exit codes inspired by sysexits.h

View Source
const (
	// AuditContractExitCodeInvalidContract is returned as exit code,
	// in case the contract was found, but failed to validate against the given validation flags.
	AuditContractExitCodeInvalidContract = 128
)

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(address, name string, configFunc func(*Config) Config)

DefaultCLIClient creates a new client for the given address. The given address is used to connect to the client daemon, using its REST API. configFunc allows you to overwrite any config, should some value returned by the daemon not be desired, it is however optional and does not have to be given

func Die

func Die(args ...interface{})

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

func DieWithError added in v1.0.7

func DieWithError(description string, err error)

DieWithError exits with an error. if the error is of the type ErrorWithStatusCode, its status will be used, otherwise the General exit code will be used

func DieWithExitCode added in v1.0.6

func DieWithExitCode(code int, args ...interface{})

DieWithExitCode prints its arguments to stderr, then exits the program with the given exit 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 AtomicSwapOutputAudit added in v1.0.7

type AtomicSwapOutputAudit struct {
	Coins    types.Currency            `json:"coins"`
	Contract types.AtomicSwapCondition `json:"contract"`
}

AtomicSwapOutputAudit represents the formatted output of the atomic swap audit command

type AtomicSwapOutputCreation added in v1.0.6

type AtomicSwapOutputCreation struct {
	Coins         types.Currency            `json:"coins"`
	Contract      types.AtomicSwapCondition `json:"contract"`
	ContractID    types.UnlockHash          `json:"contractid"`
	Secret        *types.AtomicSwapSecret   `json:"secret,omitempty"`
	OutputID      types.CoinOutputID        `json:"outputid"`
	TransactionID types.TransactionID       `json:"transactionid"`
}

AtomicSwapOutputCreation represents the formatted output of the atomic swap creation commands (initiate and participate).

type AtomicSwapOutputExtractSecret added in v1.0.6

type AtomicSwapOutputExtractSecret struct {
	Secret types.AtomicSwapSecret `json:"secret"`
}

AtomicSwapOutputExtractSecret represents the formatted output of the atomic swap extract secret command

type AtomicSwapOutputSpendContract added in v1.0.6

type AtomicSwapOutputSpendContract struct {
	TransactionID types.TransactionID `json:"transactionid"`
}

AtomicSwapOutputSpendContract represents the formatted output of the atomic swap spend commands (redeem and refund)

type Config

type Config struct {
	ChainName    string
	NetworkName  string
	ChainVersion build.ProtocolVersion

	CurrencyUnits             types.CurrencyUnits
	CurrencyCoinUnit          string
	MinimumTransactionFee     types.Currency
	DefaultTransactionVersion types.TransactionVersion

	// These values aren't used for validation,
	// but only in order to estimate progress with the syncing of your consensus.
	BlockFrequencyInSeconds int64
	GenesisBlockTimestamp   types.Timestamp
}

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

func ConfigFromDaemonConstants added in v1.0.7

func ConfigFromDaemonConstants(constants modules.DaemonConstants) Config

ConfigFromDaemonConstants returns CLI constants using a daemon's constants as input.

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, coinUnit string) CurrencyConvertor

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) 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 ErrorWithStatusCode added in v1.0.7

type ErrorWithStatusCode struct {
	Err    error
	Status int
}

ErrorWithStatusCode couples an exit status code to an error (message)

func (ErrorWithStatusCode) Error added in v1.0.7

func (ewsc ErrorWithStatusCode) Error() string

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