utils

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2022 License: LGPL-3.0 Imports: 24 Imported by: 0

Documentation

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   = "./OntBlocks.dat"
	DEFAULT_ABI_PATH      = "./abi"
	DEFAULT_EXPORT_HEIGHT = 0
	DEFAULT_WALLET_PATH   = "./wallet_data"
)
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_ONTOLOGY_COMMON  = 10000
	ERROR_ONTOLOGY_SUCCESS = 0
)
View Source
const (
	COMPRESS_TYPE_ZLIB = iota
)
View Source
const JSON_RPC_VERSION = "2.0"

JsonRpc version

Variables

View Source
var (
	//Ontology 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,
	}

	//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,
	}

	//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=ontology 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 Ontology node starts.",
	}
	AccountAddressFlag = cli.StringFlag{
		Name:  "account,a",
		Usage: "Account `<address>` when the Ontology 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:  "ontid",
		Usage: "create an ONT 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",
	}

	TransactionHashFlag = cli.StringFlag{
		Name:  "hash",
		Usage: "Transaction `<hash>`",
	}
	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 ONT of ONG to approve",
		Value: "ont",
	}
	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 Ontology",
	}
	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",
	}
	WithdrawONGReceiveAccountFlag = cli.StringFlag{
		Name:  "receive",
		Usage: "ONG receive `<address>`,Default the same with owner account",
	}
	WithdrawONGAmountFlag = 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",
	}

	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 CompressBlockData

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

func DecompressBlockData

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

func GenExportBlocksFileName added in v1.0.2

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

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 added in v1.0.1

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

func GetNetworkId added in v1.0.1

func GetNetworkId() (uint32, error)

func GetRawTransaction

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

func GetSmartContractEventInfo

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

func GetStoreDirPath added in v1.0.2

func GetStoreDirPath(dataDir, networkName string) string

func GetTxHeight added in v1.0.3

func GetTxHeight(txHash string) (uint32, error)

func MultiSigTransaction added in v1.0.3

func MultiSigTransaction(mutTx *types.Transaction, m uint16, pubKeys []keypair.PublicKey, signer *account.Account) 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] Note that if string contain some special char like :,[,] and so one, please '/' char to escape. For example: string:did/:ed1e25c9dccae0c694ee892231407afa20b76008

func PrepareSendRawTransaction added in v1.0.3

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

func SendRawTransactionData added in v1.0.3

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.Transaction) 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 OntologyError added in v1.0.3

type OntologyError struct {
	ErrorCode int64
	Error     error
}

func NewOntologyError added in v1.0.3

func NewOntologyError(err error, errCode ...int64) *OntologyError

Jump to

Keyboard shortcuts

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