opnet 1.0.13 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +71 -0
- package/README.md +6 -7
- package/browser/_version.d.ts +1 -1
- package/browser/abi/BaseContractProperty.d.ts +3 -0
- package/browser/abi/BitcoinAbiTypes.d.ts +4 -0
- package/browser/abi/BitcoinInterface.d.ts +9 -0
- package/browser/abi/interfaces/BaseContractProperties.d.ts +4 -0
- package/browser/abi/interfaces/BitcoinAbiValue.d.ts +5 -0
- package/browser/abi/interfaces/BitcoinInterfaceAbi.d.ts +11 -0
- package/browser/bitcoin/UTXOs.d.ts +1 -6
- package/browser/bitcoin/interfaces/IUTXO.d.ts +7 -0
- package/browser/common/CommonTypes.d.ts +1 -0
- package/browser/contracts/CallResult.d.ts +6 -3
- package/browser/contracts/Contract.d.ts +28 -0
- package/browser/contracts/interfaces/ICallResult.d.ts +2 -3
- package/browser/contracts/interfaces/IContract.d.ts +4 -0
- package/browser/crypto/crypto-browser.d.ts +7 -0
- package/browser/index.js +1 -1
- package/browser/opnet.d.ts +11 -0
- package/browser/scripts/testContract.d.ts +1 -0
- package/browser/scripts/testMethods.d.ts +1 -0
- package/browser/utils/BitcoinUtils.d.ts +4 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/abi/BaseContractProperty.d.ts +3 -0
- package/build/abi/BaseContractProperty.js +1 -0
- package/build/abi/BitcoinAbiTypes.d.ts +4 -0
- package/build/abi/BitcoinAbiTypes.js +5 -0
- package/build/abi/BitcoinInterface.d.ts +9 -0
- package/build/abi/BitcoinInterface.js +45 -0
- package/build/abi/BitcoinInterfaceAbi.d.ts +3 -0
- package/build/abi/BitcoinInterfaceAbi.js +1 -0
- package/build/abi/enums/ParamTypes.d.ts +0 -0
- package/build/abi/enums/ParamTypes.js +1 -0
- package/build/abi/interface/BitcoinInterface.d.ts +6 -0
- package/build/abi/interface/BitcoinInterface.js +12 -0
- package/build/abi/interface/BitcoinInterfaceAbi.d.ts +3 -0
- package/build/abi/interface/BitcoinInterfaceAbi.js +1 -0
- package/build/abi/interfaces/BaseContractProperties.d.ts +4 -0
- package/build/abi/interfaces/BaseContractProperties.js +1 -0
- package/build/abi/interfaces/BaseContractProperty.d.ts +2 -0
- package/build/abi/interfaces/BaseContractProperty.js +1 -0
- package/build/abi/interfaces/BitcoinAbiInput.d.ts +5 -0
- package/build/abi/interfaces/BitcoinAbiInput.js +1 -0
- package/build/abi/interfaces/BitcoinAbiValue.d.ts +5 -0
- package/build/abi/interfaces/BitcoinAbiValue.js +1 -0
- package/build/abi/interfaces/BitcoinInterfaceAbi.d.ts +11 -0
- package/build/abi/interfaces/BitcoinInterfaceAbi.js +1 -0
- package/build/bitcoin/UTXOs.d.ts +1 -6
- package/build/bitcoin/interfaces/IUTXO.d.ts +7 -0
- package/build/bitcoin/interfaces/IUTXO.js +1 -0
- package/build/common/CommonTypes.d.ts +1 -0
- package/build/contracts/CallResult.d.ts +6 -3
- package/build/contracts/CallResult.js +9 -2
- package/build/contracts/Contract.d.ts +28 -0
- package/build/contracts/Contract.js +206 -0
- package/build/contracts/interfaces/ICallResult.d.ts +2 -3
- package/build/contracts/interfaces/IContract.d.ts +4 -0
- package/build/contracts/interfaces/IContract.js +1 -0
- package/build/interface/BitcoinInterface.d.ts +6 -0
- package/build/interface/BitcoinInterface.js +12 -0
- package/build/interface/BitcoinInterfaceAbi.d.ts +3 -0
- package/build/interface/BitcoinInterfaceAbi.js +1 -0
- package/build/interface/Interface.d.ts +2 -0
- package/build/interface/Interface.js +2 -0
- package/build/interface.d.ts +0 -0
- package/build/interface.js +1 -0
- package/build/opnet.d.ts +11 -0
- package/build/opnet.js +11 -0
- package/build/scripts/test.js +12 -0
- package/build/scripts/testContract.d.ts +1 -0
- package/build/scripts/testContract.js +28 -0
- package/build/scripts/testMethods.d.ts +1 -0
- package/build/scripts/testMethods.js +24 -0
- package/build/utils/BitcoinUtils.d.ts +4 -0
- package/build/utils/BitcoinUtils.js +7 -0
- package/cjs/_version.d.ts +1 -0
- package/cjs/_version.js +4 -0
- package/cjs/abi/BaseContractProperty.d.ts +3 -0
- package/cjs/abi/BaseContractProperty.js +2 -0
- package/cjs/abi/BitcoinAbiTypes.d.ts +4 -0
- package/cjs/abi/BitcoinAbiTypes.js +8 -0
- package/cjs/abi/BitcoinInterface.d.ts +9 -0
- package/cjs/abi/BitcoinInterface.js +49 -0
- package/cjs/abi/interfaces/BaseContractProperties.d.ts +4 -0
- package/cjs/abi/interfaces/BaseContractProperties.js +2 -0
- package/cjs/abi/interfaces/BitcoinAbiValue.d.ts +5 -0
- package/cjs/abi/interfaces/BitcoinAbiValue.js +2 -0
- package/cjs/abi/interfaces/BitcoinInterfaceAbi.d.ts +11 -0
- package/cjs/abi/interfaces/BitcoinInterfaceAbi.js +2 -0
- package/cjs/bitcoin/BitcoinAddress.d.ts +20 -0
- package/cjs/bitcoin/BitcoinAddress.js +116 -0
- package/cjs/bitcoin/UTXOs.d.ts +15 -0
- package/cjs/bitcoin/UTXOs.js +16 -0
- package/cjs/block/Block.d.ts +2 -3
- package/cjs/block/Block.js +3 -28
- package/cjs/block/interfaces/IBlock.d.ts +28 -0
- package/cjs/block/interfaces/IBlock.js +2 -0
- package/cjs/common/CommonTypes.d.ts +4 -0
- package/cjs/common/CommonTypes.js +2 -0
- package/cjs/contracts/CallResult.d.ts +13 -0
- package/cjs/contracts/CallResult.js +25 -0
- package/cjs/contracts/Contract.d.ts +28 -0
- package/cjs/contracts/Contract.js +212 -0
- package/cjs/contracts/ContractData.d.ts +15 -0
- package/cjs/contracts/ContractData.js +36 -0
- package/cjs/contracts/interfaces/IAccessList.d.ts +6 -0
- package/cjs/contracts/interfaces/IAccessList.js +2 -0
- package/cjs/contracts/interfaces/ICallResult.d.ts +11 -0
- package/cjs/contracts/interfaces/ICallResult.js +2 -0
- package/cjs/contracts/interfaces/IContract.d.ts +4 -0
- package/cjs/contracts/interfaces/IContract.js +2 -0
- package/cjs/contracts/interfaces/IRawContract.d.ts +13 -0
- package/cjs/contracts/interfaces/IRawContract.js +2 -0
- package/cjs/crypto/crypto.d.ts +2 -0
- package/cjs/crypto/crypto.js +8 -0
- package/cjs/index.d.ts +3 -11
- package/cjs/index.js +16 -11
- package/cjs/opnet.d.ts +36 -0
- package/cjs/opnet.js +54 -0
- package/cjs/providers/AbstractRpcProvider.d.ts +34 -0
- package/cjs/providers/AbstractRpcProvider.js +161 -0
- package/cjs/providers/JSONRpcProvider.d.ts +5 -9
- package/cjs/providers/JSONRpcProvider.js +4 -29
- package/cjs/providers/WebsocketRpcProvider.d.ts +8 -0
- package/cjs/providers/WebsocketRpcProvider.js +27 -0
- package/cjs/scripts/testContract.d.ts +1 -0
- package/cjs/scripts/testContract.js +30 -0
- package/cjs/scripts/testMethods.d.ts +1 -0
- package/cjs/scripts/testMethods.js +26 -0
- package/cjs/serialize/BigInt.d.ts +6 -0
- package/cjs/serialize/BigInt.js +5 -0
- package/cjs/storage/StoredValue.d.ts +10 -0
- package/cjs/storage/StoredValue.js +28 -0
- package/cjs/storage/interfaces/IStorageValue.d.ts +9 -0
- package/cjs/storage/interfaces/IStorageValue.js +2 -0
- package/cjs/transactions/DeploymentTransaction.d.ts +10 -1
- package/cjs/transactions/DeploymentTransaction.js +16 -0
- package/cjs/transactions/GenericTransaction.d.ts +1 -1
- package/cjs/transactions/InteractionTransaction.d.ts +1 -1
- package/cjs/transactions/Transaction.d.ts +1 -1
- package/cjs/transactions/Transaction.js +1 -1
- package/cjs/transactions/TransactionParser.d.ts +7 -0
- package/cjs/transactions/TransactionParser.js +32 -0
- package/cjs/transactions/TransactionReceipt.d.ts +10 -0
- package/cjs/transactions/TransactionReceipt.js +16 -0
- package/cjs/transactions/interfaces/ITransaction.d.ts +39 -0
- package/cjs/transactions/interfaces/ITransaction.js +2 -0
- package/cjs/transactions/interfaces/ITransactionReceipt.d.ts +8 -0
- package/cjs/transactions/interfaces/ITransactionReceipt.js +2 -0
- package/cjs/utils/BitcoinUtils.d.ts +4 -0
- package/cjs/utils/BitcoinUtils.js +14 -0
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/AbstractRpcProvider.html +15 -15
- package/docs/classes/BaseContract.html +187 -0
- package/docs/classes/BitcoinAddress.html +5 -2
- package/docs/classes/BitcoinInterface.html +182 -0
- package/docs/classes/BitcoinUtils.html +183 -0
- package/docs/classes/Block.html +5 -3
- package/docs/classes/CallResult.html +6 -2
- package/docs/classes/ContractData.html +4 -2
- package/docs/classes/DeploymentTransaction.html +4 -2
- package/docs/classes/GenericTransaction.html +4 -2
- package/docs/classes/IBaseContract.html +192 -0
- package/docs/classes/InteractionTransaction.html +3 -2
- package/docs/classes/JSONRpcProvider.html +14 -14
- package/docs/classes/StoredValue.html +4 -2
- package/docs/classes/TransactionBase.html +4 -2
- package/docs/classes/TransactionInput.html +3 -2
- package/docs/classes/TransactionOutput.html +3 -2
- package/docs/classes/TransactionParser.html +3 -2
- package/docs/classes/TransactionReceipt.html +3 -2
- package/docs/classes/UTXO.html +4 -2
- package/docs/classes/WebSocketRpcProvider.html +14 -14
- package/docs/enums/ABIDataTypes.html +183 -0
- package/docs/enums/BitcoinAbiTypes.html +178 -0
- package/docs/enums/OPNetTransactionTypes.html +2 -2
- package/docs/functions/getContract.html +180 -0
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +4 -5
- package/docs/interfaces/BaseContractProperties.html +176 -0
- package/docs/interfaces/BitcoinAbiValue.html +180 -0
- package/docs/interfaces/BitcoinInterfaceAbiBase.html +182 -0
- package/docs/interfaces/IAccessList.html +3 -1
- package/docs/interfaces/IAccessListItem.html +3 -1
- package/docs/interfaces/IBlock.html +5 -3
- package/docs/interfaces/IBlockCommon.html +5 -3
- package/docs/interfaces/ICallRequestError.html +4 -2
- package/docs/interfaces/ICallResultData.html +4 -2
- package/docs/interfaces/IContract.html +177 -0
- package/docs/interfaces/IDeploymentTransaction.html +4 -2
- package/docs/interfaces/IGenericTransaction.html +4 -2
- package/docs/interfaces/IInteractionTransaction.html +4 -2
- package/docs/interfaces/IRawContract.html +5 -2
- package/docs/interfaces/IStorageValue.html +4 -2
- package/docs/interfaces/ITransactionBase.html +4 -2
- package/docs/interfaces/ITransactionInput.html +3 -2
- package/docs/interfaces/ITransactionOutput.html +3 -2
- package/docs/interfaces/ITransactionReceipt.html +4 -2
- package/docs/interfaces/IUTXO.html +4 -2
- package/docs/modules.html +38 -24
- package/docs/types/BaseContractProperty.html +176 -0
- package/docs/types/BitcoinAddressLike.html +1 -1
- package/docs/types/BitcoinInterfaceAbi.html +174 -0
- package/docs/types/BlockHeaderChecksumProof.html +1 -1
- package/docs/types/DecodedCallResult.html +174 -0
- package/docs/types/ICallResult.html +2 -1
- package/docs/types/ITransaction.html +2 -1
- package/docs/types/PointerLike.html +1 -1
- package/docs/types/UTXOs.html +3 -1
- package/docs/variables/version.html +1 -1
- package/package.json +6 -4
- package/src/_version.ts +1 -1
- package/src/abi/BaseContractProperty.ts +8 -0
- package/src/abi/BitcoinAbiTypes.ts +9 -0
- package/src/abi/BitcoinInterface.ts +63 -0
- package/src/abi/interfaces/BaseContractProperties.ts +9 -0
- package/src/abi/interfaces/BitcoinAbiValue.ts +18 -0
- package/src/abi/interfaces/BitcoinInterfaceAbi.ts +19 -0
- package/src/bitcoin/BitcoinAddress.ts +5 -0
- package/src/bitcoin/UTXOs.ts +28 -26
- package/src/bitcoin/interfaces/IUTXO.ts +12 -0
- package/src/block/Block.ts +5 -0
- package/src/block/interfaces/IBlock.ts +46 -38
- package/src/common/CommonTypes.ts +16 -4
- package/src/contracts/CallResult.ts +34 -20
- package/src/contracts/Contract.ts +321 -0
- package/src/contracts/ContractData.ts +46 -41
- package/src/contracts/interfaces/IAccessList.ts +17 -7
- package/src/contracts/interfaces/ICallResult.ts +29 -15
- package/src/contracts/interfaces/IContract.ts +10 -0
- package/src/contracts/interfaces/IRawContract.ts +17 -12
- package/src/crypto/crypto-browser.js +71 -60
- package/src/opnet.ts +17 -0
- package/src/providers/AbstractRpcProvider.ts +352 -351
- package/src/scripts/testContract.ts +51 -0
- package/src/scripts/{test.ts → testMethods.ts} +52 -54
- package/src/scripts/test_abi.json +31 -0
- package/src/storage/StoredValue.ts +35 -30
- package/src/storage/interfaces/IStorageValue.ts +15 -10
- package/src/transactions/DeploymentTransaction.ts +41 -36
- package/src/transactions/GenericTransaction.ts +19 -12
- package/src/transactions/InteractionTransaction.ts +44 -40
- package/src/transactions/Transaction.ts +8 -0
- package/src/transactions/TransactionInput.ts +8 -0
- package/src/transactions/TransactionOutput.ts +8 -0
- package/src/transactions/TransactionParser.ts +47 -43
- package/src/transactions/TransactionReceipt.ts +22 -18
- package/src/transactions/interfaces/ITransaction.ts +78 -52
- package/src/transactions/interfaces/ITransactionReceipt.ts +14 -9
- package/src/utils/BitcoinUtils.ts +22 -0
- package/webpack.config.js +71 -75
|
@@ -1,351 +1,352 @@
|
|
|
1
|
-
import '../serialize/BigInt.js';
|
|
2
|
-
import { BufferHelper } from '@btc-vision/bsi-binary';
|
|
3
|
-
import { Network, networks } from 'bitcoinjs-lib';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
BigNumberish,
|
|
7
|
-
BlockTag,
|
|
8
|
-
JsonRpcApiProvider,
|
|
9
|
-
JsonRpcError,
|
|
10
|
-
JsonRpcPayload,
|
|
11
|
-
JsonRpcResult,
|
|
12
|
-
} from 'ethers';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* @abstract
|
|
36
|
-
* @
|
|
37
|
-
* @
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
* @
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
*
|
|
59
|
-
* @param {
|
|
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
|
-
const
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
*
|
|
117
|
-
* @
|
|
118
|
-
* @param {
|
|
119
|
-
* @
|
|
120
|
-
* @
|
|
121
|
-
* @
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
*
|
|
144
|
-
* @
|
|
145
|
-
* @
|
|
146
|
-
* @
|
|
147
|
-
* @
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
*
|
|
163
|
-
* @
|
|
164
|
-
* @
|
|
165
|
-
* @
|
|
166
|
-
* @
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
*
|
|
180
|
-
* @
|
|
181
|
-
* @
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
*
|
|
202
|
-
* @
|
|
203
|
-
* @param {
|
|
204
|
-
* @
|
|
205
|
-
* @
|
|
206
|
-
* @
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
*
|
|
231
|
-
* @
|
|
232
|
-
* @param {
|
|
233
|
-
* @param {
|
|
234
|
-
* @param {
|
|
235
|
-
* @
|
|
236
|
-
* @
|
|
237
|
-
* @
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
*
|
|
266
|
-
* @
|
|
267
|
-
* @param {
|
|
268
|
-
* @param {
|
|
269
|
-
* @param {
|
|
270
|
-
* @
|
|
271
|
-
* @
|
|
272
|
-
* @
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
*
|
|
321
|
-
* @
|
|
322
|
-
* @
|
|
323
|
-
* @
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
1
|
+
import '../serialize/BigInt.js';
|
|
2
|
+
import { BufferHelper } from '@btc-vision/bsi-binary';
|
|
3
|
+
import { Network, networks } from 'bitcoinjs-lib';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
BigNumberish,
|
|
7
|
+
BlockTag,
|
|
8
|
+
JsonRpcApiProvider,
|
|
9
|
+
JsonRpcError,
|
|
10
|
+
JsonRpcPayload,
|
|
11
|
+
JsonRpcResult,
|
|
12
|
+
} from 'ethers';
|
|
13
|
+
import { IUTXO } from '../bitcoin/interfaces/IUTXO.js';
|
|
14
|
+
|
|
15
|
+
import { UTXO, UTXOs } from '../bitcoin/UTXOs.js';
|
|
16
|
+
import { Block } from '../block/Block.js';
|
|
17
|
+
import { IBlock } from '../block/interfaces/IBlock.js';
|
|
18
|
+
import { BitcoinAddressLike } from '../common/CommonTypes.js';
|
|
19
|
+
import { CallResult } from '../contracts/CallResult.js';
|
|
20
|
+
import { ContractData } from '../contracts/ContractData.js';
|
|
21
|
+
import { ICallRequestError, ICallResult } from '../contracts/interfaces/ICallResult.js';
|
|
22
|
+
import { IRawContract } from '../contracts/interfaces/IRawContract.js';
|
|
23
|
+
import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
|
|
24
|
+
import { IStorageValue } from '../storage/interfaces/IStorageValue.js';
|
|
25
|
+
import { StoredValue } from '../storage/StoredValue.js';
|
|
26
|
+
import { ITransaction } from '../transactions/interfaces/ITransaction.js';
|
|
27
|
+
import { ITransactionReceipt } from '../transactions/interfaces/ITransactionReceipt.js';
|
|
28
|
+
import { TransactionBase } from '../transactions/Transaction.js';
|
|
29
|
+
import { TransactionParser } from '../transactions/TransactionParser.js';
|
|
30
|
+
import { TransactionReceipt } from '../transactions/TransactionReceipt.js';
|
|
31
|
+
|
|
32
|
+
type JsonRpcCallResult = (JsonRpcResult | JsonRpcError)[];
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @description This class is used to provide an abstract RPC provider.
|
|
36
|
+
* @abstract
|
|
37
|
+
* @class AbstractRpcProvider
|
|
38
|
+
* @category Providers
|
|
39
|
+
*/
|
|
40
|
+
export abstract class AbstractRpcProvider {
|
|
41
|
+
protected abstract readonly provider: JsonRpcApiProvider;
|
|
42
|
+
|
|
43
|
+
private nextId: number = 0;
|
|
44
|
+
|
|
45
|
+
protected constructor() {}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get the latest block number.
|
|
49
|
+
* @description This method is used to get the latest block number.
|
|
50
|
+
* @returns {Promise<number>} The latest block number
|
|
51
|
+
* @example await getBlockNumber();
|
|
52
|
+
*/
|
|
53
|
+
public async getBlockNumber(): Promise<number> {
|
|
54
|
+
return await this.provider.getBlockNumber();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get block by number or hash.
|
|
59
|
+
* @param {BlockTag} blockNumberOrHash The block number or hash
|
|
60
|
+
* @param {boolean} prefetchTxs Whether to prefetch transactions
|
|
61
|
+
* @description This method is used to get a block by its number or hash.
|
|
62
|
+
* @returns {Promise<Block>} The requested block
|
|
63
|
+
* @throws {Error} If the block is not found
|
|
64
|
+
* @example await getBlock(123456);
|
|
65
|
+
*/
|
|
66
|
+
public async getBlock(
|
|
67
|
+
blockNumberOrHash: BlockTag,
|
|
68
|
+
prefetchTxs: boolean = false,
|
|
69
|
+
): Promise<Block> {
|
|
70
|
+
const method =
|
|
71
|
+
typeof blockNumberOrHash === 'string' ? 'btc_getBlockByHash' : 'btc_getBlockByNumber';
|
|
72
|
+
|
|
73
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(method, [
|
|
74
|
+
blockNumberOrHash,
|
|
75
|
+
prefetchTxs,
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
const block: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
79
|
+
|
|
80
|
+
const result: IBlock = block.result;
|
|
81
|
+
return new Block(result);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get block by hash. This is the same method as getBlock.
|
|
86
|
+
* @param {string} blockHash The block hash
|
|
87
|
+
* @description This method is used to get a block by its hash. Note that this method is the same as getBlock.
|
|
88
|
+
* @returns {Promise<Block>} The requested block
|
|
89
|
+
* @throws {Error} If the block is not found
|
|
90
|
+
*/
|
|
91
|
+
public async getBlockByHash(blockHash: string): Promise<Block> {
|
|
92
|
+
return await this.getBlock(blockHash);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Get the bitcoin balance of an address.
|
|
97
|
+
* @param {BitcoinAddressLike} addressLike The address to get the balance of
|
|
98
|
+
* @description This method is used to get the balance of a bitcoin address.
|
|
99
|
+
* @returns {Promise<bigint>} The balance of the address
|
|
100
|
+
* @example await getBalance('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq');
|
|
101
|
+
*/
|
|
102
|
+
public async getBalance(addressLike: BitcoinAddressLike): Promise<bigint> {
|
|
103
|
+
const address: string = addressLike.toString();
|
|
104
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload('btc_getBalance', [address]);
|
|
105
|
+
const rawBalance: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
106
|
+
|
|
107
|
+
const result: string = rawBalance.result;
|
|
108
|
+
if (!result || (result && !result.startsWith('0x'))) {
|
|
109
|
+
throw new Error(`Invalid balance returned from provider: ${result}`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return BigInt(result);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Get the UTXOs (Unspent Transaction Outputs) of an address.
|
|
117
|
+
* @description This method is used to get the UTXOs of a bitcoin address.
|
|
118
|
+
* @param {BitcoinAddressLike} address The address to get the UTXOs of
|
|
119
|
+
* @param {boolean} optimize Whether to optimize the UTXOs
|
|
120
|
+
* @returns {Promise<UTXOs>} The UTXOs of the address
|
|
121
|
+
* @example await getUXTOs('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq');
|
|
122
|
+
* @throws {Error} If something went wrong while fetching the UTXOs
|
|
123
|
+
*/
|
|
124
|
+
public async getUXTOs(
|
|
125
|
+
address: BitcoinAddressLike,
|
|
126
|
+
optimize: boolean = false,
|
|
127
|
+
): Promise<unknown> {
|
|
128
|
+
const addressStr: string = address.toString();
|
|
129
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload('btc_getUTXOs', [
|
|
130
|
+
addressStr,
|
|
131
|
+
optimize,
|
|
132
|
+
]);
|
|
133
|
+
|
|
134
|
+
const rawUXTOs: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
135
|
+
const result: UTXOs = rawUXTOs.result || [];
|
|
136
|
+
|
|
137
|
+
return result.map((utxo: IUTXO) => {
|
|
138
|
+
return new UTXO(utxo);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Get a transaction by its hash or hash id.
|
|
144
|
+
* @description This method is used to get a transaction by its hash or hash id.
|
|
145
|
+
* @param {string} txHash The transaction hash
|
|
146
|
+
* @returns {Promise<TransactionBase<OPNetTransactionTypes>>} The requested transaction
|
|
147
|
+
* @example await getTransaction('63e77ba9fa4262b3d4d0d9d97fa8a7359534606c3f3af096284662e3f619f374');
|
|
148
|
+
* @throws {Error} If something went wrong while fetching the transaction
|
|
149
|
+
*/
|
|
150
|
+
public async getTransaction(txHash: string): Promise<TransactionBase<OPNetTransactionTypes>> {
|
|
151
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload('btc_getTransactionByHash', [
|
|
152
|
+
txHash,
|
|
153
|
+
]);
|
|
154
|
+
|
|
155
|
+
const rawTransaction: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
156
|
+
const result: ITransaction = rawTransaction.result;
|
|
157
|
+
|
|
158
|
+
return TransactionParser.parseTransaction(result);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Get a transaction receipt by its hash.
|
|
163
|
+
* @description This method is used to get a transaction receipt by its hash.
|
|
164
|
+
* @param {string} txHash The transaction hash
|
|
165
|
+
* @returns {Promise<ITransactionReceipt>} The requested transaction receipt
|
|
166
|
+
* @example await getTransactionReceipt('63e77ba9fa4262b3d4d0d9d97fa8a7359534606c3f3af096284662e3f619f374');
|
|
167
|
+
* @throws {Error} Something went wrong while fetching the transaction receipt
|
|
168
|
+
*/
|
|
169
|
+
public async getTransactionReceipt(txHash: string): Promise<ITransactionReceipt> {
|
|
170
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload('btc_getTransactionReceipt', [
|
|
171
|
+
txHash,
|
|
172
|
+
]);
|
|
173
|
+
|
|
174
|
+
const rawTransaction: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
175
|
+
return new TransactionReceipt(rawTransaction.result);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Get the current connected network type.
|
|
180
|
+
* @description This method is used to get the current connected network type.
|
|
181
|
+
* @returns {Promise<Network>} The current connected network type
|
|
182
|
+
* @throws {Error} If the chain id is invalid
|
|
183
|
+
*/
|
|
184
|
+
public async getNetwork(): Promise<Network> {
|
|
185
|
+
const network = await this.provider.getNetwork();
|
|
186
|
+
|
|
187
|
+
switch (network.chainId) {
|
|
188
|
+
case 1n:
|
|
189
|
+
return networks.bitcoin;
|
|
190
|
+
case 2n:
|
|
191
|
+
return networks.testnet;
|
|
192
|
+
case 3n:
|
|
193
|
+
return networks.regtest;
|
|
194
|
+
|
|
195
|
+
default:
|
|
196
|
+
throw new Error(`Invalid chain id: ${network.chainId}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Get the contract code of an address.
|
|
202
|
+
* @description This method is used to get the contract code of an address.
|
|
203
|
+
* @param {BitcoinAddressLike} address The address of the contract
|
|
204
|
+
* @param {boolean} [onlyBytecode] Whether to return only the bytecode
|
|
205
|
+
* @returns {Promise<ContractData | Buffer>} The contract data or bytecode
|
|
206
|
+
* @example await getCode('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a');
|
|
207
|
+
* @throws {Error} If something went wrong while fetching the contract code
|
|
208
|
+
*/
|
|
209
|
+
public async getCode(
|
|
210
|
+
address: BitcoinAddressLike,
|
|
211
|
+
onlyBytecode: boolean = false,
|
|
212
|
+
): Promise<ContractData | Buffer> {
|
|
213
|
+
const addressStr: string = address.toString();
|
|
214
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload('btc_getCode', [
|
|
215
|
+
addressStr,
|
|
216
|
+
onlyBytecode,
|
|
217
|
+
]);
|
|
218
|
+
|
|
219
|
+
const rawCode: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
220
|
+
const result: IRawContract | { bytecode: string } = rawCode.result;
|
|
221
|
+
|
|
222
|
+
if ('contractAddress' in result) {
|
|
223
|
+
return new ContractData(result);
|
|
224
|
+
} else {
|
|
225
|
+
return Buffer.from(result.bytecode, 'base64');
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Get the storage at a specific address and pointer.
|
|
231
|
+
* @description This method is used to get the storage at a specific address and pointer.
|
|
232
|
+
* @param {BitcoinAddressLike} address The address to get the storage from
|
|
233
|
+
* @param {BigNumberish} rawPointer The pointer to get the storage from as base64 or bigint
|
|
234
|
+
* @param {boolean} proofs Whether to send proofs or not
|
|
235
|
+
* @param {BigNumberish} [height] The height to get the storage from
|
|
236
|
+
* @returns {Promise<StoredValue>} The storage value
|
|
237
|
+
* @example await getStorageAt('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a', 'EXLK/QhEQMI5d9DrthLvozT+UcDQ7WuSPaz7g8GV3AQ=');
|
|
238
|
+
* @throws {Error} If something went wrong while fetching the storage
|
|
239
|
+
*/
|
|
240
|
+
public async getStorageAt(
|
|
241
|
+
address: BitcoinAddressLike,
|
|
242
|
+
rawPointer: bigint | string,
|
|
243
|
+
proofs: boolean = true,
|
|
244
|
+
height?: BigNumberish,
|
|
245
|
+
): Promise<StoredValue> {
|
|
246
|
+
const addressStr: string = address.toString();
|
|
247
|
+
const pointer: string =
|
|
248
|
+
typeof rawPointer === 'string' ? rawPointer : this.bigintToBase64(rawPointer);
|
|
249
|
+
|
|
250
|
+
const params: [string, string, boolean, string?] = [addressStr, pointer, proofs];
|
|
251
|
+
|
|
252
|
+
if (height) {
|
|
253
|
+
params.push(height.toString());
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload('btc_getStorageAt', params);
|
|
257
|
+
|
|
258
|
+
const rawStorage: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
259
|
+
const result: IStorageValue = rawStorage.result;
|
|
260
|
+
|
|
261
|
+
return new StoredValue(result);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Call a contract function with a given calldata.
|
|
266
|
+
* @description This method is used to call a contract function with a given calldata.
|
|
267
|
+
* @param {BitcoinAddressLike} to The address of the contract
|
|
268
|
+
* @param {Buffer} data The calldata of the contract function
|
|
269
|
+
* @param {BitcoinAddressLike} [from] The address to call the contract from
|
|
270
|
+
* @param {BigNumberish} [height] The height to call the contract from
|
|
271
|
+
* @returns {Promise<CallResult>} The result of the contract function call
|
|
272
|
+
* @example await call('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a', Buffer.from('0x12345678'));
|
|
273
|
+
* @throws {Error} If something went wrong while calling the contract
|
|
274
|
+
*/
|
|
275
|
+
public async call(
|
|
276
|
+
to: BitcoinAddressLike,
|
|
277
|
+
data: Buffer | string,
|
|
278
|
+
from?: BitcoinAddressLike,
|
|
279
|
+
height?: BigNumberish,
|
|
280
|
+
): Promise<CallResult | ICallRequestError> {
|
|
281
|
+
const toStr: string = to.toString();
|
|
282
|
+
const fromStr: string | null = from ? from.toString() : null;
|
|
283
|
+
|
|
284
|
+
let dataStr: string = Buffer.isBuffer(data) ? this.bufferToHex(data) : data;
|
|
285
|
+
if (dataStr.startsWith('0x')) {
|
|
286
|
+
dataStr = dataStr.slice(2);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const params: [string, string, string?, string?] = [toStr, dataStr];
|
|
290
|
+
if (fromStr) {
|
|
291
|
+
params.push(fromStr);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (height) {
|
|
295
|
+
params.push(height.toString());
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload('btc_call', params);
|
|
299
|
+
const rawCall: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
300
|
+
|
|
301
|
+
const result: ICallResult = rawCall.result;
|
|
302
|
+
if ('error' in result) {
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return new CallResult(result);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
protected abstract providerUrl(url: string): string;
|
|
310
|
+
|
|
311
|
+
private bufferToHex(buffer: Buffer): string {
|
|
312
|
+
return buffer.toString('hex');
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private bigintToBase64(bigint: bigint): string {
|
|
316
|
+
return Buffer.from(BufferHelper.pointerToUint8Array(bigint)).toString('base64');
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Send a single payload. This method is used to send a single payload.
|
|
321
|
+
* @param {JsonRpcPayload} payload The payload to send
|
|
322
|
+
* @returns {Promise<JsonRpcResult>} The result of the payload
|
|
323
|
+
* @throws {Error} If no data is returned
|
|
324
|
+
* @private
|
|
325
|
+
*/
|
|
326
|
+
private async callPayloadSingle(payload: JsonRpcPayload): Promise<JsonRpcResult> {
|
|
327
|
+
const rawData: JsonRpcCallResult = await this.provider._send(payload);
|
|
328
|
+
if (rawData.length !== 1) {
|
|
329
|
+
throw new Error(`Unexpected response length for get block request: ${rawData.length}`);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const data = rawData.shift();
|
|
333
|
+
if (!data) {
|
|
334
|
+
throw new Error('Block not found');
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if ('error' in data) {
|
|
338
|
+
throw new Error(`Something went wrong while fetching: ${data.error.message}`);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return data;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
private buildJsonRpcPayload(method: string, params: unknown[]): JsonRpcPayload {
|
|
345
|
+
return {
|
|
346
|
+
method: method,
|
|
347
|
+
params: params,
|
|
348
|
+
id: this.nextId++,
|
|
349
|
+
jsonrpc: '2.0',
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
}
|