utils

package
v0.0.0-...-6425a1c Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: LGPL-3.0 Imports: 36 Imported by: 5

Documentation

Overview

* Copyright (C) 2018 The ZeepinChain Authors * This file is part of The ZeepinChain library. * * The ZeepinChain 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 ZeepinChain 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 ZeepinChain. 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 = "./blocks.dat"
	DEFAULT_ABI_PATH    = "./abi"
)
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_INTEGER64  = "int64"
	PARAM_TYPE_BOOLEAN    = "bool"
	PARAM_LEFT_BRACKET    = "["
	PARAM_RIGHT_BRACKET   = "]"
)
View Source
const (
	PRECISION_GALA = 4
	PRECISION_ZPT  = 4
)
View Source
const (
	VERSION_TRANSACTION    = byte(0)
	VERSION_CONTRACT_ZPT   = byte(0)
	VERSION_CONTRACT_GALA  = byte(0)
	CONTRACT_TRANSFER      = "transfer"
	CONTRACT_TRANSFER_FROM = "transferFrom"
	CONTRACT_APPROVE       = "approve"

	ASSET_ZPT  = "zpt"
	ASSET_GALA = "gala"
)
View Source
const (
	COMPRESS_TYPE_ZLIB = iota
)
View Source
const JSON_RPC_VERSION = "2.0"

JsonRpc version

Variables

View Source
var (
	//ZeepinChain setting
	ConfigFlag = cli.StringFlag{
		Name:  "config",
		Usage: "Use `<filename>` to specifies the genesis block config file. If doesn't specifies the genesis block config, zeepin will use Polaris config with GBFT consensus as default.",
	}
	LogLevelFlag = cli.UintFlag{
		Name:  "loglevel",
		Usage: "Set the log level to `<level>` (0~6). 0:Debug 1:Info 2:Warn 3:Error 4:Fatal 5:Trace 6:MaxLevel",
		Value: config.DEFAULT_LOG_LEVEL,
	}
	DisableEventLogFlag = cli.BoolFlag{
		Name:  "disableeventlog",
		Usage: "If set disableeventlog flag, zeepin will not record event log output by smart contract",
	}
	WalletFileFlag = cli.StringFlag{
		Name:  "wallet,w",
		Value: config.DEFAULT_WALLET_FILE_NAME,
		Usage: "Use `<filename>` as the wallet",
	}
	ImportEnableFlag = cli.BoolFlag{
		Name:  "import",
		Usage: "Import blocks for file",
	}
	ImportFileFlag = cli.StringFlag{
		Name:  "importfile",
		Usage: "Path of import file",
		Value: DEFAULT_EXPORT_FILE,
	}
	ImportHeightFlag = cli.UintFlag{
		Name:  "importheight",
		Usage: "Using to specifies the height of the imported target block. If the block height specified by importheight is less than the maximum height of the block file, it will only be imported to the height specified by importheight and the rest blocks will stop importing. The default value is 0, which means import all the blocks",
	}
	DataDirFlag = cli.StringFlag{
		Name:  "datadir",
		Usage: "Using dir `<path>` to storage block data",
		Value: config.DEFAULT_DATA_DIR,
	}

	//Consensus setting
	EnableConsensusFlag = cli.BoolFlag{
		Name:  "enableconsensus",
		Usage: "If set enableconsensus, will start consensus module",
	}
	MaxTxInBlockFlag = cli.IntFlag{
		Name:  "maxtxinblock",
		Usage: "Using maxtxinblock to set the max transaction number in block",
		Value: config.DEFAULT_MAX_TX_IN_BLOCK,
	}
	GasLimitFlag = cli.Uint64Flag{
		Name:  "gaslimit",
		Usage: "Using to set the gaslimit of the current node transaction pool to accept transactions. Transactions below this gaslimit will be discarded",
		Value: embed.MIN_TRANSACTION_GAS,
	}
	GasPriceFlag = cli.Uint64Flag{
		Name:  "gasprice",
		Usage: "Using to set the lowest gasprice of the current node transaction pool to accept transactions. Transactions below this gasprice will be discarded.(default:0 in testmode)",
		Value: config.DEFAULT_GAS_PRICE,
	}

	//Test Mode setting
	EnableTestModeFlag = cli.BoolFlag{
		Name:  "testmode",
		Usage: "Using to start a single node test network for ease of development and debug. In testmode, zeepin will start rpc, rest and web socket server, and set default gasprice to 0",
	}
	TestModeGenBlockTimeFlag = cli.UintFlag{
		Name:  "testmodegenblocktime",
		Usage: "Using to set the block-out time in test mode. The time unit is in seconds, and the minimum block-out time is 2 seconds.",
		Value: config.DEFAULT_GEN_BLOCK_TIME,
	}
	ClearTestModeDataFlag = cli.BoolFlag{
		Name:  "cleartestmodedata",
		Usage: "Clear test mode block data",
	}

	//P2P setting
	ReservedPeersOnlyFlag = cli.BoolFlag{
		Name:  "reservedonly",
		Usage: "connect reserved peers only",
	}
	ReservedPeersFileFlag = cli.StringFlag{
		Name:  "reservedfile",
		Usage: "reserved peers file",
		Value: config.DEFAULT_RESERVED_FILE,
	}
	NetworkIdFlag = cli.UintFlag{
		Name:  "networkid",
		Usage: "Using to specify the network ID. Different networkids cannot connect to the blockchain network. 1=zeepin 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: "Using to specify the P2P network port number",
		Value: config.DEFAULT_NODE_PORT,
	}
	DualPortSupportFlag = cli.BoolFlag{
		Name:  "dualport",
		Usage: "Using to initiates a dual network, i.e. a P2P network for processing transaction messages and a consensus network for consensus messages. ",
	}
	ConsensusPortFlag = cli.UintFlag{
		Name:  "consensusport",
		Usage: "Using to specifies the consensus network port number. By default, the consensus network reuses the P2P network, so it is not necessary to specify a consensus network port. After the dual network is enabled with the --dualport parameter, the consensus network port number must be set separately.",
		Value: config.DEFAULT_CONSENSUS_PORT,
	}
	MaxConnInBoundFlag = cli.UintFlag{
		Name:  "maxconninbound",
		Usage: "Max connection in bound",
		Value: config.DEFAULT_MAX_CONN_IN_BOUND,
	}
	MaxConnOutBoundFlag = cli.UintFlag{
		Name:  "maxconnoutbound",
		Usage: "Max connection out bound",
		Value: config.DEFAULT_MAX_CONN_OUT_BOUND,
	}
	MaxConnInBoundForSingleIPFlag = cli.UintFlag{
		Name:  "maxconninboundforsingleip",
		Usage: "Max connection in bound for single ip",
		Value: config.DEFAULT_MAX_CONN_IN_BOUND_FOR_SINGLE_IP,
	}
	// RPC settings
	RPCDisabledFlag = cli.BoolFlag{
		Name:  "disablerpc",
		Usage: "Using to shut down the rpc server. The zeepin node starts the rpc server by default at startup.",
	}
	RPCPortFlag = cli.UintFlag{
		Name:  "rpcport",
		Usage: "Json rpc server listening port",
		Value: config.DEFAULT_RPC_PORT,
	}
	RPCLocalEnableFlag = cli.BoolFlag{
		Name:  "localrpc",
		Usage: "Enable local rpc server",
	}
	RPCLocalProtFlag = cli.UintFlag{
		Name:  "rpclocalport",
		Usage: "Json rpc local server listening port",
		Value: config.DEFAULT_RPC_LOCAL_PORT,
	}

	//Websocket setting
	WsEnabledFlag = cli.BoolFlag{
		Name:  "ws",
		Usage: "Enable websocket server",
	}
	WsPortFlag = cli.UintFlag{
		Name:  "wsport",
		Usage: "Ws server listening port",
		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",
		Value: config.DEFAULT_REST_PORT,
	}

	//Account setting
	AccountPassFlag = cli.StringFlag{
		Name:   "password,p",
		Hidden: true,
		Usage:  "Using to specify the account `<password>` when zeepin node starts. Because the account password entered in the command line is saved in the log, it is easy to leak the password. Therefore, it is not recommended to use this parameter in a production environment.",
	}
	AccountAddressFlag = cli.StringFlag{
		Name:  "account,a",
		Usage: "Using to specify the account `<address|label|index>` when the zeepin node starts. If the account is null, it uses the wallet default account",
	}
	AccountDefaultFlag = cli.BoolFlag{
		Name:  "default,d",
		Usage: "Use 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",
	}
	AccountQuantityFlag = cli.UintFlag{
		Name:  "number,n",
		Value: 1,
		Usage: "Specifies the `<quantity>` of account to create.",
	}
	AccountSourceFileFlag = cli.StringFlag{
		Name:  "source,s",
		Usage: "Use `<filename>` as the source wallet file to import",
	}
	AccountLabelFlag = cli.StringFlag{
		Name:  "label,l",
		Usage: "Use `<label>` for newly created accounts for easy and fast use of accounts. Note that duplicate label names cannot appear in the same wallet file. An account with no label is an empty string.",
	}
	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:  "changepasswd",
		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: fmt.Sprintf("M of multi signature address. m must > 0 and <= %d, and m must <= number of pub key", constants.MULTI_SIG_MAX_PUBKEY_SIZE),
	}
	AccountMultiPubKeyFlag = cli.StringFlag{
		Name:  "pubkey",
		Usage: fmt.Sprintf("Pub key list of multi address, split pub key with `,`. Number of pub key must > 0 and <= %d", constants.MULTI_SIG_MAX_PUBKEY_SIZE),
	}
	IdentityFlag = cli.BoolFlag{
		Name:  "gid",
		Usage: "create an GID 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: "Invoke contract parameters list. use comma ',' to split params, and must add type prefix to params. Param type support bytearray(hexstring), string, integer, boolean,For example: string:foo,int:0,bool:true; If parameter is an object array, enclose array with '[]'. For example:  string:foo,[int:0,bool:true]",
	}
	ContractAttrFlag = cli.Int64Flag{
		Name:  "attr,t",
		Usage: "Invoke contract attribute, 0: embed, 1: wasm",
		Value: 1,
	}
	ContractMethodFlag = cli.StringFlag{
		Name:  "method,m",
		Usage: "Contract method to be called",
	}
	ContractParamTypeFlag = cli.Int64Flag{
		Name:  "paramtype",
		Usage: "method param type: 0: json, 1: raw, default: 0",
		Value: 0,
	}
	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.Return type support bytearray(hexstring), string, integer, boolean. If return type is object array, enclose array with '[]'. For example [string,int,bool,string]. Only prepare invoke need this flag.",
	}

	//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: "Using to specifies the transfer asset `<zpt|gala>`",
		Value: ASSET_ZPT,
	}
	TransactionFromFlag = cli.StringFlag{
		Name:  "from",
		Usage: "Using to specifies the transfer-out account `<address|label|index>`",
	}
	TransactionToFlag = cli.StringFlag{
		Name:  "to",
		Usage: "Using to specifies the transfer-in account `<address|label|index>`",
	}
	TransactionAmountFlag = cli.StringFlag{
		Name:  "amount",
		Usage: "Using to specifies the transfer amount",
	}
	TransactionHashFlag = cli.StringFlag{
		Name:  "hash",
		Usage: "Transaction <hash>",
	}
	TransactionGasPriceFlag = cli.Uint64Flag{
		Name:  "gasprice",
		Usage: "Using to specifies the gas price of transaction. The gas price of the transaction cannot be less than the lowest gas price set by node's transaction pool, otherwise the transaction will be rejected. When there are transactions that are queued for packing into the block in the transaction pool, the transaction pool will deal with transactions according to the gas price and transactions with high gas prices will be prioritized.(default:0 in testmode)",
		Value: config.DEFAULT_GAS_PRICE,
	}
	TransactionGasLimitFlag = cli.Uint64Flag{
		Name:  "gaslimit",
		Usage: "Using to specifies the gas limit of the transaction. The gas limit of the transaction cannot be less than the minimum gas limit set by the node's transaction pool, otherwise the transaction will be rejected. Gasprice * gaslimit is actual GALA costs.",
		Value: embed.MIN_TRANSACTION_GAS,
	}

	//Asset setting
	ApproveAssetFromFlag = cli.StringFlag{
		Name:  "from",
		Usage: "Using to specifies the transfer-out account `<address|label|index>`",
	}
	ApproveAssetToFlag = cli.StringFlag{
		Name:  "to",
		Usage: "Using to specifies the transfer-in account `<address|label|index>`",
	}
	ApproveAssetFlag = cli.StringFlag{
		Name:  "asset",
		Usage: "Using to specifies the transfer asset <zpt|gala> for approve",
		Value: "zpt",
	}
	ApproveAmountFlag = cli.StringFlag{
		Name:  "amount",
		Usage: "Using to specifies the transfer amount for approve",
	}
	TransferFromAmountFlag = cli.StringFlag{
		Name:  "amount",
		Usage: "Using to specifies the transfer from amount",
	}
	TransferFromSenderFlag = cli.StringFlag{
		Name:  "sender",
		Usage: "Using to specifies the sender account `<address|label|index>` of transfer from transaction, if empty sender is to account",
	}

	//Cli setting
	CliRpcPortFlag = cli.UintFlag{
		Name:  "cliport",
		Usage: "Cli rpc port",
		Value: config.DEFAULT_CLI_RPC_PORT,
	}
	CliABIPathFlag = cli.StringFlag{
		Name:  "abi",
		Usage: "Abi path",
		Value: DEFAULT_ABI_PATH,
	}

	//Export setting
	ExportFileFlag = cli.StringFlag{
		Name:  "file",
		Usage: "Path of export file",
		Value: DEFAULT_EXPORT_FILE,
	}
	ExportHeightFlag = cli.UintFlag{
		Name:  "height",
		Usage: "Using to specifies the height of the exported block. When height of the local node's current block is greater than the height required for export, the greater part will not be exported. Height is equal to 0, which means exporting all the blocks of the current node.",
		Value: 0,
	}
	ExportSpeedFlag = cli.StringFlag{
		Name:  "speed",
		Usage: "Export block speed, `<h|m|l>` h for high speed, m for middle speed and l for low speed",
		Value: "m",
	}

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

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

	BroadcastNetTxEnableFlag = cli.BoolFlag{
		Name:  "enablebroadcastnettx",
		Usage: "Enable broadcast tx from network in tx pool",
	}

	NonOptionFlag = cli.StringFlag{
		Name:  "option",
		Usage: "this command does not need option, please run directly",
	}
)

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 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, attr uint64) (string, error)

func FormatAssetAmount

func FormatAssetAmount(amount uint64, precision int) string

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

func FormatGala

func FormatGala(amount uint64) string

func FormatZpt

func FormatZpt(amount uint64) string

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 ImportBlocks

func ImportBlocks(importFile string, targetHeight uint32) error

func InvokeEmbeddedContract

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

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

func InvokeNativeContract

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

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 NewDeployCodeTransaction

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

NewDeployCodeTransaction return a smart contract deploy transaction instance

func NewEmbedContractAbi

func NewEmbedContractAbi(abiData []byte) (*abi.EmbedContractAbi, error)

func NewNativeInvokeTransaction

func NewNativeInvokeTransaction(gasPrice, gasLimit uint64, contractAddr common.Address, version byte, params []interface{}, funcAbi *abi.NativeContractFunctionAbi) (*types.MutableTransaction, 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 ParseEmbeddedContractReturnTypeBool

func ParseEmbeddedContractReturnTypeBool(hexStr string) (bool, error)

ParseEmbeddedContractReturnTypeBool return bool value of smart contract execute code.

func ParseEmbeddedContractReturnTypeByteArray

func ParseEmbeddedContractReturnTypeByteArray(hexStr string) (string, error)

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

func ParseEmbeddedContractReturnTypeString

func ParseEmbeddedContractReturnTypeString(hexStr string) (string, error)

ParseEmbeddedContractReturnTypeString return string value of smart contract execute code.

func ParseEmbeddedInvokeParams

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

ParseEmbeddedInvokeParams parse params to []interface, rawParams is array of EmbeddedInvokeParam

func ParseEmbededContractReturnTypeInteger

func ParseEmbededContractReturnTypeInteger(hexStr string) (int64, error)

ParseEmbededContractReturnTypeInteger return integer value of smart contract execute code.

func ParseEmbededFunc

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

func ParseEmbededParam

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

func ParseEmbededParamBoolean

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

func ParseEmbededParamByteArray

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

func ParseEmbededParamInteger

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

func ParseEmbededParamString

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

func ParseGala

func ParseGala(rawAmount string) uint64

func ParseNativeFuncParam

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

func ParseNativeParamAddress

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

func ParseNativeParamArray

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

func ParseNativeParamBool

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

func ParseNativeParamByte

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

func ParseNativeParamByteArray

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

func ParseNativeParamInteger

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

func ParseNativeParamString

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

func ParseNativeParamStruct

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

func ParseNativeParamUint256

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

func ParseNativeParams

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

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]

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 ParseZpt

func ParseZpt(rawAmount string) uint64

func PrepareDeployContract

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

func PrepareInvokeCodeEmbeddedContract

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

func PrepareInvokeEmbeddedContract

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

func PrepareInvokeNativeContract

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

func PrepareInvokeWASMVMContract

func PrepareInvokeWASMVMContract(
	contractAddress common.Address,
	methodName string,
	paramType wasmvm.ParamType,
	version byte,
	params []interface{},
	attr byte,
) (*cstates.PreExecResult, error)

func SendRawTransaction

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

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

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 zpt|gala 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 EmbeddedInvokeParam

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

EmbeddedInvokeParam use to express the param to invoke embedded 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 []*EmbeddedInvokeParam Example:

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

type ExportBlockMetadata

type ExportBlockMetadata struct {
	Version      byte
	CompressType byte
	BlockHeight  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

Jump to

Keyboard shortcuts

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