sdk

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: Apache-2.0 Imports: 18 Imported by: 2

README

IRITA Go SDK

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

install

Requirement
  • Go version above 1.14.0
Use Go Mod
require (
    github.com/bianjieai/irita-sdk-go latest
)

Usage

Init Client

The initialization SDK code is as follows:

options := []types.Option{
    types.KeyDAOOption(store.NewMemory(nil)),
    types.TimeoutOption(10),
}
cfg, err := types.NewClientConfig(nodeURI, chainID, options...)
if err != nil {
    panic(err)
}
client := sdk.NewIRITAClient(cfg)

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
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
Algo enum Private key generation algorithm(sm2,secp256k1)
Timeout time.Duration Transaction timeout, for example: 5s
Level string Log output level, for example: info
MaxTxBytes uint64 The maximum number of transaction bytes supported by the connected node, default: 1073741824(5M)

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

coins, err := types.ParseDecCoins("100point")
to := "caa1rgnu8grzt6mwnjg7jss7w0sfyjn67g4em9njf5"
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.

KeyDAO

The interface definition is as follows:

// KeyInfo saves the basic information of the key
type KeyInfo struct {
	Name         string `json:"name"`
	PubKey       []byte `json:"pubkey"`
	PrivKeyArmor string `json:"priv_key_armor"`
	Algo         string `json:"algo"`
}

type KeyDAO interface {
	// Write will use user password to encrypt data and save to file, the file name is user name
	Write(name, password string, store KeyInfo) error

	// Read will read encrypted data from file and decrypt with user password
	Read(name, password string) (KeyInfo, error)

	// Delete will delete user data and use user password to verify permissions
	Delete(name, password string) error

	// Has returns whether the specified user name exists
	Has(name string) bool
}

There are three different ways to implement the keyDAO interface in the SDK:

  • Based on levelDB(LevelDBDAO)
  • Based on local file system(FileDAO)
  • Based on memory(MemoryDAO)

Located under package types/store

Documentation

Overview

Package sdk 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: admin, bank, keys, nft, params, record, service, token, validator

As a quick start:

options := []types.Option{
	types.KeyDAOOption(store.NewMemory(nil)),
}
cfg, err := types.NewClientConfig(nodeURI, chainID, options...)
if err != nil {
	panic(err)
}

client := sdk.NewIRITAClient(cfg)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IRITAClient

type IRITAClient struct {
	types.BaseClient

	Token     token.TokenI
	Record    record.RecordI
	Validator validator.ValidatorI
	Identity  identity.IdentityI
	NFT       nft.NFTI
	Admin     admin.AdminI
	Params    params.ParamsI
	Bank      bank.BankI
	Service   service.ServiceI
	Key       keys.KeyI
	// contains filtered or unexported fields
}

func NewIRITAClient

func NewIRITAClient(cfg types.ClientConfig) IRITAClient

func (*IRITAClient) AppCodec

func (s *IRITAClient) AppCodec() *std.Codec

func (*IRITAClient) Codec

func (s *IRITAClient) Codec() *codec.Codec

func (*IRITAClient) Manager

func (s *IRITAClient) Manager() types.BaseClient

func (*IRITAClient) Module

func (s *IRITAClient) Module(name string) types.Module

func (*IRITAClient) RegisterModule

func (s *IRITAClient) RegisterModule(ms ...types.Module)

func (*IRITAClient) SetOutput

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

Directories

Path Synopsis
client
tx
types
Package types defines a custom wrapper for google.protobuf.Any which supports cached values as well as InterfaceRegistry which keeps track of types which can be used with Any for both security and introspection
Package types defines a custom wrapper for google.protobuf.Any which supports cached values as well as InterfaceRegistry which keeps track of types which can be used with Any for both security and introspection
hd
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.BankI As a quick start: TransferNFT coins to other account client := test.NewClient() amt := types.NewIntWithDecimal(1, 18) coins := types.NewCoins(types.NewCoin("point", amt)) to := "caa1rgnu8grzt6mwnjg7jss7w0sfyjn67g4em9njf5" baseTx := types.BaseTx{ From: "test1", Gas: 20000, Memo: "test", Mode: types.Commit, } result,err := client.BankI.Send(to,coins,baseTx) fmt.Println(result) BurnNFT some coins from your account client := test.NewClient() amt := types.NewIntWithDecimal(1, 18) coins := types.NewCoins(types.NewCoin("point", amt)) baseTx := types.BaseTx{ From: "test1", Gas: 20000, Memo: "test", Mode: types.Commit, } result,err := client.BankI.BurnNFT(coins, baseTx) fmt.Println(result) Set account memo client := test.NewClient() result,err := client.BankI.SetMemoRegexp("testMemo", baseTx) fmt.Println(result) Queries account information client := test.NewClient() result,err := client.BankI.QueryAccount("caa1rgnu8grzt6mwnjg7jss7w0sfyjn67g4em9njf5") fmt.Println(result) Queries the token information client := test.NewClient() result,err := client.BankI.QueryTokenStats("point") fmt.Println(result)
Package bank is mainly used to transfer coins between accounts,query account balances, and implement interface rpc.BankI As a quick start: TransferNFT coins to other account client := test.NewClient() amt := types.NewIntWithDecimal(1, 18) coins := types.NewCoins(types.NewCoin("point", amt)) to := "caa1rgnu8grzt6mwnjg7jss7w0sfyjn67g4em9njf5" baseTx := types.BaseTx{ From: "test1", Gas: 20000, Memo: "test", Mode: types.Commit, } result,err := client.BankI.Send(to,coins,baseTx) fmt.Println(result) BurnNFT some coins from your account client := test.NewClient() amt := types.NewIntWithDecimal(1, 18) coins := types.NewCoins(types.NewCoin("point", amt)) baseTx := types.BaseTx{ From: "test1", Gas: 20000, Memo: "test", Mode: types.Commit, } result,err := client.BankI.BurnNFT(coins, baseTx) fmt.Println(result) Set account memo client := test.NewClient() result,err := client.BankI.SetMemoRegexp("testMemo", baseTx) fmt.Println(result) Queries account information client := test.NewClient() result,err := client.BankI.QueryAccount("caa1rgnu8grzt6mwnjg7jss7w0sfyjn67g4em9njf5") fmt.Println(result) Queries the token information client := test.NewClient() result,err := client.BankI.QueryTokenStats("point") fmt.Println(result)
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 token allows individuals and companies to create and issue their own tokens.
Package token 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