-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclient.go
145 lines (101 loc) · 5.69 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package rpcx
import (
"context"
"github.com/meshplus/bitxhub-kit/crypto"
"github.com/meshplus/bitxhub-kit/types"
"github.com/meshplus/bitxhub-model/pb"
)
type SubscriptionType int
const (
SubscribeNewBlock SubscriptionType = iota
)
//go:generate mockgen -destination mock_client/mock_client.go -package mock_client -source client.go
type Client interface {
//Close all connections between BitXHub and the client.
Stop() error
//Reset ecdsa key.
SetPrivateKey(crypto.PrivateKey)
//Send a readonly transaction to BitXHub. If the transaction is writable,
// this transaction will not be executed and error wil be returned.
SendView(tx *pb.BxhTransaction) (*pb.Receipt, error)
//Send a signed transaction to BitXHub. If the signature is illegal,
//the transaction hash will be obtained but the transaction receipt is illegal.
SendTransaction(tx *pb.BxhTransaction, opts *TransactOpts) (string, error)
SendTransactions(txs *pb.MultiTransaction) (*pb.MultiTransactionHash, error)
SendRawTransaction(tx *pb.BxhTransaction) (string, error)
//Send transaction to BitXHub and get the receipt.
SendTransactionWithReceipt(tx *pb.BxhTransaction, opts *TransactOpts) (*pb.Receipt, error)
SendRawTransactionWithReceipt(tx *pb.BxhTransaction) (*pb.Receipt, error)
//Get the receipt by transaction hash,
//the status of the receipt is a sign of whether the transaction is successful.
GetReceipt(hash string) (*pb.Receipt, error)
//Get transaction from BitXHub by transaction hash.
GetTransaction(hash string) (*pb.GetTransactionResponse, error)
GetTransactionByBlockHashAndIndex(blockHash string, index uint64) (*pb.GetTransactionResponse, error)
GetTransactionByBlockNumberAndIndex(blockNum uint64, index uint64) (*pb.GetTransactionResponse, error)
//Get the current blockchain situation of BitXHub.
GetChainMeta() (*pb.ChainMeta, error)
//Get blocks of the specified block height range.
GetBlocks(start uint64, end uint64, fullTx bool) (*pb.GetBlocksResponse, error)
//Obtain block information from BitXHub.
//The block header contains the basic information of the block,
//and the block body contains all the transactions packaged.
GetBlock(value string, blockType pb.GetBlockRequest_Type, fullTx bool) (*pb.Block, error)
//Get the status of the blockchain from BitXHub, normal or abnormal.
GetChainStatus() (*pb.Response, error)
//Get the validators from BitXHub.
GetValidators() (*pb.Response, error)
//Get the current network situation of BitXHub.
GetNetworkMeta() (*pb.Response, error)
//Get account balance from BitXHub by address.
GetAccountBalance(address string) (*pb.Response, error)
//Get the missing block header from BitXHub.
GetBlockHeader(ctx context.Context, begin, end uint64, ch chan<- *pb.BlockHeader) error
//Get the missing block header from BitXHub.
GetInterchainTxWrappers(ctx context.Context, pid string, begin, end uint64, ch chan<- *pb.InterchainTxWrappers) error
//Subscribe to event notifications from BitXHub.
Subscribe(context.Context, pb.SubscriptionRequest_Type, []byte) (<-chan interface{}, error)
//SubscribeAudit to event notifications from BitXHub with permission.
SubscribeAudit(context.Context, pb.AuditSubscriptionRequest_Type, uint64, []byte) (<-chan interface{}, error)
//Deploy the contract, the contract address will be returned when the deployment is successful.
DeployContract(contract []byte, opts *TransactOpts) (contractAddr *types.Address, err error)
//GenerateContractTx generates signed transaction to invoke contract
GenerateContractTx(vmType pb.TransactionData_VMType, address *types.Address, method string, args ...*pb.Arg) (*pb.BxhTransaction, error)
// GenerateIBTPTx generates interchain tx with ibtp specified
GenerateIBTPTx(ibtp *pb.IBTP) (*pb.BxhTransaction, error)
//Call the contract according to the contract type, contract address,
//contract method, and contract method parameters
InvokeContract(vmType pb.TransactionData_VMType, address *types.Address, method string, opts *TransactOpts, args ...*pb.Arg) (*pb.Receipt, error)
//Invoke the BVM contract, BVM is BitXHub's blot contract.
InvokeBVMContract(address *types.Address, method string, opts *TransactOpts, args ...*pb.Arg) (*pb.Receipt, error)
//Invoke the XVM contract, XVM is WebAssembly contract.
InvokeXVMContract(address *types.Address, method string, opts *TransactOpts, args ...*pb.Arg) (*pb.Receipt, error)
// Get BitXHub's signatures specified by id and type.
GetMultiSigns(id string, typ pb.GetSignsRequest_Type) (*pb.SignResponse, error)
// Get BitXHub's tss signatures specified by id and type.
GetTssSigns(id string, typ pb.GetSignsRequest_Type, extra []byte) (*pb.SignResponse, error)
// Get BitXHub TPS during block [begin, end]
GetTPS(begin, end uint64) (uint64, error)
// GetPendingNonceByAccount returns the latest nonce of an account in the pending status,
// and it should be the nonce for next transaction
GetPendingNonceByAccount(account string) (uint64, error)
// IPFSPutFromLocal puts local file to ipfs network
IPFSPutFromLocal(localfPath string) (*pb.Response, error)
// IPFSGet gets from ipfs network
IPFSGet(path string) (*pb.Response, error)
// IPFSGetToLocal gets from ipfs and saves to local file path
IPFSGetToLocal(path string, localfPath string) (*pb.Response, error)
//Check whethe there is a master pier connect to the BitXHub.
CheckMasterPier(address string) (*pb.Response, error)
//Set the master pier connect to the BitXHub.
SetMasterPier(address string, index string, timeout int64) (*pb.Response, error)
//Update the master pier status
HeartBeat(address string, index string) (*pb.Response, error)
// GetChainID get BitXHub Chain ID
GetChainID() (uint64, error)
}
type TransactOpts struct {
From string
Nonce uint64
PrivKey crypto.PrivateKey
}