sdk

package module
v0.0.0-...-f705c6e Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

README

IRISHUB Chain Go SDK

Irishub Chain GO SDK makes a simple package of API provided by Irishub, which provides great convenience for users to quickly develop applications based on irishub chain.

install

Requirement

Go version above 1.13.5

Use Go Mod
require (
    github.com/junjie-bianjie/irishub-sdk-go latest
)

Usage

Init Client

The initialization SDK code is as follows:

client := sdk.NewClient(types.ClientConfig{
    NodeURI:   "localhost:26657",
    Network:   types.Mainnet,
    ChainID:   "irishub",
    Gas:       2000,
    Fee:       fees,
    Mode:      types.Commit,
    StoreType: types.PrivKey,
    Timeout:   10 * time.Second,
    Level:     "info",
})

The ClientConfig component mainly contains the parameters used in the SDK, the specific meaning is shown in the table below

Iterm Type Description
NodeURI string The RPC address of the irishub node connected to the SDK, for example: localhost: 26657
Network enum irishub network type, value: Testnet,Mainnet
ChainID string ChainID of irishub, for example: irishub
Gas uint64 The maximum gas to be paid for the transaction, for example: 20000
Fee DecCoins Transaction fees to be paid for transactions
KeyDAO KeyDAO Private key management interface, If the user does not provide it, the default LevelDB will be used
Mode enum Transaction broadcast mode, value: Sync,Async, Commit
StoreType enum Private key storage method, value: Keystore,PrivKey
Timeout time.Duration Transaction timeout, for example: 5s
Level string Log output level, for example: info

If you want to use SDK to send a transfer transaction, the example is as follows:

coins, err := types.ParseDecCoins("0.1iris")
to := "faa1hp29kuh22vpjjlnctmyml5s75evsnsd8r4x0mm"
baseTx := types.BaseTx{
    From:     "username",
    Gas:      20000,
    Memo:     "test",
    Mode:     types.Commit,
    Password: "password",
}

result, err := client.Bank().Send(to, coins, baseTx)

Note: If you use the relevant API for sending transactions, you should implement the KeyDAO interface. Use the NewKeyDaoWithAES method to initialize a KeyDAO instance, which will use the AES encryption method by default.

KeyDAO

The interface definition is as follows:

type KeyDAO interface {
    AccountAccess
    Crypto
}

type AccountAccess interface {
    Write(name string, store Store) error
    Read(name string) (Store,error)
    Delete(name string) error
}
type Crypto interface {
    Encrypt(data string, password string) (string, error)
    Decrypt(data string, password string) (string, error)
}

Among them, Store includes two storage methods, one is based on the private key, which is defined as follows:

type KeyInfo struct {
    PrivKey string `json:"priv_key"`
    Address string `json:"address"`
}

The other is based on the keystore, defined as follows:

type KeystoreInfo struct {
    Keystore string `json:"keystore"`
}

You can flexibly choose any of the private key management methods. The Encrypt and Decrypt interfaces are used to encrypt and decrypt the key. If the user does not implement it, the default is to use AES. Examples are as follows:

KeyDao implements the AccountAccess interface:

// Use memory as storage, use with caution in build environment
type MemoryDB struct {
	store map[string]Store
	AES
}

func NewMemoryDB() MemoryDB {
	return MemoryDB{
		store: make(map[string]Store),
	}
}
func (m MemoryDB) Write(name string, store Store) error {
	m.store[name] = store
	return nil
}

func (m MemoryDB) Read(name string) (Store, error) {
	return m.store[name], nil
}

func (m MemoryDB) Delete(name string) error {
	delete(m.store, name)
	return nil
}

func (m MemoryDB) Has(name string) bool {
	_, ok := m.store[name]
	return ok
}

For more API usage documentation, please check documentation

Documentation

Overview

Package client is the entrance of the entire SDK function. SDKConfig is used to configure SDK parameters.

The SDK mainly provides the functions of the following modules, including: asset, bank, distribution, gov, keys, oracle, random, service, slashing, staking

As a quick start:

fees, err := types.ParseCoins("1iris")
if err != nil {
	panic(err)
}

client := sdk.NewClient(types.ClientConfig{
	NodeURI:   NodeURI,
	Network:   Network,
	ChainID:   ChainID,
	Gas:       Gas,
	Fee:       fees,
	Mode:      Mode,
	Online:    Online,
	StoreType: types.PrivKey,
	Level:     "debug",
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Cdc sdk.Codec

	sdk.WSClient
	sdk.TxManager
	sdk.TokenConvert
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg sdk.ClientConfig) Client

func (*Client) Asset

func (s *Client) Asset() rpc.Asset

func (*Client) Bank

func (s *Client) Bank() rpc.Bank

func (*Client) Distr

func (s *Client) Distr() rpc.Distribution

func (*Client) Gov

func (s *Client) Gov() rpc.Gov

func (*Client) Htlc

func (s *Client) Htlc() rpc.Htlc

func (*Client) Keys

func (s *Client) Keys() rpc.Keys

func (*Client) Oracle

func (s *Client) Oracle() rpc.Oracle

func (*Client) Params

func (s *Client) Params() rpc.Params

func (*Client) Random

func (s *Client) Random() rpc.Random

func (*Client) Service

func (s *Client) Service() rpc.Service

func (*Client) SetOutput

func (s *Client) SetOutput(w io.Writer)

func (*Client) Slashing

func (s *Client) Slashing() rpc.Slashing

func (*Client) Staking

func (s *Client) Staking() rpc.Staking

func (*Client) Tendermint

func (s *Client) Tendermint() rpc.Tendermint

Directories

Path Synopsis
Package adapter is to adapt to the user DAO layer, the user can not override this implementation
Package adapter is to adapt to the user DAO layer, the user can not override this implementation
Package modules is to warpped the API provided by each module of irishub
Package modules is to warpped the API provided by each module of irishub
asset
Package asset allows individuals and companies to create and issue their own tokens.
Package asset allows individuals and companies to create and issue their own tokens.
bank
Package bank is mainly used to transfer coins between accounts,query account balances, and implement interface rpc.Bank In addition, the available units of tokens in the IRIShub system are defined using [coin-type](https://www.junjie-bianjie.org/docs/concepts/coin-type.html).
Package bank is mainly used to transfer coins between accounts,query account balances, and implement interface rpc.Bank In addition, the available units of tokens in the IRIShub system are defined using [coin-type](https://www.junjie-bianjie.org/docs/concepts/coin-type.html).
distribution
Package distribution in charge of distributing collected transaction fee and inflated token to all validators and delegators.
Package distribution in charge of distributing collected transaction fee and inflated token to all validators and delegators.
gov
Package gov in charge of distributing collected transaction fee and inflated token to all validators and delegators.
Package gov in charge of distributing collected transaction fee and inflated token to all validators and delegators.
keys
Package keys allows you to manage your local tendermint keystore (wallets) for iris.
Package keys allows you to manage your local tendermint keystore (wallets) for iris.
oracle
Package oracle combines service to achieve decentralized injection from trusted Oracles such as Chainlink to IRISHub Oracle.
Package oracle combines service to achieve decentralized injection from trusted Oracles such as Chainlink to IRISHub Oracle.
random
Package random describes the usage and scope of random numbers on IRISHub.
Package random describes the usage and scope of random numbers on IRISHub.
service
Package service bridge the gap between the blockchain world and the conventional business application world, by mediating a complete lifecycle of off-chain services -- from their definition, binding (provider registration), invocation, to their governance (profiling and dispute resolution).
Package service bridge the gap between the blockchain world and the conventional business application world, by mediating a complete lifecycle of off-chain services -- from their definition, binding (provider registration), invocation, to their governance (profiling and dispute resolution).
slashing
Package slashing provides the ability to access the interface of the IRISHUB slashing module In Proof-of-Stake blockchain, validators will get block provisions by staking their token.
Package slashing provides the ability to access the interface of the IRISHUB slashing module In Proof-of-Stake blockchain, validators will get block provisions by staking their token.
staking
Package staking provides staking functionalities for validators and delegators.
Package staking provides staking functionalities for validators and delegators.
tendermint
Package tendermint provides tendermint rpc queriers implementation
Package tendermint provides tendermint rpc queriers implementation
log
uuid
reference: https://github.com/binance-chain/go-sdk/blob/master/common/uuid/codec.go reference: https://github.com/binance-chain/go-sdk/blob/master/common/uuid/generator.go Package uuid reference: https://github.com/binance-chain/go-sdk/blob/master/common/uuid/uuid.go
reference: https://github.com/binance-chain/go-sdk/blob/master/common/uuid/codec.go reference: https://github.com/binance-chain/go-sdk/blob/master/common/uuid/generator.go Package uuid reference: https://github.com/binance-chain/go-sdk/blob/master/common/uuid/uuid.go

Jump to

Keyboard shortcuts

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