opnet 1.0.49 → 1.0.50
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/.babelrc +8 -7
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -20
- package/.github/workflows/ci.yml +48 -0
- package/.prettierrc.json +11 -11
- package/CONTRIBUTING.md +71 -71
- package/LICENSE.md +16 -16
- package/README.md +96 -93
- package/STAKING.md +60 -70
- package/browser/_version.d.ts +1 -1
- package/browser/bitcoin/BitcoinAddress.d.ts +0 -1
- package/browser/contracts/CallResult.d.ts +0 -1
- package/browser/contracts/Contract.d.ts +0 -1
- package/browser/contracts/ContractData.d.ts +0 -1
- package/browser/contracts/interfaces/IContract.d.ts +0 -1
- package/browser/contracts/interfaces/IRawContract.d.ts +0 -1
- package/browser/crypto/crypto.d.ts +0 -1
- package/browser/index.js +2 -2
- package/browser/providers/AbstractRpcProvider.d.ts +47 -48
- package/browser/providers/JSONRpcProvider.d.ts +10 -10
- package/browser/storage/StoredValue.d.ts +0 -1
- package/browser/storage/interfaces/IStorageValue.d.ts +0 -1
- package/browser/transactions/decoders/DeploymentTransaction.d.ts +0 -1
- package/browser/transactions/decoders/InteractionTransaction.d.ts +0 -1
- package/browser/transactions/interfaces/ITransaction.d.ts +0 -1
- package/browser/transactions/interfaces/ITransactionReceipt.d.ts +0 -1
- package/browser/transactions/interfaces/transactions/IDeploymentTransaction.d.ts +0 -1
- package/browser/transactions/interfaces/transactions/IInteractionTransaction.d.ts +0 -1
- package/browser/transactions/interfaces/transactions/IUnwrapTransaction.d.ts +0 -1
- package/browser/transactions/metadata/TransactionOutput.d.ts +0 -1
- package/browser/transactions/metadata/TransactionReceipt.d.ts +0 -1
- package/build/abi/BitcoinInterface.js +0 -1
- package/build/bitcoin/BitcoinAddress.d.ts +0 -1
- package/build/bitcoin/BitcoinAddress.js +30 -19
- package/build/bitcoin/UTXOs.js +0 -4
- package/build/block/Block.js +1 -19
- package/build/contracts/CallResult.d.ts +0 -1
- package/build/contracts/CallResult.js +2 -7
- package/build/contracts/Contract.d.ts +0 -1
- package/build/contracts/Contract.js +1 -6
- package/build/contracts/ContractData.d.ts +0 -1
- package/build/contracts/ContractData.js +0 -11
- package/build/contracts/OPNetEvent.js +2 -5
- package/build/contracts/interfaces/IContract.d.ts +0 -1
- package/build/contracts/interfaces/IRawContract.d.ts +0 -1
- package/build/crypto/crypto.d.ts +0 -1
- package/build/providers/AbstractRpcProvider.d.ts +0 -1
- package/build/providers/AbstractRpcProvider.js +3 -4
- package/build/providers/JSONRpcProvider.js +1 -3
- package/build/providers/WebsocketRpcProvider.js +0 -1
- package/build/storage/StoredValue.d.ts +0 -1
- package/build/storage/StoredValue.js +0 -4
- package/build/storage/interfaces/IStorageValue.d.ts +0 -1
- package/build/transactions/Transaction.js +0 -8
- package/build/transactions/decoders/DeploymentTransaction.d.ts +0 -1
- package/build/transactions/decoders/DeploymentTransaction.js +0 -10
- package/build/transactions/decoders/InteractionTransaction.d.ts +0 -1
- package/build/transactions/decoders/InteractionTransaction.js +0 -7
- package/build/transactions/decoders/UnwrapTransaction.js +0 -5
- package/build/transactions/decoders/WrapTransaction.js +0 -7
- package/build/transactions/interfaces/ITransaction.d.ts +0 -1
- package/build/transactions/interfaces/ITransactionReceipt.d.ts +0 -1
- package/build/transactions/interfaces/transactions/IDeploymentTransaction.d.ts +0 -1
- package/build/transactions/interfaces/transactions/IInteractionTransaction.d.ts +0 -1
- package/build/transactions/interfaces/transactions/IUnwrapTransaction.d.ts +0 -1
- package/build/transactions/metadata/TransactionInput.js +1 -5
- package/build/transactions/metadata/TransactionOutput.d.ts +0 -1
- package/build/transactions/metadata/TransactionOutput.js +0 -4
- package/build/transactions/metadata/TransactionReceipt.d.ts +0 -1
- package/build/transactions/metadata/TransactionReceipt.js +0 -4
- package/cjs/package.json +3 -3
- package/docs/assets/highlight.css +92 -92
- package/docs/classes/AbstractRpcProvider.html +334 -334
- package/docs/classes/BaseContract.html +198 -198
- package/docs/classes/BitcoinAddress.html +192 -192
- package/docs/classes/BitcoinInterface.html +182 -182
- package/docs/classes/BitcoinUtils.html +182 -182
- package/docs/classes/Block.html +196 -196
- package/docs/classes/CallResult.html +185 -185
- package/docs/classes/ContractData.html +187 -187
- package/docs/classes/DeploymentTransaction.html +220 -220
- package/docs/classes/GenericTransaction.html +200 -200
- package/docs/classes/IBaseContract.html +203 -203
- package/docs/classes/InteractionTransaction.html +213 -213
- package/docs/classes/JSONRpcProvider.html +332 -332
- package/docs/classes/OPNetEvent.html +181 -181
- package/docs/classes/StoredValue.html +181 -181
- package/docs/classes/TransactionBase.html +200 -200
- package/docs/classes/TransactionInput.html +180 -180
- package/docs/classes/TransactionOutput.html +180 -180
- package/docs/classes/TransactionParser.html +177 -177
- package/docs/classes/TransactionReceipt.html +187 -187
- package/docs/classes/UTXO.html +180 -180
- package/docs/classes/UnwrapTransaction.html +224 -224
- package/docs/classes/WebSocketRpcProvider.html +329 -329
- package/docs/classes/WrapTransaction.html +228 -228
- package/docs/enums/ABIDataTypes.html +193 -193
- package/docs/enums/BitcoinAbiTypes.html +177 -177
- package/docs/enums/GenerateTarget.html +174 -174
- package/docs/enums/JSONRPCErrorCode.html +183 -183
- package/docs/enums/JSONRPCErrorHttpCodes.html +183 -183
- package/docs/enums/JSONRpcMethods.html +196 -196
- package/docs/enums/OPNetTransactionTypes.html +178 -178
- package/docs/functions/getContract.html +182 -182
- package/docs/hierarchy.html +173 -173
- package/docs/index.html +218 -218
- package/docs/interfaces/BaseContractProperties.html +180 -180
- package/docs/interfaces/BitcoinAbiValue.html +179 -179
- package/docs/interfaces/BitcoinInterfaceAbiBase.html +177 -177
- package/docs/interfaces/BroadcastedTransaction.html +183 -183
- package/docs/interfaces/ContractEvents.html +173 -173
- package/docs/interfaces/EventBaseData.html +178 -178
- package/docs/interfaces/FunctionBaseData.html +181 -181
- package/docs/interfaces/IAccessList.html +175 -175
- package/docs/interfaces/IAccessListItem.html +175 -175
- package/docs/interfaces/IBlock.html +195 -195
- package/docs/interfaces/IBlockCommon.html +194 -194
- package/docs/interfaces/IBlockWitness.html +175 -175
- package/docs/interfaces/IBlockWitnessAPI.html +177 -177
- package/docs/interfaces/ICallRequestError.html +176 -176
- package/docs/interfaces/ICallResultData.html +179 -179
- package/docs/interfaces/ICommonTransaction.html +205 -205
- package/docs/interfaces/IContract.html +180 -180
- package/docs/interfaces/IDecodedEvent.html +177 -177
- package/docs/interfaces/IDeploymentTransaction.html +219 -219
- package/docs/interfaces/IGenericTransaction.html +199 -199
- package/docs/interfaces/IInteractionTransaction.html +213 -213
- package/docs/interfaces/IMotoContract.html +196 -196
- package/docs/interfaces/IMotoswapFactoryContract.html +193 -193
- package/docs/interfaces/IMotoswapPoolContract.html +208 -208
- package/docs/interfaces/IMotoswapRouterContract.html +227 -227
- package/docs/interfaces/IOP_20Contract.html +196 -196
- package/docs/interfaces/IOP_NETContract.html +183 -183
- package/docs/interfaces/IRawContract.html +187 -187
- package/docs/interfaces/IRawContractEvents.html +173 -173
- package/docs/interfaces/IStackingContract.html +183 -183
- package/docs/interfaces/IStorageValue.html +179 -179
- package/docs/interfaces/ITransactionBase.html +199 -199
- package/docs/interfaces/ITransactionInput.html +179 -179
- package/docs/interfaces/ITransactionOutput.html +177 -177
- package/docs/interfaces/ITransactionReceipt.html +183 -183
- package/docs/interfaces/IUTXO.html +179 -179
- package/docs/interfaces/IUnwrapTransaction.html +223 -223
- package/docs/interfaces/IWBTCContract.html +209 -209
- package/docs/interfaces/IWrapTransaction.html +227 -227
- package/docs/interfaces/JSONRpc2Request.html +177 -177
- package/docs/interfaces/JSONRpc2ResponseError.html +177 -177
- package/docs/interfaces/JSONRpc2ResponseResult.html +177 -177
- package/docs/interfaces/JSONRpc2ResultData.html +173 -173
- package/docs/interfaces/JSONRpcErrorData.html +173 -173
- package/docs/interfaces/JSONRpcParams.html +173 -173
- package/docs/interfaces/JSONRpcResultError.html +176 -176
- package/docs/interfaces/MergedOP_20AndStackingContract.html +201 -201
- package/docs/interfaces/NetEventDocument.html +182 -182
- package/docs/interfaces/ParsedPartialWBTCUTXODocument.html +178 -178
- package/docs/interfaces/PartialWBTCUTXODocument.html +178 -178
- package/docs/interfaces/ReorgInformation.html +176 -176
- package/docs/interfaces/UsedUTXO.html +175 -175
- package/docs/modules.html +296 -296
- package/docs/types/BaseContractProperty.html +175 -175
- package/docs/types/BigNumberish.html +173 -173
- package/docs/types/BitcoinAddressLike.html +173 -173
- package/docs/types/BitcoinInterfaceAbi.html +173 -173
- package/docs/types/BlockHeaderChecksumProof.html +173 -173
- package/docs/types/BlockTag.html +173 -173
- package/docs/types/BlockWitnesses.html +173 -173
- package/docs/types/ContractDecodedObjectResult.html +173 -173
- package/docs/types/DecodedCallResult.html +173 -173
- package/docs/types/DecodedOutput.html +173 -173
- package/docs/types/GenerationParameters.html +173 -173
- package/docs/types/ICallResult.html +174 -174
- package/docs/types/ITransaction.html +174 -174
- package/docs/types/InteractionType.html +173 -173
- package/docs/types/JSONRpc2RequestParams.html +173 -173
- package/docs/types/JSONRpc2Result.html +173 -173
- package/docs/types/JSONRpcId.html +173 -173
- package/docs/types/JsonRpcCallResult.html +173 -173
- package/docs/types/JsonRpcError.html +173 -173
- package/docs/types/JsonRpcPayload.html +173 -173
- package/docs/types/JsonRpcResult.html +173 -173
- package/docs/types/Numeric.html +173 -173
- package/docs/types/PointerLike.html +173 -173
- package/docs/types/RawContractEvents.html +173 -173
- package/docs/types/UTXOs.html +175 -175
- package/docs/variables/MOTOSWAP_ROUTER_ABI.html +173 -173
- package/docs/variables/MOTO_TOKEN_ABI.html +173 -173
- package/docs/variables/MotoSwapFactoryAbi.html +173 -173
- package/docs/variables/MotoSwapFactoryEvents.html +173 -173
- package/docs/variables/MotoSwapPoolEvents.html +173 -173
- package/docs/variables/MotoswapPoolAbi.html +173 -173
- package/docs/variables/OP20Events.html +173 -173
- package/docs/variables/OP_20_ABI.html +173 -173
- package/docs/variables/OP_NET_ABI.html +173 -173
- package/docs/variables/STAKING_ABI.html +173 -173
- package/docs/variables/StackingEvents.html +173 -173
- package/docs/variables/WBTCEvents.html +173 -173
- package/docs/variables/WBTC_ABI.html +173 -173
- package/docs/variables/version.html +173 -173
- package/gulpfile.js +49 -120
- package/package.json +111 -109
- package/src/_version.ts +1 -1
- package/src/abi/shared/json/MOTOSWAP_POOL_ABI.ts +299 -299
- package/src/contracts/Contract.ts +600 -600
- package/src/crypto/crypto.ts +1 -1
- package/src/providers/AbstractRpcProvider.ts +602 -602
- package/src/providers/JSONRpcProvider.ts +81 -81
- package/src/serialize/BigInt.ts +15 -15
- package/tsconfig.base.json +43 -43
- package/tsconfig.json +15 -8
- package/tsconfig.webpack.json +19 -19
- package/.github/workflows/node.js.yml +0 -21
- package/.idea/bsc.iml +0 -14
- package/.idea/bsi-binary.iml +0 -14
- package/.idea/codeStyles/Project.xml +0 -101
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -7
- package/.idea/markdown.xml +0 -7
- package/.idea/modules.xml +0 -8
- package/.idea/motoswap.iml +0 -12
- package/.idea/opnet.iml +0 -17
- package/.idea/prettier.xml +0 -7
- package/.idea/vcs.xml +0 -6
- package/browser/crypto/crypto-browser.d.ts +0 -40
- package/browser/generator/WrappedGenerationParameters.d.ts +0 -9
- package/browser/scripts/ITestContract.d.ts +0 -22
- package/browser/scripts/block.d.ts +0 -1
- package/browser/scripts/test.d.ts +0 -1
- package/browser/scripts/testContract.d.ts +0 -1
- package/browser/scripts/testMethods.d.ts +0 -1
- package/browser/scripts/testMethodsReg.d.ts +0 -1
- package/browser/scripts/testWBTCContract.d.ts +0 -1
- package/browser/transactions/DeploymentTransaction.d.ts +0 -16
- package/browser/transactions/GenericTransaction.d.ts +0 -6
- package/browser/transactions/InteractionTransaction.d.ts +0 -15
- package/browser/transactions/TransactionInput.d.ts +0 -16
- package/browser/transactions/TransactionOutput.d.ts +0 -19
- package/browser/transactions/TransactionReceipt.d.ts +0 -11
- package/build/abi/BitcoinInterfaceAbi.d.ts +0 -3
- package/build/abi/BitcoinInterfaceAbi.js +0 -1
- package/build/abi/enums/ParamTypes.d.ts +0 -0
- package/build/abi/enums/ParamTypes.js +0 -1
- package/build/abi/interface/BitcoinInterface.d.ts +0 -6
- package/build/abi/interface/BitcoinInterface.js +0 -12
- package/build/abi/interface/BitcoinInterfaceAbi.d.ts +0 -3
- package/build/abi/interface/BitcoinInterfaceAbi.js +0 -1
- package/build/abi/interfaces/BaseContractProperty.d.ts +0 -2
- package/build/abi/interfaces/BaseContractProperty.js +0 -1
- package/build/abi/interfaces/BitcoinAbiInput.d.ts +0 -5
- package/build/abi/interfaces/BitcoinAbiInput.js +0 -1
- package/build/abi/shared/MOTOSWAP_FACTORY_ABI.d.ts +0 -2
- package/build/abi/shared/MOTOSWAP_FACTORY_ABI.js +0 -68
- package/build/abi/shared/OP_20_ABI.d.ts +0 -2
- package/build/abi/shared/OP_20_ABI.js +0 -235
- package/build/abi/shared/OP_NET_ABI.d.ts +0 -2
- package/build/abi/shared/OP_NET_ABI.js +0 -31
- package/build/abi/shared/STAKING_ABI.d.ts +0 -2
- package/build/abi/shared/STAKING_ABI.js +0 -96
- package/build/abi/shared/WBTC_ABI.d.ts +0 -2
- package/build/abi/shared/WBTC_ABI.js +0 -40
- package/build/bitcoin/UXTOs.d.ts +0 -7
- package/build/bitcoin/UXTOs.js +0 -1
- package/build/block/index.d.ts +0 -2
- package/build/block/index.js +0 -1
- package/build/contracts/DecodedEvent.d.ts +0 -15
- package/build/contracts/DecodedEvent.js +0 -18
- package/build/contracts/IRawContract.d.ts +0 -13
- package/build/contracts/IRawContract.js +0 -1
- package/build/crypto/crypto-browser.d.ts +0 -0
- package/build/crypto/crypto-browser.js +0 -47
- package/build/generator/WrappedGenerationParameters.d.ts +0 -9
- package/build/generator/WrappedGenerationParameters.js +0 -14
- package/build/interface/BitcoinInterface.d.ts +0 -6
- package/build/interface/BitcoinInterface.js +0 -12
- package/build/interface/BitcoinInterfaceAbi.d.ts +0 -3
- package/build/interface/BitcoinInterfaceAbi.js +0 -1
- package/build/interface/Interface.d.ts +0 -2
- package/build/interface/Interface.js +0 -2
- package/build/interface.d.ts +0 -0
- package/build/interface.js +0 -1
- package/build/interfaces/Block.d.ts +0 -0
- package/build/interfaces/Block.js +0 -1
- package/build/interfaces/IBlock.d.ts +0 -0
- package/build/interfaces/IBlock.js +0 -1
- package/build/interfaces/blocks/IBlock.d.ts +0 -28
- package/build/interfaces/blocks/IBlock.js +0 -1
- package/build/interfaces/transactions/ITransaction.d.ts +0 -39
- package/build/interfaces/transactions/ITransaction.js +0 -1
- package/build/providers/index.d.ts +0 -4
- package/build/providers/index.js +0 -4
- package/build/providers/interfaces/GenerateResult.d.ts +0 -0
- package/build/providers/interfaces/GenerateResult.js +0 -1
- package/build/scripts/ITestContract.d.ts +0 -18
- package/build/scripts/ITestContract.js +0 -1
- package/build/scripts/block.d.ts +0 -1
- package/build/scripts/block.js +0 -13
- package/build/scripts/test.d.ts +0 -1
- package/build/scripts/test.js +0 -24
- package/build/scripts/testContract.d.ts +0 -1
- package/build/scripts/testContract.js +0 -11
- package/build/scripts/testMethods.d.ts +0 -1
- package/build/scripts/testMethods.js +0 -11
- package/build/scripts/testMethodsReg.d.ts +0 -1
- package/build/scripts/testMethodsReg.js +0 -8
- package/build/scripts/testWBTCContract.d.ts +0 -1
- package/build/scripts/testWBTCContract.js +0 -11
- package/build/storage/interfaces/IStorage.d.ts +0 -7
- package/build/storage/interfaces/IStorage.js +0 -1
- package/build/transactions/DeploymentTransaction.d.ts +0 -16
- package/build/transactions/DeploymentTransaction.js +0 -24
- package/build/transactions/GenericTransaction.d.ts +0 -6
- package/build/transactions/GenericTransaction.js +0 -6
- package/build/transactions/InteractionTransaction.d.ts +0 -15
- package/build/transactions/InteractionTransaction.js +0 -21
- package/build/transactions/TransactionInput.d.ts +0 -16
- package/build/transactions/TransactionInput.js +0 -14
- package/build/transactions/TransactionOutput.d.ts +0 -19
- package/build/transactions/TransactionOutput.js +0 -16
- package/build/transactions/TransactionReceipt.d.ts +0 -11
- package/build/transactions/TransactionReceipt.js +0 -53
- package/build/transactions/decoders/WrapInteractionTransaction.d.ts +0 -15
- package/build/transactions/decoders/WrapInteractionTransaction.js +0 -21
- package/build/transactions/index.d.ts +0 -6
- package/build/transactions/index.js +0 -6
- package/build/transactions/interfaces/IWrapTransaction.d.ts +0 -3
- package/build/transactions/interfaces/IWrapTransaction.js +0 -1
- package/build/transactions/types/DeploymentTransaction.d.ts +0 -16
- package/build/transactions/types/DeploymentTransaction.js +0 -24
- package/build/transactions/types/GenericTransaction.d.ts +0 -6
- package/build/transactions/types/GenericTransaction.js +0 -6
- package/build/transactions/types/InteractionTransaction.d.ts +0 -15
- package/build/transactions/types/InteractionTransaction.js +0 -21
- package/cjs/_version.d.ts +0 -1
- package/cjs/_version.js +0 -4
- package/cjs/abi/BaseContractProperty.d.ts +0 -3
- package/cjs/abi/BaseContractProperty.js +0 -2
- package/cjs/abi/BitcoinAbiTypes.d.ts +0 -4
- package/cjs/abi/BitcoinAbiTypes.js +0 -8
- package/cjs/abi/BitcoinInterface.d.ts +0 -10
- package/cjs/abi/BitcoinInterface.js +0 -60
- package/cjs/abi/interfaces/BaseContractProperties.d.ts +0 -5
- package/cjs/abi/interfaces/BaseContractProperties.js +0 -2
- package/cjs/abi/interfaces/BitcoinAbiValue.d.ts +0 -5
- package/cjs/abi/interfaces/BitcoinAbiValue.js +0 -2
- package/cjs/abi/interfaces/BitcoinInterfaceAbi.d.ts +0 -16
- package/cjs/abi/interfaces/BitcoinInterfaceAbi.js +0 -2
- package/cjs/abi/shared/interfaces/IMotoContract.d.ts +0 -6
- package/cjs/abi/shared/interfaces/IMotoContract.js +0 -2
- package/cjs/abi/shared/interfaces/IMotoswapFactoryContract.d.ts +0 -7
- package/cjs/abi/shared/interfaces/IMotoswapFactoryContract.js +0 -2
- package/cjs/abi/shared/interfaces/IMotoswapPoolContract.d.ts +0 -13
- package/cjs/abi/shared/interfaces/IMotoswapPoolContract.js +0 -2
- package/cjs/abi/shared/interfaces/IMotoswapRouterContract.d.ts +0 -15
- package/cjs/abi/shared/interfaces/IMotoswapRouterContract.js +0 -2
- package/cjs/abi/shared/interfaces/IOP_20Contract.d.ts +0 -16
- package/cjs/abi/shared/interfaces/IOP_20Contract.js +0 -2
- package/cjs/abi/shared/interfaces/IOP_NETContract.d.ts +0 -7
- package/cjs/abi/shared/interfaces/IOP_NETContract.js +0 -2
- package/cjs/abi/shared/interfaces/IStackingContract.d.ts +0 -11
- package/cjs/abi/shared/interfaces/IStackingContract.js +0 -2
- package/cjs/abi/shared/interfaces/IWBTCContract.d.ts +0 -8
- package/cjs/abi/shared/interfaces/IWBTCContract.js +0 -2
- package/cjs/abi/shared/json/MOTOSWAP_FACTORY_ABI.d.ts +0 -3
- package/cjs/abi/shared/json/MOTOSWAP_FACTORY_ABI.js +0 -74
- package/cjs/abi/shared/json/MOTOSWAP_POOL_ABI.d.ts +0 -3
- package/cjs/abi/shared/json/MOTOSWAP_POOL_ABI.js +0 -280
- package/cjs/abi/shared/json/MOTOSWAP_ROUTER_ABI.d.ts +0 -2
- package/cjs/abi/shared/json/MOTOSWAP_ROUTER_ABI.js +0 -277
- package/cjs/abi/shared/json/MOTO_TOKEN_ABI.d.ts +0 -2
- package/cjs/abi/shared/json/MOTO_TOKEN_ABI.js +0 -25
- package/cjs/abi/shared/json/OP_20_ABI.d.ts +0 -3
- package/cjs/abi/shared/json/OP_20_ABI.js +0 -270
- package/cjs/abi/shared/json/OP_NET_ABI.d.ts +0 -2
- package/cjs/abi/shared/json/OP_NET_ABI.js +0 -34
- package/cjs/abi/shared/json/STAKING_ABI.d.ts +0 -3
- package/cjs/abi/shared/json/STAKING_ABI.js +0 -132
- package/cjs/abi/shared/json/WBTC_ABI.d.ts +0 -3
- package/cjs/abi/shared/json/WBTC_ABI.js +0 -60
- package/cjs/bitcoin/BitcoinAddress.d.ts +0 -20
- package/cjs/bitcoin/BitcoinAddress.js +0 -116
- package/cjs/bitcoin/UTXOs.d.ts +0 -10
- package/cjs/bitcoin/UTXOs.js +0 -16
- package/cjs/bitcoin/interfaces/IUTXO.d.ts +0 -7
- package/cjs/bitcoin/interfaces/IUTXO.js +0 -2
- package/cjs/block/Block.d.ts +0 -26
- package/cjs/block/Block.js +0 -47
- package/cjs/block/interfaces/BlockWitness.d.ts +0 -11
- package/cjs/block/interfaces/BlockWitness.js +0 -2
- package/cjs/block/interfaces/IBlock.d.ts +0 -28
- package/cjs/block/interfaces/IBlock.js +0 -2
- package/cjs/common/CommonTypes.d.ts +0 -8
- package/cjs/common/CommonTypes.js +0 -2
- package/cjs/contracts/CallResult.d.ts +0 -19
- package/cjs/contracts/CallResult.js +0 -35
- package/cjs/contracts/Contract.d.ts +0 -44
- package/cjs/contracts/Contract.js +0 -398
- package/cjs/contracts/ContractData.d.ts +0 -17
- package/cjs/contracts/ContractData.js +0 -38
- package/cjs/contracts/OPNetEvent.d.ts +0 -15
- package/cjs/contracts/OPNetEvent.js +0 -22
- package/cjs/contracts/interfaces/IAccessList.d.ts +0 -6
- package/cjs/contracts/interfaces/IAccessList.js +0 -2
- package/cjs/contracts/interfaces/ICallResult.d.ts +0 -12
- package/cjs/contracts/interfaces/ICallResult.js +0 -2
- package/cjs/contracts/interfaces/IContract.d.ts +0 -12
- package/cjs/contracts/interfaces/IContract.js +0 -2
- package/cjs/contracts/interfaces/IRawContract.d.ts +0 -15
- package/cjs/contracts/interfaces/IRawContract.js +0 -2
- package/cjs/crypto/crypto.d.ts +0 -2
- package/cjs/crypto/crypto.js +0 -8
- package/cjs/index.d.ts +0 -3
- package/cjs/index.js +0 -32
- package/cjs/interfaces/opnet/OPNetTransactionTypes.d.ts +0 -8
- package/cjs/interfaces/opnet/OPNetTransactionTypes.js +0 -11
- package/cjs/opnet.d.ts +0 -70
- package/cjs/opnet.js +0 -89
- package/cjs/providers/AbstractRpcProvider.d.ts +0 -48
- package/cjs/providers/AbstractRpcProvider.js +0 -277
- package/cjs/providers/JSONRpcProvider.d.ts +0 -10
- package/cjs/providers/JSONRpcProvider.js +0 -59
- package/cjs/providers/WebsocketRpcProvider.d.ts +0 -9
- package/cjs/providers/WebsocketRpcProvider.js +0 -27
- package/cjs/providers/interfaces/Generate.d.ts +0 -5
- package/cjs/providers/interfaces/Generate.js +0 -7
- package/cjs/providers/interfaces/JSONRpc.d.ts +0 -11
- package/cjs/providers/interfaces/JSONRpc.js +0 -2
- package/cjs/providers/interfaces/JSONRpcMethods.d.ts +0 -17
- package/cjs/providers/interfaces/JSONRpcMethods.js +0 -21
- package/cjs/providers/interfaces/JSONRpcParams.d.ts +0 -3
- package/cjs/providers/interfaces/JSONRpcParams.js +0 -2
- package/cjs/providers/interfaces/JSONRpcResult.d.ts +0 -51
- package/cjs/providers/interfaces/JSONRpcResult.js +0 -29
- package/cjs/providers/interfaces/ReorgInformation.d.ts +0 -5
- package/cjs/providers/interfaces/ReorgInformation.js +0 -2
- package/cjs/serialize/BigInt.d.ts +0 -6
- package/cjs/serialize/BigInt.js +0 -5
- package/cjs/storage/StoredValue.d.ts +0 -10
- package/cjs/storage/StoredValue.js +0 -28
- package/cjs/storage/interfaces/IStorageValue.d.ts +0 -8
- package/cjs/storage/interfaces/IStorageValue.js +0 -2
- package/cjs/transactions/Transaction.d.ts +0 -17
- package/cjs/transactions/Transaction.js +0 -33
- package/cjs/transactions/TransactionParser.d.ts +0 -7
- package/cjs/transactions/TransactionParser.js +0 -43
- package/cjs/transactions/decoders/DeploymentTransaction.d.ts +0 -17
- package/cjs/transactions/decoders/DeploymentTransaction.js +0 -30
- package/cjs/transactions/decoders/GenericTransaction.d.ts +0 -6
- package/cjs/transactions/decoders/GenericTransaction.js +0 -10
- package/cjs/transactions/decoders/InteractionTransaction.d.ts +0 -15
- package/cjs/transactions/decoders/InteractionTransaction.js +0 -25
- package/cjs/transactions/decoders/UnwrapTransaction.d.ts +0 -11
- package/cjs/transactions/decoders/UnwrapTransaction.js +0 -33
- package/cjs/transactions/decoders/WrapTransaction.d.ts +0 -15
- package/cjs/transactions/decoders/WrapTransaction.js +0 -34
- package/cjs/transactions/interfaces/BroadcastedTransaction.d.ts +0 -7
- package/cjs/transactions/interfaces/BroadcastedTransaction.js +0 -2
- package/cjs/transactions/interfaces/ITransaction.d.ts +0 -23
- package/cjs/transactions/interfaces/ITransaction.js +0 -2
- package/cjs/transactions/interfaces/ITransactionReceipt.d.ts +0 -21
- package/cjs/transactions/interfaces/ITransactionReceipt.js +0 -2
- package/cjs/transactions/interfaces/transactions/ICommonTransaction.d.ts +0 -7
- package/cjs/transactions/interfaces/transactions/ICommonTransaction.js +0 -2
- package/cjs/transactions/interfaces/transactions/IDeploymentTransaction.d.ts +0 -13
- package/cjs/transactions/interfaces/transactions/IDeploymentTransaction.js +0 -2
- package/cjs/transactions/interfaces/transactions/IInteractionTransaction.d.ts +0 -14
- package/cjs/transactions/interfaces/transactions/IInteractionTransaction.js +0 -2
- package/cjs/transactions/interfaces/transactions/IUnwrapTransaction.d.ts +0 -28
- package/cjs/transactions/interfaces/transactions/IUnwrapTransaction.js +0 -2
- package/cjs/transactions/interfaces/transactions/IWrapTransaction.d.ts +0 -10
- package/cjs/transactions/interfaces/transactions/IWrapTransaction.js +0 -2
- package/cjs/transactions/metadata/TransactionInput.d.ts +0 -16
- package/cjs/transactions/metadata/TransactionInput.js +0 -18
- package/cjs/transactions/metadata/TransactionOutput.d.ts +0 -19
- package/cjs/transactions/metadata/TransactionOutput.js +0 -20
- package/cjs/transactions/metadata/TransactionReceipt.d.ts +0 -11
- package/cjs/transactions/metadata/TransactionReceipt.js +0 -57
- package/cjs/utils/BitcoinUtils.d.ts +0 -4
- package/cjs/utils/BitcoinUtils.js +0 -14
- package/tsconfig.cjs.json +0 -9
|
@@ -1,602 +1,602 @@
|
|
|
1
|
-
import '../serialize/BigInt.js';
|
|
2
|
-
import { BufferHelper } from '@btc-vision/bsi-binary';
|
|
3
|
-
import { WrappedGeneration, WrappedGenerationParameters } from '@btc-vision/transaction';
|
|
4
|
-
import { Network, networks } from 'bitcoinjs-lib';
|
|
5
|
-
import { IUTXO } from '../bitcoin/interfaces/IUTXO.js';
|
|
6
|
-
|
|
7
|
-
import { UTXO, UTXOs } from '../bitcoin/UTXOs.js';
|
|
8
|
-
import { Block } from '../block/Block.js';
|
|
9
|
-
import { BlockWitnesses } from '../block/interfaces/BlockWitness.js';
|
|
10
|
-
import { IBlock } from '../block/interfaces/IBlock.js';
|
|
11
|
-
import { BigNumberish, BitcoinAddressLike, BlockTag } from '../common/CommonTypes.js';
|
|
12
|
-
import { CallResult } from '../contracts/CallResult.js';
|
|
13
|
-
import { ContractData } from '../contracts/ContractData.js';
|
|
14
|
-
import { ICallRequestError, ICallResult } from '../contracts/interfaces/ICallResult.js';
|
|
15
|
-
import { IRawContract } from '../contracts/interfaces/IRawContract.js';
|
|
16
|
-
import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
|
|
17
|
-
import { IStorageValue } from '../storage/interfaces/IStorageValue.js';
|
|
18
|
-
import { StoredValue } from '../storage/StoredValue.js';
|
|
19
|
-
import { BroadcastedTransaction } from '../transactions/interfaces/BroadcastedTransaction.js';
|
|
20
|
-
import { ITransaction } from '../transactions/interfaces/ITransaction.js';
|
|
21
|
-
import { TransactionReceipt } from '../transactions/metadata/TransactionReceipt.js';
|
|
22
|
-
import { TransactionBase } from '../transactions/Transaction.js';
|
|
23
|
-
import { TransactionParser } from '../transactions/TransactionParser.js';
|
|
24
|
-
import { GenerateTarget } from './interfaces/Generate.js';
|
|
25
|
-
import { JsonRpcPayload } from './interfaces/JSONRpc.js';
|
|
26
|
-
import { JSONRpcMethods } from './interfaces/JSONRpcMethods.js';
|
|
27
|
-
import {
|
|
28
|
-
JSONRpc2ResponseResult,
|
|
29
|
-
JsonRpcCallResult,
|
|
30
|
-
JsonRpcResult,
|
|
31
|
-
JSONRpcResultError,
|
|
32
|
-
} from './interfaces/JSONRpcResult.js';
|
|
33
|
-
import { ReorgInformation } from './interfaces/ReorgInformation.js';
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @description This class is used to provide an abstract RPC provider.
|
|
37
|
-
* @abstract
|
|
38
|
-
* @class AbstractRpcProvider
|
|
39
|
-
* @category Providers
|
|
40
|
-
*/
|
|
41
|
-
export abstract class AbstractRpcProvider {
|
|
42
|
-
private nextId: number = 0;
|
|
43
|
-
|
|
44
|
-
private network: Network | undefined;
|
|
45
|
-
private chainId: bigint | undefined;
|
|
46
|
-
|
|
47
|
-
protected constructor() {}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Get the latest block number.
|
|
51
|
-
* @description This method is used to get the latest block number.
|
|
52
|
-
* @returns {Promise<number>} The latest block number
|
|
53
|
-
* @example await getBlockNumber();
|
|
54
|
-
*/
|
|
55
|
-
public async getBlockNumber(): Promise<bigint> {
|
|
56
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(
|
|
57
|
-
JSONRpcMethods.BLOCK_BY_NUMBER,
|
|
58
|
-
[],
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const rawBlockNumber: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
62
|
-
const result: string = rawBlockNumber.result as string;
|
|
63
|
-
|
|
64
|
-
return BigInt(result);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Get block by number or hash.
|
|
69
|
-
* @param {BlockTag} blockNumberOrHash The block number or hash
|
|
70
|
-
* @param {boolean} prefetchTxs Whether to prefetch transactions
|
|
71
|
-
* @description This method is used to get a block by its number or hash.
|
|
72
|
-
* @returns {Promise<Block>} The requested block
|
|
73
|
-
* @throws {Error} If the block is not found
|
|
74
|
-
* @example await getBlock(123456);
|
|
75
|
-
*/
|
|
76
|
-
public async getBlock(
|
|
77
|
-
blockNumberOrHash: BlockTag,
|
|
78
|
-
prefetchTxs: boolean = false,
|
|
79
|
-
): Promise<Block> {
|
|
80
|
-
const method =
|
|
81
|
-
typeof blockNumberOrHash === 'string'
|
|
82
|
-
? JSONRpcMethods.GET_BLOCK_BY_HASH
|
|
83
|
-
: JSONRpcMethods.GET_BLOCK_BY_NUMBER;
|
|
84
|
-
|
|
85
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(method, [
|
|
86
|
-
blockNumberOrHash,
|
|
87
|
-
prefetchTxs,
|
|
88
|
-
]);
|
|
89
|
-
|
|
90
|
-
const block: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
91
|
-
|
|
92
|
-
const result: IBlock = block.result as IBlock;
|
|
93
|
-
return new Block(result);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Get multiple blocks by number or hash.
|
|
98
|
-
* @param {BlockTag[]} blockNumbers The block numbers or hashes
|
|
99
|
-
* @param {boolean} prefetchTxs Whether to prefetch transactions
|
|
100
|
-
* @description This method is used to get multiple blocks by their numbers or hashes.
|
|
101
|
-
* @returns {Promise<Block[]>} The requested blocks
|
|
102
|
-
*/
|
|
103
|
-
public async getBlocks(
|
|
104
|
-
blockNumbers: BlockTag[],
|
|
105
|
-
prefetchTxs: boolean = false,
|
|
106
|
-
): Promise<Block[]> {
|
|
107
|
-
const payloads: JsonRpcPayload[] = blockNumbers.map((blockNumber) => {
|
|
108
|
-
return this.buildJsonRpcPayload(JSONRpcMethods.GET_BLOCK_BY_NUMBER, [
|
|
109
|
-
blockNumber,
|
|
110
|
-
prefetchTxs,
|
|
111
|
-
]);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const blocks: JsonRpcCallResult = await this.callMultiplePayloads(payloads);
|
|
115
|
-
|
|
116
|
-
if ('error' in blocks) {
|
|
117
|
-
const error = blocks.error as JSONRpcResultError<JSONRpcMethods.BLOCK_BY_NUMBER>;
|
|
118
|
-
|
|
119
|
-
throw new Error(`Error fetching block: ${error.message}`);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return blocks.map((block) => {
|
|
123
|
-
if ('error' in block) {
|
|
124
|
-
throw new Error(`Error fetching block: ${block.error}`);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const result: IBlock = block.result as IBlock;
|
|
128
|
-
|
|
129
|
-
return new Block(result);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Get block by hash. This is the same method as getBlock.
|
|
135
|
-
* @param {string} blockHash The block hash
|
|
136
|
-
* @description This method is used to get a block by its hash. Note that this method is the same as getBlock.
|
|
137
|
-
* @returns {Promise<Block>} The requested block
|
|
138
|
-
* @throws {Error} If the block is not found
|
|
139
|
-
*/
|
|
140
|
-
public async getBlockByHash(blockHash: string): Promise<Block> {
|
|
141
|
-
return await this.getBlock(blockHash);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Get the bitcoin balance of an address.
|
|
146
|
-
* @param {BitcoinAddressLike} addressLike The address to get the balance of
|
|
147
|
-
* @param {boolean} filterOrdinals Whether to filter ordinals or not
|
|
148
|
-
* @description This method is used to get the balance of a bitcoin address.
|
|
149
|
-
* @returns {Promise<bigint>} The balance of the address
|
|
150
|
-
* @example await getBalance('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq');
|
|
151
|
-
*/
|
|
152
|
-
public async getBalance(addressLike: BitcoinAddressLike, filterOrdinals: boolean = true): Promise<bigint> {
|
|
153
|
-
const address: string = addressLike.toString();
|
|
154
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.GET_BALANCE, [
|
|
155
|
-
address,
|
|
156
|
-
filterOrdinals
|
|
157
|
-
]);
|
|
158
|
-
|
|
159
|
-
const rawBalance: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
160
|
-
const result: string = rawBalance.result as string;
|
|
161
|
-
if (!result || (result && !result.startsWith('0x'))) {
|
|
162
|
-
throw new Error(`Invalid balance returned from provider: ${result}`);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return BigInt(result);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Get the UTXOs (Unspent Transaction Outputs) of an address.
|
|
170
|
-
* @description This method is used to get the UTXOs of a bitcoin address.
|
|
171
|
-
* @param {BitcoinAddressLike} address The address to get the UTXOs of
|
|
172
|
-
* @param {boolean} optimize Whether to optimize the UTXOs
|
|
173
|
-
* @returns {Promise<UTXOs>} The UTXOs of the address
|
|
174
|
-
* @example await getUXTOs('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq');
|
|
175
|
-
* @throws {Error} If something went wrong while fetching the UTXOs
|
|
176
|
-
*/
|
|
177
|
-
public async getUXTOs(
|
|
178
|
-
address: BitcoinAddressLike,
|
|
179
|
-
optimize: boolean = false,
|
|
180
|
-
): Promise<unknown> {
|
|
181
|
-
const addressStr: string = address.toString();
|
|
182
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.GET_UTXOS, [
|
|
183
|
-
addressStr,
|
|
184
|
-
optimize,
|
|
185
|
-
]);
|
|
186
|
-
|
|
187
|
-
const rawUXTOs: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
188
|
-
const result: UTXOs = (rawUXTOs.result as UTXOs) || [];
|
|
189
|
-
|
|
190
|
-
return result.map((utxo: IUTXO) => {
|
|
191
|
-
return new UTXO(utxo);
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Get a transaction by its hash or hash id.
|
|
197
|
-
* @description This method is used to get a transaction by its hash or hash id.
|
|
198
|
-
* @param {string} txHash The transaction hash
|
|
199
|
-
* @returns {Promise<TransactionBase<OPNetTransactionTypes>>} The requested transaction
|
|
200
|
-
* @example await getTransaction('63e77ba9fa4262b3d4d0d9d97fa8a7359534606c3f3af096284662e3f619f374');
|
|
201
|
-
* @throws {Error} If something went wrong while fetching the transaction
|
|
202
|
-
*/
|
|
203
|
-
public async getTransaction(txHash: string): Promise<TransactionBase<OPNetTransactionTypes>> {
|
|
204
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(
|
|
205
|
-
JSONRpcMethods.GET_TRANSACTION_BY_HASH,
|
|
206
|
-
[txHash],
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
const rawTransaction: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
210
|
-
const result: ITransaction = rawTransaction.result as ITransaction;
|
|
211
|
-
|
|
212
|
-
if ('error' in rawTransaction) {
|
|
213
|
-
throw new Error(
|
|
214
|
-
`Error fetching transaction: ${rawTransaction.error?.message || 'Unknown error'}`,
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return TransactionParser.parseTransaction(result);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Get a transaction receipt by its hash.
|
|
223
|
-
* @description This method is used to get a transaction receipt by its hash.
|
|
224
|
-
* @param {string} txHash The transaction hash
|
|
225
|
-
* @returns {Promise<TransactionReceipt>} The requested transaction receipt
|
|
226
|
-
* @example await getTransactionReceipt('63e77ba9fa4262b3d4d0d9d97fa8a7359534606c3f3af096284662e3f619f374');
|
|
227
|
-
* @throws {Error} Something went wrong while fetching the transaction receipt
|
|
228
|
-
*/
|
|
229
|
-
public async getTransactionReceipt(txHash: string): Promise<TransactionReceipt> {
|
|
230
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(
|
|
231
|
-
JSONRpcMethods.GET_TRANSACTION_RECEIPT,
|
|
232
|
-
[txHash],
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
const rawTransaction: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
236
|
-
return new TransactionReceipt(rawTransaction.result);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Get the current connected network type.
|
|
241
|
-
* @description This method is used to get the current connected network type.
|
|
242
|
-
* @returns {Promise<Network>} The current connected network type
|
|
243
|
-
* @throws {Error} If the chain id is invalid
|
|
244
|
-
*/
|
|
245
|
-
public async getNetwork(): Promise<Network> {
|
|
246
|
-
if (this.network) {
|
|
247
|
-
return this.network;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const network = await this.getChainId();
|
|
251
|
-
switch (network) {
|
|
252
|
-
case 1n:
|
|
253
|
-
return networks.bitcoin;
|
|
254
|
-
case 2n:
|
|
255
|
-
return networks.testnet;
|
|
256
|
-
case 3n:
|
|
257
|
-
return networks.regtest;
|
|
258
|
-
|
|
259
|
-
default:
|
|
260
|
-
throw new Error(`Invalid chain id: ${network}`);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Get the chain id.
|
|
266
|
-
* @description This method is used to get the chain id.
|
|
267
|
-
* @returns {Promise<bigint>} The chain id
|
|
268
|
-
* @throws {Error} If something went wrong while fetching the chain id
|
|
269
|
-
*/
|
|
270
|
-
public async getChainId(): Promise<bigint> {
|
|
271
|
-
if (this.chainId !== undefined) return this.chainId;
|
|
272
|
-
|
|
273
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.CHAIN_ID, []);
|
|
274
|
-
const rawChainId: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
275
|
-
if ('error' in rawChainId) {
|
|
276
|
-
throw new Error(`Something went wrong while fetching: ${rawChainId.error}`);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
const chainId = rawChainId.result as string;
|
|
280
|
-
this.chainId = BigInt(chainId);
|
|
281
|
-
|
|
282
|
-
return this.chainId;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Get the contract code of an address.
|
|
287
|
-
* @description This method is used to get the contract code of an address.
|
|
288
|
-
* @param {BitcoinAddressLike} address The address of the contract
|
|
289
|
-
* @param {boolean} [onlyBytecode] Whether to return only the bytecode
|
|
290
|
-
* @returns {Promise<ContractData | Buffer>} The contract data or bytecode
|
|
291
|
-
* @example await getCode('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a');
|
|
292
|
-
* @throws {Error} If something went wrong while fetching the contract code
|
|
293
|
-
*/
|
|
294
|
-
public async getCode(
|
|
295
|
-
address: BitcoinAddressLike,
|
|
296
|
-
onlyBytecode: boolean = false,
|
|
297
|
-
): Promise<ContractData | Buffer> {
|
|
298
|
-
const addressStr: string = address.toString();
|
|
299
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.GET_CODE, [
|
|
300
|
-
addressStr,
|
|
301
|
-
onlyBytecode,
|
|
302
|
-
]);
|
|
303
|
-
|
|
304
|
-
const rawCode: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
305
|
-
if (rawCode.error) {
|
|
306
|
-
throw new Error(
|
|
307
|
-
`${rawCode.error.code}: Something went wrong while fetching: ${rawCode.error.message}`,
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const result: IRawContract | { bytecode: string } = rawCode.result as
|
|
312
|
-
| IRawContract
|
|
313
|
-
| { bytecode: string };
|
|
314
|
-
|
|
315
|
-
if ('contractAddress' in result) {
|
|
316
|
-
return new ContractData(result);
|
|
317
|
-
} else {
|
|
318
|
-
return Buffer.from(result.bytecode, 'base64');
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Get the storage at a specific address and pointer.
|
|
324
|
-
* @description This method is used to get the storage at a specific address and pointer.
|
|
325
|
-
* @param {BitcoinAddressLike} address The address to get the storage from
|
|
326
|
-
* @param {BigNumberish} rawPointer The pointer to get the storage from as base64 or bigint
|
|
327
|
-
* @param {boolean} proofs Whether to send proofs or not
|
|
328
|
-
* @param {BigNumberish} [height] The height to get the storage from
|
|
329
|
-
* @returns {Promise<StoredValue>} The storage value
|
|
330
|
-
* @example await getStorageAt('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a', 'EXLK/QhEQMI5d9DrthLvozT+UcDQ7WuSPaz7g8GV3AQ=');
|
|
331
|
-
* @throws {Error} If something went wrong while fetching the storage
|
|
332
|
-
*/
|
|
333
|
-
public async getStorageAt(
|
|
334
|
-
address: BitcoinAddressLike,
|
|
335
|
-
rawPointer: bigint | string,
|
|
336
|
-
proofs: boolean = true,
|
|
337
|
-
height?: BigNumberish,
|
|
338
|
-
): Promise<StoredValue> {
|
|
339
|
-
const addressStr: string = address.toString();
|
|
340
|
-
const pointer: string =
|
|
341
|
-
typeof rawPointer === 'string' ? rawPointer : this.bigintToBase64(rawPointer);
|
|
342
|
-
|
|
343
|
-
const params: [string, string, boolean, string?] = [addressStr, pointer, proofs];
|
|
344
|
-
|
|
345
|
-
if (height) {
|
|
346
|
-
params.push(height.toString());
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(
|
|
350
|
-
JSONRpcMethods.GET_STORAGE_AT,
|
|
351
|
-
params,
|
|
352
|
-
);
|
|
353
|
-
const rawStorage: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
354
|
-
const result: IStorageValue = rawStorage.result as IStorageValue;
|
|
355
|
-
|
|
356
|
-
return new StoredValue(result);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Call a contract function with a given calldata.
|
|
361
|
-
* @description This method is used to call a contract function with a given calldata.
|
|
362
|
-
* @param {BitcoinAddressLike} to The address of the contract
|
|
363
|
-
* @param {Buffer} data The calldata of the contract function
|
|
364
|
-
* @param {BitcoinAddressLike} [from] The address to call the contract from
|
|
365
|
-
* @param {BigNumberish} [height] The height to call the contract from
|
|
366
|
-
* @returns {Promise<CallResult>} The result of the contract function call
|
|
367
|
-
* @example await call('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a', Buffer.from('0x12345678'));
|
|
368
|
-
* @throws {Error} If something went wrong while calling the contract
|
|
369
|
-
*/
|
|
370
|
-
public async call(
|
|
371
|
-
to: BitcoinAddressLike,
|
|
372
|
-
data: Buffer | string,
|
|
373
|
-
from?: BitcoinAddressLike,
|
|
374
|
-
height?: BigNumberish,
|
|
375
|
-
): Promise<CallResult | ICallRequestError> {
|
|
376
|
-
const toStr: string = to.toString();
|
|
377
|
-
const fromStr: string | null = from ? from.toString() : null;
|
|
378
|
-
|
|
379
|
-
let dataStr: string = Buffer.isBuffer(data) ? this.bufferToHex(data) : data;
|
|
380
|
-
if (dataStr.startsWith('0x')) {
|
|
381
|
-
dataStr = dataStr.slice(2);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
const params: [string, string, string?, string?] = [toStr, dataStr];
|
|
385
|
-
if (fromStr) {
|
|
386
|
-
params.push(fromStr);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
if (height) {
|
|
390
|
-
params.push(height.toString());
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.CALL, params);
|
|
394
|
-
const rawCall: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
395
|
-
|
|
396
|
-
const result: ICallResult = rawCall.result as ICallResult;
|
|
397
|
-
if ('error' in result) {
|
|
398
|
-
return result;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
return new CallResult(result);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Send a raw transaction.
|
|
406
|
-
* @description This method is used to send a raw transaction.
|
|
407
|
-
* @param {string} tx The raw transaction to send as hex string
|
|
408
|
-
* @param {boolean} [psbt] Whether the transaction is a PSBT or not
|
|
409
|
-
* @returns {Promise<BroadcastedTransaction>} The result of the transaction
|
|
410
|
-
* @example await sendRawTransaction('02000000000101ad897689f66c98daae5fdc3606235c1ad7a17b9e0a6aaa0ea9e58ecc1198ad2a0100000000ffffffff01a154c39400000000160014482038efcc91af945f0c756d07a46401920380520247304402201c1f8718dec637ddb41b42abc44dcbf35a94c6be6a9de8c1db48c9fa6e456b7e022032a4b3286808372a7ac2c5094d6341b4d61b17663f4ccd1c1d92efa85c7dada80121020373626d317ae8788ce3280b491068610d840c23ecb64c14075bbb9f670af52c00000000', false);
|
|
411
|
-
* @throws {Error} If something went wrong while sending the transaction
|
|
412
|
-
*/
|
|
413
|
-
public async sendRawTransaction(tx: string, psbt: boolean): Promise<BroadcastedTransaction> {
|
|
414
|
-
// verify if tx is a valid hex string
|
|
415
|
-
if (!/^[0-9A-Fa-f]+$/.test(tx)) {
|
|
416
|
-
throw new Error('sendRawTransaction: Invalid hex string');
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(
|
|
420
|
-
JSONRpcMethods.BROADCAST_TRANSACTION,
|
|
421
|
-
[tx, psbt],
|
|
422
|
-
);
|
|
423
|
-
|
|
424
|
-
const rawTx: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
425
|
-
const result: BroadcastedTransaction = rawTx.result as BroadcastedTransaction;
|
|
426
|
-
if (result && result.identifier) {
|
|
427
|
-
return {
|
|
428
|
-
...result,
|
|
429
|
-
identifier: BigInt(result.identifier),
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
return result as BroadcastedTransaction;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Get block witnesses.
|
|
438
|
-
* @description This method is used to get the witnesses of a block. This proves that the action executed inside a block are valid and confirmed by the network. If the minimum number of witnesses are not met, the block is considered as potentially invalid.
|
|
439
|
-
* @param {BlockTag} height The block number or hash, use -1 for latest block
|
|
440
|
-
* @param {boolean} [trusted] Whether to trust the witnesses or not
|
|
441
|
-
* @param {number} [limit] The maximum number of witnesses to return
|
|
442
|
-
* @param {number} [page] The page number of the witnesses
|
|
443
|
-
* @returns {Promise<BlockWitnesses>} The witnesses of the block
|
|
444
|
-
* @example await getBlockWitness(123456n);
|
|
445
|
-
* @throws {Error} If something went wrong while fetching the witnesses
|
|
446
|
-
*/
|
|
447
|
-
public async getBlockWitness(
|
|
448
|
-
height: BigNumberish | -1 = -1,
|
|
449
|
-
trusted?: boolean,
|
|
450
|
-
limit?: number,
|
|
451
|
-
page?: number,
|
|
452
|
-
): Promise<BlockWitnesses> {
|
|
453
|
-
const params: [BigNumberish | -1, boolean?, number?, number?] = [height.toString()];
|
|
454
|
-
|
|
455
|
-
if (trusted !== undefined && trusted !== null) params.push(trusted);
|
|
456
|
-
if (limit !== undefined && limit !== null) params.push(limit);
|
|
457
|
-
if (page !== undefined && page !== null) params.push(page);
|
|
458
|
-
|
|
459
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(
|
|
460
|
-
JSONRpcMethods.BLOCK_WITNESS,
|
|
461
|
-
params,
|
|
462
|
-
);
|
|
463
|
-
|
|
464
|
-
const rawWitnesses: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
465
|
-
const result: BlockWitnesses = rawWitnesses.result as BlockWitnesses;
|
|
466
|
-
|
|
467
|
-
for (let i = 0; i < result.length; i++) {
|
|
468
|
-
result[i].blockNumber = BigInt('0x' + result[i].blockNumber);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
return result;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* Get reorgs that happened between two blocks.
|
|
476
|
-
* @description This method is used to get the reorgs that happened between two blocks.
|
|
477
|
-
* @param {BigNumberish} [fromBlock] The block number to start from
|
|
478
|
-
* @param {BigNumberish} [toBlock] The block number to end at
|
|
479
|
-
* @returns {Promise<ReorgInformation>} The reorg information
|
|
480
|
-
* @example await getReorg(123456n, 123457n);
|
|
481
|
-
* @throws {Error} If something went wrong while fetching the reorg information
|
|
482
|
-
*/
|
|
483
|
-
public async getReorg(
|
|
484
|
-
fromBlock?: BigNumberish,
|
|
485
|
-
toBlock?: BigNumberish,
|
|
486
|
-
): Promise<ReorgInformation[]> {
|
|
487
|
-
const params: [string?, string?] = [];
|
|
488
|
-
|
|
489
|
-
if (fromBlock !== undefined && fromBlock !== null) params.push(fromBlock.toString());
|
|
490
|
-
if (toBlock !== undefined && toBlock !== null) params.push(toBlock.toString());
|
|
491
|
-
|
|
492
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.REORG, params);
|
|
493
|
-
const rawReorg: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
494
|
-
|
|
495
|
-
const result: ReorgInformation[] = rawReorg.result as ReorgInformation[];
|
|
496
|
-
if (result.length > 0) {
|
|
497
|
-
for (let i = 0; i < result.length; i++) {
|
|
498
|
-
const res = result[i];
|
|
499
|
-
|
|
500
|
-
res.fromBlock = BigInt('0x' + res.fromBlock);
|
|
501
|
-
res.toBlock = BigInt('0x' + res.toBlock);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
return result;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
* Generate parameters needed to wrap bitcoin.
|
|
510
|
-
* @description This method is used to generate the parameters needed to wrap bitcoin.
|
|
511
|
-
* @param {BigNumberish} amount The amount to wrap
|
|
512
|
-
* @returns {Promise<WrappedGeneration>} The wrapped generation parameters
|
|
513
|
-
* @example await requestTrustedPublicKeyForBitcoinWrapping(100000000n);
|
|
514
|
-
* @throws {Error} If something went wrong while generating the parameters
|
|
515
|
-
*/
|
|
516
|
-
public async requestTrustedPublicKeyForBitcoinWrapping(
|
|
517
|
-
amount: BigNumberish,
|
|
518
|
-
): Promise<WrappedGeneration> {
|
|
519
|
-
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.GENERATE, [
|
|
520
|
-
GenerateTarget.WRAP,
|
|
521
|
-
amount.toString(),
|
|
522
|
-
]);
|
|
523
|
-
|
|
524
|
-
const rawPublicKey: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
525
|
-
const result: WrappedGenerationParameters =
|
|
526
|
-
rawPublicKey.result as WrappedGenerationParameters;
|
|
527
|
-
|
|
528
|
-
return new WrappedGeneration(result);
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
/**
|
|
532
|
-
* Requests to the OPNET node
|
|
533
|
-
* @param {JsonRpcPayload | JsonRpcPayload[]} payload The method to call
|
|
534
|
-
* @returns {Promise<JSONRpc2Result<T extends JSONRpcMethods>>} The result of the request
|
|
535
|
-
*/
|
|
536
|
-
public abstract _send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>;
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* Send a single payload. This method is used to send a single payload.
|
|
540
|
-
* @param {JsonRpcPayload} payload The payload to send
|
|
541
|
-
* @returns {Promise<JsonRpcResult>} The result of the payload
|
|
542
|
-
* @throws {Error} If no data is returned
|
|
543
|
-
* @private
|
|
544
|
-
*/
|
|
545
|
-
public async callPayloadSingle(payload: JsonRpcPayload): Promise<JsonRpcResult> {
|
|
546
|
-
const rawData: JsonRpcCallResult = await this._send(payload);
|
|
547
|
-
if (!rawData.length) {
|
|
548
|
-
throw new Error('No data returned');
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
const data = rawData.shift();
|
|
552
|
-
if (!data) {
|
|
553
|
-
throw new Error('Block not found');
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
return data as JSONRpc2ResponseResult<JSONRpcMethods>;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Send multiple payloads. This method is used to send multiple payloads.
|
|
561
|
-
* @param {JsonRpcPayload[]} payloads The payloads to send
|
|
562
|
-
* @returns {Promise<JsonRpcResult>} The result of the payloads
|
|
563
|
-
*/
|
|
564
|
-
public async callMultiplePayloads(payloads: JsonRpcPayload[]): Promise<JsonRpcCallResult> {
|
|
565
|
-
const rawData: JsonRpcCallResult[] = (await this._send(
|
|
566
|
-
payloads,
|
|
567
|
-
)) as unknown as JsonRpcCallResult[];
|
|
568
|
-
|
|
569
|
-
if ('error' in rawData) {
|
|
570
|
-
throw new Error(`Error fetching block: ${rawData.error}`);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
const data = rawData.shift();
|
|
574
|
-
if (!data) {
|
|
575
|
-
throw new Error('Block not found');
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
return data as JsonRpcCallResult;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
protected abstract providerUrl(url: string): string;
|
|
582
|
-
|
|
583
|
-
private bufferToHex(buffer: Buffer): string {
|
|
584
|
-
return buffer.toString('hex');
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
private bigintToBase64(bigint: bigint): string {
|
|
588
|
-
return Buffer.from(BufferHelper.pointerToUint8Array(bigint)).toString('base64');
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
private buildJsonRpcPayload<T extends JSONRpcMethods>(
|
|
592
|
-
method: T,
|
|
593
|
-
params: unknown[],
|
|
594
|
-
): JsonRpcPayload {
|
|
595
|
-
return {
|
|
596
|
-
method: method,
|
|
597
|
-
params: params,
|
|
598
|
-
id: this.nextId++,
|
|
599
|
-
jsonrpc: '2.0',
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
}
|
|
1
|
+
import '../serialize/BigInt.js';
|
|
2
|
+
import { BufferHelper } from '@btc-vision/bsi-binary';
|
|
3
|
+
import { WrappedGeneration, WrappedGenerationParameters } from '@btc-vision/transaction';
|
|
4
|
+
import { Network, networks } from 'bitcoinjs-lib';
|
|
5
|
+
import { IUTXO } from '../bitcoin/interfaces/IUTXO.js';
|
|
6
|
+
|
|
7
|
+
import { UTXO, UTXOs } from '../bitcoin/UTXOs.js';
|
|
8
|
+
import { Block } from '../block/Block.js';
|
|
9
|
+
import { BlockWitnesses } from '../block/interfaces/BlockWitness.js';
|
|
10
|
+
import { IBlock } from '../block/interfaces/IBlock.js';
|
|
11
|
+
import { BigNumberish, BitcoinAddressLike, BlockTag } from '../common/CommonTypes.js';
|
|
12
|
+
import { CallResult } from '../contracts/CallResult.js';
|
|
13
|
+
import { ContractData } from '../contracts/ContractData.js';
|
|
14
|
+
import { ICallRequestError, ICallResult } from '../contracts/interfaces/ICallResult.js';
|
|
15
|
+
import { IRawContract } from '../contracts/interfaces/IRawContract.js';
|
|
16
|
+
import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
|
|
17
|
+
import { IStorageValue } from '../storage/interfaces/IStorageValue.js';
|
|
18
|
+
import { StoredValue } from '../storage/StoredValue.js';
|
|
19
|
+
import { BroadcastedTransaction } from '../transactions/interfaces/BroadcastedTransaction.js';
|
|
20
|
+
import { ITransaction } from '../transactions/interfaces/ITransaction.js';
|
|
21
|
+
import { TransactionReceipt } from '../transactions/metadata/TransactionReceipt.js';
|
|
22
|
+
import { TransactionBase } from '../transactions/Transaction.js';
|
|
23
|
+
import { TransactionParser } from '../transactions/TransactionParser.js';
|
|
24
|
+
import { GenerateTarget } from './interfaces/Generate.js';
|
|
25
|
+
import { JsonRpcPayload } from './interfaces/JSONRpc.js';
|
|
26
|
+
import { JSONRpcMethods } from './interfaces/JSONRpcMethods.js';
|
|
27
|
+
import {
|
|
28
|
+
JSONRpc2ResponseResult,
|
|
29
|
+
JsonRpcCallResult,
|
|
30
|
+
JsonRpcResult,
|
|
31
|
+
JSONRpcResultError,
|
|
32
|
+
} from './interfaces/JSONRpcResult.js';
|
|
33
|
+
import { ReorgInformation } from './interfaces/ReorgInformation.js';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @description This class is used to provide an abstract RPC provider.
|
|
37
|
+
* @abstract
|
|
38
|
+
* @class AbstractRpcProvider
|
|
39
|
+
* @category Providers
|
|
40
|
+
*/
|
|
41
|
+
export abstract class AbstractRpcProvider {
|
|
42
|
+
private nextId: number = 0;
|
|
43
|
+
|
|
44
|
+
private network: Network | undefined;
|
|
45
|
+
private chainId: bigint | undefined;
|
|
46
|
+
|
|
47
|
+
protected constructor() {}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get the latest block number.
|
|
51
|
+
* @description This method is used to get the latest block number.
|
|
52
|
+
* @returns {Promise<number>} The latest block number
|
|
53
|
+
* @example await getBlockNumber();
|
|
54
|
+
*/
|
|
55
|
+
public async getBlockNumber(): Promise<bigint> {
|
|
56
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(
|
|
57
|
+
JSONRpcMethods.BLOCK_BY_NUMBER,
|
|
58
|
+
[],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const rawBlockNumber: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
62
|
+
const result: string = rawBlockNumber.result as string;
|
|
63
|
+
|
|
64
|
+
return BigInt(result);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get block by number or hash.
|
|
69
|
+
* @param {BlockTag} blockNumberOrHash The block number or hash
|
|
70
|
+
* @param {boolean} prefetchTxs Whether to prefetch transactions
|
|
71
|
+
* @description This method is used to get a block by its number or hash.
|
|
72
|
+
* @returns {Promise<Block>} The requested block
|
|
73
|
+
* @throws {Error} If the block is not found
|
|
74
|
+
* @example await getBlock(123456);
|
|
75
|
+
*/
|
|
76
|
+
public async getBlock(
|
|
77
|
+
blockNumberOrHash: BlockTag,
|
|
78
|
+
prefetchTxs: boolean = false,
|
|
79
|
+
): Promise<Block> {
|
|
80
|
+
const method =
|
|
81
|
+
typeof blockNumberOrHash === 'string'
|
|
82
|
+
? JSONRpcMethods.GET_BLOCK_BY_HASH
|
|
83
|
+
: JSONRpcMethods.GET_BLOCK_BY_NUMBER;
|
|
84
|
+
|
|
85
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(method, [
|
|
86
|
+
blockNumberOrHash,
|
|
87
|
+
prefetchTxs,
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
const block: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
91
|
+
|
|
92
|
+
const result: IBlock = block.result as IBlock;
|
|
93
|
+
return new Block(result);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Get multiple blocks by number or hash.
|
|
98
|
+
* @param {BlockTag[]} blockNumbers The block numbers or hashes
|
|
99
|
+
* @param {boolean} prefetchTxs Whether to prefetch transactions
|
|
100
|
+
* @description This method is used to get multiple blocks by their numbers or hashes.
|
|
101
|
+
* @returns {Promise<Block[]>} The requested blocks
|
|
102
|
+
*/
|
|
103
|
+
public async getBlocks(
|
|
104
|
+
blockNumbers: BlockTag[],
|
|
105
|
+
prefetchTxs: boolean = false,
|
|
106
|
+
): Promise<Block[]> {
|
|
107
|
+
const payloads: JsonRpcPayload[] = blockNumbers.map((blockNumber) => {
|
|
108
|
+
return this.buildJsonRpcPayload(JSONRpcMethods.GET_BLOCK_BY_NUMBER, [
|
|
109
|
+
blockNumber,
|
|
110
|
+
prefetchTxs,
|
|
111
|
+
]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const blocks: JsonRpcCallResult = await this.callMultiplePayloads(payloads);
|
|
115
|
+
|
|
116
|
+
if ('error' in blocks) {
|
|
117
|
+
const error = blocks.error as JSONRpcResultError<JSONRpcMethods.BLOCK_BY_NUMBER>;
|
|
118
|
+
|
|
119
|
+
throw new Error(`Error fetching block: ${error.message}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return blocks.map((block) => {
|
|
123
|
+
if ('error' in block) {
|
|
124
|
+
throw new Error(`Error fetching block: ${block.error}`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const result: IBlock = block.result as IBlock;
|
|
128
|
+
|
|
129
|
+
return new Block(result);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Get block by hash. This is the same method as getBlock.
|
|
135
|
+
* @param {string} blockHash The block hash
|
|
136
|
+
* @description This method is used to get a block by its hash. Note that this method is the same as getBlock.
|
|
137
|
+
* @returns {Promise<Block>} The requested block
|
|
138
|
+
* @throws {Error} If the block is not found
|
|
139
|
+
*/
|
|
140
|
+
public async getBlockByHash(blockHash: string): Promise<Block> {
|
|
141
|
+
return await this.getBlock(blockHash);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Get the bitcoin balance of an address.
|
|
146
|
+
* @param {BitcoinAddressLike} addressLike The address to get the balance of
|
|
147
|
+
* @param {boolean} filterOrdinals Whether to filter ordinals or not
|
|
148
|
+
* @description This method is used to get the balance of a bitcoin address.
|
|
149
|
+
* @returns {Promise<bigint>} The balance of the address
|
|
150
|
+
* @example await getBalance('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq');
|
|
151
|
+
*/
|
|
152
|
+
public async getBalance(addressLike: BitcoinAddressLike, filterOrdinals: boolean = true): Promise<bigint> {
|
|
153
|
+
const address: string = addressLike.toString();
|
|
154
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.GET_BALANCE, [
|
|
155
|
+
address,
|
|
156
|
+
filterOrdinals
|
|
157
|
+
]);
|
|
158
|
+
|
|
159
|
+
const rawBalance: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
160
|
+
const result: string = rawBalance.result as string;
|
|
161
|
+
if (!result || (result && !result.startsWith('0x'))) {
|
|
162
|
+
throw new Error(`Invalid balance returned from provider: ${result}`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return BigInt(result);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Get the UTXOs (Unspent Transaction Outputs) of an address.
|
|
170
|
+
* @description This method is used to get the UTXOs of a bitcoin address.
|
|
171
|
+
* @param {BitcoinAddressLike} address The address to get the UTXOs of
|
|
172
|
+
* @param {boolean} optimize Whether to optimize the UTXOs
|
|
173
|
+
* @returns {Promise<UTXOs>} The UTXOs of the address
|
|
174
|
+
* @example await getUXTOs('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq');
|
|
175
|
+
* @throws {Error} If something went wrong while fetching the UTXOs
|
|
176
|
+
*/
|
|
177
|
+
public async getUXTOs(
|
|
178
|
+
address: BitcoinAddressLike,
|
|
179
|
+
optimize: boolean = false,
|
|
180
|
+
): Promise<unknown> {
|
|
181
|
+
const addressStr: string = address.toString();
|
|
182
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.GET_UTXOS, [
|
|
183
|
+
addressStr,
|
|
184
|
+
optimize,
|
|
185
|
+
]);
|
|
186
|
+
|
|
187
|
+
const rawUXTOs: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
188
|
+
const result: UTXOs = (rawUXTOs.result as UTXOs) || [];
|
|
189
|
+
|
|
190
|
+
return result.map((utxo: IUTXO) => {
|
|
191
|
+
return new UTXO(utxo);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Get a transaction by its hash or hash id.
|
|
197
|
+
* @description This method is used to get a transaction by its hash or hash id.
|
|
198
|
+
* @param {string} txHash The transaction hash
|
|
199
|
+
* @returns {Promise<TransactionBase<OPNetTransactionTypes>>} The requested transaction
|
|
200
|
+
* @example await getTransaction('63e77ba9fa4262b3d4d0d9d97fa8a7359534606c3f3af096284662e3f619f374');
|
|
201
|
+
* @throws {Error} If something went wrong while fetching the transaction
|
|
202
|
+
*/
|
|
203
|
+
public async getTransaction(txHash: string): Promise<TransactionBase<OPNetTransactionTypes>> {
|
|
204
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(
|
|
205
|
+
JSONRpcMethods.GET_TRANSACTION_BY_HASH,
|
|
206
|
+
[txHash],
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
const rawTransaction: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
210
|
+
const result: ITransaction = rawTransaction.result as ITransaction;
|
|
211
|
+
|
|
212
|
+
if ('error' in rawTransaction) {
|
|
213
|
+
throw new Error(
|
|
214
|
+
`Error fetching transaction: ${rawTransaction.error?.message || 'Unknown error'}`,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return TransactionParser.parseTransaction(result);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Get a transaction receipt by its hash.
|
|
223
|
+
* @description This method is used to get a transaction receipt by its hash.
|
|
224
|
+
* @param {string} txHash The transaction hash
|
|
225
|
+
* @returns {Promise<TransactionReceipt>} The requested transaction receipt
|
|
226
|
+
* @example await getTransactionReceipt('63e77ba9fa4262b3d4d0d9d97fa8a7359534606c3f3af096284662e3f619f374');
|
|
227
|
+
* @throws {Error} Something went wrong while fetching the transaction receipt
|
|
228
|
+
*/
|
|
229
|
+
public async getTransactionReceipt(txHash: string): Promise<TransactionReceipt> {
|
|
230
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(
|
|
231
|
+
JSONRpcMethods.GET_TRANSACTION_RECEIPT,
|
|
232
|
+
[txHash],
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
const rawTransaction: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
236
|
+
return new TransactionReceipt(rawTransaction.result);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Get the current connected network type.
|
|
241
|
+
* @description This method is used to get the current connected network type.
|
|
242
|
+
* @returns {Promise<Network>} The current connected network type
|
|
243
|
+
* @throws {Error} If the chain id is invalid
|
|
244
|
+
*/
|
|
245
|
+
public async getNetwork(): Promise<Network> {
|
|
246
|
+
if (this.network) {
|
|
247
|
+
return this.network;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const network = await this.getChainId();
|
|
251
|
+
switch (network) {
|
|
252
|
+
case 1n:
|
|
253
|
+
return networks.bitcoin;
|
|
254
|
+
case 2n:
|
|
255
|
+
return networks.testnet;
|
|
256
|
+
case 3n:
|
|
257
|
+
return networks.regtest;
|
|
258
|
+
|
|
259
|
+
default:
|
|
260
|
+
throw new Error(`Invalid chain id: ${network}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Get the chain id.
|
|
266
|
+
* @description This method is used to get the chain id.
|
|
267
|
+
* @returns {Promise<bigint>} The chain id
|
|
268
|
+
* @throws {Error} If something went wrong while fetching the chain id
|
|
269
|
+
*/
|
|
270
|
+
public async getChainId(): Promise<bigint> {
|
|
271
|
+
if (this.chainId !== undefined) return this.chainId;
|
|
272
|
+
|
|
273
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.CHAIN_ID, []);
|
|
274
|
+
const rawChainId: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
275
|
+
if ('error' in rawChainId) {
|
|
276
|
+
throw new Error(`Something went wrong while fetching: ${rawChainId.error}`);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const chainId = rawChainId.result as string;
|
|
280
|
+
this.chainId = BigInt(chainId);
|
|
281
|
+
|
|
282
|
+
return this.chainId;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Get the contract code of an address.
|
|
287
|
+
* @description This method is used to get the contract code of an address.
|
|
288
|
+
* @param {BitcoinAddressLike} address The address of the contract
|
|
289
|
+
* @param {boolean} [onlyBytecode] Whether to return only the bytecode
|
|
290
|
+
* @returns {Promise<ContractData | Buffer>} The contract data or bytecode
|
|
291
|
+
* @example await getCode('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a');
|
|
292
|
+
* @throws {Error} If something went wrong while fetching the contract code
|
|
293
|
+
*/
|
|
294
|
+
public async getCode(
|
|
295
|
+
address: BitcoinAddressLike,
|
|
296
|
+
onlyBytecode: boolean = false,
|
|
297
|
+
): Promise<ContractData | Buffer> {
|
|
298
|
+
const addressStr: string = address.toString();
|
|
299
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.GET_CODE, [
|
|
300
|
+
addressStr,
|
|
301
|
+
onlyBytecode,
|
|
302
|
+
]);
|
|
303
|
+
|
|
304
|
+
const rawCode: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
305
|
+
if (rawCode.error) {
|
|
306
|
+
throw new Error(
|
|
307
|
+
`${rawCode.error.code}: Something went wrong while fetching: ${rawCode.error.message}`,
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const result: IRawContract | { bytecode: string } = rawCode.result as
|
|
312
|
+
| IRawContract
|
|
313
|
+
| { bytecode: string };
|
|
314
|
+
|
|
315
|
+
if ('contractAddress' in result) {
|
|
316
|
+
return new ContractData(result);
|
|
317
|
+
} else {
|
|
318
|
+
return Buffer.from(result.bytecode, 'base64');
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Get the storage at a specific address and pointer.
|
|
324
|
+
* @description This method is used to get the storage at a specific address and pointer.
|
|
325
|
+
* @param {BitcoinAddressLike} address The address to get the storage from
|
|
326
|
+
* @param {BigNumberish} rawPointer The pointer to get the storage from as base64 or bigint
|
|
327
|
+
* @param {boolean} proofs Whether to send proofs or not
|
|
328
|
+
* @param {BigNumberish} [height] The height to get the storage from
|
|
329
|
+
* @returns {Promise<StoredValue>} The storage value
|
|
330
|
+
* @example await getStorageAt('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a', 'EXLK/QhEQMI5d9DrthLvozT+UcDQ7WuSPaz7g8GV3AQ=');
|
|
331
|
+
* @throws {Error} If something went wrong while fetching the storage
|
|
332
|
+
*/
|
|
333
|
+
public async getStorageAt(
|
|
334
|
+
address: BitcoinAddressLike,
|
|
335
|
+
rawPointer: bigint | string,
|
|
336
|
+
proofs: boolean = true,
|
|
337
|
+
height?: BigNumberish,
|
|
338
|
+
): Promise<StoredValue> {
|
|
339
|
+
const addressStr: string = address.toString();
|
|
340
|
+
const pointer: string =
|
|
341
|
+
typeof rawPointer === 'string' ? rawPointer : this.bigintToBase64(rawPointer);
|
|
342
|
+
|
|
343
|
+
const params: [string, string, boolean, string?] = [addressStr, pointer, proofs];
|
|
344
|
+
|
|
345
|
+
if (height) {
|
|
346
|
+
params.push(height.toString());
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(
|
|
350
|
+
JSONRpcMethods.GET_STORAGE_AT,
|
|
351
|
+
params,
|
|
352
|
+
);
|
|
353
|
+
const rawStorage: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
354
|
+
const result: IStorageValue = rawStorage.result as IStorageValue;
|
|
355
|
+
|
|
356
|
+
return new StoredValue(result);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Call a contract function with a given calldata.
|
|
361
|
+
* @description This method is used to call a contract function with a given calldata.
|
|
362
|
+
* @param {BitcoinAddressLike} to The address of the contract
|
|
363
|
+
* @param {Buffer} data The calldata of the contract function
|
|
364
|
+
* @param {BitcoinAddressLike} [from] The address to call the contract from
|
|
365
|
+
* @param {BigNumberish} [height] The height to call the contract from
|
|
366
|
+
* @returns {Promise<CallResult>} The result of the contract function call
|
|
367
|
+
* @example await call('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a', Buffer.from('0x12345678'));
|
|
368
|
+
* @throws {Error} If something went wrong while calling the contract
|
|
369
|
+
*/
|
|
370
|
+
public async call(
|
|
371
|
+
to: BitcoinAddressLike,
|
|
372
|
+
data: Buffer | string,
|
|
373
|
+
from?: BitcoinAddressLike,
|
|
374
|
+
height?: BigNumberish,
|
|
375
|
+
): Promise<CallResult | ICallRequestError> {
|
|
376
|
+
const toStr: string = to.toString();
|
|
377
|
+
const fromStr: string | null = from ? from.toString() : null;
|
|
378
|
+
|
|
379
|
+
let dataStr: string = Buffer.isBuffer(data) ? this.bufferToHex(data) : data;
|
|
380
|
+
if (dataStr.startsWith('0x')) {
|
|
381
|
+
dataStr = dataStr.slice(2);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const params: [string, string, string?, string?] = [toStr, dataStr];
|
|
385
|
+
if (fromStr) {
|
|
386
|
+
params.push(fromStr);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (height) {
|
|
390
|
+
params.push(height.toString());
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.CALL, params);
|
|
394
|
+
const rawCall: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
395
|
+
|
|
396
|
+
const result: ICallResult = rawCall.result as ICallResult;
|
|
397
|
+
if ('error' in result) {
|
|
398
|
+
return result;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return new CallResult(result);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Send a raw transaction.
|
|
406
|
+
* @description This method is used to send a raw transaction.
|
|
407
|
+
* @param {string} tx The raw transaction to send as hex string
|
|
408
|
+
* @param {boolean} [psbt] Whether the transaction is a PSBT or not
|
|
409
|
+
* @returns {Promise<BroadcastedTransaction>} The result of the transaction
|
|
410
|
+
* @example await sendRawTransaction('02000000000101ad897689f66c98daae5fdc3606235c1ad7a17b9e0a6aaa0ea9e58ecc1198ad2a0100000000ffffffff01a154c39400000000160014482038efcc91af945f0c756d07a46401920380520247304402201c1f8718dec637ddb41b42abc44dcbf35a94c6be6a9de8c1db48c9fa6e456b7e022032a4b3286808372a7ac2c5094d6341b4d61b17663f4ccd1c1d92efa85c7dada80121020373626d317ae8788ce3280b491068610d840c23ecb64c14075bbb9f670af52c00000000', false);
|
|
411
|
+
* @throws {Error} If something went wrong while sending the transaction
|
|
412
|
+
*/
|
|
413
|
+
public async sendRawTransaction(tx: string, psbt: boolean): Promise<BroadcastedTransaction> {
|
|
414
|
+
// verify if tx is a valid hex string
|
|
415
|
+
if (!/^[0-9A-Fa-f]+$/.test(tx)) {
|
|
416
|
+
throw new Error('sendRawTransaction: Invalid hex string');
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(
|
|
420
|
+
JSONRpcMethods.BROADCAST_TRANSACTION,
|
|
421
|
+
[tx, psbt],
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
const rawTx: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
425
|
+
const result: BroadcastedTransaction = rawTx.result as BroadcastedTransaction;
|
|
426
|
+
if (result && result.identifier) {
|
|
427
|
+
return {
|
|
428
|
+
...result,
|
|
429
|
+
identifier: BigInt(result.identifier),
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return result as BroadcastedTransaction;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Get block witnesses.
|
|
438
|
+
* @description This method is used to get the witnesses of a block. This proves that the action executed inside a block are valid and confirmed by the network. If the minimum number of witnesses are not met, the block is considered as potentially invalid.
|
|
439
|
+
* @param {BlockTag} height The block number or hash, use -1 for latest block
|
|
440
|
+
* @param {boolean} [trusted] Whether to trust the witnesses or not
|
|
441
|
+
* @param {number} [limit] The maximum number of witnesses to return
|
|
442
|
+
* @param {number} [page] The page number of the witnesses
|
|
443
|
+
* @returns {Promise<BlockWitnesses>} The witnesses of the block
|
|
444
|
+
* @example await getBlockWitness(123456n);
|
|
445
|
+
* @throws {Error} If something went wrong while fetching the witnesses
|
|
446
|
+
*/
|
|
447
|
+
public async getBlockWitness(
|
|
448
|
+
height: BigNumberish | -1 = -1,
|
|
449
|
+
trusted?: boolean,
|
|
450
|
+
limit?: number,
|
|
451
|
+
page?: number,
|
|
452
|
+
): Promise<BlockWitnesses> {
|
|
453
|
+
const params: [BigNumberish | -1, boolean?, number?, number?] = [height.toString()];
|
|
454
|
+
|
|
455
|
+
if (trusted !== undefined && trusted !== null) params.push(trusted);
|
|
456
|
+
if (limit !== undefined && limit !== null) params.push(limit);
|
|
457
|
+
if (page !== undefined && page !== null) params.push(page);
|
|
458
|
+
|
|
459
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(
|
|
460
|
+
JSONRpcMethods.BLOCK_WITNESS,
|
|
461
|
+
params,
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
const rawWitnesses: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
465
|
+
const result: BlockWitnesses = rawWitnesses.result as BlockWitnesses;
|
|
466
|
+
|
|
467
|
+
for (let i = 0; i < result.length; i++) {
|
|
468
|
+
result[i].blockNumber = BigInt('0x' + result[i].blockNumber);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return result;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Get reorgs that happened between two blocks.
|
|
476
|
+
* @description This method is used to get the reorgs that happened between two blocks.
|
|
477
|
+
* @param {BigNumberish} [fromBlock] The block number to start from
|
|
478
|
+
* @param {BigNumberish} [toBlock] The block number to end at
|
|
479
|
+
* @returns {Promise<ReorgInformation>} The reorg information
|
|
480
|
+
* @example await getReorg(123456n, 123457n);
|
|
481
|
+
* @throws {Error} If something went wrong while fetching the reorg information
|
|
482
|
+
*/
|
|
483
|
+
public async getReorg(
|
|
484
|
+
fromBlock?: BigNumberish,
|
|
485
|
+
toBlock?: BigNumberish,
|
|
486
|
+
): Promise<ReorgInformation[]> {
|
|
487
|
+
const params: [string?, string?] = [];
|
|
488
|
+
|
|
489
|
+
if (fromBlock !== undefined && fromBlock !== null) params.push(fromBlock.toString());
|
|
490
|
+
if (toBlock !== undefined && toBlock !== null) params.push(toBlock.toString());
|
|
491
|
+
|
|
492
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.REORG, params);
|
|
493
|
+
const rawReorg: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
494
|
+
|
|
495
|
+
const result: ReorgInformation[] = rawReorg.result as ReorgInformation[];
|
|
496
|
+
if (result.length > 0) {
|
|
497
|
+
for (let i = 0; i < result.length; i++) {
|
|
498
|
+
const res = result[i];
|
|
499
|
+
|
|
500
|
+
res.fromBlock = BigInt('0x' + res.fromBlock);
|
|
501
|
+
res.toBlock = BigInt('0x' + res.toBlock);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return result;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Generate parameters needed to wrap bitcoin.
|
|
510
|
+
* @description This method is used to generate the parameters needed to wrap bitcoin.
|
|
511
|
+
* @param {BigNumberish} amount The amount to wrap
|
|
512
|
+
* @returns {Promise<WrappedGeneration>} The wrapped generation parameters
|
|
513
|
+
* @example await requestTrustedPublicKeyForBitcoinWrapping(100000000n);
|
|
514
|
+
* @throws {Error} If something went wrong while generating the parameters
|
|
515
|
+
*/
|
|
516
|
+
public async requestTrustedPublicKeyForBitcoinWrapping(
|
|
517
|
+
amount: BigNumberish,
|
|
518
|
+
): Promise<WrappedGeneration> {
|
|
519
|
+
const payload: JsonRpcPayload = this.buildJsonRpcPayload(JSONRpcMethods.GENERATE, [
|
|
520
|
+
GenerateTarget.WRAP,
|
|
521
|
+
amount.toString(),
|
|
522
|
+
]);
|
|
523
|
+
|
|
524
|
+
const rawPublicKey: JsonRpcResult = await this.callPayloadSingle(payload);
|
|
525
|
+
const result: WrappedGenerationParameters =
|
|
526
|
+
rawPublicKey.result as WrappedGenerationParameters;
|
|
527
|
+
|
|
528
|
+
return new WrappedGeneration(result);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Requests to the OPNET node
|
|
533
|
+
* @param {JsonRpcPayload | JsonRpcPayload[]} payload The method to call
|
|
534
|
+
* @returns {Promise<JSONRpc2Result<T extends JSONRpcMethods>>} The result of the request
|
|
535
|
+
*/
|
|
536
|
+
public abstract _send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>;
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Send a single payload. This method is used to send a single payload.
|
|
540
|
+
* @param {JsonRpcPayload} payload The payload to send
|
|
541
|
+
* @returns {Promise<JsonRpcResult>} The result of the payload
|
|
542
|
+
* @throws {Error} If no data is returned
|
|
543
|
+
* @private
|
|
544
|
+
*/
|
|
545
|
+
public async callPayloadSingle(payload: JsonRpcPayload): Promise<JsonRpcResult> {
|
|
546
|
+
const rawData: JsonRpcCallResult = await this._send(payload);
|
|
547
|
+
if (!rawData.length) {
|
|
548
|
+
throw new Error('No data returned');
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const data = rawData.shift();
|
|
552
|
+
if (!data) {
|
|
553
|
+
throw new Error('Block not found');
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
return data as JSONRpc2ResponseResult<JSONRpcMethods>;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Send multiple payloads. This method is used to send multiple payloads.
|
|
561
|
+
* @param {JsonRpcPayload[]} payloads The payloads to send
|
|
562
|
+
* @returns {Promise<JsonRpcResult>} The result of the payloads
|
|
563
|
+
*/
|
|
564
|
+
public async callMultiplePayloads(payloads: JsonRpcPayload[]): Promise<JsonRpcCallResult> {
|
|
565
|
+
const rawData: JsonRpcCallResult[] = (await this._send(
|
|
566
|
+
payloads,
|
|
567
|
+
)) as unknown as JsonRpcCallResult[];
|
|
568
|
+
|
|
569
|
+
if ('error' in rawData) {
|
|
570
|
+
throw new Error(`Error fetching block: ${rawData.error}`);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
const data = rawData.shift();
|
|
574
|
+
if (!data) {
|
|
575
|
+
throw new Error('Block not found');
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
return data as JsonRpcCallResult;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
protected abstract providerUrl(url: string): string;
|
|
582
|
+
|
|
583
|
+
private bufferToHex(buffer: Buffer): string {
|
|
584
|
+
return buffer.toString('hex');
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
private bigintToBase64(bigint: bigint): string {
|
|
588
|
+
return Buffer.from(BufferHelper.pointerToUint8Array(bigint)).toString('base64');
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
private buildJsonRpcPayload<T extends JSONRpcMethods>(
|
|
592
|
+
method: T,
|
|
593
|
+
params: unknown[],
|
|
594
|
+
): JsonRpcPayload {
|
|
595
|
+
return {
|
|
596
|
+
method: method,
|
|
597
|
+
params: params,
|
|
598
|
+
id: this.nextId++,
|
|
599
|
+
jsonrpc: '2.0',
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
}
|