sdk

package module
v0.0.0-...-581f9f3 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

README

irita Chain Go SDK

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

install

Requirement

Go version above 1.13.5

Use Go Mod
require (
    github.com/bianjieai/irita-ent-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:   "irita",
    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 irita node connected to the SDK, for example: localhost: 26657
Network enum irita network type, value: Testnet,Mainnet
ChainID string ChainID of irita, for example: irita
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.1point")
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("1point")
if err != nil {
	panic(err)
}

client := sdk.NewIRITAClient(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 IRITAClient

type IRITAClient struct {
	sdk.WSClient
	sdk.TxManager
	sdk.TokenConvert

	//support module
	bank.Bank
	service.Service
	keys.Keys
	token.Token
	record.Record
	nft.NFT
	// contains filtered or unexported fields
}

func NewIRITAClient

func NewIRITAClient(cfg sdk.ClientConfig) IRITAClient

func (*IRITAClient) SetOutput

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

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 irita
Package modules is to warpped the API provided by each module of irita
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 irita system are defined using [coin-type](https://www.irisnet.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 irita system are defined using [coin-type](https://www.irisnet.org/docs/concepts/coin-type.html).
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.
nft
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).
token
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.
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