client

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: MIT Imports: 15 Imported by: 0

README

Warning! ALPHA software!

The dnode-client-go library is designed to make it easier for developers to send transactions and make queries to the dfinance blockchain network.

This library is still under heavy development and is not intended for production use.

The library now contains the minimum methods needed to sign and send transactions to the network. The full list of available methods will be available later.

Example

A simple example of use: sending asset prices to the oracle module. To work with this example, you need to have dnode installed. The installation process is described in the document at: https://github.com/dfinance/dnode#installation.

After installation, just start the dnode daemon: $ dnode start and REST-server $ dncli rest-server

package main

import (
	"github.com/cosmos/cosmos-sdk/x/auth"
	sdkcli "github.com/cosmos/cosmos-sdk/client"
	
	dncl"github.com/dfinance/dnode-client-go"
)

func main() {
	accountName := "your-account-name"
	// make Keybase from dncli context.
	kb, err = sdkcli.NewKeyBaseFromDir(os.ExpandEnv("$HOME/.dncli"))
	if err != nil {
		panic(err)
	}
	
	// make TxBuilder to sign transactions
	txb := auth.TxBuilder{}.
		WithKeybase(kb).
		WithChainID("your-chain-id").
		WithFees("your-fees").
		WithGas(200000)

	// make dnode client
	apiCl := dncl.New(
		dncl.WithTxBuilder(txb),
		dncl.WithAccountName(accountName),
		dncl.WithPassphrase("sccount-passphrase"),
	)
	
	// get your account information from the network
	keyInfo, err := kb.Get(accountName)
	if err != nil {
		panic(err)
	}
	acc, err := apiCl.Auth().Account(keyInfo.GetAddress())
	if err != nil {
		panic(err)
	}

	result, err := apiCl.WithAccount(acc).Oracle().PostPrices([]MsgPostPrice{
		{
			From:       ki.GetAddress(),
			AssetCode:  "eth_dfi",
			Price:      sdk.NewInt(1000000),
			ReceivedAt: time.Now(),
		},
		{
			From:       ki.GetAddress(),
			AssetCode:  "eth_dfi",
			Price:      sdk.NewInt(1200000),
			ReceivedAt: time.Now(),
		},
	})
}

TODO

  • A lot of tests
  • Methods available for calling but not yet implemented in this library

Documentation

Index

Constants

View Source
const (
	BroadcastBlock = flags.BroadcastBlock
	BroadcastSync  = flags.BroadcastSync
	BroadcastAsync = flags.BroadcastAsync
)

Variables

View Source
var (
	// SortJSON takes any JSON and returns it sorted by keys. Also, all white-spaces
	// are removed.
	// This method can be used to canonicalize JSON to be returned by GetSignBytes,
	// e.g. for the ledger integration.
	// If the passed JSON isn't valid it will return an error.
	SortJSON = types.SortJSON
)

Functions

func DefaultCodec

func DefaultCodec() *codec.Codec

DefaultCodec returns the initialized amino codec to marshal/unmarshal

Types

type AccAddress

type AccAddress = types.AccAddress

AccAddress a wrapper around bytes meant to represent an account address. When marshaled to a string or JSON, it uses Bech32.

type Assets

type Assets = oracle.Assets

Assets array type for oracle module

type AuthClient

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

AuthClient provides a set of methods for the Auth module

func (AuthClient) Account

func (c AuthClient) Account(address AccAddress) (auth.BaseAccount, error)

Account returns account information including AccountNumber, Sequence and Address. The AccountNumber and Sequence fields are required to sign transactions.

type BaseAccount

type BaseAccount = auth.BaseAccount

BaseAccount - a base account structure. This can be extended by embedding within in your AppAccount. However one doesn't have to use BaseAccount as long as your struct implements Account.

type BroadcastReq

type BroadcastReq = rest.BroadcastReq

BroadcastReq defines a tx broadcasting request.

type Codec

type Codec = codec.Codec

Codec amino codec to marshal/unmarshal

type CurrenciesClient

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

CurrenciesClient provides a set of methods for the Currencies module

func (CurrenciesClient) Issue

func (c CurrenciesClient) Issue(msg MsgIssueCurrency, msgID string) (TxResponse, error)

Issue currency

func (CurrenciesClient) Withdraw added in v0.6.0

Withdraw currency

type DnodeClient

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

DnodeClient implements set of methods for working with dnode blockchain. Never create an instance with the DnodeClient{} literal! To create a correctly initialized instance, always use the New() function.

func New

func New(opts ...Option) DnodeClient

New is a constructor function for DnodeClient

func (DnodeClient) AccountName

func (c DnodeClient) AccountName() string

AccountName returns the current transaction sender account name

func (DnodeClient) Auth

func (c DnodeClient) Auth() AuthClient

Auth returns initialized AuthClient

func (DnodeClient) BroadcastMode

func (c DnodeClient) BroadcastMode() string

BroadcastMode returns the current broadcast mode

func (DnodeClient) Codec

func (c DnodeClient) Codec() *Codec

Codec returns the current codec

func (DnodeClient) Currencies

func (c DnodeClient) Currencies() CurrenciesClient

Currencies returns initialized CurrenciesClient

func (DnodeClient) FromAddress

func (c DnodeClient) FromAddress() AccAddress

FromAddress returns the current transaction sender address

func (DnodeClient) NodeURL

func (c DnodeClient) NodeURL() string

NodeURL returns the current node URL

func (DnodeClient) Oracle

func (c DnodeClient) Oracle() OracleClient

Oracle returns initialized OracleClient

func (DnodeClient) Passphrase

func (c DnodeClient) Passphrase() string

Passphrase returns the current passphrase

func (DnodeClient) Tx

func (c DnodeClient) Tx() TxClient

Tx returns initialized TxClient

func (DnodeClient) TxBuilder

func (c DnodeClient) TxBuilder() TxBuilder

TxBuilder returns the current transactions bulder

func (DnodeClient) WithAccount

func (c DnodeClient) WithAccount(account BaseAccount) DnodeClient

WithAccount returns DnodeClient with AccountNumber, Sequence and FromAddress fields set. This is a short record of the call of the following methods WithAccountNumber(...).WithSequence(...).WithFromAddress(...).

func (DnodeClient) WithAccountName

func (c DnodeClient) WithAccountName(name string) DnodeClient

WithAccountName returns DnodeClient with the specified account name

func (DnodeClient) WithAccountNumber

func (c DnodeClient) WithAccountNumber(number uint64) DnodeClient

WithAccountNumber returns DnodeClient with the specified AccountNumber

func (DnodeClient) WithBroadcastMode

func (c DnodeClient) WithBroadcastMode(mode TxBroadcastMode) DnodeClient

WithBroadcastMode returns DnodeClient with the specified broadcast mode

func (DnodeClient) WithChainID

func (c DnodeClient) WithChainID(chainID string) DnodeClient

WithChainID returns DnodeClient with the specified ChainID

func (DnodeClient) WithFees

func (c DnodeClient) WithFees(fees string) DnodeClient

WithFees returns DnodeClient with the specified Fees

func (DnodeClient) WithFromAddress

func (c DnodeClient) WithFromAddress(addr AccAddress) DnodeClient

WithFromAddress returns DnodeClient with the specified transaction sender address

func (DnodeClient) WithGas

func (c DnodeClient) WithGas(gas uint64) DnodeClient

WithGas returns DnodeClient with the specified gas

func (DnodeClient) WithGasPrices

func (c DnodeClient) WithGasPrices(gasPrices string) DnodeClient

WithGasPrices returns DnodeClient with the specified gas prices

func (DnodeClient) WithKeybase

func (c DnodeClient) WithKeybase(kb Keybase) DnodeClient

WithKeybase returns DnodeClient with the specified KeyBase

func (DnodeClient) WithMemo

func (c DnodeClient) WithMemo(memo string) DnodeClient

WithMemo returns DnodeClient with the specified memo

func (DnodeClient) WithPassphrase

func (c DnodeClient) WithPassphrase(phrase string) DnodeClient

WithPassphrase returns DnodeClient with the specified passphrase

func (DnodeClient) WithSequence

func (c DnodeClient) WithSequence(seq uint64) DnodeClient

WithSequence returns DnodeClient with the specified account sequence

type Keybase

type Keybase = keys.Keybase

Keybase exposes operations on a generic keystore

type Msg

type Msg = types.Msg

Msg transactions messages must fulfill the Msg

type MsgConfirmCall

type MsgConfirmCall = msmsgs.MsgConfirmCall

MsgConfirmCall message for confirm call

type MsgIssueCurrency

type MsgIssueCurrency = curr.MsgIssueCurrency

MsgIssueCurrency struct for issue new currencies. IssueID could be txHash of transaction in another blockchain.

type MsgPostPrice

type MsgPostPrice = oracle.MsgPostPrice

MsgPostPrice struct representing a posted price message. Used by oracles to input prices to the oracle

type MsgRevokeConfirm

type MsgRevokeConfirm = msmsgs.MsgRevokeConfirm

MsgRevokeConfirm message to revoke confirmation from call

type MsgSubmitCall

type MsgSubmitCall = msmsgs.MsgSubmitCall

MsgSubmitCall message for submit call

type MsgWithdrawCurrency added in v0.6.0

type MsgWithdrawCurrency = curr.MsgWithdrawCurrency

MsgWithdrawCurrency message for destroy currency

type Option

type Option func(*DnodeClient)

func WithAccountName

func WithAccountName(name string) Option

WithAccountName sets the transaction sender's account name for the DnodeClient instance being created

func WithBroadcastMode

func WithBroadcastMode(mode TxBroadcastMode) Option

WithBroadcastMode sets the transactions broadcast mode for the DnodeClient instance being created instead of the default one

func WithCodec

func WithCodec(cdc *codec.Codec) Option

WithCodec sets the codec for the DnodeClient instance being created instead of the default one

func WithFromAddress

func WithFromAddress(addr AccAddress) Option

WithFromAddress sets the transaction sender's address for the DnodeClient instance being created

func WithHTTPClient

func WithHTTPClient(cl *http.Client) Option

WithHTTPClient sets the http.Client for the DnodeClient instance being created instead of the default one

func WithNodeURL

func WithNodeURL(url string) Option

WithNodeURL sets the node url for the DnodeClient instance being created instead of the default one

func WithPassphrase

func WithPassphrase(pp string) Option

WithPassphrase sets the passphrase for the DnodeClient instance being created

func WithTxBuilder

func WithTxBuilder(b auth.TxBuilder) Option

WithTxBuilder sets the transactions builder for the DnodeClient instance being created

type OracleClient

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

OracleClient provides a set of methods for the Oracle module

func (OracleClient) Assets

func (c OracleClient) Assets() (Assets, error)

Assets returns the array of available assets of the oracle module.

func (OracleClient) PostPrices

func (c OracleClient) PostPrices(msgs []MsgPostPrice) (result TxResponse, err error)

PostPrices sends asset prices to the oracle module.

type StdFee

type StdFee = auth.StdFee

StdFee includes the amount of coins paid in fees and the maximum gas to be used by the transaction. The ratio yields an effective "gasprice", which must be above some miminum to be accepted into the mempool.

type StdTx

type StdTx = auth.StdTx

StdTx is a standard way to wrap a Msg with Fee and Signatures. NOTE: the first signature is the fee payer (Signatures must not be nil).

type TxBroadcastMode

type TxBroadcastMode int

TxBroadcastMode enumeration type for BroadcastMode numeric presentation

const (
	TxBlockMode TxBroadcastMode = iota
	TxSyncMode
	TxAsyncMode
)

func (TxBroadcastMode) String

func (bm TxBroadcastMode) String() string

type TxBuilder

type TxBuilder = auth.TxBuilder

TxBuilder implements a transaction context created in SDK modules.

type TxClient

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

TxClient provides a set of methods for working with transactions.

func (TxClient) Broadcast

func (c TxClient) Broadcast(msgs []Msg) (TxResponse, error)

Broadcast signs and sends/broadcasts transactions to the network

type TxResponse

type TxResponse = types.TxResponse

TxResponse defines a structure containing relevant tx data and metadata. The tags are stringified and the log is JSON decoded.

Jump to

Keyboard shortcuts

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