sdk

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: Apache-2.0 Imports: 12 Imported by: 1

README

Core SDK

Golang SDK for Tendermint & Cosmos-SDK Core Modules

install

Requirement

Go version above 1.16.4

Use Go Mod

replace (
    github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4
    github.com/tendermint/tendermint => github.com/bianjieai/tendermint v0.34.1-irita-210113
)

Init Client

The initialization SDK code is as follows:

    bech32AddressPrefix := types.AddrPrefixCfg{
        AccountAddr:   "iaa",
        ValidatorAddr: "iva",
        ConsensusAddr: "ica",
        AccountPub:    "iap",
        ValidatorPub:  "ivp",
        ConsensusPub:  "icp",
    }
    options := []types.Option{
        types.KeyDAOOption(store.NewMemory(nil)),
        types.TimeoutOption(10),
        types.TokenManagerOption(TokenManager{}),
        types.KeyManagerOption(crypto.NewKeyManager()),
        types.Bech32AddressPrefixOption(bech32AddressPrefix),
        types.BIP44PathOption(""),
    }
    cfg, err := types.NewClientConfig(nodeURI, grpcAddr, chainID, options...)
    if err != nil {
        panic(err)
    }
    
    s.Client = sdk.NewClient(cfg)

The NewClientConfig 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
GRPCAddr string The GRPC address of the IRIShub node connected to the SDK, for example: localhost: 9090
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:

There is more example of query and send tx

    coins, err := types.ParseDecCoins("10iris")
    to := "iaa1hp29kuh22vpjjlnctmyml5s75evsnsd8r4x0mm"
    baseTx := types.BaseTx{
        From:               s.Account().Name,
        Gas:                200000,
        Memo:               "TEST",
        Mode:               types.Commit,
        Password:          "password",
        SimulateAndExecute: false,
        GasAdjustment:      1.5,
    }
    
    res, err := s.Bank.Send(to, coins, baseTx)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterInterfaces

func RegisterInterfaces(registry cryptotypes.InterfaceRegistry)

RegisterInterfaces registers the sdk message type.

func RegisterLegacyAminoCodec

func RegisterLegacyAminoCodec(cdc *commoncodec.LegacyAmino)

RegisterLegacyAminoCodec registers the sdk message type.

Types

type Client

type Client struct {
	types.BaseClient
	Bank     bank.Client
	Key      keys.Client
	Staking  staking.Client
	Gov      gov.Client
	Transfer transfer.Client
	FeeGrant feegrant.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg types.ClientConfig) Client

func (*Client) AppCodec

func (client *Client) AppCodec() commoncodec.Marshaler

func (*Client) Codec

func (client *Client) Codec() *commoncodec.LegacyAmino

func (*Client) EncodingConfig

func (client *Client) EncodingConfig() types.EncodingConfig

func (*Client) Manager

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

func (*Client) Module

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

func (*Client) RegisterModule

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

func (*Client) SetLogger

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

Directories

Path Synopsis
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
codec/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.
codec/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
codec/unknownproto
unknownproto implements functionality to "type check" protobuf serialized byte sequences against an expected proto.Message to report:
unknownproto implements functionality to "type check" protobuf serialized byte sequences against an expected proto.Message to report:
nolint:gocritic
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/codec.go
ibc
third_party
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
kv
rpc
tx

Jump to

Keyboard shortcuts

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