@atomiqlabs/sdk 7.0.11 → 8.0.7
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/README.md +45 -29
- package/dist/SmartChainAssets.d.ts +11 -3
- package/dist/SmartChainAssets.js +7 -3
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.d.ts +68 -0
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.js +2 -0
- package/dist/bitcoin/LightningNetworkApi.d.ts +12 -0
- package/dist/bitcoin/LightningNetworkApi.js +2 -0
- package/dist/bitcoin/coinselect2/accumulative.d.ts +6 -0
- package/dist/bitcoin/coinselect2/accumulative.js +52 -0
- package/dist/bitcoin/coinselect2/blackjack.d.ts +6 -0
- package/dist/bitcoin/coinselect2/blackjack.js +38 -0
- package/dist/bitcoin/coinselect2/index.d.ts +19 -0
- package/dist/bitcoin/coinselect2/index.js +69 -0
- package/dist/bitcoin/coinselect2/utils.d.ts +71 -0
- package/dist/bitcoin/coinselect2/utils.js +123 -0
- package/dist/bitcoin/mempool/MempoolApi.d.ts +350 -0
- package/dist/bitcoin/mempool/MempoolApi.js +311 -0
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.d.ts +44 -0
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.js +48 -0
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.d.ts +119 -0
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.js +361 -0
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.d.ts +22 -0
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.js +105 -0
- package/dist/bitcoin/wallet/BitcoinWallet.d.ts +93 -0
- package/dist/bitcoin/wallet/BitcoinWallet.js +273 -0
- package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +28 -0
- package/dist/bitcoin/wallet/IBitcoinWallet.js +20 -0
- package/dist/bitcoin/wallet/MinimalBitcoinWalletInterface.d.ts +21 -0
- package/dist/bitcoin/wallet/MinimalBitcoinWalletInterface.js +2 -0
- package/dist/bitcoin/wallet/MinimalLightningNetworkWalletInterface.d.ts +7 -0
- package/dist/bitcoin/wallet/MinimalLightningNetworkWalletInterface.js +2 -0
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +40 -0
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +86 -0
- package/dist/enums/FeeType.d.ts +8 -0
- package/dist/enums/FeeType.js +12 -0
- package/dist/enums/SwapAmountType.d.ts +8 -0
- package/dist/enums/SwapAmountType.js +12 -0
- package/dist/enums/SwapDirection.d.ts +8 -0
- package/dist/enums/SwapDirection.js +12 -0
- package/dist/enums/SwapType.d.ts +14 -0
- package/dist/enums/SwapType.js +18 -0
- package/dist/errors/IntermediaryError.d.ts +9 -0
- package/dist/errors/IntermediaryError.js +26 -0
- package/dist/errors/PaymentAuthError.d.ts +11 -0
- package/dist/errors/PaymentAuthError.js +23 -0
- package/dist/errors/RequestError.d.ts +18 -0
- package/dist/errors/RequestError.js +46 -0
- package/dist/errors/UserError.d.ts +7 -0
- package/dist/errors/UserError.js +15 -0
- package/dist/events/UnifiedSwapEventListener.d.ts +23 -0
- package/dist/events/UnifiedSwapEventListener.js +130 -0
- package/dist/http/HttpUtils.d.ts +27 -0
- package/dist/http/HttpUtils.js +91 -0
- package/dist/http/paramcoders/IParamReader.d.ts +8 -0
- package/dist/http/paramcoders/IParamReader.js +2 -0
- package/dist/http/paramcoders/ParamDecoder.d.ts +44 -0
- package/dist/http/paramcoders/ParamDecoder.js +132 -0
- package/dist/http/paramcoders/ParamEncoder.d.ts +20 -0
- package/dist/http/paramcoders/ParamEncoder.js +31 -0
- package/dist/http/paramcoders/SchemaVerifier.d.ts +26 -0
- package/dist/http/paramcoders/SchemaVerifier.js +145 -0
- package/dist/http/paramcoders/client/ResponseParamDecoder.d.ts +11 -0
- package/dist/http/paramcoders/client/ResponseParamDecoder.js +57 -0
- package/dist/http/paramcoders/client/StreamParamEncoder.d.ts +13 -0
- package/dist/http/paramcoders/client/StreamParamEncoder.js +26 -0
- package/dist/http/paramcoders/client/StreamingFetchPromise.d.ts +16 -0
- package/dist/http/paramcoders/client/StreamingFetchPromise.js +174 -0
- package/dist/index.d.ts +82 -4
- package/dist/index.js +128 -4
- package/dist/intermediaries/Intermediary.d.ts +111 -0
- package/dist/intermediaries/Intermediary.js +115 -0
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +166 -0
- package/dist/intermediaries/IntermediaryDiscovery.js +390 -0
- package/dist/intermediaries/apis/IntermediaryAPI.d.ts +436 -0
- package/dist/intermediaries/apis/IntermediaryAPI.js +600 -0
- package/dist/intermediaries/apis/TrustedIntermediaryAPI.d.ts +154 -0
- package/dist/intermediaries/apis/TrustedIntermediaryAPI.js +136 -0
- package/dist/lnurl/LNURL.d.ts +102 -0
- package/dist/lnurl/LNURL.js +321 -0
- package/dist/prices/RedundantSwapPrice.d.ts +89 -0
- package/dist/prices/RedundantSwapPrice.js +202 -0
- package/dist/prices/SingleSwapPrice.d.ts +31 -0
- package/dist/prices/SingleSwapPrice.js +41 -0
- package/dist/prices/SwapPriceWithChain.d.ts +70 -0
- package/dist/prices/SwapPriceWithChain.js +91 -0
- package/dist/prices/abstract/ICachedSwapPrice.d.ts +28 -0
- package/dist/prices/abstract/ICachedSwapPrice.js +62 -0
- package/dist/prices/abstract/IPriceProvider.d.ts +81 -0
- package/dist/prices/abstract/IPriceProvider.js +74 -0
- package/dist/prices/abstract/ISwapPrice.d.ts +117 -0
- package/dist/prices/abstract/ISwapPrice.js +219 -0
- package/dist/prices/providers/BinancePriceProvider.d.ts +16 -0
- package/dist/prices/providers/BinancePriceProvider.js +23 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +17 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.js +23 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +19 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.js +23 -0
- package/dist/prices/providers/CustomPriceProvider.d.ts +13 -0
- package/dist/prices/providers/CustomPriceProvider.js +24 -0
- package/dist/prices/providers/KrakenPriceProvider.d.ts +29 -0
- package/dist/prices/providers/KrakenPriceProvider.js +36 -0
- package/dist/prices/providers/OKXPriceProvider.d.ts +28 -0
- package/dist/prices/providers/OKXPriceProvider.js +23 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +14 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.js +18 -0
- package/dist/prices/providers/abstract/HttpPriceProvider.d.ts +7 -0
- package/dist/prices/providers/abstract/HttpPriceProvider.js +12 -0
- package/dist/storage/IUnifiedStorage.d.ts +73 -0
- package/dist/storage/IUnifiedStorage.js +2 -0
- package/dist/storage/UnifiedSwapStorage.d.ts +82 -0
- package/dist/storage/UnifiedSwapStorage.js +83 -0
- package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +39 -0
- package/dist/storage-browser/IndexedDBUnifiedStorage.js +275 -0
- package/dist/{storage → storage-browser}/LocalStorageManager.d.ts +1 -0
- package/dist/{storage → storage-browser}/LocalStorageManager.js +2 -1
- package/dist/swapper/Swapper.d.ts +533 -0
- package/dist/swapper/Swapper.js +1566 -0
- package/dist/swapper/SwapperFactory.d.ts +87 -0
- package/dist/{SwapperFactory.js → swapper/SwapperFactory.js} +40 -22
- package/dist/swapper/SwapperUtils.d.ts +153 -0
- package/dist/swapper/SwapperUtils.js +420 -0
- package/dist/swapper/SwapperWithChain.d.ts +214 -0
- package/dist/swapper/SwapperWithChain.js +315 -0
- package/dist/swapper/SwapperWithSigner.d.ts +178 -0
- package/dist/swapper/SwapperWithSigner.js +172 -0
- package/dist/swaps/IAddressSwap.d.ts +13 -0
- package/dist/swaps/IAddressSwap.js +13 -0
- package/dist/swaps/IBTCWalletSwap.d.ts +55 -0
- package/dist/swaps/IBTCWalletSwap.js +17 -0
- package/dist/swaps/IClaimableSwap.d.ts +17 -0
- package/dist/swaps/IClaimableSwap.js +14 -0
- package/dist/swaps/IClaimableSwapWrapper.d.ts +5 -0
- package/dist/swaps/IClaimableSwapWrapper.js +2 -0
- package/dist/swaps/IRefundableSwap.d.ts +17 -0
- package/dist/swaps/IRefundableSwap.js +13 -0
- package/dist/swaps/ISwap.d.ts +207 -0
- package/dist/swaps/ISwap.js +264 -0
- package/dist/swaps/ISwapWithGasDrop.d.ts +15 -0
- package/dist/swaps/ISwapWithGasDrop.js +11 -0
- package/dist/swaps/ISwapWrapper.d.ts +153 -0
- package/dist/swaps/ISwapWrapper.js +227 -0
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +53 -0
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +116 -0
- package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +70 -0
- package/dist/swaps/escrow_swaps/IEscrowSwap.js +132 -0
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +85 -0
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +122 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +86 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +115 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +93 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +121 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +45 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +65 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +263 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +933 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +110 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +307 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +236 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +898 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +125 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +393 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +245 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +841 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +120 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +294 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +228 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +721 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +37 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +93 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +86 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +213 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +170 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +520 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +50 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +109 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +93 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +217 -0
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +315 -0
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +1098 -0
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +125 -0
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +631 -0
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +107 -0
- package/dist/swaps/trusted/ln/LnForGasSwap.js +343 -0
- package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +21 -0
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +62 -0
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +164 -0
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +520 -0
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +48 -0
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +74 -0
- package/dist/types/AmountData.d.ts +9 -0
- package/dist/types/AmountData.js +2 -0
- package/dist/types/CustomPriceFunction.d.ts +5 -0
- package/dist/types/CustomPriceFunction.js +2 -0
- package/dist/types/PriceInfoType.d.ts +28 -0
- package/dist/types/PriceInfoType.js +57 -0
- package/dist/types/SwapExecutionAction.d.ts +7 -0
- package/dist/types/SwapExecutionAction.js +2 -0
- package/dist/types/SwapWithSigner.d.ts +14 -0
- package/dist/types/SwapWithSigner.js +40 -0
- package/dist/types/Token.d.ts +53 -0
- package/dist/types/Token.js +58 -0
- package/dist/types/TokenAmount.d.ts +57 -0
- package/dist/types/TokenAmount.js +47 -0
- package/dist/types/fees/Fee.d.ts +49 -0
- package/dist/types/fees/Fee.js +2 -0
- package/dist/types/fees/FeeBreakdown.d.ts +10 -0
- package/dist/types/fees/FeeBreakdown.js +2 -0
- package/dist/types/fees/PercentagePPM.d.ts +15 -0
- package/dist/types/fees/PercentagePPM.js +17 -0
- package/dist/types/lnurl/LNURLPay.d.ts +54 -0
- package/dist/types/lnurl/LNURLPay.js +28 -0
- package/dist/types/lnurl/LNURLWithdraw.d.ts +42 -0
- package/dist/types/lnurl/LNURLWithdraw.js +24 -0
- package/dist/utils/AutomaticClockDriftCorrection.d.ts +1 -0
- package/dist/utils/AutomaticClockDriftCorrection.js +70 -0
- package/dist/utils/BitcoinUtils.d.ts +13 -0
- package/dist/utils/BitcoinUtils.js +98 -0
- package/dist/utils/BitcoinWalletUtils.d.ts +7 -0
- package/dist/utils/BitcoinWalletUtils.js +14 -0
- package/dist/utils/Logger.d.ts +7 -0
- package/dist/utils/Logger.js +12 -0
- package/dist/utils/RetryUtils.d.ts +21 -0
- package/dist/utils/RetryUtils.js +66 -0
- package/dist/utils/SwapUtils.d.ts +31 -0
- package/dist/utils/SwapUtils.js +18 -0
- package/dist/{Utils.d.ts → utils/TimeoutUtils.d.ts} +9 -3
- package/dist/utils/TimeoutUtils.js +55 -0
- package/dist/utils/TokenUtils.d.ts +11 -0
- package/dist/utils/TokenUtils.js +29 -0
- package/dist/utils/TypeUtils.d.ts +7 -0
- package/dist/utils/TypeUtils.js +2 -0
- package/dist/utils/Utils.d.ts +57 -0
- package/dist/utils/Utils.js +178 -0
- package/package.json +14 -6
- package/src/SmartChainAssets.ts +11 -3
- package/src/bitcoin/BitcoinRpcWithAddressIndex.ts +87 -0
- package/src/bitcoin/LightningNetworkApi.ts +16 -0
- package/src/bitcoin/coinselect2/accumulative.ts +68 -0
- package/src/bitcoin/coinselect2/blackjack.ts +49 -0
- package/src/bitcoin/coinselect2/index.ts +92 -0
- package/src/bitcoin/coinselect2/utils.ts +189 -0
- package/src/bitcoin/mempool/MempoolApi.ts +554 -0
- package/src/bitcoin/mempool/MempoolBitcoinBlock.ts +88 -0
- package/src/bitcoin/mempool/MempoolBitcoinRpc.ts +437 -0
- package/src/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.ts +134 -0
- package/src/bitcoin/wallet/BitcoinWallet.ts +375 -0
- package/src/bitcoin/wallet/IBitcoinWallet.ts +44 -0
- package/src/bitcoin/wallet/MinimalBitcoinWalletInterface.ts +19 -0
- package/src/bitcoin/wallet/MinimalLightningNetworkWalletInterface.ts +7 -0
- package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +108 -0
- package/src/enums/FeeType.ts +9 -0
- package/src/enums/SwapAmountType.ts +9 -0
- package/src/enums/SwapDirection.ts +9 -0
- package/src/enums/SwapType.ts +15 -0
- package/src/errors/IntermediaryError.ts +24 -0
- package/src/errors/PaymentAuthError.ts +26 -0
- package/src/errors/RequestError.ts +51 -0
- package/src/errors/UserError.ts +14 -0
- package/src/events/UnifiedSwapEventListener.ts +171 -0
- package/src/http/HttpUtils.ts +92 -0
- package/src/http/paramcoders/IParamReader.ts +10 -0
- package/src/http/paramcoders/ParamDecoder.ts +142 -0
- package/src/http/paramcoders/ParamEncoder.ts +37 -0
- package/src/http/paramcoders/SchemaVerifier.ts +153 -0
- package/src/http/paramcoders/client/ResponseParamDecoder.ts +58 -0
- package/src/http/paramcoders/client/StreamParamEncoder.ts +29 -0
- package/src/http/paramcoders/client/StreamingFetchPromise.ts +193 -0
- package/src/index.ts +102 -4
- package/src/intermediaries/Intermediary.ts +204 -0
- package/src/intermediaries/IntermediaryDiscovery.ts +485 -0
- package/src/intermediaries/apis/IntermediaryAPI.ts +940 -0
- package/src/intermediaries/apis/TrustedIntermediaryAPI.ts +257 -0
- package/src/lnurl/LNURL.ts +403 -0
- package/src/prices/RedundantSwapPrice.ts +245 -0
- package/src/prices/SingleSwapPrice.ts +47 -0
- package/src/prices/SwapPriceWithChain.ts +157 -0
- package/src/prices/abstract/ICachedSwapPrice.ts +86 -0
- package/src/prices/abstract/IPriceProvider.ts +128 -0
- package/src/prices/abstract/ISwapPrice.ts +328 -0
- package/src/prices/providers/BinancePriceProvider.ts +41 -0
- package/src/prices/providers/CoinGeckoPriceProvider.ts +40 -0
- package/src/prices/providers/CoinPaprikaPriceProvider.ts +44 -0
- package/src/prices/providers/CustomPriceProvider.ts +29 -0
- package/src/prices/providers/KrakenPriceProvider.ts +74 -0
- package/src/prices/providers/OKXPriceProvider.ts +53 -0
- package/src/prices/providers/abstract/ExchangePriceProvider.ts +29 -0
- package/src/prices/providers/abstract/HttpPriceProvider.ts +15 -0
- package/src/storage/IUnifiedStorage.ts +83 -0
- package/src/storage/UnifiedSwapStorage.ts +104 -0
- package/src/storage-browser/IndexedDBUnifiedStorage.ts +328 -0
- package/src/{storage → storage-browser}/LocalStorageManager.ts +2 -1
- package/src/swapper/Swapper.ts +2107 -0
- package/src/{SwapperFactory.ts → swapper/SwapperFactory.ts} +116 -75
- package/src/swapper/SwapperUtils.ts +510 -0
- package/src/swapper/SwapperWithChain.ts +464 -0
- package/src/swapper/SwapperWithSigner.ts +300 -0
- package/src/swaps/IAddressSwap.ts +20 -0
- package/src/swaps/IBTCWalletSwap.ts +77 -0
- package/src/swaps/IClaimableSwap.ts +30 -0
- package/src/swaps/IClaimableSwapWrapper.ts +9 -0
- package/src/swaps/IRefundableSwap.ts +29 -0
- package/src/swaps/ISwap.ts +490 -0
- package/src/swaps/ISwapWithGasDrop.ts +19 -0
- package/src/swaps/ISwapWrapper.ts +344 -0
- package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +168 -0
- package/src/swaps/escrow_swaps/IEscrowSwap.ts +197 -0
- package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +210 -0
- package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +150 -0
- package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +219 -0
- package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +84 -0
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +1082 -0
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +429 -0
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +1078 -0
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +549 -0
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +974 -0
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +443 -0
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +860 -0
- package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +104 -0
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +256 -0
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +716 -0
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +151 -0
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +299 -0
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +1394 -0
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +796 -0
- package/src/swaps/trusted/ln/LnForGasSwap.ts +402 -0
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +70 -0
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +633 -0
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +110 -0
- package/src/types/AmountData.ts +9 -0
- package/src/types/CustomPriceFunction.ts +5 -0
- package/src/types/PriceInfoType.ts +67 -0
- package/src/types/SwapExecutionAction.ts +8 -0
- package/src/types/SwapWithSigner.ts +57 -0
- package/src/types/Token.ts +90 -0
- package/src/types/TokenAmount.ts +110 -0
- package/src/types/fees/Fee.ts +55 -0
- package/src/types/fees/FeeBreakdown.ts +11 -0
- package/src/types/fees/PercentagePPM.ts +24 -0
- package/src/types/lnurl/LNURLPay.ts +72 -0
- package/src/types/lnurl/LNURLWithdraw.ts +55 -0
- package/src/utils/AutomaticClockDriftCorrection.ts +71 -0
- package/src/utils/BitcoinUtils.ts +86 -0
- package/src/utils/BitcoinWalletUtils.ts +16 -0
- package/src/utils/Logger.ts +15 -0
- package/src/utils/RetryUtils.ts +71 -0
- package/src/utils/SwapUtils.ts +38 -0
- package/src/utils/TimeoutUtils.ts +50 -0
- package/src/utils/TokenUtils.ts +25 -0
- package/src/utils/TypeUtils.ts +9 -0
- package/src/utils/Utils.ts +182 -0
- package/dist/SwapperFactory.d.ts +0 -52
- package/dist/Utils.js +0 -37
- package/dist/fs-storage/FileSystemStorageManager.d.ts +0 -15
- package/dist/fs-storage/FileSystemStorageManager.js +0 -60
- package/dist/fs-storage/index.d.ts +0 -1
- package/dist/fs-storage/index.js +0 -17
- package/src/SmartChainAssets.js +0 -75
- package/src/SwapperFactory.js +0 -120
- package/src/Utils.js +0 -37
- package/src/Utils.ts +0 -31
- package/src/fs-storage/FileSystemStorageManager.ts +0 -71
- package/src/fs-storage/index.ts +0 -1
- package/src/index.js +0 -21
- package/src/storage/LocalStorageManager.js +0 -72
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
import {Buffer} from "buffer";
|
|
2
|
+
import {promiseAny} from "../../utils/Utils";
|
|
3
|
+
import {RequestError} from "../../errors/RequestError";
|
|
4
|
+
import {fetchWithTimeout} from "../../http/HttpUtils";
|
|
5
|
+
import {tryWithRetries} from "../../utils/RetryUtils";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Bitcoin transaction confirmation status
|
|
9
|
+
* @category Bitcoin
|
|
10
|
+
*/
|
|
11
|
+
export type BitcoinTransactionStatus = {
|
|
12
|
+
confirmed: boolean,
|
|
13
|
+
block_height: number,
|
|
14
|
+
block_hash: string,
|
|
15
|
+
block_time: number
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Bitcoin transaction output
|
|
20
|
+
* @category Bitcoin
|
|
21
|
+
*/
|
|
22
|
+
export type TxVout = {
|
|
23
|
+
scriptpubkey: string,
|
|
24
|
+
scriptpubkey_asm: string,
|
|
25
|
+
scriptpubkey_type: string,
|
|
26
|
+
scriptpubkey_address: string,
|
|
27
|
+
value: number
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Bitcoin transaction input
|
|
32
|
+
* @category Bitcoin
|
|
33
|
+
*/
|
|
34
|
+
export type TxVin = {
|
|
35
|
+
txid: string,
|
|
36
|
+
vout: number,
|
|
37
|
+
prevout: TxVout,
|
|
38
|
+
scriptsig: string,
|
|
39
|
+
scriptsig_asm: string,
|
|
40
|
+
witness: string[],
|
|
41
|
+
is_coinbase: boolean,
|
|
42
|
+
sequence: number,
|
|
43
|
+
inner_witnessscript_asm: string
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Full Bitcoin transaction data
|
|
48
|
+
* @category Bitcoin
|
|
49
|
+
*/
|
|
50
|
+
export type BitcoinTransaction = {
|
|
51
|
+
txid: string,
|
|
52
|
+
version: number,
|
|
53
|
+
locktime: number,
|
|
54
|
+
vin: TxVin[],
|
|
55
|
+
vout: TxVout[],
|
|
56
|
+
size: number,
|
|
57
|
+
weight: number,
|
|
58
|
+
fee: number,
|
|
59
|
+
status: BitcoinTransactionStatus
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Bitcoin block data
|
|
64
|
+
* @category Bitcoin
|
|
65
|
+
*/
|
|
66
|
+
export type BlockData = {
|
|
67
|
+
bits: number,
|
|
68
|
+
difficulty: number,
|
|
69
|
+
extras: any,
|
|
70
|
+
height: number,
|
|
71
|
+
id: string,
|
|
72
|
+
mediantime: number,
|
|
73
|
+
merkle_root: string,
|
|
74
|
+
nonce: number,
|
|
75
|
+
previousblockhash: string,
|
|
76
|
+
size: number,
|
|
77
|
+
timestamp: number,
|
|
78
|
+
tx_count: number,
|
|
79
|
+
version: number,
|
|
80
|
+
weight: number
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Bitcoin block header data
|
|
85
|
+
* @category Bitcoin
|
|
86
|
+
*/
|
|
87
|
+
export type BitcoinBlockHeader = {
|
|
88
|
+
id: string,
|
|
89
|
+
height: number,
|
|
90
|
+
version: number,
|
|
91
|
+
timestamp: number,
|
|
92
|
+
tx_count: number,
|
|
93
|
+
size: number,
|
|
94
|
+
weight: number,
|
|
95
|
+
merkle_root: string,
|
|
96
|
+
previousblockhash: string,
|
|
97
|
+
mediantime: number,
|
|
98
|
+
nonce: number,
|
|
99
|
+
bits: number,
|
|
100
|
+
difficulty: number
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export type LNNodeInfo = {
|
|
104
|
+
public_key: string,
|
|
105
|
+
alias: string,
|
|
106
|
+
first_seen: number,
|
|
107
|
+
updated_at: number,
|
|
108
|
+
color: string,
|
|
109
|
+
sockets: string,
|
|
110
|
+
as_number: number,
|
|
111
|
+
city_id: number,
|
|
112
|
+
country_id: number,
|
|
113
|
+
subdivision_id: number,
|
|
114
|
+
longtitude: number,
|
|
115
|
+
latitude: number,
|
|
116
|
+
iso_code: string,
|
|
117
|
+
as_organization: string,
|
|
118
|
+
city: {[lang: string]: string},
|
|
119
|
+
country: {[lang: string]: string},
|
|
120
|
+
subdivision: {[lang: string]: string},
|
|
121
|
+
active_channel_count: number,
|
|
122
|
+
capacity: string,
|
|
123
|
+
opened_channel_count: number,
|
|
124
|
+
closed_channel_count: number
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export type AddressInfo = {
|
|
128
|
+
address: string;
|
|
129
|
+
chain_stats: {
|
|
130
|
+
funded_txo_count: number;
|
|
131
|
+
funded_txo_sum: number;
|
|
132
|
+
spent_txo_count: number;
|
|
133
|
+
spent_txo_sum: number;
|
|
134
|
+
tx_count: number;
|
|
135
|
+
};
|
|
136
|
+
mempool_stats: {
|
|
137
|
+
funded_txo_count: number;
|
|
138
|
+
funded_txo_sum: number;
|
|
139
|
+
spent_txo_count: number;
|
|
140
|
+
spent_txo_sum: number;
|
|
141
|
+
tx_count: number;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export type TransactionCPFPData = {
|
|
146
|
+
ancestors: {
|
|
147
|
+
txid: string,
|
|
148
|
+
fee: number,
|
|
149
|
+
weight: number
|
|
150
|
+
}[],
|
|
151
|
+
descendants: {
|
|
152
|
+
txid: string,
|
|
153
|
+
fee: number,
|
|
154
|
+
weight: number
|
|
155
|
+
}[],
|
|
156
|
+
effectiveFeePerVsize: number,
|
|
157
|
+
sigops: number,
|
|
158
|
+
adjustedVsize: number
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export type BitcoinFees = {
|
|
162
|
+
fastestFee: number,
|
|
163
|
+
halfHourFee: number,
|
|
164
|
+
hourFee: number,
|
|
165
|
+
economyFee: number,
|
|
166
|
+
minimumFee: number
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export type BitcoinPendingBlock = {
|
|
170
|
+
blockSize: number,
|
|
171
|
+
blockVSize: number,
|
|
172
|
+
nTx: number,
|
|
173
|
+
totalFees: number,
|
|
174
|
+
medianFee: number,
|
|
175
|
+
feeRange: number[]
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export type BlockStatus = {
|
|
179
|
+
in_best_chain: boolean,
|
|
180
|
+
height: number,
|
|
181
|
+
next_best: string
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export type TransactionProof = {
|
|
185
|
+
block_height: number,
|
|
186
|
+
merkle: string[],
|
|
187
|
+
pos: number
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export type TransactionOutspend = {
|
|
191
|
+
spent: boolean,
|
|
192
|
+
txid: string,
|
|
193
|
+
vin: number,
|
|
194
|
+
status: BitcoinTransactionStatus
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Mempool.space REST API client for Bitcoin blockchain data
|
|
199
|
+
* @category Bitcoin
|
|
200
|
+
*/
|
|
201
|
+
export class MempoolApi {
|
|
202
|
+
|
|
203
|
+
backends: {
|
|
204
|
+
url: string,
|
|
205
|
+
operational: boolean | null
|
|
206
|
+
}[];
|
|
207
|
+
timeout: number;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Returns api url that should be operational
|
|
211
|
+
*
|
|
212
|
+
* @private
|
|
213
|
+
*/
|
|
214
|
+
private getOperationalApi(): {url: string, operational: boolean | null} | undefined {
|
|
215
|
+
return this.backends.find(e => e.operational===true);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Returns api urls that are maybe operational, in case none is considered operational returns all of the price
|
|
220
|
+
* apis such that they can be tested again whether they are operational
|
|
221
|
+
*
|
|
222
|
+
* @private
|
|
223
|
+
*/
|
|
224
|
+
private getMaybeOperationalApis(): {url: string, operational: boolean | null}[] {
|
|
225
|
+
let operational = this.backends.filter(e => e.operational===true || e.operational===null);
|
|
226
|
+
if(operational.length===0) {
|
|
227
|
+
this.backends.forEach(e => e.operational=null);
|
|
228
|
+
operational = this.backends;
|
|
229
|
+
}
|
|
230
|
+
return operational;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Sends a GET or POST request to the mempool api, handling the non-200 responses as errors & throwing
|
|
235
|
+
*
|
|
236
|
+
* @param url
|
|
237
|
+
* @param path
|
|
238
|
+
* @param responseType
|
|
239
|
+
* @param type
|
|
240
|
+
* @param body
|
|
241
|
+
*/
|
|
242
|
+
private async _request<T>(
|
|
243
|
+
url: string,
|
|
244
|
+
path: string,
|
|
245
|
+
responseType: T extends string ? "str" : "obj",
|
|
246
|
+
type: "GET" | "POST" = "GET",
|
|
247
|
+
body?: string | any
|
|
248
|
+
) : Promise<T> {
|
|
249
|
+
const response: Response = await fetchWithTimeout(url+path, {
|
|
250
|
+
method: type,
|
|
251
|
+
timeout: this.timeout,
|
|
252
|
+
body: typeof(body)==="string" ? body : JSON.stringify(body)
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
if(response.status!==200) {
|
|
256
|
+
let resp: string;
|
|
257
|
+
try {
|
|
258
|
+
resp = await response.text();
|
|
259
|
+
} catch (e) {
|
|
260
|
+
throw new RequestError(response.statusText, response.status);
|
|
261
|
+
}
|
|
262
|
+
throw RequestError.parse(resp, response.status);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if(responseType==="str") return await response.text() as any;
|
|
266
|
+
return await response.json();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Sends request in parallel to multiple maybe operational api urls
|
|
271
|
+
*
|
|
272
|
+
* @param path
|
|
273
|
+
* @param responseType
|
|
274
|
+
* @param type
|
|
275
|
+
* @param body
|
|
276
|
+
* @private
|
|
277
|
+
*/
|
|
278
|
+
private async requestFromMaybeOperationalUrls<T>(
|
|
279
|
+
path: string,
|
|
280
|
+
responseType: T extends string ? "str" : "obj",
|
|
281
|
+
type: "GET" | "POST" = "GET",
|
|
282
|
+
body?: string | any
|
|
283
|
+
) : Promise<T> {
|
|
284
|
+
try {
|
|
285
|
+
return await promiseAny<T>(this.getMaybeOperationalApis().map(
|
|
286
|
+
obj => (async () => {
|
|
287
|
+
try {
|
|
288
|
+
const result = await this._request<T>(obj.url, path, responseType, type, body);
|
|
289
|
+
obj.operational = true;
|
|
290
|
+
return result;
|
|
291
|
+
} catch (e) {
|
|
292
|
+
//Only mark as non operational on 5xx server errors!
|
|
293
|
+
if(e instanceof RequestError && Math.floor(e.httpCode/100)!==5) {
|
|
294
|
+
obj.operational = true;
|
|
295
|
+
throw e;
|
|
296
|
+
} else {
|
|
297
|
+
obj.operational = false;
|
|
298
|
+
throw e;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
})()
|
|
302
|
+
))
|
|
303
|
+
} catch (_e: any) {
|
|
304
|
+
const e = _e as any[];
|
|
305
|
+
throw e.find(err => err instanceof RequestError && Math.floor(err.httpCode/100)!==5) || e[0];
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Sends a request to mempool API, first tries to use the operational API (if any) and if that fails it falls back
|
|
311
|
+
* to using maybe operational price APIs
|
|
312
|
+
*
|
|
313
|
+
* @param path
|
|
314
|
+
* @param responseType
|
|
315
|
+
* @param type
|
|
316
|
+
* @param body
|
|
317
|
+
* @private
|
|
318
|
+
*/
|
|
319
|
+
private async request<T>(
|
|
320
|
+
path: string,
|
|
321
|
+
responseType: T extends string ? "str" : "obj",
|
|
322
|
+
type: "GET" | "POST" = "GET",
|
|
323
|
+
body?: string | any
|
|
324
|
+
) : Promise<T> {
|
|
325
|
+
return tryWithRetries<T>(() => {
|
|
326
|
+
const operationalPriceApi = this.getOperationalApi();
|
|
327
|
+
if(operationalPriceApi!=null) {
|
|
328
|
+
return this._request(operationalPriceApi.url, path, responseType, type, body).catch(err => {
|
|
329
|
+
//Only retry on 5xx server errors!
|
|
330
|
+
if(err instanceof RequestError && Math.floor(err.httpCode/100)!==5) throw err;
|
|
331
|
+
operationalPriceApi.operational = false;
|
|
332
|
+
return this.requestFromMaybeOperationalUrls(path, responseType, type, body);
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
return this.requestFromMaybeOperationalUrls(path, responseType, type, body);
|
|
336
|
+
}, undefined, (err: any) => err instanceof RequestError && Math.floor(err.httpCode/100)!==5);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
constructor(url?: string | string[], timeout?: number) {
|
|
340
|
+
url = url ?? "https://mempool.space/testnet/api/";
|
|
341
|
+
if(Array.isArray(url)) {
|
|
342
|
+
this.backends = url.map(val => {
|
|
343
|
+
return {url: val, operational: null}
|
|
344
|
+
});
|
|
345
|
+
} else {
|
|
346
|
+
this.backends = [
|
|
347
|
+
{url: url, operational: null}
|
|
348
|
+
];
|
|
349
|
+
}
|
|
350
|
+
this.timeout = timeout ?? 15*1000;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Returns information about a specific lightning network node as identified by the public key (in hex encoding)
|
|
355
|
+
*
|
|
356
|
+
* @param pubkey
|
|
357
|
+
*/
|
|
358
|
+
getLNNodeInfo(pubkey: string): Promise<LNNodeInfo | null> {
|
|
359
|
+
//500, 200
|
|
360
|
+
return this.request<LNNodeInfo>("v1/lightning/nodes/"+pubkey, "obj").catch((e: Error) => {
|
|
361
|
+
if(e.message==="This node does not exist, or our node is not seeing it yet") return null;
|
|
362
|
+
throw e;
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Returns on-chain transaction as identified by its txId
|
|
368
|
+
*
|
|
369
|
+
* @param txId
|
|
370
|
+
*/
|
|
371
|
+
getTransaction(txId: string): Promise<BitcoinTransaction | null> {
|
|
372
|
+
//404 ("Transaction not found"), 200
|
|
373
|
+
return this.request<BitcoinTransaction>("tx/"+txId, "obj").catch((e: Error) => {
|
|
374
|
+
if(e.message==="Transaction not found") return null;
|
|
375
|
+
throw e;
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Returns raw binary encoded bitcoin transaction, also strips the witness data from the transaction
|
|
381
|
+
*
|
|
382
|
+
* @param txId
|
|
383
|
+
*/
|
|
384
|
+
async getRawTransaction(txId: string): Promise<Buffer | null> {
|
|
385
|
+
//404 ("Transaction not found"), 200
|
|
386
|
+
const rawTransaction: string | null = await this.request<string>("tx/"+txId+"/hex", "str").catch((e: Error) => {
|
|
387
|
+
if(e.message==="Transaction not found") return null;
|
|
388
|
+
throw e;
|
|
389
|
+
});
|
|
390
|
+
return rawTransaction==null ? null : Buffer.from(rawTransaction, "hex")
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Returns confirmed & unconfirmed balance of the specific bitcoin address
|
|
395
|
+
*
|
|
396
|
+
* @param address
|
|
397
|
+
*/
|
|
398
|
+
async getAddressBalances(address: string): Promise<{
|
|
399
|
+
confirmedBalance: bigint,
|
|
400
|
+
unconfirmedBalance: bigint
|
|
401
|
+
}> {
|
|
402
|
+
//400 ("Invalid Bitcoin address"), 200
|
|
403
|
+
const jsonBody = await this.request<AddressInfo>("address/"+address, "obj");
|
|
404
|
+
|
|
405
|
+
const confirmedInput = BigInt(jsonBody.chain_stats.funded_txo_sum);
|
|
406
|
+
const confirmedOutput = BigInt(jsonBody.chain_stats.spent_txo_sum);
|
|
407
|
+
const unconfirmedInput = BigInt(jsonBody.mempool_stats.funded_txo_sum);
|
|
408
|
+
const unconfirmedOutput = BigInt(jsonBody.mempool_stats.spent_txo_sum);
|
|
409
|
+
|
|
410
|
+
return {
|
|
411
|
+
confirmedBalance: confirmedInput - confirmedOutput,
|
|
412
|
+
unconfirmedBalance: unconfirmedInput - unconfirmedOutput
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Returns CPFP (children pays for parent) data for a given transaction
|
|
418
|
+
*
|
|
419
|
+
* @param txId
|
|
420
|
+
*/
|
|
421
|
+
getCPFPData(txId: string): Promise<TransactionCPFPData> {
|
|
422
|
+
//200
|
|
423
|
+
return this.request<TransactionCPFPData>("v1/cpfp/"+txId, "obj");
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Returns UTXOs (unspent transaction outputs) for a given address
|
|
428
|
+
*
|
|
429
|
+
* @param address
|
|
430
|
+
*/
|
|
431
|
+
async getAddressUTXOs(address: string): Promise<{
|
|
432
|
+
txid: string,
|
|
433
|
+
vout: number,
|
|
434
|
+
status: {
|
|
435
|
+
confirmed: boolean,
|
|
436
|
+
block_height: number,
|
|
437
|
+
block_hash: string,
|
|
438
|
+
block_time: number
|
|
439
|
+
},
|
|
440
|
+
value: bigint
|
|
441
|
+
}[]> {
|
|
442
|
+
//400 ("Invalid Bitcoin address"), 200
|
|
443
|
+
let jsonBody = await this.request<any[]>("address/"+address+"/utxo", "obj");
|
|
444
|
+
jsonBody.forEach(e => e.value = BigInt(e.value));
|
|
445
|
+
|
|
446
|
+
return jsonBody;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Returns current on-chain bitcoin fees
|
|
451
|
+
*/
|
|
452
|
+
getFees(): Promise<BitcoinFees> {
|
|
453
|
+
//200
|
|
454
|
+
return this.request<BitcoinFees>("v1/fees/recommended", "obj");
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Returns all transactions for a given address
|
|
459
|
+
*
|
|
460
|
+
* @param address
|
|
461
|
+
*/
|
|
462
|
+
getAddressTransactions(address: string): Promise<BitcoinTransaction[]> {
|
|
463
|
+
//400 ("Invalid Bitcoin address"), 200
|
|
464
|
+
return this.request<BitcoinTransaction[]>("address/"+address+"/txs", "obj");
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Returns expected pending (mempool) blocks
|
|
469
|
+
*/
|
|
470
|
+
getPendingBlocks(): Promise<BitcoinPendingBlock[]> {
|
|
471
|
+
//200
|
|
472
|
+
return this.request<BitcoinPendingBlock[]>("v1/fees/mempool-blocks", "obj");
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Returns the blockheight of the current bitcoin blockchain's tip
|
|
477
|
+
*/
|
|
478
|
+
async getTipBlockHeight() : Promise<number> {
|
|
479
|
+
//200
|
|
480
|
+
const response: string = await this.request<string>("blocks/tip/height", "str");
|
|
481
|
+
return parseInt(response);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Returns the bitcoin blockheader as identified by its blockhash
|
|
486
|
+
*
|
|
487
|
+
* @param blockhash
|
|
488
|
+
*/
|
|
489
|
+
getBlockHeader(blockhash: string): Promise<BitcoinBlockHeader> {
|
|
490
|
+
//404 ("Block not found"), 200
|
|
491
|
+
return this.request<BitcoinBlockHeader>("block/"+blockhash, "obj");
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Returns the block status
|
|
496
|
+
*
|
|
497
|
+
* @param blockhash
|
|
498
|
+
*/
|
|
499
|
+
getBlockStatus(blockhash: string): Promise<BlockStatus> {
|
|
500
|
+
//200
|
|
501
|
+
return this.request<BlockStatus>("block/"+blockhash+"/status", "obj");
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Returns the transaction's proof (merkle proof)
|
|
506
|
+
*
|
|
507
|
+
* @param txId
|
|
508
|
+
*/
|
|
509
|
+
getTransactionProof(txId: string) : Promise<TransactionProof> {
|
|
510
|
+
//404 ("Transaction not found or is unconfirmed"), 200
|
|
511
|
+
return this.request<TransactionProof>("tx/"+txId+"/merkle-proof", "obj");
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Returns the transaction's proof (merkle proof)
|
|
516
|
+
*
|
|
517
|
+
* @param txId
|
|
518
|
+
*/
|
|
519
|
+
getOutspends(txId: string) : Promise<TransactionOutspend[]> {
|
|
520
|
+
//404 ("Transaction not found"), 200
|
|
521
|
+
return this.request<TransactionOutspend[]>("tx/"+txId+"/outspends", "obj");
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Returns blockhash of a block at a specific blockheight
|
|
526
|
+
*
|
|
527
|
+
* @param height
|
|
528
|
+
*/
|
|
529
|
+
getBlockHash(height: number): Promise<string> {
|
|
530
|
+
//404 ("Block not found"), 200
|
|
531
|
+
return this.request<string>("block-height/"+height, "str");
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Returns past 15 blockheaders before (and including) the specified height
|
|
536
|
+
*
|
|
537
|
+
* @param endHeight
|
|
538
|
+
*/
|
|
539
|
+
getPast15BlockHeaders(endHeight: number) : Promise<BlockData[]> {
|
|
540
|
+
//200
|
|
541
|
+
return this.request<BlockData[]>("v1/blocks/"+endHeight, "obj");
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Sends raw hex encoded bitcoin transaction
|
|
546
|
+
*
|
|
547
|
+
* @param transactionHex
|
|
548
|
+
*/
|
|
549
|
+
sendTransaction(transactionHex: string): Promise<string> {
|
|
550
|
+
//400??, 200
|
|
551
|
+
return this.request<string>("tx", "str", "POST", transactionHex);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {BtcBlock} from "@atomiqlabs/base";
|
|
2
|
+
import {Buffer} from "buffer";
|
|
3
|
+
|
|
4
|
+
export type MempoolBitcoinBlockType = {
|
|
5
|
+
id: string,
|
|
6
|
+
height: number,
|
|
7
|
+
version: number,
|
|
8
|
+
timestamp: number,
|
|
9
|
+
tx_count: number,
|
|
10
|
+
size: number,
|
|
11
|
+
weight: number,
|
|
12
|
+
merkle_root: string,
|
|
13
|
+
previousblockhash: string,
|
|
14
|
+
mediantime: number,
|
|
15
|
+
nonce: number,
|
|
16
|
+
bits: number,
|
|
17
|
+
difficulty: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class MempoolBitcoinBlock implements BtcBlock {
|
|
21
|
+
|
|
22
|
+
id: string;
|
|
23
|
+
height: number;
|
|
24
|
+
version: number;
|
|
25
|
+
timestamp: number;
|
|
26
|
+
tx_count: number;
|
|
27
|
+
size: number;
|
|
28
|
+
weight: number;
|
|
29
|
+
merkle_root: string;
|
|
30
|
+
previousblockhash: string;
|
|
31
|
+
mediantime: number;
|
|
32
|
+
nonce: number;
|
|
33
|
+
bits: number;
|
|
34
|
+
difficulty: number;
|
|
35
|
+
|
|
36
|
+
constructor(obj: MempoolBitcoinBlockType) {
|
|
37
|
+
this.id = obj.id;
|
|
38
|
+
this.height = obj.height;
|
|
39
|
+
this.version = obj.version;
|
|
40
|
+
this.timestamp = obj.timestamp;
|
|
41
|
+
this.tx_count = obj.tx_count;
|
|
42
|
+
this.size = obj.size;
|
|
43
|
+
this.weight = obj.weight;
|
|
44
|
+
this.merkle_root = obj.merkle_root;
|
|
45
|
+
this.previousblockhash = obj.previousblockhash;
|
|
46
|
+
this.mediantime = obj.mediantime;
|
|
47
|
+
this.nonce = obj.nonce;
|
|
48
|
+
this.bits = obj.bits;
|
|
49
|
+
this.difficulty = obj.difficulty;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getHeight(): number {
|
|
53
|
+
return this.height;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getHash(): string {
|
|
57
|
+
return this.id;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getMerkleRoot(): string {
|
|
61
|
+
return this.merkle_root;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getNbits(): number {
|
|
65
|
+
return this.bits;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getNonce(): number {
|
|
69
|
+
return this.nonce;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getPrevBlockhash(): string {
|
|
73
|
+
return this.previousblockhash;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getTimestamp(): number {
|
|
77
|
+
return this.timestamp;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
getVersion(): number {
|
|
81
|
+
return this.version;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
getChainWork(): Buffer {
|
|
85
|
+
throw new Error("Unsupported");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
}
|