core

package
v0.16.4 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultConfigFilePath = "/config.json"
)

Variables

View Source
var (
	DeployCmd = cli.Command{
		Name:   "deploy",
		Usage:  "deploy a contract",
		Action: deploy,
		Flags:  deployCmdFlags,
	}

	InvokeCmd = cli.Command{
		Name:    "invoke",
		Aliases: []string{"i"},
		Usage:   "invoke contract function",
		Action:  invoke,
		Flags:   invokeCmdFlags,
	}
)
View Source
var (
	ConfigPathFlag = cli.StringFlag{
		Name:  "config",
		Usage: "config path",
	}
	PKFilePathFlag = cli.StringFlag{
		Name:  "pkfile",
		Value: "",
		Usage: "private key file path",
	}
	StabExecTimesFlag = cli.IntFlag{
		Name:  "times",
		Value: 1000,
		Usage: "execute times",
	}
	SendTxIntervalFlag = cli.IntFlag{
		Name:  "interval",
		Value: 10,
		Usage: "Time interval for sending transactions",
	}
	AccountSizeFlag = cli.IntFlag{
		Name:  "size",
		Value: 10,
		Usage: "account size",
	}
	TxJsonDataFlag = cli.StringFlag{
		Name:  "data",
		Usage: "transaction data",
	}
	ContractWasmFilePathFlag = cli.StringFlag{
		Name:  "code",
		Usage: "wasm file path",
	}
	ContractAddrFlag = cli.StringFlag{
		Name: "addr",

		Usage: "the contract address",
	}
	ContractFuncNameFlag = cli.StringFlag{
		Name:  "func",
		Usage: "function and param ,eg :set(1,\"a\")",
	}
	TransactionTypeFlag = cli.IntFlag{
		Name:  "type",
		Value: 2,
		Usage: "tx type ,default 2",
	}
	ContractAbiFilePathFlag = cli.StringFlag{
		Name:  "abi",
		Usage: "abi file path",
	}
	TransactionHashFlag = cli.StringFlag{
		Name:  "hash",
		Usage: "tx hash",
	}
	TxFromFlag = cli.StringFlag{
		Name:  "from",
		Usage: "transaction sender addr",
	}
	TxToFlag = cli.StringFlag{
		Name:  "to",
		Usage: "transaction acceptor addr",
	}
	TransferValueFlag = cli.StringFlag{
		Name:  "value",
		Value: "0xDE0B6B3A7640000",
		Usage: "transfer value",
	}

	TxStressSourceFilesPathFlag = cli.StringSliceFlag{
		Name:  "sourceFile",
		Usage: "the tps source file path",
	}

	TxStressStatisticTimeFlag = cli.IntFlag{
		Name:  "statisticTime",
		Usage: "Statistics every few seconds",
	}

	TxStressOutPutFileFlag = cli.StringFlag{
		Name:  "output",
		Usage: "the output file path",
	}
)
View Source
var (
	SendTransactionCmd = cli.Command{
		Name:   "sendTransaction",
		Usage:  "send a transaction",
		Action: sendTransactionCmd,
		Flags:  sendTransactionCmdFlags,
	}
	SendRawTransactionCmd = cli.Command{
		Name:   "sendRawTransaction",
		Usage:  "send a raw transaction",
		Action: sendRawTransactionCmd,
		Flags:  sendRawTransactionCmdFlags,
	}
	GetTxReceiptCmd = cli.Command{
		Name:   "getTxReceipt",
		Usage:  "get transaction receipt by hash",
		Action: getTxReceiptCmd,
		Flags:  getTxReceiptCmdFlags,
	}
)
View Source
var (
	StressTransferValue = 1000

	DefaultPrivateKeyFilePath  = "./test/privateKeys.txt"
	DefaultAccountAddrFilePath = "./test/addr.json"

	StabilityCmd = cli.Command{
		Name:    "stability",
		Aliases: []string{"stab"},
		Usage:   "start stability test ",
		Action:  stabilityTest,
		Flags:   stabilityCmdFlags,
	}
	StabPrepareCmd = cli.Command{
		Name:    "prepare",
		Aliases: []string{"pre"},
		Usage:   "prepare some accounts are used for stability test ",
		Action:  prepareAccount,
		Flags:   stabPrepareCmdFlags,
	}
)
View Source
var (
	AnalyzeStressTestCmd = cli.Command{
		Name:   "analyzeStressTest",
		Usage:  "analyze the tx stress test source file to generate  result data",
		Action: analyzeStressTest,
		Flags:  txStressFlags,
	}
)

Functions

func BoolToBytes

func BoolToBytes(b bool) []byte

func BytesConverter

func BytesConverter(source []byte, t string) interface{}

func BytesToFloat32

func BytesToFloat32(bytes []byte) float32

func BytesToFloat64

func BytesToFloat64(bytes []byte) float64

func BytesToInt32

func BytesToInt32(b []byte) int32

func BytesToInt64

func BytesToInt64(b []byte) int64

func DeployContract

func DeployContract(abiFilePath string, codeFilePath string) error

func Float32ToBytes

func Float32ToBytes(float float32) []byte

func Float64ToBytes

func Float64ToBytes(float float64) []byte

func GetFuncNameAndParams

func GetFuncNameAndParams(f string) (string, []string)

*

Find the method called by parsing abi

func GetTransactionReceipt

func GetTransactionReceipt(txHash string, ch chan string, exit chan string)

Loop call to get transactionReceipt... until 200s timeout

func HttpPost

func HttpPost(param JsonParam) (string, error)

func Int32ToBytes

func Int32ToBytes(n int32) []byte

func Int64ToBytes

func Int64ToBytes(n int64) []byte

func InvokeContract

func InvokeContract(contractAddr string, abiPath string, funcParams string, txType int) error

*

func PrepareAccount

func PrepareAccount(size int, pkFile, value string) error

func Send

func Send(params interface{}, action string) (string, error)

func SendRawTransaction

func SendRawTransaction(from, to, value string, pkFilePath string) (string, error)

func SendTransaction

func SendTransaction(from, to, value string) (string, error)

func StabilityTest

func StabilityTest(pkFile string, times, interval int) error

func StringConverter

func StringConverter(source string, t string) ([]byte, error)

func TestMain

func TestMain(m *testing.M)

Types

type Config

type Config struct {
	From     string `json:"from"`
	Gas      string `json:"gas"`
	GasPrice string `json:"gasPrice"`
	Url      string `json:"url"`
}

type DeployParams

type DeployParams struct {
	From     string `json:"from"`
	Gas      string `json:"gas"`
	GasPrice string `json:"gasPrice"`
	Data     string `json:"data"`
}

type FuncDesc

type FuncDesc struct {
	Name   string `json:"name"`
	Inputs []struct {
		Name string `json:"name"`
		Type string `json:"type"`
	} `json:"inputs"`
	Outputs []struct {
		Name string `json:"name"`
		Type string `json:"type"`
	} `json:"outputs"`
	Constant string `json:"constant"`
	Type     string `json:"type"`
}

type JsonParam

type JsonParam struct {
	Jsonrpc string      `json:"jsonrpc"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params"`
	Id      int         `json:"id"`
}

type PriAccount

type PriAccount struct {
	Priv    *ecdsa.PrivateKey
	Nonce   uint64
	Address common.Address
}

type RawTxParams

type RawTxParams struct {
	TxParams
	Nonce int64 `json:"Nonce"`
}

type Receipt

type Receipt struct {
	Jsonrpc string `json:"jsonrpc"`
	Id      int    `json:"id"`
	Result  struct {
		BlockHash         string `json:"blockHash"`
		BlockNumber       string `json:"blockNumber"`
		ContractAddress   string `json:"contractAddress"`
		CumulativeGasUsed string `json:"cumulativeGas_used"`
		From              string `json:"from"`
		GasUsed           string `json:"gasUsed"`
		Root              string `json:"root"`
		To                string `json:"to"`
		TransactionHash   string `json:"transactionHash"`
		TransactionIndex  string `json:"transactionIndex"`
	} `json:"result"`
}

func GetTxReceipt

func GetTxReceipt(txHash string) (Receipt, error)

type Response

type Response struct {
	Jsonrpc string `json:"jsonrpc"`
	Result  string `json:"result"`
	Id      int    `json:"id"`
	Error   struct {
		Code    int32  `json:"code"`
		Message string `json:"message"`
	} `json:"error"`
}

type TxParams

type TxParams struct {
	From     string `json:"from"`
	To       string `json:"to"`
	Gas      string `json:"gas"`
	GasPrice string `json:"gasPrice"`
	Value    string `json:"value"`
	Data     string `json:"data"`
}

Jump to

Keyboard shortcuts

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