@subwallet/extension-base 1.3.41-0 → 1.3.43-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 +134 -5
- package/background/KoniTypes.js +18 -0
- package/background/errors/BitcoinProviderError.d.ts +6 -0
- package/background/errors/BitcoinProviderError.js +47 -0
- package/background/types.d.ts +1 -1
- 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/request.js +316 -3
- 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 +477 -93
- package/cjs/koni/background/handlers/State.js +249 -16
- package/cjs/koni/background/handlers/Tabs.js +119 -6
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/bitcoin/index.js +67 -0
- package/cjs/page/index.js +5 -0
- 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/buy-service/index.js +17 -2
- 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/earning-service/handlers/native-staking/para-chain.js +27 -5
- 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/AuthRequestHandler.js +18 -0
- package/cjs/services/request-service/handler/BitcoinRequestHandler.js +427 -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 +206 -16
- 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/auth.js +2 -1
- 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/request.d.ts +6 -2
- package/core/logic-validation/request.js +309 -3
- 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 +5 -0
- package/koni/background/handlers/Extension.js +387 -9
- package/koni/background/handlers/State.d.ts +10 -3
- package/koni/background/handlers/State.js +240 -15
- package/koni/background/handlers/Tabs.d.ts +7 -2
- package/koni/background/handlers/Tabs.js +119 -9
- package/package.json +149 -8
- package/packageInfo.js +1 -1
- package/page/bitcoin/index.d.ts +17 -0
- package/page/bitcoin/index.js +60 -0
- package/page/index.d.ts +2 -1
- package/page/index.js +4 -0
- 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/cardano-transfer.d.ts +2 -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/buy-service/index.js +17 -2
- 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/earning-service/handlers/native-staking/para-chain.js +27 -5
- 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/AuthRequestHandler.js +19 -1
- package/services/request-service/handler/BitcoinRequestHandler.d.ts +22 -0
- package/services/request-service/handler/BitcoinRequestHandler.js +414 -0
- package/services/request-service/index.d.ts +8 -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 +4 -5
- package/services/transaction-service/index.js +205 -17
- package/services/transaction-service/types.d.ts +13 -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 +19 -0
- package/types/bitcoin.d.ts +93 -0
- package/types/bitcoin.js +17 -0
- package/types/buy.d.ts +1 -1
- 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/auth.js +3 -2
- 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
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { SWError } from '@subwallet/extension-base/background/errors/SWError';
|
|
5
|
+
import { _BTC_SERVICE_TOKEN } from '@subwallet/extension-base/services/chain-service/constants';
|
|
6
|
+
import { BaseApiRequestStrategy } from '@subwallet/extension-base/strategy/api-request-strategy';
|
|
7
|
+
import { BaseApiRequestContext } from '@subwallet/extension-base/strategy/api-request-strategy/context/base';
|
|
8
|
+
import { getRequest } from '@subwallet/extension-base/strategy/api-request-strategy/utils';
|
|
9
|
+
const BITCOIN_API_URL = 'https://btc-api.koni.studio';
|
|
10
|
+
const BITCOIN_API_URL_TEST = 'https://api-testnet.openbit.app';
|
|
11
|
+
export class RunesService extends BaseApiRequestStrategy {
|
|
12
|
+
constructor(url) {
|
|
13
|
+
const context = new BaseApiRequestContext();
|
|
14
|
+
super(context);
|
|
15
|
+
this.baseUrl = url;
|
|
16
|
+
}
|
|
17
|
+
headers = {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
Authorization: `Bearer ${_BTC_SERVICE_TOKEN}`
|
|
20
|
+
};
|
|
21
|
+
isRateLimited() {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
getUrl(path) {
|
|
25
|
+
return `${this.baseUrl}/${path}`;
|
|
26
|
+
}
|
|
27
|
+
getAddressRunesInfo(address, params) {
|
|
28
|
+
return this.addRequest(async () => {
|
|
29
|
+
const _rs = await getRequest(this.getUrl(`rune/address/${address}`), params, this.headers);
|
|
30
|
+
const rs = await _rs.json();
|
|
31
|
+
if (rs.status_code !== 200) {
|
|
32
|
+
throw new SWError('RuneScanService.getAddressRunesInfo', rs.message);
|
|
33
|
+
}
|
|
34
|
+
return rs.result;
|
|
35
|
+
}, 1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// * Deprecated
|
|
39
|
+
getRuneCollectionsByBatch(params) {
|
|
40
|
+
return this.addRequest(async () => {
|
|
41
|
+
const url = this.getUrl('rune');
|
|
42
|
+
const rs = await getRequest(url, params);
|
|
43
|
+
if (rs.status !== 200) {
|
|
44
|
+
throw new SWError('RuneScanService.getRuneCollectionsByBatch', await rs.text());
|
|
45
|
+
}
|
|
46
|
+
return await rs.json();
|
|
47
|
+
}, 1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// * Deprecated
|
|
51
|
+
getAddressRuneTxs(address, params) {
|
|
52
|
+
return this.addRequest(async () => {
|
|
53
|
+
const url = this.getUrl(`address/${address}/txs`);
|
|
54
|
+
const rs = await getRequest(url, params);
|
|
55
|
+
if (rs.status !== 200) {
|
|
56
|
+
throw new SWError('RuneScanService.getAddressRuneTxs', await rs.text());
|
|
57
|
+
}
|
|
58
|
+
return await rs.json();
|
|
59
|
+
}, 0);
|
|
60
|
+
}
|
|
61
|
+
getRuneMetadata(runeid) {
|
|
62
|
+
return this.addRequest(async () => {
|
|
63
|
+
const _rs = await getRequest(this.getUrl(`rune/metadata/${runeid}`), undefined, this.headers);
|
|
64
|
+
const rs = await _rs.json();
|
|
65
|
+
if (rs.status_code !== 200) {
|
|
66
|
+
throw new SWError('RuneScanService.getRuneMetadata', rs.message);
|
|
67
|
+
}
|
|
68
|
+
return rs.result;
|
|
69
|
+
}, 0);
|
|
70
|
+
}
|
|
71
|
+
getAddressRuneUtxos(address) {
|
|
72
|
+
return this.addRequest(async () => {
|
|
73
|
+
const _rs = await getRequest(this.getUrl(`rune/address/${address}/rune/utxo`), undefined, this.headers);
|
|
74
|
+
const rs = await _rs.json();
|
|
75
|
+
if (rs.status_code !== 200) {
|
|
76
|
+
throw new SWError('RuneScanService.getAddressRuneUtxos', rs.message);
|
|
77
|
+
}
|
|
78
|
+
return rs.result;
|
|
79
|
+
}, 0);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Singleton
|
|
83
|
+
|
|
84
|
+
static getInstance(isTestnet = false) {
|
|
85
|
+
if (isTestnet) {
|
|
86
|
+
if (!RunesService.testnet) {
|
|
87
|
+
RunesService.testnet = new RunesService(BITCOIN_API_URL_TEST);
|
|
88
|
+
}
|
|
89
|
+
return RunesService.testnet;
|
|
90
|
+
} else {
|
|
91
|
+
if (!RunesService.mainnet) {
|
|
92
|
+
RunesService.mainnet = new RunesService(BITCOIN_API_URL);
|
|
93
|
+
}
|
|
94
|
+
return RunesService.mainnet;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { CardanoTransactionConfig } from '@subwallet/extension-base/services/balance-service/transfer/cardano-transfer';
|
|
3
3
|
import { TonTransactionConfig } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
|
|
4
|
-
import { SWTransactionBase } from '@subwallet/extension-base/services/transaction-service/types';
|
|
4
|
+
import { SWTransaction, SWTransactionBase } from '@subwallet/extension-base/services/transaction-service/types';
|
|
5
|
+
import { Psbt } from 'bitcoinjs-lib';
|
|
5
6
|
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
|
|
6
7
|
export declare const getTransactionId: (chainType: string, chain: string, isInternal: boolean, isWalletConnect?: boolean) => string;
|
|
7
8
|
export declare const getValidationId: (chainType: string, chain: string) => string;
|
|
8
9
|
export declare const isSubstrateTransaction: (tx: SWTransactionBase['transaction']) => tx is SubmittableExtrinsic;
|
|
9
10
|
export declare const isTonTransaction: (tx: SWTransactionBase['transaction']) => tx is TonTransactionConfig;
|
|
10
11
|
export declare const isCardanoTransaction: (tx: SWTransactionBase['transaction']) => tx is CardanoTransactionConfig;
|
|
12
|
+
export declare const isBitcoinTransaction: (tx: SWTransaction['transaction']) => tx is Psbt;
|
|
11
13
|
export declare const getBaseTransactionInfo: (transaction: SWTransactionBase, chainInfoMap: Record<string, _ChainInfo>) => string;
|
|
@@ -21,6 +21,11 @@ export const isCardanoTransaction = tx => {
|
|
|
21
21
|
const cardanoTransactionConfig = tx;
|
|
22
22
|
return cardanoTransactionConfig.cardanoPayload !== null && cardanoTransactionConfig.cardanoPayload !== undefined;
|
|
23
23
|
};
|
|
24
|
+
|
|
25
|
+
// TODO: [Review] this function
|
|
26
|
+
export const isBitcoinTransaction = tx => {
|
|
27
|
+
return 'data' in tx && Array.isArray(tx.data.inputs);
|
|
28
|
+
};
|
|
24
29
|
const typeName = type => {
|
|
25
30
|
switch (type) {
|
|
26
31
|
case ExtrinsicType.TRANSFER_BALANCE:
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
2
2
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
3
|
-
import { SWDutchTransactionInput, SWPermitTransactionInput, SWTransactionBase, SWTransactionInput, SWTransactionResponse, TransactionEmitter } from '@subwallet/extension-base/services/transaction-service/types';
|
|
3
|
+
import { SWDutchTransactionInput, SWPermitTransactionInput, SWTransactionBase, SWTransactionInput, SWTransactionResponse, TransactionEmitter, TransactionEventResponse } from '@subwallet/extension-base/services/transaction-service/types';
|
|
4
4
|
import { BaseStepType, BriefProcessStep, ProcessStep, ProcessTransactionData } from '@subwallet/extension-base/types';
|
|
5
5
|
import { BehaviorSubject } from 'rxjs';
|
|
6
6
|
import { TransactionConfig } from 'web3-core';
|
|
7
7
|
import { HexString } from '@polkadot/util/types';
|
|
8
8
|
export default class TransactionService {
|
|
9
9
|
private readonly state;
|
|
10
|
-
private readonly eventService;
|
|
11
|
-
private readonly historyService;
|
|
12
|
-
private readonly notificationService;
|
|
13
|
-
private readonly chainService;
|
|
14
10
|
private readonly watchTransactionSubscribes;
|
|
15
11
|
private aliveProcessMap;
|
|
16
12
|
private readonly transactionSubject;
|
|
@@ -40,6 +36,7 @@ export default class TransactionService {
|
|
|
40
36
|
addDutchTransaction(inputTransaction: SWDutchTransactionInput): TransactionEmitter;
|
|
41
37
|
generateBeforeHandleResponseErrors(errors: TransactionError[]): SWTransactionResponse;
|
|
42
38
|
handleTransaction(transaction: SWTransactionInput): Promise<SWTransactionResponse>;
|
|
39
|
+
handleTransactionAfterConfirmation(transaction: SWTransactionInput): Promise<SWTransactionResponse>;
|
|
43
40
|
handlePermitTransaction(transaction: SWPermitTransactionInput): Promise<SWTransactionResponse>;
|
|
44
41
|
handleDutchTransaction(transaction: SWDutchTransactionInput): Promise<SWTransactionResponse>;
|
|
45
42
|
private sendTransaction;
|
|
@@ -63,6 +60,8 @@ export default class TransactionService {
|
|
|
63
60
|
private signAndSendSubstrateTransaction;
|
|
64
61
|
private signAndSendTonTransaction;
|
|
65
62
|
private signAndSendCardanoTransaction;
|
|
63
|
+
emitterEventTransaction: (emitter: TransactionEmitter, eventData: TransactionEventResponse, chain: string, payload: string) => void;
|
|
64
|
+
private signAndSendBitcoinTransaction;
|
|
66
65
|
private handleTransactionTimeout;
|
|
67
66
|
private handlePostEarningTransaction;
|
|
68
67
|
createProcessIfNeed(process: ProcessTransactionData): Promise<void>;
|
|
@@ -11,7 +11,7 @@ import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _get
|
|
|
11
11
|
import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
|
|
12
12
|
import { TRANSACTION_TIMEOUT } from '@subwallet/extension-base/services/transaction-service/constants';
|
|
13
13
|
import { parseLiquidStakingEvents, parseLiquidStakingFastUnstakeEvents, parseTransferEventLogs, parseXcmEventLogs } from '@subwallet/extension-base/services/transaction-service/event-parser';
|
|
14
|
-
import { getBaseTransactionInfo, getTransactionId, isCardanoTransaction, isSubstrateTransaction, isTonTransaction } from '@subwallet/extension-base/services/transaction-service/helpers';
|
|
14
|
+
import { getBaseTransactionInfo, getTransactionId, isBitcoinTransaction, isCardanoTransaction, isSubstrateTransaction, isTonTransaction } from '@subwallet/extension-base/services/transaction-service/helpers';
|
|
15
15
|
import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils';
|
|
16
16
|
import { isWalletConnectRequest } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
17
17
|
import { BasicTxErrorType, StepStatus, YieldPoolType } from '@subwallet/extension-base/types';
|
|
@@ -39,10 +39,6 @@ export default class TransactionService {
|
|
|
39
39
|
}
|
|
40
40
|
constructor(state) {
|
|
41
41
|
this.state = state;
|
|
42
|
-
this.eventService = state.eventService;
|
|
43
|
-
this.historyService = state.historyService;
|
|
44
|
-
this.notificationService = state.notificationService;
|
|
45
|
-
this.chainService = state.chainService;
|
|
46
42
|
}
|
|
47
43
|
get allTransactions() {
|
|
48
44
|
return Object.values(this.transactions);
|
|
@@ -74,6 +70,7 @@ export default class TransactionService {
|
|
|
74
70
|
additionalValidator,
|
|
75
71
|
address,
|
|
76
72
|
chain,
|
|
73
|
+
chainType,
|
|
77
74
|
extrinsicType
|
|
78
75
|
} = validationResponse;
|
|
79
76
|
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
@@ -103,27 +100,32 @@ export default class TransactionService {
|
|
|
103
100
|
const evmApi = this.state.chainService.getEvmApi(chainInfo.slug);
|
|
104
101
|
const tonApi = this.state.chainService.getTonApi(chainInfo.slug);
|
|
105
102
|
const cardanoApi = this.state.chainService.getCardanoApi(chainInfo.slug);
|
|
103
|
+
const bitcoinApi = this.state.chainService.getBitcoinApi(chainInfo.slug);
|
|
106
104
|
// todo: should split into isEvmTx && isNoEvmApi. Because other chains type also has no Evm Api. Same to all blockchain.
|
|
107
105
|
// todo: refactor check evmTransaction.
|
|
108
|
-
const isNoEvmApi = transaction && !isSubstrateTransaction(transaction) && !isTonTransaction(transaction) && !isCardanoTransaction(transaction) && !evmApi;
|
|
106
|
+
const isNoEvmApi = transaction && !isSubstrateTransaction(transaction) && !isTonTransaction(transaction) && !isCardanoTransaction(transaction) && !isBitcoinTransaction(transaction) && !evmApi;
|
|
109
107
|
const isNoTonApi = transaction && isTonTransaction(transaction) && !tonApi;
|
|
110
108
|
const isNoCardanoApi = transaction && isCardanoTransaction(transaction) && !cardanoApi;
|
|
111
|
-
|
|
109
|
+
const isNoBitcoinApi = transaction && isBitcoinTransaction(transaction) && !bitcoinApi;
|
|
110
|
+
if (isNoEvmApi || isNoTonApi || isNoCardanoApi || isNoBitcoinApi) {
|
|
112
111
|
validationResponse.errors.push(new TransactionError(BasicTxErrorType.CHAIN_DISCONNECTED, undefined));
|
|
113
112
|
}
|
|
114
113
|
|
|
115
114
|
// Estimate fee for transaction
|
|
116
115
|
const id = getId();
|
|
117
|
-
const feeInfo = await this.state.feeService.subscribeChainFee(id, chain,
|
|
116
|
+
const feeInfo = await this.state.feeService.subscribeChainFee(id, chain, chainType);
|
|
118
117
|
const nativeTokenInfo = this.state.chainService.getNativeTokenInfo(chain);
|
|
119
118
|
const tokenPayFeeSlug = transactionInput.tokenPayFeeSlug;
|
|
120
119
|
const isNonNativeTokenPayFee = tokenPayFeeSlug && !_isNativeTokenBySlug(tokenPayFeeSlug);
|
|
121
|
-
const nonNativeTokenPayFeeInfo = isNonNativeTokenPayFee ? this.chainService.getAssetBySlug(tokenPayFeeSlug) : undefined;
|
|
120
|
+
const nonNativeTokenPayFeeInfo = isNonNativeTokenPayFee ? this.state.chainService.getAssetBySlug(tokenPayFeeSlug) : undefined;
|
|
122
121
|
const priceMap = (await this.state.priceService.getPrice()).priceMap;
|
|
123
|
-
|
|
122
|
+
if (!transactionInput.skipFeeRecalculation) {
|
|
123
|
+
validationResponse.estimateFee = await estimateFeeForTransaction(validationResponse, transaction, chainInfo, evmApi, substrateApi, priceMap, feeInfo, nativeTokenInfo, nonNativeTokenPayFeeInfo, transactionInput.isTransferLocalTokenAndPayThatTokenAsFee);
|
|
124
|
+
}
|
|
124
125
|
const chainInfoMap = this.state.chainService.getChainInfoMap();
|
|
125
126
|
|
|
126
127
|
// Check account signing transaction
|
|
128
|
+
|
|
127
129
|
checkSigningAccountForTransaction(validationResponse, chainInfoMap);
|
|
128
130
|
const nativeTokenAvailable = await this.state.balanceService.getTransferableBalance(address, chain, nativeTokenInfo.slug, extrinsicType);
|
|
129
131
|
|
|
@@ -186,7 +188,7 @@ export default class TransactionService {
|
|
|
186
188
|
}
|
|
187
189
|
fillTransactionDefaultInfo(transaction) {
|
|
188
190
|
const isInternal = !transaction.url;
|
|
189
|
-
const transactionId = getTransactionId(transaction.chainType, transaction.chain, isInternal, isWalletConnectRequest(transaction.id));
|
|
191
|
+
const transactionId = transaction.id || getTransactionId(transaction.chainType, transaction.chain, isInternal, isWalletConnectRequest(transaction.id));
|
|
190
192
|
return {
|
|
191
193
|
...transaction,
|
|
192
194
|
createdAt: new Date().getTime(),
|
|
@@ -300,6 +302,73 @@ export default class TransactionService {
|
|
|
300
302
|
'eventsHandler' in validatedTransaction && delete validatedTransaction.eventsHandler;
|
|
301
303
|
return validatedTransaction;
|
|
302
304
|
}
|
|
305
|
+
async handleTransactionAfterConfirmation(transaction) {
|
|
306
|
+
const validatedTransaction = await this.validateTransaction(transaction);
|
|
307
|
+
const stopByErrors = validatedTransaction.errors.length > 0;
|
|
308
|
+
const stopByWarnings = validatedTransaction.warnings.length > 0 && !validatedTransaction.ignoreWarnings;
|
|
309
|
+
if (stopByErrors || stopByWarnings) {
|
|
310
|
+
// @ts-ignore
|
|
311
|
+
'transaction' in validatedTransaction && delete validatedTransaction.transaction;
|
|
312
|
+
'additionalValidator' in validatedTransaction && delete validatedTransaction.additionalValidator;
|
|
313
|
+
'eventsHandler' in validatedTransaction && delete validatedTransaction.eventsHandler;
|
|
314
|
+
return validatedTransaction;
|
|
315
|
+
}
|
|
316
|
+
validatedTransaction.warnings = [];
|
|
317
|
+
const transactionsSubject = this.transactions;
|
|
318
|
+
const emitter = new EventEmitter();
|
|
319
|
+
|
|
320
|
+
// Fill transaction default info
|
|
321
|
+
const transactionUpdated = this.fillTransactionDefaultInfo(validatedTransaction);
|
|
322
|
+
|
|
323
|
+
// Add Transaction
|
|
324
|
+
transactionsSubject[transactionUpdated.id] = {
|
|
325
|
+
...transactionUpdated,
|
|
326
|
+
emitterTransaction: emitter
|
|
327
|
+
};
|
|
328
|
+
this.transactionSubject.next({
|
|
329
|
+
...transactionsSubject
|
|
330
|
+
});
|
|
331
|
+
emitter.on('success', data => {
|
|
332
|
+
validatedTransaction.id = data.id;
|
|
333
|
+
validatedTransaction.extrinsicHash = data.extrinsicHash;
|
|
334
|
+
this.handlePostProcessing(data.id);
|
|
335
|
+
this.onSuccess(data);
|
|
336
|
+
});
|
|
337
|
+
emitter.on('signed', data => {
|
|
338
|
+
validatedTransaction.id = data.id;
|
|
339
|
+
validatedTransaction.extrinsicHash = data.extrinsicHash;
|
|
340
|
+
this.onSigned(data);
|
|
341
|
+
});
|
|
342
|
+
emitter.on('error', data => {
|
|
343
|
+
if (data.errors.length > 0) {
|
|
344
|
+
validatedTransaction.errors.push(...data.errors);
|
|
345
|
+
}
|
|
346
|
+
this.onFailed({
|
|
347
|
+
...data,
|
|
348
|
+
errors: [...data.errors, new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
emitter.on('send', data => {
|
|
352
|
+
this.onSend(data);
|
|
353
|
+
});
|
|
354
|
+
emitter.on('extrinsicHash', data => {
|
|
355
|
+
this.onHasTransactionHash(data);
|
|
356
|
+
});
|
|
357
|
+
emitter.on('timeout', data => {
|
|
358
|
+
this.onTimeOut({
|
|
359
|
+
...data,
|
|
360
|
+
errors: [...data.errors, new TransactionError(BasicTxErrorType.TIMEOUT)]
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// @ts-ignore
|
|
365
|
+
'transaction' in validatedTransaction && delete validatedTransaction.transaction;
|
|
366
|
+
'additionalValidator' in validatedTransaction && delete validatedTransaction.additionalValidator;
|
|
367
|
+
'eventsHandler' in validatedTransaction && delete validatedTransaction.eventsHandler;
|
|
368
|
+
return {
|
|
369
|
+
...validatedTransaction
|
|
370
|
+
};
|
|
371
|
+
}
|
|
303
372
|
async handlePermitTransaction(transaction) {
|
|
304
373
|
var _transaction$step;
|
|
305
374
|
const transactionId = getTransactionId(transaction.chainType, transaction.chain, true);
|
|
@@ -410,7 +479,7 @@ export default class TransactionService {
|
|
|
410
479
|
}
|
|
411
480
|
async sendTransaction(transaction) {
|
|
412
481
|
// Send Transaction
|
|
413
|
-
const emitter = await (transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : transaction.chainType === 'evm' ? this.signAndSendEvmTransaction(transaction) : transaction.chainType === 'cardano' ? this.signAndSendCardanoTransaction(transaction) : this.signAndSendTonTransaction(transaction));
|
|
482
|
+
const emitter = await (transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : transaction.chainType === 'evm' ? this.signAndSendEvmTransaction(transaction) : transaction.chainType === 'cardano' ? this.signAndSendCardanoTransaction(transaction) : transaction.chainType === 'ton' ? this.signAndSendTonTransaction(transaction) : this.signAndSendBitcoinTransaction(transaction));
|
|
414
483
|
const {
|
|
415
484
|
eventsHandler,
|
|
416
485
|
step
|
|
@@ -669,6 +738,7 @@ export default class TransactionService {
|
|
|
669
738
|
extrinsicHash: transaction.extrinsicHash,
|
|
670
739
|
time: transaction.createdAt,
|
|
671
740
|
fee: transaction.estimateFee,
|
|
741
|
+
blockTime: undefined,
|
|
672
742
|
blockNumber: 0,
|
|
673
743
|
// Will be added in next step
|
|
674
744
|
blockHash: '',
|
|
@@ -1055,6 +1125,24 @@ export default class TransactionService {
|
|
|
1055
1125
|
if ([ExtrinsicType.STAKING_JOIN_POOL, ExtrinsicType.STAKING_BOND, ExtrinsicType.JOIN_YIELD_POOL, ExtrinsicType.MINT_LDOT, ExtrinsicType.MINT_QDOT, ExtrinsicType.MINT_SDOT, ExtrinsicType.MINT_STDOT, ExtrinsicType.MINT_VDOT, ExtrinsicType.MINT_VMANTA].includes(transaction.extrinsicType)) {
|
|
1056
1126
|
this.handlePostEarningTransaction(id);
|
|
1057
1127
|
}
|
|
1128
|
+
|
|
1129
|
+
// Trigger balance update for Bitcoin transactions after receiving extrinsicHash
|
|
1130
|
+
if (ExtrinsicType.TRANSFER_BALANCE && transaction.chainType === 'bitcoin') {
|
|
1131
|
+
const balanceService = this.state.balanceService;
|
|
1132
|
+
const inputData = parseTransactionData(transaction.data);
|
|
1133
|
+
try {
|
|
1134
|
+
const sender = keyring.getPair(inputData.from);
|
|
1135
|
+
balanceService.refreshBalanceForAddress(sender.address, transaction.chain, inputData.tokenSlug, transaction.extrinsicType).catch(error => console.error('Failed to run balance subscription:', error));
|
|
1136
|
+
} catch (e) {
|
|
1137
|
+
console.error(e);
|
|
1138
|
+
}
|
|
1139
|
+
try {
|
|
1140
|
+
const recipient = keyring.getPair(inputData.to);
|
|
1141
|
+
balanceService.refreshBalanceForAddress(recipient.address, transaction.chain, inputData.tokenSlug, transaction.extrinsicType).catch(error => console.error('Failed to run balance subscription:', error));
|
|
1142
|
+
} catch (e) {
|
|
1143
|
+
console.error(e);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1058
1146
|
}
|
|
1059
1147
|
handlePostProcessing(id) {
|
|
1060
1148
|
// must be done after success/failure to make sure the transaction is finalized
|
|
@@ -1093,6 +1181,7 @@ export default class TransactionService {
|
|
|
1093
1181
|
onSuccess({
|
|
1094
1182
|
blockHash,
|
|
1095
1183
|
blockNumber,
|
|
1184
|
+
blockTime,
|
|
1096
1185
|
extrinsicHash,
|
|
1097
1186
|
id
|
|
1098
1187
|
}) {
|
|
@@ -1107,7 +1196,8 @@ export default class TransactionService {
|
|
|
1107
1196
|
extrinsicHash,
|
|
1108
1197
|
status: ExtrinsicStatus.SUCCESS,
|
|
1109
1198
|
blockNumber: blockNumber || 0,
|
|
1110
|
-
blockHash: blockHash || ''
|
|
1199
|
+
blockHash: blockHash || '',
|
|
1200
|
+
blockTime
|
|
1111
1201
|
}).catch(console.error);
|
|
1112
1202
|
const info = isHex(extrinsicHash) ? extrinsicHash : getBaseTransactionInfo(transaction, this.state.chainService.getChainInfoMap());
|
|
1113
1203
|
this.state.notificationService.notify({
|
|
@@ -1180,14 +1270,14 @@ export default class TransactionService {
|
|
|
1180
1270
|
errors,
|
|
1181
1271
|
extrinsicHash
|
|
1182
1272
|
});
|
|
1183
|
-
this.historyService.updateHistoryByExtrinsicHash(transaction.extrinsicHash, {
|
|
1273
|
+
this.state.historyService.updateHistoryByExtrinsicHash(transaction.extrinsicHash, {
|
|
1184
1274
|
extrinsicHash: extrinsicHash || transaction.extrinsicHash,
|
|
1185
1275
|
status: nextStatus,
|
|
1186
1276
|
blockNumber: blockNumber || 0,
|
|
1187
1277
|
blockHash: blockHash || ''
|
|
1188
1278
|
}).catch(console.error);
|
|
1189
|
-
const info = isHex(transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash) ? transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash : getBaseTransactionInfo(transaction, this.chainService.getChainInfoMap());
|
|
1190
|
-
this.notificationService.notify({
|
|
1279
|
+
const info = isHex(transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash) ? transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash : getBaseTransactionInfo(transaction, this.state.chainService.getChainInfoMap());
|
|
1280
|
+
this.state.notificationService.notify({
|
|
1191
1281
|
type: NotificationType.ERROR,
|
|
1192
1282
|
title: t('Transaction timed out'),
|
|
1193
1283
|
message: t('Transaction {{info}} timed out', {
|
|
@@ -1201,7 +1291,7 @@ export default class TransactionService {
|
|
|
1201
1291
|
notifyViaBrowser: true
|
|
1202
1292
|
});
|
|
1203
1293
|
}
|
|
1204
|
-
this.eventService.emit('transaction.timeout', transaction);
|
|
1294
|
+
this.state.eventService.emit('transaction.timeout', transaction);
|
|
1205
1295
|
}
|
|
1206
1296
|
generateHashPayload(chain, transaction) {
|
|
1207
1297
|
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
@@ -1864,6 +1954,104 @@ export default class TransactionService {
|
|
|
1864
1954
|
});
|
|
1865
1955
|
return emitter;
|
|
1866
1956
|
}
|
|
1957
|
+
emitterEventTransaction = (emitter, eventData, chain, payload) => {
|
|
1958
|
+
// Emit signed event
|
|
1959
|
+
emitter.emit('signed', eventData);
|
|
1960
|
+
// Add start info
|
|
1961
|
+
emitter.emit('send', eventData);
|
|
1962
|
+
const event = this.state.chainService.getBitcoinApi(chain).api.sendRawTransaction(payload);
|
|
1963
|
+
event.on('extrinsicHash', txHash => {
|
|
1964
|
+
eventData.extrinsicHash = txHash;
|
|
1965
|
+
emitter.emit('extrinsicHash', eventData);
|
|
1966
|
+
});
|
|
1967
|
+
event.on('success', transactionStatus => {
|
|
1968
|
+
console.log(transactionStatus);
|
|
1969
|
+
eventData.blockHash = transactionStatus.block_hash || undefined;
|
|
1970
|
+
eventData.blockNumber = transactionStatus.block_height || undefined;
|
|
1971
|
+
eventData.blockTime = transactionStatus.block_time ? transactionStatus.block_time * 1000 : undefined;
|
|
1972
|
+
emitter.emit('success', eventData);
|
|
1973
|
+
});
|
|
1974
|
+
event.on('error', error => {
|
|
1975
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SEND, error));
|
|
1976
|
+
emitter.emit('error', eventData);
|
|
1977
|
+
});
|
|
1978
|
+
};
|
|
1979
|
+
signAndSendBitcoinTransaction({
|
|
1980
|
+
address,
|
|
1981
|
+
chain,
|
|
1982
|
+
id,
|
|
1983
|
+
transaction,
|
|
1984
|
+
url
|
|
1985
|
+
}) {
|
|
1986
|
+
const tx = transaction;
|
|
1987
|
+
// const bitcoinApi = this.state.chainService.getBitcoinApi(chain);
|
|
1988
|
+
// const chainInfo = this.state.chainService.getChainInfoByKey(chain);
|
|
1989
|
+
|
|
1990
|
+
const accountPair = keyring.getPair(address);
|
|
1991
|
+
const account = pairToAccount(accountPair);
|
|
1992
|
+
const payload = {
|
|
1993
|
+
payload: undefined,
|
|
1994
|
+
payloadJson: undefined,
|
|
1995
|
+
address,
|
|
1996
|
+
canSign: true,
|
|
1997
|
+
hashPayload: tx.toHex(),
|
|
1998
|
+
id
|
|
1999
|
+
};
|
|
2000
|
+
const emitter = new EventEmitter();
|
|
2001
|
+
const eventData = {
|
|
2002
|
+
id,
|
|
2003
|
+
errors: [],
|
|
2004
|
+
warnings: [],
|
|
2005
|
+
extrinsicHash: id
|
|
2006
|
+
};
|
|
2007
|
+
const isInjected = !!account.isInjected;
|
|
2008
|
+
// const isExternal = !!account.isExternal;
|
|
2009
|
+
|
|
2010
|
+
if (isInjected) {
|
|
2011
|
+
throw new TransactionError(BasicTxErrorType.UNSUPPORTED);
|
|
2012
|
+
} else {
|
|
2013
|
+
this.state.requestService.addConfirmationBitcoin(id, url || EXTENSION_REQUEST_URL, 'bitcoinSendTransactionRequest', payload, {}).then(({
|
|
2014
|
+
isApproved,
|
|
2015
|
+
payload
|
|
2016
|
+
}) => {
|
|
2017
|
+
if (isApproved) {
|
|
2018
|
+
if (!payload) {
|
|
2019
|
+
throw new Error('Bad signature');
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
// Emit signed event
|
|
2023
|
+
emitter.emit('signed', eventData);
|
|
2024
|
+
// Add start info
|
|
2025
|
+
emitter.emit('send', eventData);
|
|
2026
|
+
const bitcoinApi = this.state.chainService.getBitcoinApi(chain);
|
|
2027
|
+
const event = bitcoinApi.api.sendRawTransaction(payload);
|
|
2028
|
+
event.on('extrinsicHash', txHash => {
|
|
2029
|
+
eventData.extrinsicHash = txHash;
|
|
2030
|
+
emitter.emit('extrinsicHash', eventData);
|
|
2031
|
+
});
|
|
2032
|
+
event.on('success', transactionStatus => {
|
|
2033
|
+
eventData.blockHash = transactionStatus.block_hash || undefined;
|
|
2034
|
+
eventData.blockNumber = transactionStatus.block_height || undefined;
|
|
2035
|
+
eventData.blockTime = transactionStatus.block_time ? transactionStatus.block_time * 1000 : undefined;
|
|
2036
|
+
emitter.emit('success', eventData);
|
|
2037
|
+
});
|
|
2038
|
+
event.on('error', error => {
|
|
2039
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SEND, error));
|
|
2040
|
+
emitter.emit('error', eventData);
|
|
2041
|
+
});
|
|
2042
|
+
} else {
|
|
2043
|
+
this.removeTransaction(id);
|
|
2044
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.USER_REJECT_REQUEST));
|
|
2045
|
+
emitter.emit('error', eventData);
|
|
2046
|
+
}
|
|
2047
|
+
}).catch(e => {
|
|
2048
|
+
this.removeTransaction(id);
|
|
2049
|
+
eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SIGN, e.message));
|
|
2050
|
+
emitter.emit('error', eventData);
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
return emitter;
|
|
2054
|
+
}
|
|
1867
2055
|
handleTransactionTimeout(emitter, eventData) {
|
|
1868
2056
|
const timeout = setTimeout(() => {
|
|
1869
2057
|
const transaction = this.getTransaction(eventData.id);
|
|
@@ -3,11 +3,12 @@ import { SignTypedDataMessageV3V4 } from '@subwallet/extension-base/core/logic-v
|
|
|
3
3
|
import { TonTransactionConfig } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
|
|
4
4
|
import { UniswapOrderInfo } from '@subwallet/extension-base/services/swap-service/handler/uniswap-handler';
|
|
5
5
|
import { BaseRequestSign, BriefProcessStep, ProcessTransactionData, TransactionFee } from '@subwallet/extension-base/types';
|
|
6
|
+
import { Psbt } from 'bitcoinjs-lib';
|
|
6
7
|
import EventEmitter from 'eventemitter3';
|
|
7
8
|
import { TransactionConfig } from 'web3-core';
|
|
8
9
|
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
|
|
9
10
|
import { EventRecord } from '@polkadot/types/interfaces';
|
|
10
|
-
export interface SWTransactionBase extends ValidateTransactionResponse, Partial<Pick<BaseRequestSign, 'ignoreWarnings'>>, TransactionFee {
|
|
11
|
+
export interface SWTransactionBase extends ValidateTransactionResponse, Partial<Pick<BaseRequestSign, 'ignoreWarnings'>>, TransactionFee, SWTransactionEmitter {
|
|
11
12
|
id: string;
|
|
12
13
|
url?: string;
|
|
13
14
|
isInternal: boolean;
|
|
@@ -31,7 +32,7 @@ export interface SWTransactionBase extends ValidateTransactionResponse, Partial<
|
|
|
31
32
|
step?: BriefProcessStep;
|
|
32
33
|
}
|
|
33
34
|
export interface SWTransaction extends SWTransactionBase {
|
|
34
|
-
transaction: SubmittableExtrinsic | TransactionConfig | TonTransactionConfig;
|
|
35
|
+
transaction: SubmittableExtrinsic | TransactionConfig | TonTransactionConfig | Psbt;
|
|
35
36
|
}
|
|
36
37
|
export interface SWPermitTransaction extends SWTransactionBase {
|
|
37
38
|
transaction: SignTypedDataMessageV3V4;
|
|
@@ -45,6 +46,9 @@ export interface SWDutchTransaction extends SWTransactionBase {
|
|
|
45
46
|
export interface SWTransactionResult extends Omit<SWTransactionBase, 'transaction' | 'additionalValidator' | 'eventsHandler' | 'process'> {
|
|
46
47
|
process?: ProcessTransactionData;
|
|
47
48
|
}
|
|
49
|
+
export interface SWTransactionEmitter {
|
|
50
|
+
emitterTransaction?: TransactionEmitter;
|
|
51
|
+
}
|
|
48
52
|
declare type SwInputBase = Pick<SWTransactionBase, 'address' | 'url' | 'data' | 'extrinsicType' | 'chain' | 'chainType' | 'ignoreWarnings' | 'transferNativeAmount'> & Partial<Pick<SWTransactionBase, 'additionalValidator' | 'eventsHandler'>>;
|
|
49
53
|
export interface SWTransactionInput extends SwInputBase, Partial<Pick<SWTransactionBase, 'estimateFee' | 'signAfterCreate' | 'isPassConfirmation' | 'step' | 'errorOnTimeOut' | 'xcmFeeDryRun'>>, TransactionFee {
|
|
50
54
|
id?: string;
|
|
@@ -56,6 +60,7 @@ export interface SWTransactionInput extends SwInputBase, Partial<Pick<SWTransact
|
|
|
56
60
|
isTransferLocalTokenAndPayThatTokenAsFee?: boolean;
|
|
57
61
|
resolveOnDone?: boolean;
|
|
58
62
|
skipFeeValidation?: boolean;
|
|
63
|
+
skipFeeRecalculation?: boolean;
|
|
59
64
|
}
|
|
60
65
|
export interface SWPermitTransactionInput extends Omit<SWTransactionInput, 'transaction'> {
|
|
61
66
|
transaction?: SWPermitTransaction['transaction'] | null;
|
|
@@ -66,6 +71,11 @@ export interface SWDutchTransactionInput extends Omit<SWTransactionInput, 'trans
|
|
|
66
71
|
export declare type SWTransactionResponse = SwInputBase & Pick<SWTransactionBase, 'warnings' | 'errors'> & Partial<Pick<SWTransactionBase, 'id' | 'extrinsicHash' | 'status' | 'estimateFee' | 'xcmFeeDryRun'>> & TransactionFee & {
|
|
67
72
|
processId?: string;
|
|
68
73
|
};
|
|
74
|
+
export declare type BitcoinTransactionData = {
|
|
75
|
+
data: Psbt;
|
|
76
|
+
dataBase64: string;
|
|
77
|
+
dataToHex: string;
|
|
78
|
+
};
|
|
69
79
|
export declare type ValidateTransactionResponseInput = SWTransactionInput;
|
|
70
80
|
export declare type TransactionEmitter = EventEmitter<TransactionEventMap>;
|
|
71
81
|
export interface TransactionEventResponse extends ValidateTransactionResponse {
|
|
@@ -77,6 +87,7 @@ export interface TransactionEventResponse extends ValidateTransactionResponse {
|
|
|
77
87
|
eventLogs?: EventRecord[];
|
|
78
88
|
nonce?: number;
|
|
79
89
|
startBlock?: number;
|
|
90
|
+
blockTime?: number;
|
|
80
91
|
}
|
|
81
92
|
export interface TransactionEventMap {
|
|
82
93
|
send: (response: TransactionEventResponse) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { _getBlockExplorerFromChain, _isChainTestNet, _isPureCardanoChain, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
4
|
+
import { _getBlockExplorerFromChain, _isChainTestNet, _isPureBitcoinChain, _isPureCardanoChain, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
5
|
import { CHAIN_FLIP_MAINNET_EXPLORER, CHAIN_FLIP_TESTNET_EXPLORER, SIMPLE_SWAP_EXPLORER } from '@subwallet/extension-base/services/swap-service/utils';
|
|
6
6
|
import { hexAddPrefix, isHex, u8aToHex } from '@polkadot/util';
|
|
7
7
|
import { decodeAddress } from '@polkadot/util-crypto';
|
|
@@ -28,8 +28,8 @@ function getBlockExplorerAccountRoute(explorerLink) {
|
|
|
28
28
|
if (explorerLink.includes('statescan.io')) {
|
|
29
29
|
return '#/accounts';
|
|
30
30
|
}
|
|
31
|
-
if (explorerLink.includes('explorer.
|
|
32
|
-
return '
|
|
31
|
+
if (explorerLink.includes('explorer.gen6.app')) {
|
|
32
|
+
return '#/accounts';
|
|
33
33
|
}
|
|
34
34
|
if (explorerLink.includes('astral.autonomys')) {
|
|
35
35
|
return 'accounts';
|
|
@@ -40,7 +40,7 @@ function getBlockExplorerAccountRoute(explorerLink) {
|
|
|
40
40
|
return 'address';
|
|
41
41
|
}
|
|
42
42
|
function getBlockExplorerTxRoute(chainInfo) {
|
|
43
|
-
if (_isPureEvmChain(chainInfo)) {
|
|
43
|
+
if (_isPureEvmChain(chainInfo) || _isPureBitcoinChain(chainInfo)) {
|
|
44
44
|
return 'tx';
|
|
45
45
|
}
|
|
46
46
|
if (_isPureCardanoChain(chainInfo)) {
|
|
@@ -49,6 +49,9 @@ function getBlockExplorerTxRoute(chainInfo) {
|
|
|
49
49
|
if (['aventus', 'deeper_network'].includes(chainInfo.slug)) {
|
|
50
50
|
return 'transaction';
|
|
51
51
|
}
|
|
52
|
+
if (['gen6_public'].includes(chainInfo.slug)) {
|
|
53
|
+
return '#/extrinsics';
|
|
54
|
+
}
|
|
52
55
|
const explorerLink = _getBlockExplorerFromChain(chainInfo);
|
|
53
56
|
if (explorerLink && explorerLink.includes('statescan.io')) {
|
|
54
57
|
return '#/extrinsics';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApiRequestContext } from '@subwallet/extension-base/strategy/api-request-strategy/types';
|
|
2
|
+
export declare class BaseApiRequestContext implements ApiRequestContext {
|
|
3
|
+
callRate: number;
|
|
4
|
+
limitRate: number;
|
|
5
|
+
intervalCheck: number;
|
|
6
|
+
maxRetry: number;
|
|
7
|
+
private rollbackRateTime;
|
|
8
|
+
private timeoutRollbackRate;
|
|
9
|
+
constructor(options?: {
|
|
10
|
+
limitRate?: number;
|
|
11
|
+
intervalCheck?: number;
|
|
12
|
+
maxRetry?: number;
|
|
13
|
+
});
|
|
14
|
+
reduceLimitRate(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export class BaseApiRequestContext {
|
|
5
|
+
callRate = 2; // limit per interval check
|
|
6
|
+
limitRate = 2; // max rate per interval check
|
|
7
|
+
intervalCheck = 1000; // interval check in ms
|
|
8
|
+
maxRetry = 9; // interval check in ms
|
|
9
|
+
rollbackRateTime = 30 * 1000; // rollback rate time in ms
|
|
10
|
+
timeoutRollbackRate = undefined;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.callRate = (options === null || options === void 0 ? void 0 : options.limitRate) || this.callRate;
|
|
13
|
+
this.limitRate = (options === null || options === void 0 ? void 0 : options.limitRate) || this.limitRate;
|
|
14
|
+
this.intervalCheck = (options === null || options === void 0 ? void 0 : options.intervalCheck) || this.intervalCheck;
|
|
15
|
+
this.maxRetry = (options === null || options === void 0 ? void 0 : options.maxRetry) || this.maxRetry;
|
|
16
|
+
}
|
|
17
|
+
reduceLimitRate() {
|
|
18
|
+
clearTimeout(this.timeoutRollbackRate);
|
|
19
|
+
this.callRate = Math.ceil(this.limitRate / 2);
|
|
20
|
+
this.timeoutRollbackRate = setTimeout(() => {
|
|
21
|
+
this.callRate = this.limitRate;
|
|
22
|
+
}, this.rollbackRateTime);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApiRequest, ApiRequestContext, ApiRequestStrategy } from './types';
|
|
2
|
+
export declare abstract class BaseApiRequestStrategy implements ApiRequestStrategy {
|
|
3
|
+
private nextId;
|
|
4
|
+
private isRunning;
|
|
5
|
+
private requestMap;
|
|
6
|
+
private context;
|
|
7
|
+
private processInterval;
|
|
8
|
+
private getId;
|
|
9
|
+
protected constructor(context: ApiRequestContext);
|
|
10
|
+
addRequest<T>(run: ApiRequest<T>['run'], ordinal: number): Promise<T>;
|
|
11
|
+
abstract isRateLimited(error: Error): boolean;
|
|
12
|
+
private process;
|
|
13
|
+
stop(): void;
|
|
14
|
+
setContext(context: ApiRequestContext): void;
|
|
15
|
+
}
|