edge-currency-plugins 1.2.1 → 1.2.2
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/lib/common/plugin/types.js +5 -0
- package/lib/common/utxobased/db/Models/ProcessorTransaction.js +1 -0
- package/lib/common/utxobased/db/types.js +1 -0
- package/lib/common/utxobased/engine/makeUtxoEngineState.js +130 -6
- package/lib/common/utxobased/info/dash.js +18 -1
- package/lib/common/utxobased/network/BlockBookAPI.js +12 -0
- package/lib/src/common/plugin/types.d.ts +2 -1
- package/lib/src/common/utxobased/db/types.d.ts +1 -0
- package/lib/src/common/utxobased/engine/makeUtxoEngineState.d.ts +6 -0
- package/lib/src/common/utxobased/network/BlockBookAPI.d.ts +4 -0
- package/package.json +1 -1
|
@@ -117,6 +117,7 @@ var _keymanager = require('../../keymanager/keymanager');
|
|
|
117
117
|
currencyCode: currencyInfo.currencyCode,
|
|
118
118
|
txid: tx.txid,
|
|
119
119
|
blockHeight: tx.blockHeight,
|
|
120
|
+
confirmations: tx.confirmations,
|
|
120
121
|
date: tx.date,
|
|
121
122
|
nativeAmount: tx.ourAmount,
|
|
122
123
|
networkFee: tx.fees,
|
|
@@ -41,6 +41,7 @@ var _keymanager = require('../keymanager/keymanager');
|
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
|
|
44
|
+
|
|
44
45
|
var _BlockBookAPI = require('../network/BlockBookAPI');
|
|
45
46
|
var _Deferred = require('../network/Deferred'); var _Deferred2 = _interopRequireDefault(_Deferred);
|
|
46
47
|
|
|
@@ -108,7 +109,8 @@ var _utils3 = require('./utils');
|
|
|
108
109
|
addressUtxoCache: {},
|
|
109
110
|
rawUtxoCache: {},
|
|
110
111
|
processorUtxoCache: {},
|
|
111
|
-
updateTransactionCache: {}
|
|
112
|
+
updateTransactionCache: {},
|
|
113
|
+
updateTransactionSpecificCache: {}
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
const clearTaskCache = () => {
|
|
@@ -131,6 +133,9 @@ var _utils3 = require('./utils');
|
|
|
131
133
|
for (const key of Object.keys(taskCache.updateTransactionCache)) {
|
|
132
134
|
_utils.removeItem.call(void 0, taskCache.updateTransactionCache, key)
|
|
133
135
|
}
|
|
136
|
+
for (const key of Object.keys(taskCache.updateTransactionSpecificCache)) {
|
|
137
|
+
_utils.removeItem.call(void 0, taskCache.updateTransactionSpecificCache, key)
|
|
138
|
+
}
|
|
134
139
|
}
|
|
135
140
|
|
|
136
141
|
/**
|
|
@@ -525,6 +530,10 @@ var _utils3 = require('./utils');
|
|
|
525
530
|
|
|
526
531
|
|
|
527
532
|
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
528
537
|
|
|
529
538
|
|
|
530
539
|
|
|
@@ -669,7 +678,7 @@ const addToAddressTransactionCache = async (
|
|
|
669
678
|
args
|
|
670
679
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
671
680
|
) => {
|
|
672
|
-
const { taskCache, uri, serverStates } = args
|
|
681
|
+
const { pluginInfo, taskCache, uri, serverStates } = args
|
|
673
682
|
|
|
674
683
|
const {
|
|
675
684
|
addressSubscribeCache,
|
|
@@ -677,9 +686,17 @@ const addToAddressTransactionCache = async (
|
|
|
677
686
|
rawUtxoCache,
|
|
678
687
|
processorUtxoCache,
|
|
679
688
|
addressTransactionCache,
|
|
680
|
-
updateTransactionCache
|
|
689
|
+
updateTransactionCache,
|
|
690
|
+
updateTransactionSpecificCache
|
|
681
691
|
} = taskCache
|
|
682
692
|
|
|
693
|
+
/**
|
|
694
|
+
* Some currencies require an additional blockbook payload 'getTransactionSpecific' in order
|
|
695
|
+
* to provide all relevant transaction data. Since this is currency-specific, we can limit
|
|
696
|
+
* the useage to currencies that require it.
|
|
697
|
+
**/
|
|
698
|
+
const needsTxSpecific = pluginInfo.engineInfo.txSpecificHandling != null
|
|
699
|
+
|
|
683
700
|
const serverState = serverStates.getServerState(uri)
|
|
684
701
|
if (serverState == null) return
|
|
685
702
|
|
|
@@ -799,6 +816,37 @@ const addToAddressTransactionCache = async (
|
|
|
799
816
|
}
|
|
800
817
|
}
|
|
801
818
|
|
|
819
|
+
// filled when transactions potentially changed (e.g. through new block notification)
|
|
820
|
+
if (Object.keys(updateTransactionSpecificCache).length > 0) {
|
|
821
|
+
let hasProcessedAtLeastOnce = false
|
|
822
|
+
for (const [txId, state] of Object.entries(
|
|
823
|
+
updateTransactionSpecificCache
|
|
824
|
+
)) {
|
|
825
|
+
if (!state.processing && serverStates.serverCanGetTx(uri, txId)) {
|
|
826
|
+
hasProcessedAtLeastOnce = true
|
|
827
|
+
state.processing = true
|
|
828
|
+
_utils.removeItem.call(void 0, updateTransactionSpecificCache, txId)
|
|
829
|
+
const updateTransactionSpecificTask = updateTransactionsSpecific({
|
|
830
|
+
...args,
|
|
831
|
+
txId
|
|
832
|
+
})
|
|
833
|
+
// once resolved, add the txid to the server cache
|
|
834
|
+
updateTransactionSpecificTask.deferred.promise
|
|
835
|
+
.then(() => {
|
|
836
|
+
serverState.txids.add(txId)
|
|
837
|
+
})
|
|
838
|
+
.catch(err => {
|
|
839
|
+
updateTransactionSpecificCache[txId] = state
|
|
840
|
+
console.error(err)
|
|
841
|
+
args.log('error in updateTransactionSpecificCache:', err)
|
|
842
|
+
})
|
|
843
|
+
return updateTransactionSpecificTask
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
// This condition prevents infinite loops
|
|
847
|
+
if (hasProcessedAtLeastOnce) return true
|
|
848
|
+
}
|
|
849
|
+
|
|
802
850
|
// filled when transactions potentially changed (e.g. through new block notification)
|
|
803
851
|
if (Object.keys(updateTransactionCache).length > 0) {
|
|
804
852
|
let hasProcessedAtLeastOnce = false
|
|
@@ -807,7 +855,11 @@ const addToAddressTransactionCache = async (
|
|
|
807
855
|
hasProcessedAtLeastOnce = true
|
|
808
856
|
state.processing = true
|
|
809
857
|
_utils.removeItem.call(void 0, updateTransactionCache, txId)
|
|
810
|
-
const updateTransactionTask = updateTransactions({
|
|
858
|
+
const updateTransactionTask = updateTransactions({
|
|
859
|
+
...args,
|
|
860
|
+
txId,
|
|
861
|
+
needsTxSpecific
|
|
862
|
+
})
|
|
811
863
|
// once resolved, add the txid to the server cache
|
|
812
864
|
updateTransactionTask.deferred.promise
|
|
813
865
|
.then(() => {
|
|
@@ -836,7 +888,8 @@ const addToAddressTransactionCache = async (
|
|
|
836
888
|
const wsTask = await processAddressTransactions({
|
|
837
889
|
...args,
|
|
838
890
|
addressTransactionState: state,
|
|
839
|
-
address
|
|
891
|
+
address,
|
|
892
|
+
needsTxSpecific
|
|
840
893
|
})
|
|
841
894
|
wsTask.deferred.promise
|
|
842
895
|
.then(() => {
|
|
@@ -856,11 +909,65 @@ const addToAddressTransactionCache = async (
|
|
|
856
909
|
|
|
857
910
|
|
|
858
911
|
|
|
859
|
-
const
|
|
912
|
+
const updateTransactionsSpecific = (
|
|
860
913
|
args
|
|
861
914
|
) => {
|
|
862
915
|
const { emitter, walletTools, txId, pluginInfo, processor, taskCache } = args
|
|
863
916
|
const deferred = new _Deferred2.default()
|
|
917
|
+
deferred.promise
|
|
918
|
+
.then(async (txResponse) => {
|
|
919
|
+
// Grab tx to update it
|
|
920
|
+
const txs = await processor.fetchTransactions({ txId })
|
|
921
|
+
let tx = txs[0]
|
|
922
|
+
if (tx == null) return
|
|
923
|
+
|
|
924
|
+
if (pluginInfo.engineInfo.txSpecificHandling != null) {
|
|
925
|
+
// Do coin-specific things to it
|
|
926
|
+
tx = pluginInfo.engineInfo.txSpecificHandling(tx, txResponse)
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
// Process and save new tx
|
|
930
|
+
const processedTx = await processor.saveTransaction({
|
|
931
|
+
tx
|
|
932
|
+
})
|
|
933
|
+
|
|
934
|
+
await exports.transactionChanged.call(void 0, {
|
|
935
|
+
emitter,
|
|
936
|
+
walletTools,
|
|
937
|
+
processor,
|
|
938
|
+
pluginInfo,
|
|
939
|
+
tx: processedTx
|
|
940
|
+
})
|
|
941
|
+
})
|
|
942
|
+
.catch(err => {
|
|
943
|
+
console.error(err)
|
|
944
|
+
args.log('error in updateTransactionsSpecific:', err)
|
|
945
|
+
taskCache.updateTransactionSpecificCache[txId] = { processing: false }
|
|
946
|
+
})
|
|
947
|
+
return {
|
|
948
|
+
..._BlockBookAPI.transactionMessageSpecific.call(void 0, txId),
|
|
949
|
+
deferred
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
const updateTransactions = (
|
|
959
|
+
args
|
|
960
|
+
) => {
|
|
961
|
+
const {
|
|
962
|
+
emitter,
|
|
963
|
+
walletTools,
|
|
964
|
+
txId,
|
|
965
|
+
needsTxSpecific,
|
|
966
|
+
pluginInfo,
|
|
967
|
+
processor,
|
|
968
|
+
taskCache
|
|
969
|
+
} = args
|
|
970
|
+
const deferred = new _Deferred2.default()
|
|
864
971
|
deferred.promise
|
|
865
972
|
.then(async (txResponse) => {
|
|
866
973
|
// check if raw tx is still not confirmed, if so, don't change anything
|
|
@@ -885,6 +992,7 @@ const updateTransactions = (
|
|
|
885
992
|
const processedTx = await processor.saveTransaction({
|
|
886
993
|
tx
|
|
887
994
|
})
|
|
995
|
+
|
|
888
996
|
await exports.transactionChanged.call(void 0, {
|
|
889
997
|
emitter,
|
|
890
998
|
walletTools,
|
|
@@ -892,6 +1000,13 @@ const updateTransactions = (
|
|
|
892
1000
|
pluginInfo,
|
|
893
1001
|
tx: processedTx
|
|
894
1002
|
})
|
|
1003
|
+
|
|
1004
|
+
if (needsTxSpecific) {
|
|
1005
|
+
// Add task to grab transactionSpecific payload
|
|
1006
|
+
taskCache.updateTransactionSpecificCache[txId] = {
|
|
1007
|
+
processing: false
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
895
1010
|
})
|
|
896
1011
|
.catch(err => {
|
|
897
1012
|
console.error(err)
|
|
@@ -1002,6 +1117,7 @@ const internalGetFreshAddress = async (
|
|
|
1002
1117
|
|
|
1003
1118
|
|
|
1004
1119
|
|
|
1120
|
+
|
|
1005
1121
|
const processAddressTransactions = async (
|
|
1006
1122
|
args
|
|
1007
1123
|
) => {
|
|
@@ -1009,6 +1125,7 @@ const processAddressTransactions = async (
|
|
|
1009
1125
|
address,
|
|
1010
1126
|
addressTransactionState,
|
|
1011
1127
|
emitter,
|
|
1128
|
+
needsTxSpecific,
|
|
1012
1129
|
pluginInfo,
|
|
1013
1130
|
processor,
|
|
1014
1131
|
walletTools,
|
|
@@ -1055,6 +1172,13 @@ const processAddressTransactions = async (
|
|
|
1055
1172
|
pluginInfo,
|
|
1056
1173
|
tx: processedTx
|
|
1057
1174
|
})
|
|
1175
|
+
|
|
1176
|
+
if (needsTxSpecific) {
|
|
1177
|
+
// Add task to grab transactionSpecific payload
|
|
1178
|
+
taskCache.updateTransactionSpecificCache[tx.txid] = {
|
|
1179
|
+
processing: false
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1058
1182
|
}
|
|
1059
1183
|
|
|
1060
1184
|
// Halt on finishing the processing of address transaction until
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _cleaners = require('cleaners');
|
|
2
|
+
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
|
|
4
6
|
|
|
@@ -52,6 +54,21 @@ const engineInfo = {
|
|
|
52
54
|
standardFeeHigh: '200',
|
|
53
55
|
standardFeeLowAmount: '20000000',
|
|
54
56
|
standardFeeHighAmount: '981000000'
|
|
57
|
+
},
|
|
58
|
+
txSpecificHandling: (
|
|
59
|
+
tx,
|
|
60
|
+
txSpecific
|
|
61
|
+
) => {
|
|
62
|
+
const asDashTransactionSpecific = _cleaners.asObject.call(void 0, {
|
|
63
|
+
instantlock: _cleaners.asOptional.call(void 0, _cleaners.asBoolean)
|
|
64
|
+
})
|
|
65
|
+
const cleanedTxSpecific = _cleaners.asMaybe.call(void 0, asDashTransactionSpecific)(txSpecific)
|
|
66
|
+
|
|
67
|
+
if (_optionalChain([cleanedTxSpecific, 'optionalAccess', _ => _.instantlock]) === true) {
|
|
68
|
+
tx.confirmations = 'confirmed'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return tx
|
|
55
72
|
}
|
|
56
73
|
}
|
|
57
74
|
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
|
|
11
12
|
var _cleaners = require('cleaners');
|
|
12
13
|
|
|
13
14
|
|
|
@@ -211,6 +212,17 @@ var _cleaners = require('cleaners');
|
|
|
211
212
|
|
|
212
213
|
const asTransactionResponse = exports.asBlockbookTransaction; exports.asTransactionResponse = asTransactionResponse
|
|
213
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Get Transaction Specific
|
|
217
|
+
*/
|
|
218
|
+
const transactionMessageSpecific = (
|
|
219
|
+
hash
|
|
220
|
+
) => ({
|
|
221
|
+
method: 'getTransactionSpecific',
|
|
222
|
+
params: { txid: hash },
|
|
223
|
+
cleaner: exports.asBlockbookResponse.call(void 0, _cleaners.asUnknown)
|
|
224
|
+
}); exports.transactionMessageSpecific = transactionMessageSpecific
|
|
225
|
+
|
|
214
226
|
/**
|
|
215
227
|
* Send Transaction
|
|
216
228
|
*/
|
|
@@ -3,7 +3,7 @@ import { bip32 } from 'altcoin-js';
|
|
|
3
3
|
import { Cleaner } from 'cleaners';
|
|
4
4
|
import { Disklet } from 'disklet';
|
|
5
5
|
import { EdgeCurrencyEngineOptions, EdgeCurrencyInfo, EdgeCurrencyTools, EdgeIo, EdgeParsedUri, EdgeWalletInfo } from 'edge-core-js/types';
|
|
6
|
-
import { IUTXO } from '../utxobased/db/types';
|
|
6
|
+
import { IProcessorTransaction, IUTXO } from '../utxobased/db/types';
|
|
7
7
|
import { ScriptTemplates } from '../utxobased/info/scriptTemplates/types';
|
|
8
8
|
import { UtxoPicker } from '../utxobased/keymanager/utxopicker';
|
|
9
9
|
import { EngineEmitter } from './makeEngineEmitter';
|
|
@@ -41,6 +41,7 @@ export interface EngineInfo {
|
|
|
41
41
|
simpleFeeSettings: SimpleFeeSettings;
|
|
42
42
|
scriptTemplates?: ScriptTemplates;
|
|
43
43
|
asBlockbookAddress?: Cleaner<string>;
|
|
44
|
+
txSpecificHandling?: (tx: IProcessorTransaction, specialTx: unknown) => IProcessorTransaction;
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
46
47
|
* Coin Info
|
|
@@ -52,12 +52,18 @@ interface TaskCache {
|
|
|
52
52
|
readonly processorUtxoCache: ProcessorUtxoCache;
|
|
53
53
|
readonly addressTransactionCache: AddressTransactionCache;
|
|
54
54
|
readonly updateTransactionCache: UpdateTransactionCache;
|
|
55
|
+
readonly updateTransactionSpecificCache: UpdateTransactionSpecificCache;
|
|
55
56
|
}
|
|
56
57
|
interface UpdateTransactionCache {
|
|
57
58
|
[key: string]: {
|
|
58
59
|
processing: boolean;
|
|
59
60
|
};
|
|
60
61
|
}
|
|
62
|
+
interface UpdateTransactionSpecificCache {
|
|
63
|
+
[key: string]: {
|
|
64
|
+
processing: boolean;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
61
67
|
interface AddressSubscribeCache {
|
|
62
68
|
[key: string]: {
|
|
63
69
|
processing: boolean;
|
|
@@ -96,6 +96,10 @@ export declare const asAddressUtxosResponse: (asAddress?: Cleaner<string>) => Cl
|
|
|
96
96
|
export declare const transactionMessage: (hash: string, asAddress?: Cleaner<string>) => BlockbookTask<TransactionResponse>;
|
|
97
97
|
export declare type TransactionResponse = BlockbookTransaction;
|
|
98
98
|
export declare const asTransactionResponse: (asAddress?: Cleaner<string>) => Cleaner<BlockbookTransaction>;
|
|
99
|
+
/**
|
|
100
|
+
* Get Transaction Specific
|
|
101
|
+
*/
|
|
102
|
+
export declare const transactionMessageSpecific: (hash: string) => BlockbookTask<unknown>;
|
|
99
103
|
/**
|
|
100
104
|
* Send Transaction
|
|
101
105
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edge-currency-plugins",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Edge currency plugins to fetch and process wallet accounts, balances and transactions.",
|
|
5
5
|
"repository": "https://github.com/EdgeApp/edge-currency-plugins",
|
|
6
6
|
"license": "MIT",
|