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": BytesToString,

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

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

	"bool": RlpBytesToBool,
}

Functions

func BytesToString

func BytesToString(b []byte) string

func ConvertRlpBytesTo

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

func EventParsing

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

func EvmEventParsingPerLog

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

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 ListAbiFuncName

func ListAbiFuncName(abiFuncs []FuncDesc) string

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 WasmEventParsingPerLog

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

Types

type Cns

type Cns struct {
	To   string
	Name string // the cns name of contract
	// contains filtered or unexported fields
}

func NewCns

func NewCns(to, name string, txType uint64) *Cns

type ContractDataGen

type ContractDataGen struct {
	Interp contractInter
	// contains filtered or unexported fields
}

ContractDataGen is used for combining the data of contract execution

func NewContractDataGen

func NewContractDataGen(data *RawData, name string) *ContractDataGen

func NewContractDataGenWrap

func NewContractDataGenWrap(funcName string, funcParams []string, funcAbi []byte, cns Cns, vm string) *ContractDataGen

NewContractDataGen new a ContractDataGen object

func (*ContractDataGen) CombineData

func (dataGen *ContractDataGen) CombineData() (string, []abi.ArgumentMarshaling, bool, error)

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

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 string)

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 {
	TxType            uint64
	ConstructorParams []string
	Interpreter       deployInter
	// contains filtered or unexported fields
}

DeployCall, used for combining the data of contract deployment

func NewDeployDataGen

func NewDeployDataGen(codeBytes, abiBytes []byte, consParams []string, vm string, txType uint64) *DeployDataGen

NewDeployCall new a DeployCall object

func (DeployDataGen) CombineData

func (dataGen DeployDataGen) CombineData() (string, []abi.ArgumentMarshaling, bool, error)

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

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) error

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

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

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 ParseAbiFromJson

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

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

func ParseFuncFromAbi

func ParseFuncFromAbi(abiBytes []byte, name string) (*FuncDesc, error)

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

type FuncIO

type FuncIO struct {
	Name         string   `json:"name"`
	Type         string   `json:"type"`
	Indexed      bool     `json:"indexed,omitempty"`
	InternalType string   `json:"internalType,omitempty"`
	Components   []FuncIO `json:"components,omitempty"`
}

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)
	ReceiptParsing(receipt *Receipt) *ReceiptParsingReturn
	ParseNonConstantResponse(respStr string, outputType []abi.ArgumentMarshaling) []interface{}
}

MessageCallDemo, the interface for different types of data package methods

type RawData

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

RawData, used to store function methods and abi

func NewData

func NewData(funcName string, funcParams []string, funcAbi []byte) *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

type ReceiptParsingReturn

type ReceiptParsingReturn struct {
	Status          string   `json:"status"`
	ContractAddress string   `json:"contractAddress,omitempty"`
	Logs            []string `json:"logs,omitempty"`
	BlockNumber     uint64   `json:"blockNumber"`
	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(keyfileJson []byte) string

GetSignedTx gets the signed transaction

func (*TxParams) SendMode

func (tx *TxParams) SendMode(isWrite bool, keyfileJson []byte) ([]interface{}, string)

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

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

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

Jump to

Keyboard shortcuts

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