@subwallet/extension-base 1.3.41-0 → 1.3.42-0
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/background/KoniTypes.d.ts +121 -4
- package/background/KoniTypes.js +18 -0
- package/background/errors/BitcoinProviderError.d.ts +6 -0
- package/background/errors/BitcoinProviderError.js +47 -0
- package/cjs/background/KoniTypes.js +20 -1
- package/cjs/background/errors/BitcoinProviderError.js +54 -0
- package/cjs/constants/bitcoin.js +22 -0
- package/cjs/constants/index.js +16 -1
- package/cjs/core/logic-validation/recipientAddress.js +9 -0
- package/cjs/core/logic-validation/transfer.js +25 -5
- package/cjs/core/types.js +1 -0
- package/cjs/core/utils.js +15 -1
- package/cjs/koni/background/handlers/Extension.js +59 -3
- package/cjs/koni/background/handlers/State.js +52 -11
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/bitcoin.js +94 -0
- package/cjs/services/balance-service/helpers/subscribe/index.js +19 -7
- package/cjs/services/balance-service/index.js +32 -4
- package/cjs/services/balance-service/transfer/bitcoin-transfer.js +119 -0
- package/cjs/services/balance-service/transfer/token.js +2 -0
- package/cjs/services/base/types.js +2 -0
- package/cjs/services/chain-service/constants.js +14 -3
- package/cjs/services/chain-service/handler/bitcoin/BitcoinApi.js +105 -0
- package/cjs/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +78 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +371 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +19 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +368 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +302 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
- package/cjs/services/chain-service/index.js +27 -3
- package/cjs/services/chain-service/utils/index.js +57 -4
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/event-service/index.js +4 -0
- package/cjs/services/fee-service/service.js +8 -3
- package/cjs/services/hiro-service/index.js +96 -0
- package/cjs/services/hiro-service/utils/index.js +85 -0
- package/cjs/services/history-service/bitcoin-history.js +58 -0
- package/cjs/services/history-service/helpers/recoverHistoryStatus.js +96 -4
- package/cjs/services/history-service/index.js +41 -3
- package/cjs/services/keyring-service/context/handlers/Derive.js +1 -1
- package/cjs/services/keyring-service/context/handlers/Migration.js +2 -2
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +4 -3
- package/cjs/services/migration-service/scripts/MigrateNewUnifiedAccount.js +29 -0
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/request-service/handler/BitcoinRequestHandler.js +440 -0
- package/cjs/services/request-service/index.js +29 -3
- package/cjs/services/rune-service/index.js +105 -0
- package/cjs/services/transaction-service/helpers/index.js +7 -1
- package/cjs/services/transaction-service/index.js +136 -15
- package/cjs/services/transaction-service/utils.js +6 -3
- package/cjs/strategy/api-request-strategy/context/base.js +31 -0
- package/cjs/strategy/api-request-strategy/index.js +90 -0
- package/cjs/strategy/api-request-strategy/types.js +1 -0
- package/cjs/strategy/api-request-strategy/utils/index.js +33 -0
- package/cjs/types/account/info/keyring.js +1 -1
- package/cjs/types/bitcoin.js +24 -0
- package/cjs/types/fee/bitcoin.js +1 -0
- package/cjs/types/fee/index.js +11 -0
- package/cjs/types/index.js +11 -0
- package/cjs/utils/account/analyze.js +3 -3
- package/cjs/utils/account/common.js +16 -6
- package/cjs/utils/account/derive/info/solo.js +68 -19
- package/cjs/utils/account/derive/info/unified.js +2 -0
- package/cjs/utils/account/derive/validate.js +70 -2
- package/cjs/utils/account/transform.js +11 -5
- package/cjs/utils/bitcoin/common.js +98 -0
- package/cjs/utils/bitcoin/fee.js +21 -0
- package/cjs/utils/bitcoin/index.js +38 -0
- package/cjs/utils/bitcoin/utxo-management.js +281 -0
- package/cjs/utils/fee/transfer.js +48 -0
- package/cjs/utils/index.js +15 -1
- package/constants/bitcoin.d.ts +3 -0
- package/constants/bitcoin.js +13 -0
- package/constants/index.d.ts +2 -0
- package/constants/index.js +3 -1
- package/core/logic-validation/recipientAddress.js +10 -1
- package/core/logic-validation/transfer.d.ts +2 -2
- package/core/logic-validation/transfer.js +27 -7
- package/core/types.d.ts +1 -0
- package/core/types.js +1 -0
- package/core/utils.d.ts +1 -0
- package/core/utils.js +15 -2
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +58 -4
- package/koni/background/handlers/State.d.ts +7 -3
- package/koni/background/handlers/State.js +52 -12
- package/package.json +144 -8
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/bitcoin.d.ts +2 -0
- package/services/balance-service/helpers/subscribe/bitcoin.js +87 -0
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
- package/services/balance-service/helpers/subscribe/index.js +20 -8
- package/services/balance-service/index.d.ts +2 -0
- package/services/balance-service/index.js +32 -4
- package/services/balance-service/transfer/bitcoin-transfer.d.ts +14 -0
- package/services/balance-service/transfer/bitcoin-transfer.js +112 -0
- package/services/balance-service/transfer/token.js +2 -0
- package/services/base/types.d.ts +2 -0
- package/services/base/types.js +2 -0
- package/services/chain-service/constants.d.ts +6 -0
- package/services/chain-service/constants.js +8 -2
- package/services/chain-service/handler/bitcoin/BitcoinApi.d.ts +31 -0
- package/services/chain-service/handler/bitcoin/BitcoinApi.js +98 -0
- package/services/chain-service/handler/bitcoin/BitcoinChainHandler.d.ts +16 -0
- package/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +70 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.d.ts +28 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +362 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.d.ts +2 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +5 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.d.ts +28 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +359 -0
- package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.d.ts +28 -0
- package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +293 -0
- package/services/chain-service/handler/bitcoin/strategy/types.d.ts +291 -0
- package/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
- package/services/chain-service/index.d.ts +3 -0
- package/services/chain-service/index.js +31 -5
- package/services/chain-service/types.d.ts +20 -0
- package/services/chain-service/utils/index.d.ts +4 -0
- package/services/chain-service/utils/index.js +50 -4
- package/services/chain-service/utils/patch.js +1 -1
- package/services/event-service/index.d.ts +3 -0
- package/services/event-service/index.js +4 -0
- package/services/event-service/types.d.ts +3 -0
- package/services/fee-service/service.js +8 -3
- package/services/hiro-service/index.d.ts +17 -0
- package/services/hiro-service/index.js +88 -0
- package/services/hiro-service/utils/index.d.ts +6 -0
- package/services/hiro-service/utils/index.js +72 -0
- package/services/history-service/bitcoin-history.d.ts +4 -0
- package/services/history-service/bitcoin-history.js +52 -0
- package/services/history-service/helpers/recoverHistoryStatus.d.ts +3 -1
- package/services/history-service/helpers/recoverHistoryStatus.js +96 -4
- package/services/history-service/index.d.ts +1 -0
- package/services/history-service/index.js +42 -4
- package/services/keyring-service/context/handlers/Derive.js +2 -2
- package/services/keyring-service/context/handlers/Migration.js +2 -2
- package/services/keyring-service/context/handlers/Mnemonic.js +4 -3
- package/services/migration-service/scripts/MigrateNewUnifiedAccount.d.ts +4 -0
- package/services/migration-service/scripts/MigrateNewUnifiedAccount.js +21 -0
- package/services/migration-service/scripts/index.js +3 -1
- package/services/request-service/handler/BitcoinRequestHandler.d.ts +23 -0
- package/services/request-service/handler/BitcoinRequestHandler.js +427 -0
- package/services/request-service/index.d.ts +9 -2
- package/services/request-service/index.js +25 -3
- package/services/rune-service/index.d.ts +17 -0
- package/services/rune-service/index.js +97 -0
- package/services/transaction-service/helpers/index.d.ts +3 -1
- package/services/transaction-service/helpers/index.js +5 -0
- package/services/transaction-service/index.d.ts +3 -5
- package/services/transaction-service/index.js +135 -16
- package/services/transaction-service/types.d.ts +12 -2
- package/services/transaction-service/utils.js +7 -4
- package/strategy/api-request-strategy/context/base.d.ts +15 -0
- package/strategy/api-request-strategy/context/base.js +24 -0
- package/strategy/api-request-strategy/index.d.ts +15 -0
- package/strategy/api-request-strategy/index.js +83 -0
- package/strategy/api-request-strategy/types.d.ts +22 -0
- package/strategy/api-request-strategy/types.js +1 -0
- package/strategy/api-request-strategy/utils/index.d.ts +2 -0
- package/strategy/api-request-strategy/utils/index.js +23 -0
- package/types/account/info/keyring.d.ts +1 -1
- package/types/account/info/keyring.js +1 -1
- package/types/balance/index.d.ts +4 -1
- package/types/balance/transfer.d.ts +17 -0
- package/types/bitcoin.d.ts +93 -0
- package/types/bitcoin.js +17 -0
- package/types/fee/base.d.ts +4 -1
- package/types/fee/bitcoin.d.ts +18 -0
- package/types/fee/bitcoin.js +1 -0
- package/types/fee/index.d.ts +1 -0
- package/types/fee/index.js +2 -1
- package/types/fee/subscription.d.ts +4 -3
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/utils/account/analyze.js +4 -4
- package/utils/account/common.d.ts +7 -8
- package/utils/account/common.js +16 -6
- package/utils/account/derive/info/solo.js +70 -21
- package/utils/account/derive/info/unified.js +2 -0
- package/utils/account/derive/validate.d.ts +1 -0
- package/utils/account/derive/validate.js +68 -1
- package/utils/account/transform.d.ts +1 -1
- package/utils/account/transform.js +11 -5
- package/utils/bitcoin/common.d.ts +22 -0
- package/utils/bitcoin/common.js +88 -0
- package/utils/bitcoin/fee.d.ts +2 -0
- package/utils/bitcoin/fee.js +14 -0
- package/utils/bitcoin/index.d.ts +3 -0
- package/utils/bitcoin/index.js +6 -0
- package/utils/bitcoin/utxo-management.d.ts +33 -0
- package/utils/bitcoin/utxo-management.js +266 -0
- package/utils/fee/transfer.d.ts +3 -1
- package/utils/fee/transfer.js +47 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +6 -3
|
@@ -8,6 +8,7 @@ exports.filterAssetInfoMap = exports.ChainService = void 0;
|
|
|
8
8
|
var _chainList = require("@subwallet/chain-list");
|
|
9
9
|
var _types = require("@subwallet/chain-list/types");
|
|
10
10
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
11
|
+
var _BitcoinChainHandler = require("@subwallet/extension-base/services/chain-service/handler/bitcoin/BitcoinChainHandler");
|
|
11
12
|
var _CardanoChainHandler = require("@subwallet/extension-base/services/chain-service/handler/CardanoChainHandler");
|
|
12
13
|
var _EvmChainHandler = require("@subwallet/extension-base/services/chain-service/handler/EvmChainHandler");
|
|
13
14
|
var _MantaPrivateHandler = require("@subwallet/extension-base/services/chain-service/handler/manta/MantaPrivateHandler");
|
|
@@ -30,13 +31,19 @@ var _logger = require("@polkadot/util/logger");
|
|
|
30
31
|
const filterChainInfoMap = (data, ignoredChains) => {
|
|
31
32
|
return Object.fromEntries(Object.entries(data).filter(_ref => {
|
|
32
33
|
let [slug, info] = _ref;
|
|
33
|
-
return !
|
|
34
|
+
return !ignoredChains.includes(slug);
|
|
34
35
|
}));
|
|
35
36
|
};
|
|
37
|
+
// .filter(([slug, info]) => !info.bitcoinInfo && !ignoredChains.includes(slug))
|
|
38
|
+
|
|
36
39
|
const ignoredList = ['bevm', 'bevmTest', 'bevm_testnet', 'layerEdge_testnet', 'merlinEvm', 'botanixEvmTest', 'syscoin_evm', 'syscoin_evm_testnet', 'rollux_evm', 'rollux_testnet', 'boolAlpha', 'boolBeta_testnet', 'core', 'satoshivm', 'satoshivm_testnet', 'storyPartner_testnet'];
|
|
37
40
|
const filterAssetInfoMap = (chainInfo, assets, addedChains) => {
|
|
38
41
|
return Object.fromEntries(Object.entries(assets).filter(_ref2 => {
|
|
39
42
|
let [, info] = _ref2;
|
|
43
|
+
const isBitcoinChain = (chainInfo === null || chainInfo === void 0 ? void 0 : chainInfo[info.originChain]) && (0, _utils._isChainBitcoinCompatible)(chainInfo[info.originChain]);
|
|
44
|
+
if (isBitcoinChain) {
|
|
45
|
+
return ![_types._AssetType.RUNE, _types._AssetType.BRC20].includes(info.assetType);
|
|
46
|
+
}
|
|
40
47
|
return chainInfo[info.originChain] || (addedChains === null || addedChains === void 0 ? void 0 : addedChains.includes(info.originChain));
|
|
41
48
|
}));
|
|
42
49
|
};
|
|
@@ -87,6 +94,7 @@ class ChainService {
|
|
|
87
94
|
this.evmChainHandler = new _EvmChainHandler.EvmChainHandler(this);
|
|
88
95
|
this.tonChainHandler = new _TonChainHandler.TonChainHandler(this);
|
|
89
96
|
this.cardanoChainHandler = new _CardanoChainHandler.CardanoChainHandler(this);
|
|
97
|
+
this.bitcoinChainHandler = new _BitcoinChainHandler.BitcoinChainHandler(this);
|
|
90
98
|
this.logger = (0, _logger.logger)('chain-service');
|
|
91
99
|
}
|
|
92
100
|
get value() {
|
|
@@ -164,6 +172,12 @@ class ChainService {
|
|
|
164
172
|
getSubstrateApiMap() {
|
|
165
173
|
return this.substrateChainHandler.getSubstrateApiMap();
|
|
166
174
|
}
|
|
175
|
+
getBitcoinApi(slug) {
|
|
176
|
+
return this.bitcoinChainHandler.getApiByChain(slug);
|
|
177
|
+
}
|
|
178
|
+
getBitcoinApiMap() {
|
|
179
|
+
return this.bitcoinChainHandler.getApiMap();
|
|
180
|
+
}
|
|
167
181
|
getTonApi(slug) {
|
|
168
182
|
return this.tonChainHandler.getTonApiByChain(slug);
|
|
169
183
|
}
|
|
@@ -849,6 +863,13 @@ class ChainService {
|
|
|
849
863
|
});
|
|
850
864
|
this.cardanoChainHandler.setCardanoApi(chainInfo.slug, chainApi);
|
|
851
865
|
}
|
|
866
|
+
if (chainInfo.bitcoinInfo !== null && chainInfo.bitcoinInfo !== undefined) {
|
|
867
|
+
const chainApi = await this.bitcoinChainHandler.initApi(chainInfo.slug, endpoint, {
|
|
868
|
+
providerName,
|
|
869
|
+
onUpdateStatus
|
|
870
|
+
});
|
|
871
|
+
this.bitcoinChainHandler.setApi(chainInfo.slug, chainApi);
|
|
872
|
+
}
|
|
852
873
|
}
|
|
853
874
|
destroyApiForChain(chainInfo) {
|
|
854
875
|
if (chainInfo.substrateInfo !== null) {
|
|
@@ -863,6 +884,9 @@ class ChainService {
|
|
|
863
884
|
if (chainInfo.cardanoInfo !== null) {
|
|
864
885
|
this.cardanoChainHandler.destroyCardanoApi(chainInfo.slug);
|
|
865
886
|
}
|
|
887
|
+
if (chainInfo.bitcoinInfo !== null && chainInfo.bitcoinInfo !== undefined) {
|
|
888
|
+
this.bitcoinChainHandler.destroyApi(chainInfo.slug);
|
|
889
|
+
}
|
|
866
890
|
}
|
|
867
891
|
async enableChain(chainSlug) {
|
|
868
892
|
const chainInfo = this.getChainInfoByKey(chainSlug);
|
|
@@ -1722,11 +1746,11 @@ class ChainService {
|
|
|
1722
1746
|
this.evmChainHandler.recoverApi(slug).catch(console.error);
|
|
1723
1747
|
}
|
|
1724
1748
|
async stopAllChainApis() {
|
|
1725
|
-
await Promise.all([this.substrateChainHandler.sleep(), this.evmChainHandler.sleep(), this.tonChainHandler.sleep(), this.cardanoChainHandler.sleep()]);
|
|
1749
|
+
await Promise.all([this.substrateChainHandler.sleep(), this.evmChainHandler.sleep(), this.tonChainHandler.sleep(), this.cardanoChainHandler.sleep(), this.bitcoinChainHandler.sleep()]);
|
|
1726
1750
|
this.stopCheckLatestChainData();
|
|
1727
1751
|
}
|
|
1728
1752
|
async resumeAllChainApis() {
|
|
1729
|
-
await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp(), this.tonChainHandler.wakeUp(), this.cardanoChainHandler.wakeUp()]);
|
|
1753
|
+
await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp(), this.tonChainHandler.wakeUp(), this.cardanoChainHandler.wakeUp(), this.bitcoinChainHandler.wakeUp()]);
|
|
1730
1754
|
this.checkLatestData();
|
|
1731
1755
|
}
|
|
1732
1756
|
initAssetSettings() {
|
|
@@ -13,6 +13,7 @@ var _exportNames = {
|
|
|
13
13
|
_isPureSubstrateChain: true,
|
|
14
14
|
_isPureTonChain: true,
|
|
15
15
|
_isPureCardanoChain: true,
|
|
16
|
+
_isPureBitcoinChain: true,
|
|
16
17
|
_getOriginChainOfAsset: true,
|
|
17
18
|
_getContractAddressOfToken: true,
|
|
18
19
|
_isNativeTokenTransferredByEvm: true,
|
|
@@ -21,6 +22,7 @@ var _exportNames = {
|
|
|
21
22
|
_isJettonToken: true,
|
|
22
23
|
_isTokenTransferredByTon: true,
|
|
23
24
|
_isTokenTransferredByCardano: true,
|
|
25
|
+
_isTokenTransferredByBitcoin: true,
|
|
24
26
|
_getTokenOnChainAssetId: true,
|
|
25
27
|
_getTokenOnChainInfo: true,
|
|
26
28
|
_isBridgedToken: true,
|
|
@@ -99,6 +101,7 @@ var _exportNames = {
|
|
|
99
101
|
_isAssetCanPayTxFee: true,
|
|
100
102
|
updateLatestChainInfo: true,
|
|
101
103
|
_chainInfoToChainType: true,
|
|
104
|
+
_isChainInfoCompatibleWithAccountInfo: true,
|
|
102
105
|
_getAssetNetuid: true
|
|
103
106
|
};
|
|
104
107
|
exports._chainInfoToChainType = void 0;
|
|
@@ -151,6 +154,7 @@ exports._isChainBitcoinCompatible = _isChainBitcoinCompatible;
|
|
|
151
154
|
exports._isChainCardanoCompatible = _isChainCardanoCompatible;
|
|
152
155
|
exports._isChainEnabled = _isChainEnabled;
|
|
153
156
|
exports._isChainEvmCompatible = _isChainEvmCompatible;
|
|
157
|
+
exports._isChainInfoCompatibleWithAccountInfo = void 0;
|
|
154
158
|
exports._isChainSubstrateCompatible = _isChainSubstrateCompatible;
|
|
155
159
|
exports._isChainSupportEvmERC20 = _isChainSupportEvmERC20;
|
|
156
160
|
exports._isChainSupportEvmNft = _isChainSupportEvmNft;
|
|
@@ -173,6 +177,7 @@ exports._isMantaZkAsset = _isMantaZkAsset;
|
|
|
173
177
|
exports._isNativeToken = _isNativeToken;
|
|
174
178
|
exports._isNativeTokenBySlug = _isNativeTokenBySlug;
|
|
175
179
|
exports._isNativeTokenTransferredByEvm = _isNativeTokenTransferredByEvm;
|
|
180
|
+
exports._isPureBitcoinChain = _isPureBitcoinChain;
|
|
176
181
|
exports._isPureCardanoChain = _isPureCardanoChain;
|
|
177
182
|
exports._isPureEvmChain = _isPureEvmChain;
|
|
178
183
|
exports._isPureSubstrateChain = _isPureSubstrateChain;
|
|
@@ -185,6 +190,7 @@ exports._isSupportOrdinal = void 0;
|
|
|
185
190
|
exports._isTokenEvmSmartContract = _isTokenEvmSmartContract;
|
|
186
191
|
exports._isTokenGearSmartContract = _isTokenGearSmartContract;
|
|
187
192
|
exports._isTokenTonSmartContract = _isTokenTonSmartContract;
|
|
193
|
+
exports._isTokenTransferredByBitcoin = _isTokenTransferredByBitcoin;
|
|
188
194
|
exports._isTokenTransferredByCardano = _isTokenTransferredByCardano;
|
|
189
195
|
exports._isTokenTransferredByEvm = _isTokenTransferredByEvm;
|
|
190
196
|
exports._isTokenTransferredByTon = _isTokenTransferredByTon;
|
|
@@ -200,6 +206,7 @@ var _types = require("@subwallet/chain-list/types");
|
|
|
200
206
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
201
207
|
var _types2 = require("@subwallet/extension-base/services/chain-service/types");
|
|
202
208
|
var _types3 = require("@subwallet/extension-base/types");
|
|
209
|
+
var _types4 = require("@subwallet/keyring/types");
|
|
203
210
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
204
211
|
var _patch = require("./patch");
|
|
205
212
|
Object.keys(_patch).forEach(function (key) {
|
|
@@ -258,16 +265,19 @@ function _isEqualSmartContractAsset(asset1, asset2) {
|
|
|
258
265
|
return false;
|
|
259
266
|
}
|
|
260
267
|
function _isPureEvmChain(chainInfo) {
|
|
261
|
-
return !!chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo;
|
|
268
|
+
return !!chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo && !chainInfo.bitcoinInfo;
|
|
262
269
|
}
|
|
263
270
|
function _isPureSubstrateChain(chainInfo) {
|
|
264
|
-
return !chainInfo.evmInfo && !!chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo;
|
|
271
|
+
return !chainInfo.evmInfo && !!chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo && !chainInfo.bitcoinInfo;
|
|
265
272
|
}
|
|
266
273
|
function _isPureTonChain(chainInfo) {
|
|
267
|
-
return !chainInfo.evmInfo && !chainInfo.substrateInfo && !!chainInfo.tonInfo && !chainInfo.cardanoInfo;
|
|
274
|
+
return !chainInfo.evmInfo && !chainInfo.substrateInfo && !!chainInfo.tonInfo && !chainInfo.cardanoInfo && !chainInfo.bitcoinInfo;
|
|
268
275
|
}
|
|
269
276
|
function _isPureCardanoChain(chainInfo) {
|
|
270
|
-
return !chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !!chainInfo.cardanoInfo;
|
|
277
|
+
return !chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !!chainInfo.cardanoInfo && !chainInfo.bitcoinInfo;
|
|
278
|
+
}
|
|
279
|
+
function _isPureBitcoinChain(chainInfo) {
|
|
280
|
+
return !chainInfo.evmInfo && !chainInfo.substrateInfo && !chainInfo.tonInfo && !chainInfo.cardanoInfo && !!chainInfo.bitcoinInfo;
|
|
271
281
|
}
|
|
272
282
|
function _getOriginChainOfAsset(assetSlug) {
|
|
273
283
|
if (assetSlug.startsWith(_types2._CUSTOM_PREFIX)) {
|
|
@@ -324,6 +334,11 @@ function _isTokenTransferredByCardano(tokenInfo) {
|
|
|
324
334
|
return _isCIP26Token(tokenInfo) || _isNativeToken(tokenInfo);
|
|
325
335
|
}
|
|
326
336
|
|
|
337
|
+
// TODO [Review]: Currently supports transferring only the native token, Bitcoin.
|
|
338
|
+
function _isTokenTransferredByBitcoin(tokenInfo) {
|
|
339
|
+
return _isNativeToken(tokenInfo);
|
|
340
|
+
}
|
|
341
|
+
|
|
327
342
|
// Utils for balance functions
|
|
328
343
|
function _getTokenOnChainAssetId(tokenInfo) {
|
|
329
344
|
var _tokenInfo$metadata5;
|
|
@@ -500,6 +515,11 @@ function _getChainNativeTokenBasicInfo(chainInfo) {
|
|
|
500
515
|
symbol: chainInfo.cardanoInfo.symbol,
|
|
501
516
|
decimals: chainInfo.cardanoInfo.decimals
|
|
502
517
|
};
|
|
518
|
+
} else if (chainInfo.bitcoinInfo) {
|
|
519
|
+
return {
|
|
520
|
+
symbol: chainInfo.bitcoinInfo.symbol,
|
|
521
|
+
decimals: chainInfo.bitcoinInfo.decimals
|
|
522
|
+
};
|
|
503
523
|
}
|
|
504
524
|
return defaultTokenInfo;
|
|
505
525
|
}
|
|
@@ -613,6 +633,9 @@ function _getBlockExplorerFromChain(chainInfo) {
|
|
|
613
633
|
} else if (_isPureCardanoChain(chainInfo)) {
|
|
614
634
|
var _chainInfo$cardanoInf;
|
|
615
635
|
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$cardanoInf = chainInfo.cardanoInfo) === null || _chainInfo$cardanoInf === void 0 ? void 0 : _chainInfo$cardanoInf.blockExplorer;
|
|
636
|
+
} else if (_isPureBitcoinChain(chainInfo)) {
|
|
637
|
+
var _chainInfo$bitcoinInf;
|
|
638
|
+
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$bitcoinInf = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf === void 0 ? void 0 : _chainInfo$bitcoinInf.blockExplorer;
|
|
616
639
|
} else {
|
|
617
640
|
var _chainInfo$substrateI18;
|
|
618
641
|
blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI18 = chainInfo.substrateInfo) === null || _chainInfo$substrateI18 === void 0 ? void 0 : _chainInfo$substrateI18.blockExplorer;
|
|
@@ -793,6 +816,36 @@ const _chainInfoToChainType = chainInfo => {
|
|
|
793
816
|
return _types3.AccountChainType.SUBSTRATE;
|
|
794
817
|
};
|
|
795
818
|
exports._chainInfoToChainType = _chainInfoToChainType;
|
|
819
|
+
const _isChainInfoCompatibleWithAccountInfo = (chainInfo, accountChainType, accountType) => {
|
|
820
|
+
if (accountChainType === _types3.AccountChainType.SUBSTRATE) {
|
|
821
|
+
return _isPureSubstrateChain(chainInfo) && _types4.SubstrateKeypairTypes.includes(accountType);
|
|
822
|
+
}
|
|
823
|
+
if (accountChainType === _types3.AccountChainType.ETHEREUM) {
|
|
824
|
+
return _isChainEvmCompatible(chainInfo) && _types4.EthereumKeypairTypes.includes(accountType);
|
|
825
|
+
}
|
|
826
|
+
if (accountChainType === _types3.AccountChainType.TON) {
|
|
827
|
+
return _isChainTonCompatible(chainInfo) && _types4.TonKeypairTypes.includes(accountType);
|
|
828
|
+
}
|
|
829
|
+
if (accountChainType === _types3.AccountChainType.CARDANO) {
|
|
830
|
+
return _isChainCardanoCompatible(chainInfo) && _types4.CardanoKeypairTypes.includes(accountType);
|
|
831
|
+
}
|
|
832
|
+
if (accountChainType === _types3.AccountChainType.BITCOIN) {
|
|
833
|
+
var _chainInfo$bitcoinInf2;
|
|
834
|
+
if (!_isChainBitcoinCompatible(chainInfo) || ![..._types4.BitcoinMainnetKeypairTypes, ..._types4.BitcoinTestnetKeypairTypes].includes(accountType)) {
|
|
835
|
+
return false;
|
|
836
|
+
}
|
|
837
|
+
const network = (_chainInfo$bitcoinInf2 = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf2 === void 0 ? void 0 : _chainInfo$bitcoinInf2.bitcoinNetwork;
|
|
838
|
+
if (_types4.BitcoinMainnetKeypairTypes.includes(accountType)) {
|
|
839
|
+
return network === 'mainnet';
|
|
840
|
+
}
|
|
841
|
+
if (_types4.BitcoinTestnetKeypairTypes.includes(accountType)) {
|
|
842
|
+
return network === 'testnet';
|
|
843
|
+
}
|
|
844
|
+
return false;
|
|
845
|
+
}
|
|
846
|
+
return false;
|
|
847
|
+
};
|
|
848
|
+
exports._isChainInfoCompatibleWithAccountInfo = _isChainInfoCompatibleWithAccountInfo;
|
|
796
849
|
const _getAssetNetuid = assetInfo => {
|
|
797
850
|
var _assetInfo$metadata$n, _assetInfo$metadata;
|
|
798
851
|
// @ts-ignore
|
|
@@ -11,7 +11,7 @@ const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
|
|
|
11
11
|
const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
|
|
12
12
|
const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
|
|
13
13
|
const fetchFile = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'list.json' : 'preview.json';
|
|
14
|
-
const ChainListVersion = '0.2.
|
|
14
|
+
const ChainListVersion = '0.2.107'; // update this when build chainlist
|
|
15
15
|
|
|
16
16
|
// todo: move this interface to chainlist
|
|
17
17
|
|
|
@@ -25,6 +25,10 @@ class EventService extends _eventemitter.default {
|
|
|
25
25
|
this.waitDatabaseReady = this.generateWaitPromise('database.ready');
|
|
26
26
|
this.waitKeyringReady = this.generateWaitPromise('keyring.ready');
|
|
27
27
|
this.waitAccountReady = this.generateWaitPromise('account.ready');
|
|
28
|
+
this.waitAppInitialized = this.generateWaitPromise('general.init');
|
|
29
|
+
this.waitAppStart = this.generateWaitPromise('general.start');
|
|
30
|
+
this.waitAppStartFull = this.generateWaitPromise('general.start_full');
|
|
31
|
+
|
|
28
32
|
// TODO: Need to merge logic on web-runner file
|
|
29
33
|
this.waitInjectReady = _utils.TARGET_ENV === 'webapp' ? this.generateWaitPromise('inject.ready') : Promise.resolve(true);
|
|
30
34
|
this.waitChainReady = this.generateWaitPromise('chain.ready');
|
|
@@ -16,7 +16,8 @@ class FeeService {
|
|
|
16
16
|
evm: {},
|
|
17
17
|
substrate: {},
|
|
18
18
|
ton: {},
|
|
19
|
-
cardano: {}
|
|
19
|
+
cardano: {},
|
|
20
|
+
bitcoin: {}
|
|
20
21
|
};
|
|
21
22
|
constructor(state) {
|
|
22
23
|
this.state = state;
|
|
@@ -107,10 +108,9 @@ class FeeService {
|
|
|
107
108
|
if (cancel) {
|
|
108
109
|
clearInterval(interval);
|
|
109
110
|
} else {
|
|
110
|
-
const api = this.state.getEvmApi(chain);
|
|
111
|
-
|
|
112
111
|
// TODO: Handle case type === evm and not have api
|
|
113
112
|
if (type === 'evm') {
|
|
113
|
+
const api = this.state.getEvmApi(chain);
|
|
114
114
|
if (api) {
|
|
115
115
|
(0, _utils2.calculateGasFeeParams)(api, chain).then(info => {
|
|
116
116
|
observer.next(info);
|
|
@@ -132,6 +132,11 @@ class FeeService {
|
|
|
132
132
|
options: undefined
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
|
+
} else if (type === 'bitcoin') {
|
|
136
|
+
const api = this.state.getBitcoinApi(chain);
|
|
137
|
+
api.api.getRecommendedFeeRate().then(info => {
|
|
138
|
+
observer.next(info);
|
|
139
|
+
}).catch(console.error);
|
|
135
140
|
} else {
|
|
136
141
|
observer.next({
|
|
137
142
|
type,
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.HiroService = void 0;
|
|
7
|
+
var _SWError = require("@subwallet/extension-base/background/errors/SWError");
|
|
8
|
+
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
9
|
+
var _apiRequestStrategy = require("@subwallet/extension-base/strategy/api-request-strategy");
|
|
10
|
+
var _base = require("@subwallet/extension-base/strategy/api-request-strategy/context/base");
|
|
11
|
+
var _utils = require("@subwallet/extension-base/strategy/api-request-strategy/utils");
|
|
12
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
13
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
14
|
+
|
|
15
|
+
const BITCOIN_API_URL = 'https://btc-api.koni.studio';
|
|
16
|
+
const BITCOIN_API_URL_TEST = 'https://api-testnet.openbit.app';
|
|
17
|
+
class HiroService extends _apiRequestStrategy.BaseApiRequestStrategy {
|
|
18
|
+
constructor(url) {
|
|
19
|
+
const context = new _base.BaseApiRequestContext();
|
|
20
|
+
super(context);
|
|
21
|
+
this.baseUrl = url;
|
|
22
|
+
}
|
|
23
|
+
headers = {
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
Authorization: `Bearer ${_constants._BTC_SERVICE_TOKEN}`
|
|
26
|
+
};
|
|
27
|
+
isRateLimited() {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
getUrl(path) {
|
|
31
|
+
return `${this.baseUrl}/${path}`;
|
|
32
|
+
}
|
|
33
|
+
getBRC20Metadata(ticker) {
|
|
34
|
+
return this.addRequest(async () => {
|
|
35
|
+
const _rs = await (0, _utils.getRequest)(this.getUrl(`brc-20/tokens/${ticker}`), undefined, this.headers);
|
|
36
|
+
const rs = await _rs.json();
|
|
37
|
+
if (rs.status_code !== 200) {
|
|
38
|
+
throw new _SWError.SWError('HiroService.getBRC20Metadata', rs.message);
|
|
39
|
+
}
|
|
40
|
+
return rs.result;
|
|
41
|
+
}, 3);
|
|
42
|
+
}
|
|
43
|
+
getAddressBRC20BalanceInfo(address, params) {
|
|
44
|
+
return this.addRequest(async () => {
|
|
45
|
+
const _rs = await (0, _utils.getRequest)(this.getUrl(`brc-20/balances/${address}`), params, this.headers);
|
|
46
|
+
const rs = await _rs.json();
|
|
47
|
+
if (rs.status_code !== 200) {
|
|
48
|
+
throw new _SWError.SWError('HiroService.getAddressBRC20BalanceInfo', rs.message);
|
|
49
|
+
}
|
|
50
|
+
return rs.result;
|
|
51
|
+
}, 3);
|
|
52
|
+
}
|
|
53
|
+
getAddressInscriptionsInfo(params) {
|
|
54
|
+
return this.addRequest(async () => {
|
|
55
|
+
const _rs = await (0, _utils.getRequest)(this.getUrl('inscriptions'), params, this.headers);
|
|
56
|
+
const rs = await _rs.json();
|
|
57
|
+
if (rs.status_code !== 200) {
|
|
58
|
+
throw new _SWError.SWError('HiroService.getAddressInscriptionsInfo', rs.message);
|
|
59
|
+
}
|
|
60
|
+
return rs.result;
|
|
61
|
+
}, 0);
|
|
62
|
+
}
|
|
63
|
+
getInscriptionContent(inscriptionId) {
|
|
64
|
+
return this.addRequest(async () => {
|
|
65
|
+
const _rs = await (0, _utils.getRequest)(this.getUrl(`inscriptions/${inscriptionId}/content`), undefined, this.headers);
|
|
66
|
+
const rs = await _rs.json();
|
|
67
|
+
if (rs.status_code !== 200) {
|
|
68
|
+
throw new _SWError.SWError('HiroService.getInscriptionContent', rs.message);
|
|
69
|
+
}
|
|
70
|
+
return rs.result;
|
|
71
|
+
}, 0);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// todo: handle token authen for url preview
|
|
75
|
+
getPreviewUrl(inscriptionId) {
|
|
76
|
+
return `${BITCOIN_API_URL}/inscriptions/${inscriptionId}/content`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Singleton
|
|
80
|
+
|
|
81
|
+
static getInstance() {
|
|
82
|
+
let isTestnet = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
83
|
+
if (isTestnet) {
|
|
84
|
+
if (!HiroService.testnet) {
|
|
85
|
+
HiroService.testnet = new HiroService(BITCOIN_API_URL_TEST);
|
|
86
|
+
}
|
|
87
|
+
return HiroService.testnet;
|
|
88
|
+
} else {
|
|
89
|
+
if (!HiroService.mainnet) {
|
|
90
|
+
HiroService.mainnet = new HiroService(BITCOIN_API_URL);
|
|
91
|
+
}
|
|
92
|
+
return HiroService.mainnet;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.HiroService = HiroService;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAddressInscriptions = getAddressInscriptions;
|
|
7
|
+
exports.getBrc20Metadata = getBrc20Metadata;
|
|
8
|
+
exports.getInscriptionContent = getInscriptionContent;
|
|
9
|
+
exports.getPreviewUrl = getPreviewUrl;
|
|
10
|
+
exports.isValidBrc20Ticker = isValidBrc20Ticker;
|
|
11
|
+
var _hiroService = require("@subwallet/extension-base/services/hiro-service");
|
|
12
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
13
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
14
|
+
|
|
15
|
+
// todo: handle inscription testnet
|
|
16
|
+
async function getBrc20Metadata() {
|
|
17
|
+
let isTestnet = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
18
|
+
let ticker = arguments.length > 1 ? arguments[1] : undefined;
|
|
19
|
+
const hiroService = _hiroService.HiroService.getInstance(isTestnet);
|
|
20
|
+
const defaultMetadata = {
|
|
21
|
+
ticker: '',
|
|
22
|
+
decimals: 0
|
|
23
|
+
};
|
|
24
|
+
try {
|
|
25
|
+
const response = await hiroService.getBRC20Metadata(ticker);
|
|
26
|
+
const rs = response === null || response === void 0 ? void 0 : response.token;
|
|
27
|
+
if (rs) {
|
|
28
|
+
return {
|
|
29
|
+
ticker: rs.ticker,
|
|
30
|
+
decimals: rs.decimals
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return defaultMetadata;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.log(`Error on request brc20 metadata with ticker ${ticker}`);
|
|
36
|
+
return defaultMetadata;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function getInscriptionContent(isTestnet, inscriptionId) {
|
|
40
|
+
const hiroService = _hiroService.HiroService.getInstance(isTestnet);
|
|
41
|
+
try {
|
|
42
|
+
return await hiroService.getInscriptionContent(inscriptionId);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.log(`Error on request inscription ${inscriptionId} content`);
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// todo: handle large inscriptions
|
|
50
|
+
async function getAddressInscriptions(address, isTestnet) {
|
|
51
|
+
let offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
52
|
+
let limit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 25;
|
|
53
|
+
const hiroService = _hiroService.HiroService.getInstance(isTestnet);
|
|
54
|
+
try {
|
|
55
|
+
const response = await hiroService.getAddressInscriptionsInfo({
|
|
56
|
+
limit: String(limit),
|
|
57
|
+
offset: String(offset),
|
|
58
|
+
address: String(address)
|
|
59
|
+
});
|
|
60
|
+
return response.results;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error(`Failed to get ${address} inscriptions with offset ${offset} and limit ${limit}`, error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function getPreviewUrl(inscriptionId) {
|
|
67
|
+
const hiroService = _hiroService.HiroService.getInstance();
|
|
68
|
+
try {
|
|
69
|
+
return hiroService.getPreviewUrl(inscriptionId);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error(`Failed to get inscription ${inscriptionId} preview url`, error);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function isValidBrc20Ticker(ticker) {
|
|
76
|
+
const bytesLength = getByteLength(ticker);
|
|
77
|
+
return bytesLength === 4 || bytesLength === 5;
|
|
78
|
+
}
|
|
79
|
+
function getByteLength(str) {
|
|
80
|
+
const encoder = new TextEncoder();
|
|
81
|
+
const encodedStr = encoder.encode(str);
|
|
82
|
+
|
|
83
|
+
// Return the length of the encoded array, which represents the number of bytes
|
|
84
|
+
return encodedStr.length;
|
|
85
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseBitcoinTransferData = parseBitcoinTransferData;
|
|
7
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
8
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
9
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
|
|
11
|
+
function isSender(address, transferItem) {
|
|
12
|
+
return transferItem.vin.some(i => i.prevout.scriptpubkey_address === address);
|
|
13
|
+
}
|
|
14
|
+
function parseBitcoinTransferData(address, transferItem, chainInfo) {
|
|
15
|
+
var _chainInfo$bitcoinInf, _chainInfo$bitcoinInf2, _transferItem$vin$, _transferItem$vin$$pr, _transferItem$vout$;
|
|
16
|
+
const chainType = _KoniTypes.ChainType.BITCOIN;
|
|
17
|
+
const nativeDecimals = ((_chainInfo$bitcoinInf = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf === void 0 ? void 0 : _chainInfo$bitcoinInf.decimals) || 8;
|
|
18
|
+
const nativeSymbol = ((_chainInfo$bitcoinInf2 = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf2 === void 0 ? void 0 : _chainInfo$bitcoinInf2.symbol) || '';
|
|
19
|
+
const isCurrentAddressSender = isSender(address, transferItem);
|
|
20
|
+
const sender = isCurrentAddressSender ? address : ((_transferItem$vin$ = transferItem.vin[0]) === null || _transferItem$vin$ === void 0 ? void 0 : (_transferItem$vin$$pr = _transferItem$vin$.prevout) === null || _transferItem$vin$$pr === void 0 ? void 0 : _transferItem$vin$$pr.scriptpubkey_address) || '';
|
|
21
|
+
const receiver = isCurrentAddressSender ? ((_transferItem$vout$ = transferItem.vout[0]) === null || _transferItem$vout$ === void 0 ? void 0 : _transferItem$vout$.scriptpubkey_address) || '' : address;
|
|
22
|
+
const amountValue = (() => {
|
|
23
|
+
const targetAddress = isCurrentAddressSender ? receiver : address;
|
|
24
|
+
const vouts = transferItem.vout.filter(i => i.scriptpubkey_address === targetAddress);
|
|
25
|
+
if (vouts.length) {
|
|
26
|
+
return vouts.reduce((total, item) => total + item.value, 0).toString();
|
|
27
|
+
} else {
|
|
28
|
+
return '0';
|
|
29
|
+
}
|
|
30
|
+
})();
|
|
31
|
+
return {
|
|
32
|
+
address,
|
|
33
|
+
origin: 'blockstream',
|
|
34
|
+
time: 0,
|
|
35
|
+
// From api, cannot get time submit transaction
|
|
36
|
+
blockTime: transferItem.status.block_time ? transferItem.status.block_time * 1000 : undefined,
|
|
37
|
+
chainType,
|
|
38
|
+
type: _KoniTypes.ExtrinsicType.TRANSFER_BALANCE,
|
|
39
|
+
extrinsicHash: transferItem.txid,
|
|
40
|
+
chain: chainInfo.slug,
|
|
41
|
+
direction: address === sender ? _KoniTypes.TransactionDirection.SEND : _KoniTypes.TransactionDirection.RECEIVED,
|
|
42
|
+
fee: {
|
|
43
|
+
value: `${transferItem.fee}`,
|
|
44
|
+
decimals: nativeDecimals,
|
|
45
|
+
symbol: nativeSymbol
|
|
46
|
+
},
|
|
47
|
+
from: sender,
|
|
48
|
+
to: receiver,
|
|
49
|
+
blockNumber: transferItem.status.block_height || 0,
|
|
50
|
+
blockHash: transferItem.status.block_hash || '',
|
|
51
|
+
amount: {
|
|
52
|
+
value: amountValue,
|
|
53
|
+
decimals: nativeDecimals,
|
|
54
|
+
symbol: nativeSymbol
|
|
55
|
+
},
|
|
56
|
+
status: transferItem.status.confirmed ? _KoniTypes.ExtrinsicStatus.SUCCESS : _KoniTypes.ExtrinsicStatus.PROCESSING
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -17,6 +17,7 @@ exports.HistoryRecoverStatus = HistoryRecoverStatus;
|
|
|
17
17
|
HistoryRecoverStatus["LACK_INFO"] = "LACK_INFO";
|
|
18
18
|
HistoryRecoverStatus["FAIL_DETECT"] = "FAIL_DETECT";
|
|
19
19
|
HistoryRecoverStatus["UNKNOWN"] = "UNKNOWN";
|
|
20
|
+
HistoryRecoverStatus["TX_PENDING"] = "TX_PENDING";
|
|
20
21
|
})(HistoryRecoverStatus || (exports.HistoryRecoverStatus = HistoryRecoverStatus = {}));
|
|
21
22
|
const BLOCK_LIMIT = 6;
|
|
22
23
|
const substrateRecover = async (history, chainService) => {
|
|
@@ -216,6 +217,80 @@ const evmRecover = async (history, chainService) => {
|
|
|
216
217
|
};
|
|
217
218
|
}
|
|
218
219
|
};
|
|
220
|
+
const bitcoinRecover = async (history, chainService) => {
|
|
221
|
+
const {
|
|
222
|
+
chain,
|
|
223
|
+
extrinsicHash
|
|
224
|
+
} = history;
|
|
225
|
+
const result = {
|
|
226
|
+
status: HistoryRecoverStatus.UNKNOWN
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// TODO: 1. Consider rebroadcasting transaction if stuck in mempool
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
const bitcoinApi = chainService.getBitcoinApi(chain);
|
|
233
|
+
if (bitcoinApi) {
|
|
234
|
+
const api = bitcoinApi.api;
|
|
235
|
+
if (extrinsicHash) {
|
|
236
|
+
try {
|
|
237
|
+
const timeout = new Promise(resolve => {
|
|
238
|
+
setTimeout(() => {
|
|
239
|
+
resolve(undefined);
|
|
240
|
+
}, 60000);
|
|
241
|
+
});
|
|
242
|
+
const txStatus = await Promise.race([api.getTransactionStatus(extrinsicHash), timeout]);
|
|
243
|
+
if (!txStatus) {
|
|
244
|
+
return {
|
|
245
|
+
...result,
|
|
246
|
+
status: HistoryRecoverStatus.API_INACTIVE
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
if (txStatus.confirmed) {
|
|
250
|
+
const transactionDetail = await Promise.race([api.getTransactionDetail(extrinsicHash), timeout]);
|
|
251
|
+
if (transactionDetail) {
|
|
252
|
+
result.blockHash = transactionDetail.status.block_hash || undefined;
|
|
253
|
+
result.blockNumber = transactionDetail.status.block_height || undefined;
|
|
254
|
+
result.blockTime = transactionDetail.status.block_time ? transactionDetail.status.block_time * 1000 : undefined;
|
|
255
|
+
return {
|
|
256
|
+
...result,
|
|
257
|
+
status: HistoryRecoverStatus.SUCCESS
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
...result,
|
|
262
|
+
status: HistoryRecoverStatus.API_INACTIVE
|
|
263
|
+
};
|
|
264
|
+
} else {
|
|
265
|
+
return {
|
|
266
|
+
...result,
|
|
267
|
+
status: HistoryRecoverStatus.TX_PENDING
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
} catch (e) {
|
|
271
|
+
// Fail when cannot find transaction
|
|
272
|
+
return {
|
|
273
|
+
...result,
|
|
274
|
+
status: HistoryRecoverStatus.FAILED
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
status: HistoryRecoverStatus.FAIL_DETECT
|
|
280
|
+
};
|
|
281
|
+
} else {
|
|
282
|
+
console.error(`Fail to update history ${chain}-${extrinsicHash}: Api not active`);
|
|
283
|
+
return {
|
|
284
|
+
status: HistoryRecoverStatus.API_INACTIVE
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
} catch (e) {
|
|
288
|
+
console.error(`Fail to update history ${chain}-${extrinsicHash}:`, e.message);
|
|
289
|
+
return {
|
|
290
|
+
status: HistoryRecoverStatus.UNKNOWN
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
};
|
|
219
294
|
|
|
220
295
|
// undefined: Cannot check status
|
|
221
296
|
// true: Transaction success
|
|
@@ -224,13 +299,30 @@ const historyRecover = async (history, chainService) => {
|
|
|
224
299
|
const {
|
|
225
300
|
chainType
|
|
226
301
|
} = history;
|
|
227
|
-
if (chainType) {
|
|
228
|
-
const checkFunction = chainType === 'substrate' ? substrateRecover : evmRecover;
|
|
229
|
-
return await checkFunction(history, chainService);
|
|
230
|
-
} else {
|
|
302
|
+
if (!chainType) {
|
|
231
303
|
return {
|
|
232
304
|
status: HistoryRecoverStatus.LACK_INFO
|
|
233
305
|
};
|
|
234
306
|
}
|
|
307
|
+
const recoverFunctions = {
|
|
308
|
+
substrate: substrateRecover,
|
|
309
|
+
evm: evmRecover,
|
|
310
|
+
bitcoin: bitcoinRecover
|
|
311
|
+
};
|
|
312
|
+
const checkFunction = recoverFunctions[chainType];
|
|
313
|
+
if (!checkFunction) {
|
|
314
|
+
console.warn(`Chain type ${chainType} is not supported for recoverHistory`);
|
|
315
|
+
return {
|
|
316
|
+
status: HistoryRecoverStatus.UNKNOWN
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
return await checkFunction(history, chainService);
|
|
321
|
+
} catch (error) {
|
|
322
|
+
console.error(`Failed to recover history for chain type ${chainType}:`, error);
|
|
323
|
+
return {
|
|
324
|
+
status: HistoryRecoverStatus.FAILED
|
|
325
|
+
};
|
|
326
|
+
}
|
|
235
327
|
};
|
|
236
328
|
exports.historyRecover = historyRecover;
|