utils

package
v0.0.0-...-86e039a Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: LGPL-3.0 Imports: 40 Imported by: 0

Documentation

Overview

* Copyright (C) 2019 The onyxchain Authors * This file is part of The onyxchain library. * * The onyxchain is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The onyxchain is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with The onyxchain. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	DEFAULT_COMPRESS_TYPE         = COMPRESS_TYPE_ZLIB
	EXPORT_BLOCK_METADATA_LEN     = 256
	EXPORT_BLOCK_METADATA_VERSION = 1
)
View Source
const (
	DEFAULT_EXPORT_FILE   = "./OnxBlocks.dat"
	DEFAULT_ABI_PATH      = "./abi"
	DEFAULT_EXPORT_HEIGHT = 0
	DEFAULT_WALLET_PATH   = "./wallet_data"
)
View Source
const (
	VERSION_TRANSACTION    = byte(0)
	VERSION_CONTRACT_ONX   = byte(0)
	VERSION_CONTRACT_OXG   = byte(0)
	CONTRACT_TRANSFER      = "transfer"
	CONTRACT_TRANSFER_FROM = "transferFrom"
	CONTRACT_APPROVE       = "approve"

	ASSET_ONX = "onyx"
	ASSET_OXG = "oxg"
)
View Source
const (
	PARAMS_SPLIT          = ","
	PARAM_TYPE_SPLIT      = ":"
	PARAM_TYPE_ARRAY      = "array"
	PARAM_TYPE_BYTE_ARRAY = "bytearray"
	PARAM_TYPE_STRING     = "string"
	PARAM_TYPE_INTEGER    = "int"
	PARAM_TYPE_BOOLEAN    = "bool"
	PARAM_LEFT_BRACKET    = "["
	PARAM_RIGHT_BRACKET   = "]"
	PARAM_ESC_CHAR        = `/`
)
View Source
const (
	ERROR_INVALID_PARAMS    = rpcerr.INVALID_PARAMS
	ERROR_ONYXCHAIN_COMMON  = 10000
	ERROR_ONYXCHAIN_SUCCESS = 0
)
View Source
const (
	PRECISION_OXG = 9
	PRECISION_ONX = 0
)
View Source
const (
	COMPRESS_TYPE_ZLIB = iota
)
View Source
const JSON_RPC_VERSION = "2.0"

JsonRpc version

Variables

View Source
var (
	//OnyxChain setting
	ConfigFlag = cli.StringFlag{
		Name:  "config",
		Usage: "Genesis block config `<file>`. If doesn't specifies, use main net config as default.",
	}
	LogLevelFlag = cli.UintFlag{
		Name:  "loglevel",
		Usage: "Set the log level to `<level>` (0~6). 0:Trace 1:Debug 2:Info 3:Warn 4:Error 5:Fatal 6:MaxLevel",
		Value: config.DEFAULT_LOG_LEVEL,
	}
	DisableEventLogFlag = cli.BoolFlag{
		Name:  "disable-event-log",
		Usage: "Discard event log output by smart contract execution",
	}
	WalletFileFlag = cli.StringFlag{
		Name:  "wallet,w",
		Value: config.DEFAULT_WALLET_FILE_NAME,
		Usage: "Wallet `<file>`",
	}
	ImportFileFlag = cli.StringFlag{
		Name:  "import-file",
		Usage: "Path of import `<file>`",
		Value: DEFAULT_EXPORT_FILE,
	}
	ImportEndHeightFlag = cli.UintFlag{
		Name:  "end-height",
		Usage: "Stop import block `<height>` of the import.",
		Value: DEFAULT_EXPORT_HEIGHT,
	}
	DataDirFlag = cli.StringFlag{
		Name:  "data-dir",
		Usage: "Block data storage `<path>`",
		Value: config.DEFAULT_DATA_DIR,
	}
	CertFileFlag = cli.StringFlag{
		Name:  "cert-file",
		Usage: "Path to a `<file>` with TLS certificate",
		Value: "",
	}
	KeyFileFlag = cli.StringFlag{
		Name:  "key-file",
		Usage: "Path to a `<file>` with TLS private key",
		Value: "",
	}

	//Consensus setting
	EnableConsensusFlag = cli.BoolFlag{
		Name:  "enable-consensus",
		Usage: "Start consensus module",
	}
	MaxTxInBlockFlag = cli.IntFlag{
		Name:  "max-tx-in-block",
		Usage: "Max transaction `<number>` in block",
		Value: config.DEFAULT_MAX_TX_IN_BLOCK,
	}
	GasLimitFlag = cli.Uint64Flag{
		Name:  "gaslimit",
		Usage: "Min gas limit `<value>` of transaction to be accepted by tx pool.",
		Value: neovm.MIN_TRANSACTION_GAS,
	}
	GasPriceFlag = cli.Uint64Flag{
		Name:  "gasprice",
		Usage: "Min gas price `<value>` of transaction to be accepted by tx pool.",
		Value: config.DEFAULT_GAS_PRICE,
	}

	//Test Mode setting
	EnableTestModeFlag = cli.BoolFlag{
		Name:  "testmode",
		Usage: "Single node network for testing. In test mode, will start rpc, rest, web socket server, and set default gasprice to 0",
	}
	TestModeGenBlockTimeFlag = cli.UintFlag{
		Name:  "testmode-gen-block-time",
		Usage: "Block-out `<time>`(s) in test mode.",
		Value: config.DEFAULT_GEN_BLOCK_TIME,
	}

	//P2P setting
	ReservedPeersOnlyFlag = cli.BoolFlag{
		Name:  "reserved-only",
		Usage: "Connect reserved peers only. Reserved peers are configured with --reserved-file.",
	}
	ReservedPeersFileFlag = cli.StringFlag{
		Name:  "reserved-file",
		Usage: "Reserved peers `<file>`",
		Value: config.DEFAULT_RESERVED_FILE,
	}
	NetworkIdFlag = cli.UintFlag{
		Name:  "networkid",
		Usage: "Network id `<number>`. 1=onyxchain main net, 2=polaris test net, 3=testmode, and other for custom network",
		Value: config.NETWORK_ID_MAIN_NET,
	}
	NodePortFlag = cli.UintFlag{
		Name:  "nodeport",
		Usage: "P2P network port `<number>`",
		Value: config.DEFAULT_NODE_PORT,
	}
	DualPortSupportFlag = cli.BoolFlag{
		Name:  "dual-port",
		Usage: "Enable a dual network, P2P network for transaction messages and for consensus messages.",
	}
	ConsensusPortFlag = cli.UintFlag{
		Name:  "consensus-port",
		Usage: "Consensus network port `<number>`. Effectively after set --dual-port parameter",
		Value: config.DEFAULT_CONSENSUS_PORT,
	}
	HttpInfoPortFlag = cli.UintFlag{
		Name:  "httpinfo-port",
		Usage: "The listening port of http server for viewing node information `<number>`",
		Value: config.DEFAULT_HTTP_INFO_PORT,
	}
	MaxConnInBoundFlag = cli.UintFlag{
		Name:  "max-conn-in-bound",
		Usage: "Max connection `<number>` in bound",
		Value: config.DEFAULT_MAX_CONN_IN_BOUND,
	}
	MaxConnOutBoundFlag = cli.UintFlag{
		Name:  "max-conn-out-bound",
		Usage: "Max connection `<number>` out bound",
		Value: config.DEFAULT_MAX_CONN_OUT_BOUND,
	}
	MaxConnInBoundForSingleIPFlag = cli.UintFlag{
		Name:  "max-conn-in-bound-single-ip",
		Usage: "Max connection `<number>` in bound for single ip",
		Value: config.DEFAULT_MAX_CONN_IN_BOUND_FOR_SINGLE_IP,
	}
	// RPC settings
	RPCDisabledFlag = cli.BoolFlag{
		Name:  "disable-rpc",
		Usage: "Shut down the rpc server.",
	}
	RPCPortFlag = cli.UintFlag{
		Name:  "rpcport",
		Usage: "Json rpc server listening port `<number>`",
		Value: config.DEFAULT_RPC_PORT,
	}
	RPCLocalEnableFlag = cli.BoolFlag{
		Name:  "localrpc",
		Usage: "Enable local rpc server",
	}
	RPCLocalProtFlag = cli.UintFlag{
		Name:  "localrpcport",
		Usage: "Json rpc local server listening port `<number>`",
		Value: config.DEFAULT_RPC_LOCAL_PORT,
	}

	//Websocket setting
	WsEnabledFlag = cli.BoolFlag{
		Name:  "ws",
		Usage: "Enable web socket server",
	}
	WsPortFlag = cli.UintFlag{
		Name:  "wsport",
		Usage: "Ws server listening port `<number>`",
		Value: config.DEFAULT_WS_PORT,
	}

	//Restful setting
	RestfulEnableFlag = cli.BoolFlag{
		Name:  "rest",
		Usage: "Enable restful api server",
	}
	RestfulPortFlag = cli.UintFlag{
		Name:  "restport",
		Usage: "Restful server listening port `<number>`",
		Value: config.DEFAULT_REST_PORT,
	}
	RestfulMaxConnsFlag = cli.UintFlag{
		Name:  "restmaxconns",
		Usage: "Restful server maximum connections `<number>`",
		Value: config.DEFAULT_REST_MAX_CONN,
	}

	//Account setting
	AccountPassFlag = cli.StringFlag{
		Name:   "password,p",
		Hidden: true,
		Usage:  "Account `<password>` when OnyxChain node starts.",
	}
	AccountAddressFlag = cli.StringFlag{
		Name:  "account,a",
		Usage: "Account `<address>` when the OnyxChain node starts. If not specific, using default account instead",
	}
	AccountDefaultFlag = cli.BoolFlag{
		Name:  "default,d",
		Usage: "Default settings to create a new account (equal to '-t ecdsa -b 256 -s SHA256withECDSA')",
	}
	AccountTypeFlag = cli.StringFlag{
		Name:  "type,t",
		Usage: "Specifies the `<key-type>` by signature algorithm.",
	}
	AccountKeylenFlag = cli.StringFlag{
		Name:  "bit-length,b",
		Usage: "Specifies the `<bit-length>` of key",
	}
	AccountSigSchemeFlag = cli.StringFlag{
		Name:  "signature-scheme,s",
		Usage: "Specifies the signature scheme `<scheme>`",
	}
	AccountSetDefaultFlag = cli.BoolFlag{
		Name:  "as-default,d",
		Usage: "Set the specified account to default account of wallet",
	}
	AccountQuantityFlag = cli.UintFlag{
		Name:  "number,n",
		Value: 1,
		Usage: "Specifies the `<quantity>` of account to create.",
	}
	AccountSourceFileFlag = cli.StringFlag{
		Name:  "source,s",
		Usage: "Source wallet `<file>` to import",
	}
	AccountLabelFlag = cli.StringFlag{
		Name:  "label,l",
		Usage: "Set account `<label>` for easy and fast use of accounts.",
	}
	AccountKeyFlag = cli.StringFlag{
		Name:  "key,k",
		Usage: "Use `<private key>` (hex encoding) of the account",
	}
	AccountVerboseFlag = cli.BoolFlag{
		Name:  "verbose,v",
		Usage: "Display accounts with details",
	}
	AccountChangePasswdFlag = cli.BoolFlag{
		Name:  "change-passwd",
		Usage: "Change account password",
	}
	AccountLowSecurityFlag = cli.BoolFlag{
		Name:  "low-security",
		Usage: "Change account to low protection strength for low performance devices",
	}
	AccountWIFFlag = cli.BoolFlag{
		Name:  "wif",
		Usage: "Import WIF keys from the source file specified by --source option",
	}
	AccountMultiMFlag = cli.UintFlag{
		Name:  "m",
		Usage: "Min signature `<number>` of multi signature address",
		Value: 1,
	}
	AccountMultiPubKeyFlag = cli.StringFlag{
		Name:  "pubkey",
		Usage: "Pub key list of multi `<addresses>`, separate addreses with comma `,`",
	}
	IdentityFlag = cli.BoolFlag{
		Name:  "onxid",
		Usage: "create an ONX ID instead of account",
	}

	//SmartContract setting
	ContractAddrFlag = cli.StringFlag{
		Name:  "address",
		Usage: "Contract `<address>`",
	}
	ContractStorageFlag = cli.BoolFlag{
		Name:  "needstore",
		Usage: "Is need use storage in contract",
	}
	ContractCodeFileFlag = cli.StringFlag{
		Name:  "code",
		Usage: "File path of contract code `<path>`",
	}
	ContractNameFlag = cli.StringFlag{
		Name:  "name",
		Usage: "Specifies contract name to `<name>`",
	}
	ContractVersionFlag = cli.StringFlag{
		Name:  "version",
		Usage: "Specifies contract version to `<ver>`",
	}
	ContractAuthorFlag = cli.StringFlag{
		Name:  "author",
		Usage: "Set `<address>` as the contract owner",
		Value: "",
	}
	ContractEmailFlag = cli.StringFlag{
		Name:  "email",
		Usage: "Set `<email>` owner's email address",
		Value: "",
	}
	ContractDescFlag = cli.StringFlag{
		Name:  "desc",
		Usage: "Set `<text>` as the description of the contract",
		Value: "",
	}
	ContractParamsFlag = cli.StringFlag{
		Name:  "params",
		Usage: "Contract parameters list to invoke. separate params with comma ','",
	}
	ContractPrepareDeployFlag = cli.BoolFlag{
		Name:  "prepare,p",
		Usage: "Prepare deploy contract without commit to ledger",
	}
	ContractPrepareInvokeFlag = cli.BoolFlag{
		Name:  "prepare,p",
		Usage: "Prepare invoke contract without commit to ledger",
	}
	ContractReturnTypeFlag = cli.StringFlag{
		Name:  "return",
		Usage: "Return `<type>` of contract. bytearray(hexstring), string, integer, boolean",
	}

	//information cmd settings
	BlockHashInfoFlag = cli.StringFlag{
		Name:  "hash",
		Usage: "Get block info by block hash",
	}
	BlockHeightInfoFlag = cli.UintFlag{
		Name:  "height",
		Usage: "Get block info by block height",
	}

	//Transfer setting
	TransactionAssetFlag = cli.StringFlag{
		Name:  "asset",
		Usage: "Asset of ONX or OXG",
		Value: ASSET_ONX,
	}
	TransactionFromFlag = cli.StringFlag{
		Name:  "from",
		Usage: "Transfer-out account `<address>`",
	}
	TransactionToFlag = cli.StringFlag{
		Name:  "to",
		Usage: "Transfer-in account `<address>`",
	}
	TransactionAmountFlag = cli.StringFlag{
		Name:  "amount",
		Usage: "Transfer `<amount>`. Float number",
	}
	TransactionHashFlag = cli.StringFlag{
		Name:  "hash",
		Usage: "Transaction `<hash>`",
	}
	TransactionGasPriceFlag = cli.Uint64Flag{
		Name:  "gasprice",
		Usage: "Gas price of transaction",
		Value: config.DEFAULT_GAS_PRICE,
	}
	TransactionGasLimitFlag = cli.Uint64Flag{
		Name:  "gaslimit",
		Usage: "Gas limit of the transaction",
		Value: neovm.MIN_TRANSACTION_GAS,
	}
	TransactionPayerFlag = cli.StringFlag{
		Name:  "payer",
		Usage: "Transaction fee payer `<address>`,Default is the signer address",
	}

	//Asset setting
	ApproveAssetFromFlag = cli.StringFlag{
		Name:  "from",
		Usage: "Transfer-out account `<address>`",
	}
	ApproveAssetToFlag = cli.StringFlag{
		Name:  "to",
		Usage: "Transfer-in account `<address>`",
	}
	ApproveAssetFlag = cli.StringFlag{
		Name:  "asset",
		Usage: "Asset of ONYX of OXG to approve",
		Value: "onyx",
	}
	ApproveAmountFlag = cli.StringFlag{
		Name:  "amount",
		Usage: "Amount of approve. Float number",
	}
	TransferFromAmountFlag = cli.StringFlag{
		Name:  "amount",
		Usage: "Amount of transfer from. Float number",
	}
	TransferFromSenderFlag = cli.StringFlag{
		Name:  "sender",
		Usage: "Sender account `<address>` of transfer from transaction, Default is transfer-to account",
	}
	SendTxFlag = cli.BoolFlag{
		Name:  "send,s",
		Usage: "Send raw transaction to OnyxChain",
	}
	ForceSendTxFlag = cli.BoolFlag{
		Name:  "force,f",
		Usage: "Force to send transaction",
	}
	RawTransactionFlag = cli.StringFlag{
		Name:  "raw-tx",
		Usage: "Raw `<transaction>` encode with hex string",
	}
	PrepareExecTransactionFlag = cli.BoolFlag{
		Name:  "prepare,p",
		Usage: "Prepare execute transaction, without commit to ledger",
	}
	WithdrawOXGReceiveAccountFlag = cli.StringFlag{
		Name:  "receive",
		Usage: "OXG receive `<address>`,Default the same with owner account",
	}
	WithdrawOXGAmountFlag = cli.StringFlag{
		Name:  "amount",
		Usage: "Withdraw amount `<number>`, Float number. Default withdraw all",
	}
	ForceTxFlag = cli.BoolFlag{
		Name:  "force,f",
		Usage: "Force to send transaction",
	}

	//Cli setting
	CliAddressFlag = cli.StringFlag{
		Name:  "cliaddress",
		Usage: "Rpc bind `<address>`",
		Value: config.DEFUALT_CLI_RPC_ADDRESS,
	}
	CliRpcPortFlag = cli.UintFlag{
		Name:  "cliport",
		Usage: "Rpc bind port `<number>`",
		Value: config.DEFAULT_CLI_RPC_PORT,
	}
	CliABIPathFlag = cli.StringFlag{
		Name:  "abi",
		Usage: "Abi `<file>` path",
		Value: DEFAULT_ABI_PATH,
	}
	CliWalletDirFlag = cli.StringFlag{
		Name:  "walletdir",
		Usage: "Wallet data `<path>`",
		Value: DEFAULT_WALLET_PATH,
	}

	//Export setting
	ExportFileFlag = cli.StringFlag{
		Name:  "export-file",
		Usage: "Export `<file>` path",
		Value: DEFAULT_EXPORT_FILE,
	}
	ExportStartHeightFlag = cli.UintFlag{
		Name:  "start-height",
		Usage: "Start block height `<number>` to export",
		Value: DEFAULT_EXPORT_HEIGHT,
	}
	ExportEndHeightFlag = cli.UintFlag{
		Name:  "end-height",
		Usage: "Stop block height `<number>` to export",
		Value: DEFAULT_EXPORT_HEIGHT,
	}
	ExportSpeedFlag = cli.StringFlag{
		Name:  "export-speed",
		Usage: "Export block speed `<level>` (h|m|l), h for high speed, m for middle speed and l for low speed",
		Value: "m",
	}

	//PreExecute switcher
	TxpoolPreExecDisableFlag = cli.BoolFlag{
		Name:  "disable-tx-pool-pre-exec",
		Usage: "Disable preExecute in tx pool",
	}

	//local PreExecute switcher
	DisableSyncVerifyTxFlag = cli.BoolFlag{
		Name:  "disable-sync-verify-tx",
		Usage: "Disable sync verify transaction in interface",
	}

	DisableBroadcastNetTxFlag = cli.BoolFlag{
		Name:  "disable-broadcast-net-tx",
		Usage: "Disable broadcast tx from network in tx pool",
	}

	NonOptionFlag = cli.StringFlag{
		Name:  "option",
		Usage: "this command does not need option, please run directly",
	}
)
View Source
var (
	PARAM_TYPE_SPLIT_INC = string([]byte{0})
	PARAM_SPLIT_INC      = string([]byte{1})
)

Functions

func Approve

func Approve(gasPrice, gasLimit uint64, signer *account.Account, asset, from, to string, amount uint64) (string, error)

func ApproveTx

func ApproveTx(gasPrice, gasLimit uint64, asset string, from, to string, amount uint64) (*types.MutableTransaction, error)

func BuildWasmVMInvokeCode

func BuildWasmVMInvokeCode(smartcodeAddress common.Address, methodName string, paramType wasmvm.ParamType, version byte, params []interface{}) ([]byte, error)

BuildWasmVMInvokeCode return wasn vm invoke code

func CheckAssetAmount

func CheckAssetAmount(asset string, amount uint64) error

func CompressBlockData

func CompressBlockData(data []byte, compressType byte) ([]byte, error)

func DecompressBlockData

func DecompressBlockData(data []byte, compressType byte) ([]byte, error)

func DeployContract

func DeployContract(
	gasPrice,
	gasLimit uint64,
	signer *account.Account,
	needStorage bool,
	code,
	cname,
	cversion,
	cauthor,
	cemail,
	cdesc string) (string, error)

func FormatAssetAmount

func FormatAssetAmount(amount uint64, precision byte) string

FormatAssetAmount return asset amount multiplied by math.Pow10(precision) to raw float string For example 1000000000123456789 => 1000000000.123456789

func FormatOnx

func FormatOnx(amount uint64) string

func FormatOxg

func FormatOxg(amount uint64) string

func GenExportBlocksFileName

func GenExportBlocksFileName(name string, start, end uint32) string

func GetAccountBalance

func GetAccountBalance(address, asset string) (uint64, error)

func GetAllowance

func GetAllowance(asset, from, to string) (string, error)

func GetBalance

func GetBalance(address string) (*httpcom.BalanceOfRsp, error)

Return balance of address in base58 code

func GetBlock

func GetBlock(hashOrHeight interface{}) ([]byte, error)

func GetBlockCount

func GetBlockCount() (uint32, error)

func GetBlockData

func GetBlockData(hashOrHeight interface{}) ([]byte, error)

func GetFlagName

func GetFlagName(flag cli.Flag) string

GetFlagName deal with short flag, and return the flag name whether flag name have short name

func GetJsonObjectFromFile

func GetJsonObjectFromFile(filePath string, jsonObject interface{}) error

func GetNetworkId

func GetNetworkId() (uint32, error)

func GetRawTransaction

func GetRawTransaction(txHash string) ([]byte, error)

func GetSmartContractEvent

func GetSmartContractEvent(txHash string) (*rpccommon.ExecuteNotify, error)

GetSmartContractEvent return smart contract event execute by invoke transaction by hex string code

func GetSmartContractEventInfo

func GetSmartContractEventInfo(txHash string) ([]byte, error)

func GetStoreDirPath

func GetStoreDirPath(dataDir, networkName string) string

func GetTxHeight

func GetTxHeight(txHash string) (uint32, error)

func InvokeNativeContract

func InvokeNativeContract(
	gasPrice,
	gasLimit uint64,
	signer *account.Account,
	contractAddress common.Address,
	version byte,
	method string,
	params []interface{},
) (string, error)

func InvokeNeoVMContract

func InvokeNeoVMContract(
	gasPrice,
	gasLimit uint64,
	signer *account.Account,
	smartcodeAddress common.Address,
	params []interface{}) (string, error)

Invoke neo vm smart contract. if isPreExec is true, the invoke will not really execute

func InvokeSmartContract

func InvokeSmartContract(signer *account.Account, tx *types.MutableTransaction) (string, error)

InvokeSmartContract is low level method to invoke contact.

func InvokeWasmVMContract

func InvokeWasmVMContract(
	gasPrice,
	gasLimit uint64,
	siger *account.Account,
	cversion byte,
	contractAddress common.Address,
	method string,
	paramType wasmvm.ParamType,
	params []interface{}) (string, error)

Invoke wasm smart contract methodName is wasm contract action name paramType is Json or Raw format version should be greater than 0 (0 is reserved for test)

func MultiSigTransaction

func MultiSigTransaction(mutTx *types.MutableTransaction, m uint16, pubKeys []keypair.PublicKey, signer *account.Account) error

func NewDeployCodeTransaction

func NewDeployCodeTransaction(gasPrice, gasLimit uint64, code []byte, needStorage bool,
	cname, cversion, cauthor, cemail, cdesc string) *types.MutableTransaction

NewDeployCodeTransaction return a smart contract deploy transaction instance

func NewInvokeTransaction

func NewInvokeTransaction(gasPrice, gasLimit uint64, invokeCode []byte) *types.MutableTransaction

NewInvokeTransaction return smart contract invoke transaction

func NewNativeInvokeTransaction

func NewNativeInvokeTransaction(gasPrice, gasLimit uint64, contractAddr common.Address, version byte,
	params []interface{}, funcAbi *abi.NativeContractFunctionAbi) (*types.MutableTransaction, error)

func NewNeovmContractAbi

func NewNeovmContractAbi(abiData []byte) (*abi.NeovmContractAbi, error)

func ParseAssetAmount

func ParseAssetAmount(rawAmount string, precision byte) uint64

ParseAssetAmount return raw float string to uint64 multiplied by math.Pow10(precision) For example 1000000000.123456789 => 1000000000123456789

func ParseNativeFuncParam

func ParseNativeFuncParam(builder *neovm.ParamsBuilder, funName string, params []interface{}, paramsAbi []*abi.NativeContractParamAbi) error

func ParseNativeParamAddress

func ParseNativeParamAddress(builder *neovm.ParamsBuilder, param string) error

func ParseNativeParamArray

func ParseNativeParamArray(builder *neovm.ParamsBuilder, param interface{}, arrayAbi *abi.NativeContractParamAbi) error

func ParseNativeParamBool

func ParseNativeParamBool(builder *neovm.ParamsBuilder, param string) error

func ParseNativeParamByte

func ParseNativeParamByte(builder *neovm.ParamsBuilder, param string) error

func ParseNativeParamByteArray

func ParseNativeParamByteArray(builder *neovm.ParamsBuilder, param string) error

func ParseNativeParamInteger

func ParseNativeParamInteger(builder *neovm.ParamsBuilder, param string) error

func ParseNativeParamString

func ParseNativeParamString(builder *neovm.ParamsBuilder, param string) error

func ParseNativeParamStruct

func ParseNativeParamStruct(builder *neovm.ParamsBuilder, param interface{}, structAbi *abi.NativeContractParamAbi) error

func ParseNativeParamUint256

func ParseNativeParamUint256(builder *neovm.ParamsBuilder, param string) error

func ParseNativeParams

func ParseNativeParams(builder *neovm.ParamsBuilder, params []interface{}, paramsAbi []*abi.NativeContractParamAbi) error

func ParseNeoVMContractReturnTypeBool

func ParseNeoVMContractReturnTypeBool(hexStr string) (bool, error)

ParseNeoVMContractReturnTypeBool return bool value of smart contract execute code.

func ParseNeoVMContractReturnTypeByteArray

func ParseNeoVMContractReturnTypeByteArray(hexStr string) (string, error)

ParseNeoVMContractReturnTypeByteArray return []byte value of smart contract execute code.

func ParseNeoVMContractReturnTypeInteger

func ParseNeoVMContractReturnTypeInteger(hexStr string) (int64, error)

ParseNeoVMContractReturnTypeInteger return integer value of smart contract execute code.

func ParseNeoVMContractReturnTypeString

func ParseNeoVMContractReturnTypeString(hexStr string) (string, error)

ParseNeoVMContractReturnTypeString return string value of smart contract execute code.

func ParseNeoVMInvokeParams

func ParseNeoVMInvokeParams(rawParams []interface{}) ([]interface{}, error)

ParseNeoVMInvokeParams parse params to []interface, rawParams is array of NeoVMInvokeParam

func ParseNeovmFunc

func ParseNeovmFunc(rawParams []string, funcAbi *abi.NeovmContractFunctionAbi) ([]interface{}, error)

func ParseNeovmParam

func ParseNeovmParam(params []string, paramsAbi []*abi.NeovmContractParamsAbi) ([]interface{}, error)

func ParseNeovmParamBoolean

func ParseNeovmParamBoolean(param string) (interface{}, error)

func ParseNeovmParamByteArray

func ParseNeovmParamByteArray(param string) (interface{}, error)

func ParseNeovmParamInteger

func ParseNeovmParamInteger(param string) (interface{}, error)

func ParseNeovmParamString

func ParseNeovmParamString(param string) (interface{}, error)

func ParseOnx

func ParseOnx(rawAmount string) uint64

func ParseOxg

func ParseOxg(rawAmount string) uint64

func ParseParams

func ParseParams(rawParamStr string) ([]interface{}, error)

ParseParams return interface{} array of encode params item. A param item compose of type and value, type can be: bytearray, string, int, bool Param type and param value split with ":", such as int:10 Param array can be express with "[]", such [int:10,string:foo], param array can be nested, such as [int:10,[int:12,bool:true]] A raw params example: string:foo,[int:0,[bool:true,string:bar],bool:false] Note that if string contain some special char like :,[,] and so one, please '/' char to escape. For example: string:did/:ed1e25c9dccae0c694ee892231407afa20b76008

func ParseReturnValue

func ParseReturnValue(rawValue interface{}, rawReturnTypeStr string) ([]interface{}, error)

ParseReturnValue return the value of rawReturnTypeStr type. Return type can be: bytearray, string, int, bool. Types can be split with "," each other, such as int,string,bool Type array can be express with "[]", such [int,string], param array can be nested, such as [int,[int,bool]]

func PrepareDeployContract

func PrepareDeployContract(
	needStorage bool,
	code,
	cname,
	cversion,
	cauthor,
	cemail,
	cdesc string) (*cstates.PreExecResult, error)

func PrepareInvokeCodeNeoVMContract

func PrepareInvokeCodeNeoVMContract(code []byte) (*cstates.PreExecResult, error)

func PrepareInvokeNativeContract

func PrepareInvokeNativeContract(
	contractAddress common.Address,
	version byte,
	method string,
	params []interface{}) (*cstates.PreExecResult, error)

func PrepareInvokeNeoVMContract

func PrepareInvokeNeoVMContract(
	contractAddress common.Address,
	params []interface{},
) (*cstates.PreExecResult, error)

func PrepareSendRawTransaction

func PrepareSendRawTransaction(txData string) (*cstates.PreExecResult, error)

func SendRawTransaction

func SendRawTransaction(tx *types.Transaction) (string, error)

SendRawTransaction send a transaction to onyxchain network, and return hash of the transaction

func SendRawTransactionData

func SendRawTransactionData(txData string) (string, error)

func Sign

func Sign(data []byte, signer *account.Account) ([]byte, error)

Sign sign return the signature to the data of private key

func SignTransaction

func SignTransaction(signer *account.Account, tx *types.MutableTransaction) error

func Transfer

func Transfer(gasPrice, gasLimit uint64, signer *account.Account, asset, from, to string, amount uint64) (string, error)

Transfer onx|oxg from account to another account

func TransferFrom

func TransferFrom(gasPrice, gasLimit uint64, signer *account.Account, asset, sender, from, to string, amount uint64) (string, error)

func TransferFromTx

func TransferFromTx(gasPrice, gasLimit uint64, asset, sender, from, to string, amount uint64) (*types.MutableTransaction, error)

func TransferTx

func TransferTx(gasPrice, gasLimit uint64, asset, from, to string, amount uint64) (*types.MutableTransaction, error)

func ZLibCompress

func ZLibCompress(data []byte) ([]byte, error)

func ZLibDecompress

func ZLibDecompress(data []byte) ([]byte, error)

Types

type ExportBlockMetadata

type ExportBlockMetadata struct {
	Version          byte
	CompressType     byte
	StartBlockHeight uint32
	EndBlockHeight   uint32
}

func NewExportBlockMetadata

func NewExportBlockMetadata() *ExportBlockMetadata

func (*ExportBlockMetadata) Deserialize

func (this *ExportBlockMetadata) Deserialize(r io.Reader) error

func (*ExportBlockMetadata) Serialize

func (this *ExportBlockMetadata) Serialize(w io.Writer) error

type JsonRpcRequest

type JsonRpcRequest struct {
	Version string        `json:"jsonrpc"`
	Id      string        `json:"id"`
	Method  string        `json:"method"`
	Params  []interface{} `json:"params"`
}

JsonRpcRequest object in rpc

type JsonRpcResponse

type JsonRpcResponse struct {
	Error  int64           `json:"error"`
	Desc   string          `json:"desc"`
	Result json.RawMessage `json:"result"`
}

JsonRpcResponse object response for JsonRpcRequest

type NeoVMInvokeParam

type NeoVMInvokeParam struct {
	Type  string
	Value interface{} //string or []*NeoVMInvokeParam
}

NeoVMInvokeParam use to express the param to invoke neovm contract. Type can be of array, bytearray, string, int and bool If type is one of bytearray, string, int and bool, value must be a string If Type is array, value must be []*NeoVMInvokeParam Example:

[]interface{}{
	&NeoVMInvokeParam{
		Type:  "string",
		Value: "foo",
	},
	&NeoVMInvokeParam{
		Type: "array",
		Value: []interface{}{
			&NeoVMInvokeParam{
				Type:  "int",
				Value: "0",
			},
			&NeoVMInvokeParam{
				Type:  "bool",
				Value: "true",
			},
		},
	},
}

type OnyxChainError

type OnyxChainError struct {
	ErrorCode int64
	Error     error
}

func NewOnyxChainError

func NewOnyxChainError(err error, errCode ...int64) *OnyxChainError

Jump to

Keyboard shortcuts

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