gosdk

package module
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

README

OKChain Go SDK

CircleCI codecov Go Report Card license LoC GolangCI

OKChain Go SDK is a lightweight Go library to interact with OKChain.

1. Components

  • client.go - The main client of GO SDK is created in this file. Developers are supposed to set up the config with own requirement during the client creation.
  • expose - Abstraction with the interfaces of each module. The implements of it are filled in the folder module.
  • module - The main logic for GO SDK queries and txs are classfied by their own module names in OKChain. Developers can find out the concrete designs under the specific module folder. Please focus on the files, tx.go and query.go.
  • mocks - Mock client tools for unit test of the main client in GO SDK.
  • sample - A clear short user guild is showed here.
  • types - The necessary struct set of OKChain is built here. Developers are allowed to import some basic types like Dec and AccAddress directly if they want.
  • utils - A useful tool set for the one who is going to send more transcations and queries is spilted by module names as the file names. Beyond that, the operation of account keys with mnemonics remains in the file account.go.

2. Installation

Go version above 1.12 is required.

The developer can get the OKChain Go SDK directly by git clone from github : https://github.com/okex/okchain-go-sdk

3. API

The api functions of transactions and queries are all under the path expose. You can find more details in okchain-docs : https://okchain-docs.readthedocs.io/zh_CN/latest/api/sdk/go-sdk.html

4. Tendermint query

OKChain Go SDK also provides node query functions so that the underlying information of the blockchain is available for developers.

The tendermint query functions could be found in the file exposed/tendermint.go . Developers could make it through with the file module/tendermint/query.go and get clear how to invoke them.

5. Example

Client seems necessary to every operation with Go SDK. Here are the examples :

	// rpcURL should be modified according to the actual situation
	rpcURL   = "3.13.150.20:26657"
	name     = "alice"
	passWd   = "12345678"
	mnemonic = "dumb thought reward exhibit quick manage force imitate blossom vendor ketchup sniff"
	addr     = "okchain1hw4r48aww06ldrfeuq2v438ujnl6alszzzqpph"
	
	// build the client with own config
	config, _ := sdk.NewClientConfig(rpcURL, "okchain", sdk.BroadcastBlock, "0.01okt", 20000, 0, "")
	client := sdk.NewClient(config)

	// create your account key info by 'name','passWd' and 'mnemonic'
	keyInfo, _, _ := utils.CreateAccountWithMnemo(mnemonic, name, passWd)

	// get info of your account from OKChain
	accInfo, _ := client.Auth().QueryAccount(keyInfo.GetAddress().String())

	// transfer some okt to addr
	res, _ := client.Token().Send(keyInfo, passWd, addr, "0.1024okt", "my memno", accInfo.GetAccountNumber(), accInfo.GetSequence())

You can invoke more and more api functions with the object client.

6. Testing

All changes and addition of codes will be pushed with unit tests strictly.

7. Contributing

No doubt that it's admirable to make contributions to OKChain Go SDK. You can provide your code as long as you have tested it with a local client and your unit test showed its validity.

Documentation

Index

Constants

View Source
const (
	BroadcastSync  = sdk.BroadcastSync
	BroadcastAsync = sdk.BroadcastAsync
	BroadcastBlock = sdk.BroadcastBlock

	// vote for the proposal
	VoteYes        = "yes"
	VoteAbstain    = "abstain"
	VoteNo         = "no"
	VoteNoWithVeto = "no_with_veto"
)

const

Variables

View Source
var (
	// NewClientConfig gives an easy way for the callers to set client config
	NewClientConfig = sdk.NewClientConfig
)

Functions

This section is empty.

Types

type Account

type Account = auth.Account

auth

type AccountTokensInfo

type AccountTokensInfo = token.AccountTokensInfo

nolint

type Block

type Block = tendermint.Block

tendermint

type BlockResults

type BlockResults = tendermint.BlockResults

nolint

type BookRes

type BookRes = order.BookRes

order

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client - structure of the main client of okchain gosdk

func NewClient

func NewClient(config sdk.ClientConfig) Client

NewClient creates a new instance of Client

func (*Client) Auth

func (cli *Client) Auth() exposed.Auth

nolint

func (*Client) Backend

func (cli *Client) Backend() exposed.Backend

func (*Client) Dex

func (cli *Client) Dex() exposed.Dex

func (*Client) Distribution

func (cli *Client) Distribution() exposed.Distribution

func (*Client) GetConfig

func (cli *Client) GetConfig() sdk.ClientConfig

GetConfig returns the client config

func (*Client) Governance added in v0.11.0

func (cli *Client) Governance() exposed.Governance

func (*Client) Order

func (cli *Client) Order() exposed.Order

func (*Client) Slashing

func (cli *Client) Slashing() exposed.Slashing

func (*Client) Staking

func (cli *Client) Staking() exposed.Staking

func (*Client) Tendermint

func (cli *Client) Tendermint() exposed.Tendermint

func (*Client) Token

func (cli *Client) Token() exposed.Token

type Deal

type Deal = backend.Deal

nolint

type DelegatorResp

type DelegatorResp = staking.DelegatorResp

nolint

type MatchResult

type MatchResult = backend.MatchResult

nolint

type Order

type Order = backend.Order

nolint

type OrderDetail

type OrderDetail = order.OrderDetail

nolint

type Proposal added in v0.11.0

type Proposal = governance.Proposal

governance

type ResultCommit

type ResultCommit = tendermint.ResultCommit

nolint

type ResultTx

type ResultTx = tendermint.ResultTx

nolint

type ResultTxs

type ResultTxs = tendermint.ResultTxs

nolint

type ResultValidators

type ResultValidators = tendermint.ResultValidators

nolint

type Ticker

type Ticker = backend.Ticker

backend

type Token

type Token = token.Token

token

type TokenPair

type TokenPair = dex.TokenPair

dex

type TxResponse

type TxResponse = sdk.TxResponse

nolint

type Validator

type Validator = staking.Validator

staking

Directories

Path Synopsis
dex
Package types is a generated GoMock package.
Package types is a generated GoMock package.
crypto/keys/hd
Package hd provides basic functionality Hierarchical Deterministic Wallets.
Package hd provides basic functionality Hierarchical Deterministic Wallets.
tx

Jump to

Keyboard shortcuts

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