packet

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TxReceiptSuccessMsg = "Operation Succeeded"
	TxReceiptFailureMsg = "Operation Failed"
)

Variables

View Source
var Bytes2X_CMD = map[string]interface{}{
	"string": byteutil.BytesToString,

	"uint16": RlpBytesToUint16,
	"uint32": RlpBytesToUint32,
	"uint64": RlpBytesToUint64,

	"int16": RlpBytesToUint16,
	"int32": RlpBytesToUint32,
	"int64": RlpBytesToUint64,

	"bool": RlpBytesToBool,
}

Functions

func ConvertRlpBytesTo

func ConvertRlpBytesTo(input []byte, targetType string) interface{}

func EventParsing

func EventParsing(logs RecptLogs, abiBytesArr [][]byte, fn eventParsingFunc) []string

func EventParsingV2

func EventParsingV2(logs RecptLogs, events []*FuncDesc, fn eventParsingFuncV2) []string

func EvmEventParsingPerLog

func EvmEventParsingPerLog(eLog *Log, abiBytes []byte) string

================================== EVM ========================

func EvmEventParsingPerLogV2

func EvmEventParsingPerLogV2(eLog *Log, events []*FuncDesc) string

------------------------------ EVM --------------------------------------

func EvmStringToEncodeByte

func EvmStringToEncodeByte(abiFunc *FuncDesc, funcParams []string) ([]byte, []string, error)

EvmStringToEncodeByte if the funcParams is nil, the return byte is nil

func GenFuncSig

func GenFuncSig(input abi.ArgumentMarshaling) string

func GenUnpackArgs

func GenUnpackArgs(data []abi.ArgumentMarshaling) (arguments abi.Arguments)

func IsWasmContract

func IsWasmContract(codeBytes []byte) bool

IsWasmContract judge whether the bytes satisfy the code format of wasm virtual machine

func RlpBytesToBool

func RlpBytesToBool(b []byte) bool

func RlpBytesToUint16

func RlpBytesToUint16(b []byte) uint16

func RlpBytesToUint32

func RlpBytesToUint32(b []byte) uint32

func RlpBytesToUint64

func RlpBytesToUint64(b []byte) uint64

func UnpackError

func UnpackError(res []byte) (string, error)

func WasmEventParsingPerLog

func WasmEventParsingPerLog(eLog *Log, abiBytes []byte) string

func WasmEventParsingPerLogV2

func WasmEventParsingPerLogV2(eLog *Log, events []*FuncDesc) string

--------------------------- WASM ------------------------------------

Types

type ContractAbi

type ContractAbi []*FuncDesc

func ParseAbiFromJson

func ParseAbiFromJson(abiBytes []byte) (ContractAbi, error)

ParseAbiFromJson parses the application binary interface(abi) files to []FuncDesc object array

func (ContractAbi) GetConstructor

func (funcs ContractAbi) GetConstructor() *FuncDesc

func (ContractAbi) GetEvents

func (funcs ContractAbi) GetEvents() []*FuncDesc

func (ContractAbi) GetFuncFromAbi

func (funcs ContractAbi) GetFuncFromAbi(name string) (*FuncDesc, error)

ParseFuncFromAbi searches the function (or event) names in the []FuncDesc object array

func (ContractAbi) ListAbiFuncName

func (abiFuncs ContractAbi) ListAbiFuncName() string

type ContractDataGen

type ContractDataGen struct {
	TxType uint64
	/// name   string
	Interp contractInter
	// contains filtered or unexported fields
}

ContractDataGen is used for combining the data of contract execution

func NewContractDataGen

func NewContractDataGen(data *RawData, conAbi ContractAbi, txType uint64) *ContractDataGen

func (*ContractDataGen) CombineData

func (dataGen *ContractDataGen) CombineData() (string, error)

CombineData of Contractcall data struct is used for packeting the data of wasm or evm contracts execution Implement the MessageCallDemo interface

func (*ContractDataGen) GetContractDataDen

func (dataGen *ContractDataGen) GetContractDataDen() *ContractDataGen

func (*ContractDataGen) GetIsWrite

func (dataGen *ContractDataGen) GetIsWrite() bool

func (*ContractDataGen) GetMethodAbi

func (dataGen *ContractDataGen) GetMethodAbi() *FuncDesc

func (*ContractDataGen) ParseNonConstantResponse

func (dataGen *ContractDataGen) ParseNonConstantResponse(respStr string, outputType []abi.ArgumentMarshaling) []interface{}

func (*ContractDataGen) ReceiptParsing

func (dataGen *ContractDataGen) ReceiptParsing(receipt *Receipt) *ReceiptParsingReturn

func (*ContractDataGen) SetInterpreter

func (dataGen *ContractDataGen) SetInterpreter(vm, name string, txType uint64)

SetInterpreter set the interpreter of ContractDataGen object

type ContractReturn

type ContractReturn struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

ContractReturn, system contract return object

func ParseSysContractResult

func ParseSysContractResult(result []byte) (*ContractReturn, error)

ParseSysContractResult parsed the result to ContractReturn object

type DeployDataGen

type DeployDataGen struct {
	/// codeBytes         []byte
	/// abiBytes          []byte
	/// ConstructorParams []string
	Interpreter deployInter
	// contains filtered or unexported fields
}

DeployCall, used for combining the data of contract deployment

func NewDeployDataGen

func NewDeployDataGen(conAbi ContractAbi) *DeployDataGen

NewDeployCall new a DeployCall object

func (DeployDataGen) CombineData

func (dataGen DeployDataGen) CombineData() (string, error)

CombineData of DeployCall data struct is used for packeting the data of wasm or evm contracts deployment Implement the MessageCallDemo interface

func (*DeployDataGen) GetContractDataDen

func (dataGen *DeployDataGen) GetContractDataDen() *ContractDataGen

func (*DeployDataGen) GetIsWrite

func (dataGen *DeployDataGen) GetIsWrite() bool

func (*DeployDataGen) ParseNonConstantResponse

func (dataGen *DeployDataGen) ParseNonConstantResponse(respStr string, outputType []abi.ArgumentMarshaling) []interface{}

func (*DeployDataGen) ReceiptParsing

func (dataGen *DeployDataGen) ReceiptParsing(receipt *Receipt) *ReceiptParsingReturn

func (*DeployDataGen) SetInterpreter

func (dataGen *DeployDataGen) SetInterpreter(vm string, abiBytes, codeBytes []byte, consParams []interface{}, methodAbi *FuncDesc)

SetInterpreter set the interpreter of DeployCall object

type EvmContractInterpreter

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

func (EvmContractInterpreter) ParseNonConstantResponse

func (i EvmContractInterpreter) ParseNonConstantResponse(respStr string, outputType []abi.ArgumentMarshaling) []interface{}

func (EvmContractInterpreter) ReceiptParsing

func (i EvmContractInterpreter) ReceiptParsing(receipt *Receipt, abiBytes []byte) *ReceiptParsingReturn

func (EvmContractInterpreter) ReceiptParsingV2

func (i EvmContractInterpreter) ReceiptParsingV2(receipt *Receipt, conAbi ContractAbi) *ReceiptParsingReturn

type EvmDeployInterpreter

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

EvmInterpreter, packet data in the way defined by the evm virtual machine

func (EvmDeployInterpreter) ReceiptParsing

func (i EvmDeployInterpreter) ReceiptParsing(receipt *Receipt, abiBytes []byte) *ReceiptParsingReturn

func (EvmDeployInterpreter) ReceiptParsingV2

func (i EvmDeployInterpreter) ReceiptParsingV2(receipt *Receipt, conAbi ContractAbi) *ReceiptParsingReturn

type FuncDesc

type FuncDesc struct {
	Name            string                   `json:"name"`
	Inputs          []abi.ArgumentMarshaling `json:"inputs"`
	Outputs         []abi.ArgumentMarshaling `json:"outputs"`
	Constant        interface{}              `json:"constant"` // ???
	Type            string                   `json:"type"`
	StateMutability string                   `json:"stateMutability,omitempty"` // tag for solidity ver > 0.6.0
}

================================ABI================================ todo: change FuncDesc to Method in abi/method.go FuncDesc, the object of the contract abi files

func (*FuncDesc) StringToArgs

func (abiFunc *FuncDesc) StringToArgs(funcParams []string) ([]interface{}, error)

EvmStringToEncodeByte if the funcParams is nil, the return byte is nil

type Log

type Log struct {
	Address string   `json:"address"`
	Topics  []string `json:"topics"`
	Data    string   `json:"data"`
}

type MsgDataGen

type MsgDataGen interface {
	// CombineData() (string, []abi.ArgumentMarshaling, bool, error)
	CombineData() (string, error)
	ReceiptParsing(receipt *Receipt) *ReceiptParsingReturn

	GetIsWrite() bool
	GetContractDataDen() *ContractDataGen
}

MessageCallDemo, the interface for different types of data package methods

type RawData

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

func NewData

func NewData(funcParams []interface{}, funcAbi *FuncDesc) *RawData

NewData new a RawData object

type Receipt

type Receipt struct {
	BlockHash         string    `json:"blockHash"`         // hash of the block
	BlockNumber       string    `json:"blockNumber"`       // height of the block
	ContractAddress   string    `json:"contractAddress"`   // contract address of the contract deployment. otherwise null
	CumulativeGasUsed string    `json:"cumulativeGasUsed"` //
	From              string    `json:"from"`              // the account address used to send the transaction
	GasUsed           string    `json:"gasUsed"`           // gas used by executing the transaction
	Root              string    `json:"root"`
	To                string    `json:"to"`               // the address the transaction is sent to
	TransactionHash   string    `json:"transactionHash"`  // the hash of the transaction
	TransactionIndex  string    `json:"transactionIndex"` // the index of the transaction
	Logs              RecptLogs `json:"logs"`
	Status            string    `json:"status"` // the execution status of the transaction, "0x1" for success
}

Receipt, eth_getTransactionReceipt return data struct

func ParseTxReceipt

func ParseTxReceipt(response interface{}) (*Receipt, error)

ParseSysContractResult parsed the rpc response to Receipt object

func (*Receipt) Parsing

func (receipt *Receipt) Parsing() *ReceiptParsingReturn

func (*Receipt) ParsingWrap

func (receipt *Receipt) ParsingWrap(events []*FuncDesc, fn eventParsingFuncV2) *ReceiptParsingReturn

type ReceiptParsingReturn

type ReceiptParsingReturn struct {
	Status          string   `json:"status"`
	ContractAddress string   `json:"contractAddress,omitempty"`
	Logs            []string `json:"logs,omitempty"`
	BlockNumber     uint64   `json:"blockNumber"`
	GasUsed         uint64
	From            string
	To              string
	TxHash          string
	Err             string `json:"err,omitempty"`
}

func (*ReceiptParsingReturn) String

func (r *ReceiptParsingReturn) String() string

type RecptLogs

type RecptLogs []*Log

type TxParams

type TxParams struct {
	From     common.Address  `json:"from"` // the address used to send the transaction
	To       *common.Address `json:"to"`   // the address receives the transactions
	Gas      string          `json:"gas"`
	GasPrice string          `json:"gasPrice"`
	Value    string          `json:"value"`
	Data     string          `json:"data"`
}

TxParamsDemo, the object of the eth_call, eth_sendTransaction

func NewTxParams

func NewTxParams(from common.Address, to *common.Address, value, gas, gasPrice, data string) *TxParams

NewTxParams news a TxParams object

func (*TxParams) GetSignedTx

func (tx *TxParams) GetSignedTx(keyfile *utils.Keyfile) (string, error)

GetSignedTx gets the signed transaction

func (*TxParams) SendMode

func (tx *TxParams) SendMode(isWrite bool, keyfile *utils.Keyfile) ([]interface{}, string)

SendMode selects the rpc calls (eth_call, eth_sendTransaction, and eth_sendRawTransaction)

func (*TxParams) SendModeV2

func (tx *TxParams) SendModeV2(keyfile *utils.Keyfile) ([]interface{}, string, error)

type WasmContractInterpreter

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

func (WasmContractInterpreter) ParseNonConstantResponse

func (i WasmContractInterpreter) ParseNonConstantResponse(respStr string, outputType []abi.ArgumentMarshaling) []interface{}

func (WasmContractInterpreter) ReceiptParsing

func (i WasmContractInterpreter) ReceiptParsing(receipt *Receipt, abiBytes []byte) *ReceiptParsingReturn

func (WasmContractInterpreter) ReceiptParsingV2

func (i WasmContractInterpreter) ReceiptParsingV2(receipt *Receipt, conAbi ContractAbi) *ReceiptParsingReturn

type WasmDeployInterpreter

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

WasmInterpreter, packet data in the way defined by the evm virtual machine

func (WasmDeployInterpreter) ReceiptParsing

func (i WasmDeployInterpreter) ReceiptParsing(receipt *Receipt, abiBytes []byte) *ReceiptParsingReturn

func (WasmDeployInterpreter) ReceiptParsingV2

func (i WasmDeployInterpreter) ReceiptParsingV2(receipt *Receipt, conAbi ContractAbi) *ReceiptParsingReturn

Jump to

Keyboard shortcuts

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