xuper_sgx

package
v2.0.0-...-d7ce1a4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NativeContractModule native contract module.
	NativeContractModule = "native"
	// WasmContractModule wasm contract module.
	WasmContractModule = "wasm"
	// EvmContractModule evm contract module.
	EvmContractModule = "evm"

	// GoRuntime go contract runtime.
	GoRuntime = "go"
	// CRuntime c++ contract runtime.
	CRuntime = "c"
	// JavaRuntime java contract runtime.
	JavaRuntime = "java"

	// EvmJSONEncoded evm contract invoke abi encoded.
	EvmJSONEncoded = "jsonEncoded"
	// EvmJSONEncodedTrue evm contract invoke abi encoded.
	EvmJSONEncodedTrue = "true"

	// XkernelModule xkernel contract module
	XkernelModule = "kernel"
	// Xkernel3Module xkernel contract module
	Xkernel3Module = "xkernel"
	// XkernelDeployMethod xkernel contract deploy contract method.
	XkernelDeployMethod = "Deploy"
	// XkernelUpgradeMethod xkernel contract upgrade contract method.
	XkernelUpgradeMethod = "Upgrade"
	// XkernelNewAccountMethod xkernel contract create contract account method.
	XkernelNewAccountMethod = "NewAccount"
	// XkernelSetAccountACLMethod xkernel contract set account ACL method.
	XkernelSetAccountACLMethod = "SetAccountAcl"
	// XkernelSetMethodACLMethod xkernel contract set method ACL method.
	XkernelSetMethodACLMethod = "SetMethodAcl"

	// ArgAccountName account name field.
	ArgAccountName = "account_name"
	// ArgContractName contract name field.
	ArgContractName = "contract_name"
	// ArgContractCode contract code field.
	ArgContractCode = "contract_code"
	// ArgContractDesc contract desc field.
	ArgContractDesc = "contract_desc"
	// ArgInitArgs contract init args field.
	ArgInitArgs = "init_args"
	// ArgContractAbi evm abi field.
	ArgContractAbi = "contract_abi"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ACL

type ACL struct {
	PM        PermissionModel    `json:"pm"`
	AksWeight map[string]float64 `json:"aksWeight"`
}

ACL acl.

func NewACL

func NewACL(rule int32, acceptValue float64) *ACL

NewACL new ACl instance.

func (*ACL) AddAK

func (a *ACL) AddAK(ak string, weight float64)

AddAK add ak and weight pair.

type BalanceDetail

type BalanceDetail struct {
	Balance  string
	IsFrozen bool
}

BalanceDetail address or account balance detailds.

type BlockEventOption

type BlockEventOption func(*blockEventOption) error

BlockEventOption event opt.

func WithAuthRequire

func WithAuthRequire(authRequire string) BlockEventOption

WithAuthRequire indicates the auth require from which tx are to be received.

func WithBlockChanBufferSize

func WithBlockChanBufferSize(size uint) BlockEventOption

WithBlockChanBufferSize block event block channel size, default 100.

func WithBlockEventBcname

func WithBlockEventBcname(name string) BlockEventOption

WithBlockEventBcname blockchain name.

func WithBlockRange

func WithBlockRange(startBlock, endBlock string) BlockEventOption

WithBlockRange indicates the block range.

func WithContract

func WithContract(contract string) BlockEventOption

WithContract indicates the contract name from which tx are to be received.

func WithEventName

func WithEventName(eventName string) BlockEventOption

WithEventName indicates the event name from which events are to be received.

func WithExcludeTx

func WithExcludeTx(excludeTx bool) BlockEventOption

WithExcludeTx indicates if exclude tx.

func WithExcludeTxEvent

func WithExcludeTxEvent(excludeTxEvent bool) BlockEventOption

WithExcludeTxEvent indicates if exclude tx event.

func WithFromAddr

func WithFromAddr(fromAddr string) BlockEventOption

WithFromAddr indicates the transfer address from which tx are to be received.

func WithInitiator

func WithInitiator(initiator string) BlockEventOption

WithInitiator indicates the contract initiator from which tx are to be received.

func WithSkipEmplyTx

func WithSkipEmplyTx() BlockEventOption

WithSkipEmplyTx block event skip emply tx block.

func WithToAddr

func WithToAddr(toAddr string) BlockEventOption

WithToAddr indicates the receiver address from which tx are to be received.

type ClientOption

type ClientOption func(opt *clientOptions) error

ClientOption xuperclient opt.

func WithConfigFile

func WithConfigFile(configFile string) ClientOption

WithConfigFile set xuperclient config file.

func WithGrpcGZIP

func WithGrpcGZIP() ClientOption

WithGrpcGZIP use gzip.

func WithGrpcTLS

func WithGrpcTLS(serverName, cacertFile, certFile, keyFile string) ClientOption

WithGrpcTLS grpc TLS cert config.

type ContractEvent

type ContractEvent struct {
	Contract string `json:"contract,omitempty"`
	Name     string `json:"name,omitempty"`
	Body     string `json:"body,omitempty"`
}

ContractEvent pb.ContractEvent

type FilteredBlock

type FilteredBlock struct {
	Bcname      string                 `json:"bcname,omitempty"`
	Blockid     string                 `json:"blockid,omitempty"`
	BlockHeight int64                  `json:"block_height,omitempty"`
	Txs         []*FilteredTransaction `json:"txs,omitempty"`
}

FilteredBlock pb.FilteredBlock

type FilteredTransaction

type FilteredTransaction struct {
	Txid   string           `json:"txid,omitempty"`
	Events []*ContractEvent `json:"events,omitempty"`
}

FilteredTransaction pb.FilteredTransaction

type PermissionModel

type PermissionModel struct {
	Rule        int32   `json:"rule"`
	AcceptValue float64 `json:"acceptValue"`
}

PermissionModel acl permission model.

type Proposal

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

Proposal 代表单个请求,构造交易,但不 post。

func NewProposal

func NewProposal(xclient *XClient, request *Request, cfg *config.CommConfig) (*Proposal, error)

NewProposal new Proposal instance.

func (*Proposal) Build

func (p *Proposal) Build() (*Transaction, error)

Build 发起预执行,构造交易。

func (*Proposal) GenCompleteTx

func (p *Proposal) GenCompleteTx() (*Transaction, error)

GenCompleteTx 根据预执行结果构造完整的交易。

func (*Proposal) PreExecWithSelectUtxo

func (p *Proposal) PreExecWithSelectUtxo() error

PreExecWithSelectUtxo 预执行并选择 utxo,如果有背书则调用 EndorserCall。

type QueryOption

type QueryOption func(opt *queryOption) error

QueryOption query opt.

func WithQueryBcname

func WithQueryBcname(bcname string) QueryOption

WithQueryBcname query method bcname option.

type Request

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

Request xuperchain transaction request.

func NewCreateContractAccountRequest

func NewCreateContractAccountRequest(from *account_sgx.AccountSgx, contractAccount string, opts ...RequestOption) (*Request, error)

NewCreateContractAccountRequest new request for create contract account.

func NewDeployContractRequest

func NewDeployContractRequest(from *account_sgx.AccountSgx, name string, abi, code []byte, args map[string]string, contractType, runtime string, opts ...RequestOption) (*Request, error)

NewDeployContractRequest new request for deploy contract, wasm, evm and native.

func NewInvokeContractRequest

func NewInvokeContractRequest(from *account_sgx.AccountSgx, module, name, method string, args map[string]string, opts ...RequestOption) (*Request, error)

NewInvokeContractRequest new request for invoke contract, wasm, evm and native.

func NewRequest

func NewRequest(
	initiator *account_sgx.AccountSgx,
	module, contractName, methodName string,
	args map[string][]byte,
	transferTo, transferAmount string,
	opts ...RequestOption) (*Request, error)

NewRequest new custom request.

func NewSetAccountACLRequest

func NewSetAccountACLRequest(from *account_sgx.AccountSgx, acl *ACL, opts ...RequestOption) (*Request, error)

NewSetAccountACLRequest new request for set contract account acl.

func NewSetMethodACLRequest

func NewSetMethodACLRequest(from *account_sgx.AccountSgx, name, method string, acl *ACL, opts ...RequestOption) (*Request, error)

NewSetMethodACLRequest new request for set method ACL.

func NewTransferRequest

func NewTransferRequest(from *account_sgx.AccountSgx, to, amount string, opts ...RequestOption) (*Request, error)

////////////////////////////////////////

sdk逻辑实现

////////////////////////////////////////

func NewUpgradeContractRequest

func NewUpgradeContractRequest(from *account_sgx.AccountSgx, module, name string, code []byte, opts ...RequestOption) (*Request, error)

NewUpgradeContractRequest new upgrade contract request. NOTE: evm contract upgrade disabled!

func (*Request) SetArgs

func (r *Request) SetArgs(args map[string][]byte) error

SetArgs set request args. NOTE: this is pb.InvokeRPCRequest args, not contract invoke args.

func (*Request) SetContractName

func (r *Request) SetContractName(contractName string) error

SetContractName set

func (*Request) SetInitiatorAccount

func (r *Request) SetInitiatorAccount(account *account_sgx.AccountSgx) error

SetInitiatorAccount set request initiator.

func (*Request) SetModule

func (r *Request) SetModule(module string) error

SetModule set request contract module.

func (*Request) SetTransferAmount

func (r *Request) SetTransferAmount(amount string) error

SetTransferAmount set

func (*Request) SetTransferTo

func (r *Request) SetTransferTo(to string) error

SetTransferTo set

type RequestOption

type RequestOption func(opt *requestOptions) error

RequestOption tx opt.

func WithBcname

func WithBcname(name string) RequestOption

WithBcname set blockchain name.

func WithContractInvokeAmount

func WithContractInvokeAmount(amount string) RequestOption

WithContractInvokeAmount set transfer to contract when invoke contract.

func WithDesc

func WithDesc(desc string) RequestOption

WithDesc set tx desc.

func WithFee

func WithFee(fee string) RequestOption

WithFee set fee.

func WithFeeFromAccount

func WithFeeFromAccount() RequestOption

WithFeeFromAccount fee & gas from contract account.

func WithNotPost

func WithNotPost() RequestOption

WithNotPost generate transaction only, won't post to server.

func WithOtherAuthRequires

func WithOtherAuthRequires(authRequires []string) RequestOption

WithOtherAuthRequires for multisign, other address need sign, exclude initiator.

type Transaction

type Transaction struct {
	Tx               *pb.Transaction
	ContractResponse *pb.ContractResponse
	Bcname           string

	Fee     string
	GasUsed int64

	DigestHash []byte
}

Transaction xuperchain transaction.

func (*Transaction) Sign

func (t *Transaction) Sign(account *account_sgx.AccountSgx) error

Sign account sign for tx, for multisign.multisign

type Watcher

type Watcher struct {
	FilteredBlockChan <-chan *FilteredBlock
	// contains filtered or unexported fields
}

Watcher event watcher.

func (*Watcher) Close

func (w *Watcher) Close()

Close close watcher.

type XClient

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

与节点连接的客户端 XClient xuperchain client.

func New

func New(node string, opts ...ClientOption) (*XClient, error)

New new xuper client.

Parameters:

  • `node`: node GRPC URL.

func (*XClient) Close

func (x *XClient) Close() error

Close close xuper client all connections.

func (*XClient) CreateContractAccount

func (x *XClient) CreateContractAccount(from *account_sgx.AccountSgx, contractAccount string, opts ...RequestOption) (*Transaction, error)

CreateContractAccount create contract account for initiator.

Parameters:

  • `from` : Transaction initiator. NOTE: from must be NOT set contract account, if you set please remove it.
  • `contractAccount`:The contract account you want to create, such as: XC8888888899999999@xuper.

func (*XClient) DeployEVMContract

func (x *XClient) DeployEVMContract(from *account_sgx.AccountSgx, name string, abi, bin []byte, args map[string]string, opts ...RequestOption) (*Transaction, error)

DeployEVMContract deploy evm contract.

Parameters:

  • `from`: Transaction initiator.
  • `name`: Contract name.
  • `abi` : Solidity contract abi.
  • `bin` : Solidity contract bin.
  • `args`: Contract init args.

func (*XClient) DeployNativeGoContract

func (x *XClient) DeployNativeGoContract(from *account_sgx.AccountSgx, name string, code []byte, args map[string]string, opts ...RequestOption) (*Transaction, error)

DeployNativeGoContract deploy native go contract.

Parameters:

  • `from`: Transaction initiator.
  • `name`: Contract name.
  • `code`: Contract code bytes.
  • `args`: Contract init args.

func (*XClient) DeployNativeJavaContract

func (x *XClient) DeployNativeJavaContract(from *account_sgx.AccountSgx, name string, code []byte, args map[string]string, opts ...RequestOption) (*Transaction, error)

DeployNativeJavaContract deploy native java contract.

Parameters:

  • `from`: Transaction initiator.
  • `name`: Contract name.
  • `code`: Contract code bytes.
  • `args`: Contract init args.

func (*XClient) DeployWasmContract

func (x *XClient) DeployWasmContract(from *account_sgx.AccountSgx, name string, code []byte, args map[string]string, opts ...RequestOption) (*Transaction, error)

DeployWasmContract deploy wasm c++ contract.

Parameters:

  • `from`: Transaction initiator.
  • `name`: Contract name.
  • `code`: Contract code bytes.
  • `args`: Contract init args.

func (*XClient) Do

func (x *XClient) Do(req *Request) (*Transaction, error)

////////////////////////////// / client <------> node ////////////////////////////// Do generete tx & post tx.

func (*XClient) GenerateTx

func (x *XClient) GenerateTx(req *Request) (*Transaction, error)

GenerateTx generate Transaction.

func (*XClient) InvokeEVMContract

func (x *XClient) InvokeEVMContract(from *account_sgx.AccountSgx, name, method string, args map[string]string, opts ...RequestOption) (*Transaction, error)

InvokeEVMContract invoke evm contract.

Parameters:

  • `from` : Transaction initiator.
  • `name` : Contract name.
  • `method`: Contract method.
  • `args` : Contract invoke args.

func (*XClient) InvokeNativeContract

func (x *XClient) InvokeNativeContract(from *account_sgx.AccountSgx, name, method string, args map[string]string, opts ...RequestOption) (*Transaction, error)

InvokeNativeContract invoke native contract.

Parameters:

  • `from` : Transaction initiator.
  • `name` : Contract name.
  • `method`: Contract method.
  • `args` : Contract invoke args.

func (*XClient) InvokeWasmContract

func (x *XClient) InvokeWasmContract(from *account_sgx.AccountSgx, name, method string, args map[string]string, opts ...RequestOption) (*Transaction, error)

InvokeWasmContract invoke wasm c++ contract.

Parameters:

  • `from` : Transaction initiator.
  • `name` : Contract name.
  • `method`: Contract method.
  • `args` : Contract invoke args.

func (*XClient) PostTx

func (x *XClient) PostTx(tx *Transaction) (*Transaction, error)

PostTx post tx to node.

func (*XClient) PreExecTx

func (x *XClient) PreExecTx(req *Request) (*Transaction, error)

PreExecTx preExec for query.

func (*XClient) QueryAccountACL

func (x *XClient) QueryAccountACL(account string, opts ...QueryOption) (*ACL, error)

QueryAccountACL query the ACL by account

Parameters:

  • `account` : account, such as XC1111111111111111@xuper

func (*XClient) QueryAccountByAK

func (x *XClient) QueryAccountByAK(address string, opts ...QueryOption) ([]string, error)

QueryAccountByAK query the account by AK

Parameters:

  • `address` : address

func (*XClient) QueryAccountContracts

func (x *XClient) QueryAccountContracts(account string, opts ...QueryOption) ([]*pb.ContractStatus, error)

QueryAccountContracts query all contracts for account

Parameters:

  • `account` : account,such as XC1111111111111111@xuper

func (*XClient) QueryAddressContracts

func (x *XClient) QueryAddressContracts(address string, opts ...QueryOption) (map[string]*pb.ContractList, error)

QueryAddressContracts query all contracts for address

Parameters:

  • `address` : address

Returns:

  • `map` : contractAccount => contractStatusList
  • `error`: error

func (*XClient) QueryBalance

func (x *XClient) QueryBalance(address string, opts ...QueryOption) (*big.Int, error)

QueryBalance query balance by the address

Parameters:

  • `address` : address

func (*XClient) QueryBalanceDetail

func (x *XClient) QueryBalanceDetail(address string, opts ...QueryOption) ([]*BalanceDetail, error)

QueryBalanceDetail query the balance detail by address

Parameters:

  • `address` : address

func (*XClient) QueryBlockByHeight

func (x *XClient) QueryBlockByHeight(height int64, opts ...QueryOption) (*pb.Block, error)

QueryBlockByHeight query the block by block height

Parameters:

  • `height` : block height

func (*XClient) QueryBlockByID

func (x *XClient) QueryBlockByID(blockID string, opts ...QueryOption) (*pb.Block, error)

QueryBlockByID query the block by blockID

Parameters:

  • `blockID` : block id

func (*XClient) QueryBlockChainStatus

func (x *XClient) QueryBlockChainStatus(opts ...QueryOption) (*pb.BCStatus, error)

QueryBlockChainStatus query the block chain status

func (*XClient) QueryBlockChains

func (x *XClient) QueryBlockChains(opts ...QueryOption) ([]string, error)

QueryBlockChains query block chains

func (*XClient) QueryEVMContract

func (x *XClient) QueryEVMContract(from *account_sgx.AccountSgx, name, method string, args map[string]string, opts ...RequestOption) (*Transaction, error)

QueryEVMContract query evm contract.

Parameters:

  • `from` : Transaction initiator.
  • `name` : Contract name.
  • `method`: Contract method.
  • `args` : Contract invoke args.

func (*XClient) QueryMethodACL

func (x *XClient) QueryMethodACL(name, method string, opts ...QueryOption) (*ACL, error)

QueryMethodACL query the ACL by method

Parameters:

  • `name` : contract name
  • `account` : account

func (*XClient) QueryNativeContract

func (x *XClient) QueryNativeContract(from *account_sgx.AccountSgx, name, method string, args map[string]string, opts ...RequestOption) (*Transaction, error)

QueryNativeContract query native contract.

Parameters:

  • `from` : Transaction initiator.
  • `name` : Contract name.
  • `method`: Contract method.
  • `args` : Contract invoke args.

func (*XClient) QueryNetURL

func (x *XClient) QueryNetURL(opts ...QueryOption) (string, error)

QueryNetURL query the net URL

func (*XClient) QuerySystemStatus

func (x *XClient) QuerySystemStatus(opts ...QueryOption) (*pb.SystemsStatusReply, error)

QuerySystemStatus query the system status

func (*XClient) QueryTxByID

func (x *XClient) QueryTxByID(txID string, opts ...QueryOption) (*pb.Transaction, error)

//////////////////////////////////////////////

query

///////////////////////////////////////////// QueryTxByID query the tx by txID

Parameters

  • `txID` : transaction id

func (*XClient) QueryWasmContract

func (x *XClient) QueryWasmContract(from *account_sgx.AccountSgx, name, method string, args map[string]string, opts ...RequestOption) (*Transaction, error)

QueryWasmContract query wasm c++ contract.

Parameters:

  • `from` : Transaction initiator.
  • `name` : Contract name.
  • `method`: Contract method.
  • `args` : Contract invoke args.

func (*XClient) SetAccountACL

func (x *XClient) SetAccountACL(from *account_sgx.AccountSgx, acl *ACL, opts ...RequestOption) (*Transaction, error)

SetAccountACL update contract account acl. NOTE: from account must be set contract account.

Parameters:

  • `from`: Transaction initiator.
  • `acl` : The ACL you want to set.

func (*XClient) SetMethodACL

func (x *XClient) SetMethodACL(from *account_sgx.AccountSgx, name, method string, acl *ACL, opts ...RequestOption) (*Transaction, error)

SetMethodACL update contract method acl.

Parameters:

  • `from` : Transaction initiator.
  • `name` : Contract name.
  • `method`: Contract method.
  • `acl` : The ACL you want to set.

func (*XClient) Transfer

func (x *XClient) Transfer(from *account_sgx.AccountSgx, to, amount string, opts ...RequestOption) (*Transaction, error)

Transfer to another address.

Parameters:

  • `from` : Transaction initiator.
  • `to` : Transfer receiving address.
  • `amount`: Transfer amount.

func (*XClient) UpgradeNativeContract

func (x *XClient) UpgradeNativeContract(from *account_sgx.AccountSgx, name string, code []byte, opts ...RequestOption) (*Transaction, error)

UpgradeNativeContract upgrade native contract.

Parameters:

  • `from`: Transaction initiator.
  • `name`: Contract name.
  • `code`: Contract code bytes.
  • `args`: Contract init args.

func (*XClient) UpgradeWasmContract

func (x *XClient) UpgradeWasmContract(from *account_sgx.AccountSgx, name string, code []byte, opts ...RequestOption) (*Transaction, error)

UpgradeWasmContract upgrade wasm contract.

Parameters:

  • `from`: Transaction initiator.
  • `name`: Contract name.
  • `code`: Contract code bytes.
  • `args`: Contract init args.

func (*XClient) WatchBlockEvent

func (x *XClient) WatchBlockEvent(opts ...BlockEventOption) (*Watcher, error)

WatchBlockEvent new watcher for block event.

Jump to

Keyboard shortcuts

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