gosdk

package module
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: MIT Imports: 16 Imported by: 0

README

mondo golang-sdk

[TOC]

重要说明

  • REST-API SDK访问mondo 的API程序,查询代币转账记录需要API事先配置代币信息生成转账记录
  • 执行OLO转账时,接收方账户如果不存在会自动创建,不额外消耗gas,因此OLO转账使用固定gas:21000
  • 执行代币转账时,接收方账户如果不存在会自动创建,额外消耗gas数量32000,代币转账gas建议值:100000
  • 执行代币转账自动创建的账户没有OLO账户,需要额外创建

方法索引

REST-API SDK
方法 功能 备注
GenKey 生成OLO以及基于OLO的代币账户
ValidAddress 检查是否式合法的OLO地址
ValidPublicKey 检查是否式合法的OLO公钥
Exist 检查账户是否已在链上存在
GetBalance 查询OLO账户余额
Payment OLO转账
Payments 批量OLO转账
V3GetLedgers 查询所有账本(区块)
V3GetLedger 根据高度查询账本(区块)
V3GetLedgerTransactions 根据高度查询交易
V3GetLedgerPayments 根据高度查询转账记录
V3GetTransactions 代币交易
V3GetTransaction 指定交易hash查询交易
V3GetPayments 查询所有转账记录
V3GetTxPayments 根据交易hash查询转账记录
V3GetAccountPayments 根据账户地址查询转账记录
ERC20BalanceOf 查询代币余额
ERC20Pay 代币转账
BuildEvmTx 生成EVM交易
SendEvmTx 发送EVM交易
CheckTx 检查交易是否上链并处理成功
CheckTxWithCtx 检查交易是否上链并处理成功

Documentation

Index

Constants

View Source
const (
	MODE_DEFAULT = "commit"
	MODE_ASYNC   = "async"
	MODE_SYNC    = "sync"
)
View Source
const VERSION = "gosdk-v1.3.0"

Variables

This section is empty.

Functions

func BytesToHex

func BytesToHex(bz []byte) string

func GenKey

func GenKey() (string, string, string, error)

GenKey 本地生成mondo链格式的账户 返回:公钥,地址,私钥,mondo采用压缩公钥

func HexToBytes

func HexToBytes(str string) []byte

func RLPHash

func RLPHash(x interface{}) (h ethcmn.Hash)

func ValidAddress

func ValidAddress(address string) bool

ValidAddress 校验地址是否合法

func ValidPublicKey

func ValidPublicKey(publicKey string) bool

ValidPublicKey 校验是否是合法公钥

Types

type APIClient

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

func NewAPIClient

func NewAPIClient(addr string) *APIClient

NewAPIClient new mondo api client,addr is mondo api http base url,like http://127.0.0.1:8889

func (*APIClient) BuildEvmTx

func (cli *APIClient) BuildEvmTx(senderPubKey, senderPriKey, receiver, value string, load string,
	gasLimit uint64, gasPrice string, memo string) (*types.TxEvm, error)

BuildEvmTx 生成一个EVM交易

func (*APIClient) CheckTx

func (cli *APIClient) CheckTx(hash string) (bool, error)

CheckTx 检查交易是否已上链,并处理成功

func (*APIClient) CheckTxWithCtx

func (cli *APIClient) CheckTxWithCtx(ctx context.Context, hash string) (bool, error)

CheckTxWithCtx 检查交易是否已上链,并处理成功.ctx应待deadline

func (*APIClient) DeployTx

func (cli *APIClient) DeployTx(mode string, senderPubKey, senderPriKey,
	value string, load string, gasLimit uint64, gasPrice string, memo string) (string, string, uint64, error)

DeployTx 部署合约 返回交易hash,合约地址,gas消耗,错误信息 大多数错误evm错误都是gas不足导致的,排查问题时首先提高gasLimit

func (*APIClient) ERC20BalanceOf

func (cli *APIClient) ERC20BalanceOf(senderPubKey, senderPriKey, contractAddr, address string) (*big.Int, error)

ERC20BalanceOf 查询ERC20代币账户余额 此方法不消耗gas,不上链

func (*APIClient) ERC20Pay

func (cli *APIClient) ERC20Pay(mode string, senderPubKey, senderPriKey, contractAddr, receiver,
	value string, gasLimit uint64, gasPrice string, memo string) (string, uint64, error)

ERC20Pay ERC20代币转账,返回交易hash、使用的gas数量、错误信息

func (*APIClient) Exist

func (cli *APIClient) Exist(address string) (bool, error)

Exist 用户是否在链上存在 输入:地址或者公钥

func (*APIClient) GetAccount

func (cli *APIClient) GetAccount(address string) (string, uint64, error)

GetAccount 获取账户信息,返回余额、nonce,如果账户未上链,返回余额为0,nonce为0

func (*APIClient) GetBalance

func (cli *APIClient) GetBalance(address string) (*big.Int, error)

GetBalance 获取账户余额 输入:账户地址或者公钥 输出:如果账户未上链返回余额0,error为nil;如果error不为空表示出错

func (*APIClient) GetContract

func (cli *APIClient) GetContract(address string) (*big.Int, uint64, string, bool, error)

GetContract 获取合约 输入:合约地址 输出:余额、nonce、合约字节码、是否已自杀、错误信息;如果合约不存在,返回错误;如果是普通地址,正确返回;

func (*APIClient) GetNonce

func (cli *APIClient) GetNonce(address string) uint64

GetNonce 获取账户nonce

func (*APIClient) InvokeTx

func (cli *APIClient) InvokeTx(mode string, senderPubKey, senderPriKey, receiver, value string, load string,
	gasLimit uint64, gasPrice string, memo string) (string, string, uint64, error)

InvokeTx 调用合约 返回 交易hash,合约执行返回字节码,gas消耗,错误信息

func (*APIClient) Payment

func (cli *APIClient) Payment(mode string, senderPubKey, senderPriKey, receiver, value string, gasLimit uint64, gasPrice string, memo string) (string, error)

Payment 发送签名交易 mode:交易模式 默认为commit模式:交易上链后返回 async:异步模式,节点成功接收交易后返回 sync:同步模式,节点对基本参数校验完成后返回 senderPubKey:转出方公钥 senderPriKey:转出方私钥 receiver:接收方公钥或地址 value:转账金额(实际金额*1e8) gasLimit:gas限额,普通转账21000 gasPrice:建议值1 返回交易hash和错误信息

func (*APIClient) Payments

func (cli *APIClient) Payments(mode string, senderPubKey, senderPriKey string, pays []Operation, gasLimit uint64, gasPrice string, memo string) (string, error)

Payments 发送批量交易 1vN gasLimit:len(pays)*21000

func (*APIClient) QueryTx

func (cli *APIClient) QueryTx(senderPubKey, senderPriKey, receiver, value string, load string, gasLimit uint64, gasPrice string) (string, uint64, error)

QueryTx 查询合约 用于估算gas消耗或者调用合约的只读方法查数据 只在本节点evm内查询,不形成交易,不上链;在不同的节点查询结果可能不一致(节点高度不一致); 返回 合约执行返回字节码,gas消耗,错误信息

func (*APIClient) SendEvmTx

func (cli *APIClient) SendEvmTx(mode string, tx *types.TxEvm) error

SendEvmTx 通过API发送EVM Tx

func (*APIClient) SendMultisigEvmTx

func (cli *APIClient) SendMultisigEvmTx(mode string, tx *types.MultisigEvmTx) error

SendMultisigEvmTx 发送多签交易

func (*APIClient) V3GetAccountPayments

func (cli *APIClient) V3GetAccountPayments(address string, cursor, limit int64, order string) ([]V3Payment, error)

V3GetAccountPayments 指定账户查payment,账户可以是地址,也可以是公钥

func (*APIClient) V3GetAccountTransactions

func (cli *APIClient) V3GetAccountTransactions(address string, cursor, limit int64, order string) ([]V3Transaction, error)

V3GetAccountTransactions 指定账户查payment

func (*APIClient) V3GetLedger

func (cli *APIClient) V3GetLedger(height int64) (*V3Ledger, error)

V3GetLedger 指定高度查询账本(区块)

func (*APIClient) V3GetLedgerPayments

func (cli *APIClient) V3GetLedgerPayments(height int64, cursor, limit int64, order string) ([]V3Payment, error)

V3GetLedgerPayments 指定高度查账本

func (*APIClient) V3GetLedgerTransactions

func (cli *APIClient) V3GetLedgerTransactions(height int64, cursor, limit int64, order string) ([]V3Transaction, error)

V3GetLedgerTransactions 指定高度查tx

func (*APIClient) V3GetLedgers

func (cli *APIClient) V3GetLedgers(cursor, limit int64, order string) ([]V3Ledger, error)

V3GetLedgers 查询所有账本(区块)

func (*APIClient) V3GetPayments

func (cli *APIClient) V3GetPayments(symbol string, cursor, limit int64, order string) ([]V3Payment, error)

V3GetPayments 查询所有转账记录 symbol:币种,例如OLO,大写,为空时查询所有币种的转账记录

func (*APIClient) V3GetTransaction

func (cli *APIClient) V3GetTransaction(tx string) (*V3Transaction, error)

V3GetTransaction 指定hash查交易

func (*APIClient) V3GetTransactions

func (cli *APIClient) V3GetTransactions(cursor, limit int64, order string) ([]V3Transaction, error)

V3GetTransactions 查询所有交易

func (*APIClient) V3GetTxPayments

func (cli *APIClient) V3GetTxPayments(tx string, cursor, limit int64, order string) ([]V3Payment, error)

V1GetTxPayments 指定交易hash查payment

type MultiSignature

type MultiSignature struct {
	PubKey     PubKeyMultisigThreshold `json:"pubKey"`     // 多签公钥
	Signatures []string                `json:"signatures"` // 用户签名列表
}

type Operation

type Operation struct {
	To    string `json:"to"`    // 合约地址
	Value string `json:"value"` //
}

type PubKeyMultisigThreshold

type PubKeyMultisigThreshold struct {
	K       int      `json:"threshold"` // 多签阈值
	PubKeys []string `json:"pubkeys"`   // 多签用户公钥列表
}

type SignedBatchTx

type SignedBatchTx struct {
	Mode      int         `json:"mode"`      // 模式:0-default/commit 1-async 2-sync
	CreatedAt uint64      `json:"createdAt"` // unix nano
	GasLimit  uint64      `json:"gasLimit"`  //
	GasPrice  string      `json:"gasPrice"`  //
	Nonce     uint64      `json:"nonce"`     //
	Sender    string      `json:"sender"`    // address
	Ops       []Operation `json:"operations"`
	Memo      string      `json:"memo"`      // 备注
	Signature string      `json:"signature"` // hex编码
}

批量交易

type SignedEvmTx

type SignedEvmTx struct {
	Mode      int    `json:"mode"`      // 模式:0-default/commit 1-async 2-sync
	CreatedAt uint64 `json:"createdAt"` // 时间戳unixNano
	GasLimit  uint64 `json:"gasLimit"`  //
	GasPrice  string `json:"gasPrice"`  //
	Nonce     uint64 `json:"nonce"`     //
	Sender    string `json:"sender"`    // pubkey
	Body      struct {
		To    string `json:"to"`    // 合约地址
		Value string `json:"value"` //
		Load  string `json:"load"`  // hex编码
		Memo  string `json:"memo"`  // 备注
	} `json:"body"`
	Signature string `json:"signature"` // hex编码
}

type SignedMultisigEvmTx

type SignedMultisigEvmTx struct {
	Mode     int    `json:"mode"`     // 交易模式,默认为0;0-同步模式 1-全异步 2-半异步;如果tx执行时间较长、网络不稳定、出块慢,建议使用半异步模式。
	Deadline uint64 `json:"deadline"` // 有效截止时间
	GasLimit uint64 `json:"gasLimit"` // gas限额
	GasPrice string `json:"gasPrice"` // gas价格,最低为1
	From     string `json:"from"`     // 多签账户地址
	Nonce    uint64 `json:"nonce"`    // 多签账户nonce
	To       string `json:"to"`       // 交易接受者地址或合约地址
	Value    string `json:"value"`    // 交易金额
	Load     string `json:"load"`     // 合约负载,普通原声币转账时为空
	Memo     string `json:"memo"`     // 备注

	Signature MultiSignature `json:"signature"` // 交易签名
}

----合约相关

type V3Ledger

type V3Ledger struct {
	Id         uint64    `db:"id" json:"id"`
	Height     int64     `db:"height" json:"height"`
	BlockHash  string    `db:"blockHash" json:"blockHash"`
	BlockSize  int       `db:"blockSize" json:"blockSize"`
	Validator  string    `db:"validator" json:"validator"`
	TxCount    int64     `db:"txCount" json:"txCount"`
	GasLimit   int64     `db:"gasLimit" json:"gasLimit"`
	GasUsed    int64     `db:"gasUsed" json:"gasUsed"`
	GasPrice   string    `db:"gasPrice" json:"gasPrice"`
	CreatedAt  time.Time `db:"createdAt" json:"createdAt"`
	TotalPrice *big.Int  `db:"-" json:"-"`
}

type V3Payment

type V3Payment struct {
	Id        uint64    `db:"id" json:"id"`
	Hash      string    `db:"hash" json:"hash"`
	Height    int64     `db:"height" json:"height"`
	Idx       int       `db:"idx" json:"idx"`
	Sender    string    `db:"sender" json:"sender"`
	Receiver  string    `db:"receiver" json:"receiver"`
	Symbol    string    `db:"symbol" json:"symbol"`
	Contract  string    `db:"contract" json:"contract"`
	Value     string    `db:"value" json:"value"`
	CreatedAt time.Time `db:"createdAt" json:"createdAt"`
}

type V3Transaction

type V3Transaction struct {
	Id        uint64    `db:"id" json:"id"`
	Hash      string    `db:"hash" json:"hash"`
	Height    int64     `db:"height" json:"height"`
	Typei     int       `db:"typei" json:"typei"`
	Types     string    `db:"types" json:"types"`
	Sender    string    `db:"sender" json:"sender"`
	Nonce     int64     `db:"nonce" json:"nonce"`
	Receiver  string    `db:"receiver" json:"receiver"`
	Value     string    `db:"value" json:"value"`
	GasLimit  int64     `db:"gasLimit" json:"gasLimit"`
	GasUsed   int64     `db:"gasUsed" json:"gasUsed"`
	GasPrice  string    `db:"gasPrice" json:"gasPrice"`
	Memo      string    `db:"memo" json:"memo"`
	Payload   string    `db:"payload" json:"payload"`
	Events    string    `db:"events" json:"events"`
	Codei     uint32    `db:"codei" json:"codei"`
	Codes     string    `db:"codes" json:"codes"`
	CreatedAt time.Time `db:"createdAt" json:"createdAt"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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