1
1
package client
2
2
3
3
import (
4
- "math/big"
5
-
4
+ "github.com/bnb-chain/zkbnb-go-sdk/signer"
6
5
"github.com/ethereum/go-ethereum/common"
7
6
"github.com/ethereum/go-ethereum/ethclient"
7
+ "math/big"
8
8
9
9
"github.com/bnb-chain/zkbnb-go-sdk/accounts"
10
10
"github.com/bnb-chain/zkbnb-go-sdk/client/abi"
@@ -120,43 +120,59 @@ type ZkBNBQuerier interface {
120
120
121
121
// GetNftsByAccountIndex returns nfts by account index
122
122
GetNftsByAccountIndex (accountIndex , offset , limit int64 ) (* types.Nfts , error )
123
+
124
+ // GetRollbacks returns tx rollback info
125
+ GetRollbacks (fromBlockHeight , offset , limit int64 ) (total uint32 , rollbacks []* types.Rollback , err error )
126
+
127
+ // GetMaxCollectionId returns max collection id by accountIndex
128
+ GetMaxCollectionId (accountIndex int64 ) (* types.MaxCollectionId , error )
129
+
130
+ // GetNftByTxHash returns nfts by txHash
131
+ GetNftByTxHash (txHash string ) (* types.NftIndex , error )
132
+
133
+ // UpdateNftByIndex updates mutable attribute by NftIndex
134
+ UpdateNftByIndex (privateKey string , nft * types.UpdateNftReq ) (* types.Mutable , error )
123
135
}
124
136
125
137
type ZkBNBTxSender interface {
126
- // SetKeyManager sets the key manager for signing txs.
127
- SetKeyManager (keyManager accounts.KeyManager )
128
138
129
139
// KeyManager returns the key manager for signing txs.
130
140
KeyManager () accounts.KeyManager
131
141
132
142
// SendRawTx sends signed raw transaction and returns tx hash
133
- SendRawTx (txType uint32 , txInfo string ) (string , error )
143
+ SendRawTx (txType uint32 , txInfo string , signature string ) (string , error )
144
+
145
+ // GenerateSignBody generates the signature body for caller to calculate signature
146
+ GenerateSignBody (txData interface {}) (string , error )
147
+
148
+ // GenerateSignature generates the signature for l1 identifier validation
149
+ GenerateSignature (privateKey string , txData interface {}) (string , error )
134
150
135
151
// NOTE: You need to call SetKeyManager first before using following functions
136
152
137
153
// MintNft will sign tx with key manager and send signed transaction
138
- MintNft (tx * types.MintNftTxReq , ops * types.TransactOpts ) (string , error )
154
+ MintNft (tx * types.MintNftTxReq , ops * types.TransactOpts , signatureList ... string ) (string , error )
139
155
140
156
// CreateCollection will sign tx with key manager and send signed transaction
141
- CreateCollection (tx * types.CreateCollectionReq , ops * types.TransactOpts ) (string , error )
157
+ CreateCollection (tx * types.CreateCollectionTxReq , ops * types.TransactOpts , signatureList ... string ) (string , error )
142
158
143
159
// CancelOffer will sign tx with key manager and send signed transaction
144
- CancelOffer (tx * types.CancelOfferReq , ops * types.TransactOpts ) (string , error )
160
+ CancelOffer (tx * types.CancelOfferTxReq , ops * types.TransactOpts , signatureList ... string ) (string , error )
145
161
146
162
// AtomicMatch will sign tx with key manager and send signed transaction
147
- AtomicMatch (tx * types.AtomicMatchTxReq , ops * types.TransactOpts ) (string , error )
163
+ AtomicMatch (tx * types.AtomicMatchTxReq , ops * types.TransactOpts , signatureList ... string ) (string , error )
148
164
149
165
// WithdrawNft will sign tx with key manager and send signed transaction
150
- WithdrawNft (tx * types.WithdrawNftTxReq , ops * types.TransactOpts ) (string , error )
166
+ WithdrawNft (tx * types.WithdrawNftTxReq , ops * types.TransactOpts , signatureList ... string ) (string , error )
151
167
152
168
// TransferNft will sign tx with key manager and send signed transaction
153
- TransferNft (tx * types.TransferNftTxReq , ops * types.TransactOpts ) (string , error )
169
+ TransferNft (tx * types.TransferNftTxReq , ops * types.TransactOpts , signatureList ... string ) (string , error )
154
170
155
171
// Transfer will sign tx with key manager and send signed transaction
156
- Transfer (tx * types.TransferTxReq , ops * types.TransactOpts ) (string , error )
172
+ Transfer (tx * types.TransferTxReq , ops * types.TransactOpts , signatureList ... string ) (string , error )
157
173
158
174
// Withdraw will sign tx with key manager and send signed transaction
159
- Withdraw (tx * types.WithdrawReq , ops * types.TransactOpts ) (string , error )
175
+ Withdraw (tx * types.WithdrawTxReq , ops * types.TransactOpts , signatureList ... string ) (string , error )
160
176
}
161
177
162
178
type ZkBNBL1Client interface {
@@ -182,10 +198,42 @@ type ZkBNBL1Client interface {
182
198
RequestFullExitNft (accountName string , nftIndex uint32 ) (common.Hash , error )
183
199
}
184
200
185
- func NewZkBNBClient (url string ) ZkBNBClient {
201
+ func NewZkBNBClientWithPrivateKey (url , privateKey string , chainId uint64 ) (ZkBNBClient , error ) {
202
+ l1Signer , err := signer .NewL1Singer (privateKey )
203
+ if err != nil {
204
+ return nil , err
205
+ }
206
+ seed , err := accounts .GenerateSeed (privateKey , chainId )
207
+ if err != nil {
208
+ return nil , err
209
+ }
210
+ keyManager , err := accounts .NewSeedKeyManager (seed )
211
+ if err != nil {
212
+ return nil , err
213
+ }
214
+
186
215
return & l2Client {
187
- endpoint : url ,
216
+ endpoint : url ,
217
+ privateKey : privateKey ,
218
+ chainId : chainId ,
219
+ l1Signer : l1Signer ,
220
+ keyManager : keyManager ,
221
+ }, nil
222
+ }
223
+
224
+ func NewZkBNBClientWithSeed (url , seed string , chainId uint64 ) (ZkBNBClient , error ) {
225
+ keyManager , err := accounts .NewSeedKeyManager (seed )
226
+ if err != nil {
227
+ return nil , err
188
228
}
229
+
230
+ return & l2Client {
231
+ endpoint : url ,
232
+ privateKey : "" ,
233
+ chainId : chainId ,
234
+ l1Signer : nil ,
235
+ keyManager : keyManager ,
236
+ }, nil
189
237
}
190
238
191
239
func NewZkBNBL1Client (provider , zkbnbContract string ) (ZkBNBL1Client , error ) {
0 commit comments