sdk

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2020 License: Apache-2.0 Imports: 14 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

func RegisterInterfaces added in v1.1.0

func RegisterInterfaces(registry cdctypes.InterfaceRegistry)

RegisterInterfaces registers the sdk message type.

func RegisterLegacyAminoCodec added in v1.1.0

func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino)

RegisterLegacyAminoCodec registers the sdk message type.

Types

type IRITAClient

type IRITAClient struct {
	types.BaseClient
	Bank    bank.BankI
	Token   token.TokenI
	Record  record.RecordI
	NFT     nft.NFTI
	Service service.ServiceI
	Key     keys.KeyI
	// contains filtered or unexported fields
}

func NewIRITAClient

func NewIRITAClient(cfg types.ClientConfig) IRITAClient

func (*IRITAClient) AppCodec

func (client *IRITAClient) AppCodec() codec.Marshaler

func (*IRITAClient) Codec

func (client *IRITAClient) Codec() *codec.LegacyAmino

func (*IRITAClient) Manager

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

func (*IRITAClient) Module

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

func (*IRITAClient) RegisterModule

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

func (*IRITAClient) SetLogger added in v1.1.0

func (client *IRITAClient) SetLogger(logger log.Logger)

Directories

Path Synopsis
client
tx
legacy
Package legacy contains a global amino Cdc which is deprecated but still used in several places within the SDK.
Package legacy contains a global amino Cdc which is deprecated but still used in several places within the SDK.
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
unknownproto
unknownproto implements functionality to "type check" protobuf serialized byte sequences against an expected proto.Message to report: a) Unknown fields in the stream -- this is indicative of mismatched services, perhaps a malicious actor b) Mismatched wire types for a field -- this is indicative of mismatched services Its API signature is similar to proto.Unmarshal([]byte, proto.Message) in the strict case if err := RejectUnknownFieldsStrict(protoBlob, protoMessage, false); err != nil { // Handle the error.
unknownproto implements functionality to "type check" protobuf serialized byte sequences against an expected proto.Message to report: a) Unknown fields in the stream -- this is indicative of mismatched services, perhaps a malicious actor b) Mismatched wire types for a field -- this is indicative of mismatched services Its API signature is similar to proto.Unmarshal([]byte, proto.Message) in the strict case if err := RejectUnknownFieldsStrict(protoBlob, protoMessage, false); err != nil { // Handle the error.
hd
keys/secp256k1/internal/secp256k1
nolint:gocritic Package secp256k1 wraps the bitcoin secp256k1 C library.
nolint:gocritic Package secp256k1 wraps the bitcoin secp256k1 C library.
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 := "iaa1rgnu8grzt6mwnjg7jss7w0sfyjn67g4et0hzfz" 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("iaa1rgnu8grzt6mwnjg7jss7w0sfyjn67g4et0hzfz") 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 := "iaa1rgnu8grzt6mwnjg7jss7w0sfyjn67g4et0hzfz" 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("iaa1rgnu8grzt6mwnjg7jss7w0sfyjn67g4et0hzfz") 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).
kv
tx
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