edge-currency-plugins 2.6.2 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -2
- package/android/build.gradle +45 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/assets/edge-currency-plugins/669.chunk.js +1 -0
- package/android/src/main/assets/edge-currency-plugins/edge-currency-plugins.js +76 -0
- package/android/src/main/java/app/edge/reactnative/currencyplugins/EdgeCurrencyPluginsModule.java +26 -0
- package/android/src/main/java/app/edge/reactnative/currencyplugins/EdgeCurrencyPluginsPackage.java +24 -0
- package/edge-currency-plugins.d.ts +34 -0
- package/edge-currency-plugins.podspec +28 -0
- package/ios/EdgeCurrencyPluginsModule.m +4 -0
- package/ios/EdgeCurrencyPluginsModule.swift +20 -0
- package/ios/edge-currency-plugins.xcodeproj/project.pbxproj +1 -0
- package/lib/common/constants.js +1 -2
- package/lib/common/plugin/CurrencyPlugin.js +17 -1
- package/lib/common/utxobased/db/Models/ProcessorTransaction.js +3 -2
- package/lib/common/utxobased/db/Processor.js +5 -0
- package/lib/common/utxobased/engine/ServerStates.js +159 -28
- package/lib/common/utxobased/engine/UtxoEngine.js +3 -2
- package/lib/common/utxobased/engine/UtxoEngineState.js +66 -72
- package/lib/common/utxobased/engine/types.js +3 -1
- package/lib/common/utxobased/info/bitcoin.js +1 -6
- package/lib/common/utxobased/info/bitcoincash.js +1 -6
- package/lib/common/utxobased/info/bitcoincashtestnet.js +0 -5
- package/lib/common/utxobased/info/bitcoinsv.js +0 -5
- package/lib/common/utxobased/info/bitcointestnet.js +0 -5
- package/lib/common/utxobased/info/dash.js +1 -1
- package/lib/common/utxobased/info/digibyte.js +1 -1
- package/lib/common/utxobased/info/feathercoin.js +0 -5
- package/lib/common/utxobased/info/groestlcoin.js +1 -1
- package/lib/common/utxobased/info/litecoin.js +1 -6
- package/lib/common/utxobased/info/zcoin.js +6 -5
- package/lib/common/utxobased/keymanager/keymanager.js +1 -1
- package/lib/common/utxobased/keymanager/types.js +2 -1
- package/lib/common/utxobased/network/Blockbook.js +178 -105
- package/lib/common/utxobased/network/BlockbookElectrum.js +216 -0
- package/lib/common/utxobased/network/Socket.js +130 -66
- package/lib/common/utxobased/network/blockbookApi.js +6 -6
- package/lib/common/utxobased/network/electrumApi.js +203 -0
- package/lib/{types.js → declare-modules.d.js} +2 -0
- package/lib/index.js +7 -3
- package/lib/react-native.js +26 -0
- package/lib/src/common/constants.d.ts +0 -1
- package/lib/src/common/utxobased/db/Processor.d.ts +6 -1
- package/lib/src/common/utxobased/engine/ServerStates.d.ts +8 -0
- package/lib/src/common/utxobased/engine/UtxoEngineState.d.ts +1 -4
- package/lib/src/common/utxobased/keymanager/types.d.ts +3 -3
- package/lib/src/common/utxobased/network/Blockbook.d.ts +20 -7
- package/lib/src/common/utxobased/network/BlockbookElectrum.d.ts +25 -0
- package/lib/src/common/utxobased/network/Socket.d.ts +11 -0
- package/lib/src/common/utxobased/network/blockbookApi.d.ts +2 -16
- package/lib/src/common/utxobased/network/electrumApi.d.ts +90 -0
- package/lib/src/index.d.ts +5 -1
- package/lib/src/react-native.d.ts +10 -0
- package/lib/test/utils.d.ts +4 -0
- package/package.json +24 -11
- package/lib/src/types.d.ts +0 -6
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
var _EngineEmitter = require('../../plugin/EngineEmitter');
|
|
5
|
+
var _constants = require('../engine/constants');
|
|
6
|
+
|
|
7
|
+
|
|
5
8
|
|
|
6
9
|
|
|
7
10
|
|
|
@@ -49,6 +52,42 @@ var _Socket = require('./Socket');
|
|
|
49
52
|
|
|
50
53
|
|
|
51
54
|
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
52
91
|
|
|
53
92
|
|
|
54
93
|
|
|
@@ -73,6 +112,7 @@ var _Socket = require('./Socket');
|
|
|
73
112
|
function makeBlockbook(config) {
|
|
74
113
|
const {
|
|
75
114
|
asAddress,
|
|
115
|
+
asResponse,
|
|
76
116
|
connectionUri,
|
|
77
117
|
engineEmitter,
|
|
78
118
|
log,
|
|
@@ -84,120 +124,153 @@ var _Socket = require('./Socket');
|
|
|
84
124
|
|
|
85
125
|
const instance = {
|
|
86
126
|
isConnected: false,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
127
|
+
|
|
128
|
+
async broadcastTx(
|
|
129
|
+
transaction
|
|
130
|
+
) {
|
|
131
|
+
return await instance.promisifyWsMessage(
|
|
132
|
+
_blockbookApi.broadcastTxMessage.call(void 0, transaction.signedTx)
|
|
133
|
+
)
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
async connect() {
|
|
137
|
+
log(`connecting to blockbook socket with uri ${connectionUri}`)
|
|
138
|
+
if (instance.isConnected) return
|
|
139
|
+
|
|
140
|
+
await socket.connect()
|
|
141
|
+
instance.isConnected = socket.isConnected()
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
async disconnect() {
|
|
145
|
+
log(
|
|
146
|
+
`disconnecting from blockbook socket with uri ${connectionUri}, currently connected: ${instance.isConnected}`
|
|
147
|
+
)
|
|
148
|
+
if (!instance.isConnected) return
|
|
149
|
+
|
|
150
|
+
socket.disconnect()
|
|
151
|
+
instance.isConnected = false
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
async fetchAddress(
|
|
155
|
+
address,
|
|
156
|
+
params = {}
|
|
157
|
+
) {
|
|
158
|
+
return await instance.promisifyWsMessage(
|
|
159
|
+
_blockbookApi.addressMessage.call(void 0, address, asAddress, params)
|
|
160
|
+
)
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
async fetchAddressUtxos(account) {
|
|
164
|
+
return await instance.promisifyWsMessage(_blockbookApi.addressUtxosMessage.call(void 0, account))
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
async fetchInfo() {
|
|
168
|
+
return await instance.promisifyWsMessage(_blockbookApi.infoMessage.call(void 0, ))
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
async fetchTransaction(hash) {
|
|
172
|
+
return await instance.promisifyWsMessage(_blockbookApi.transactionMessage.call(void 0, hash))
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
onQueueSpace(cb) {
|
|
176
|
+
socket.onQueueSpace(cb)
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
async promisifyWsMessage(message) {
|
|
180
|
+
const deferred = new _Deferred2.default()
|
|
181
|
+
socket.submitTask({ ...message, deferred })
|
|
182
|
+
return await deferred.promise
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
watchAddresses(
|
|
186
|
+
addresses,
|
|
187
|
+
deferredAddressSub
|
|
188
|
+
) {
|
|
189
|
+
const socketCb = async (res) => {
|
|
190
|
+
engineEmitter.emit(
|
|
191
|
+
_EngineEmitter.EngineEvent.NEW_ADDRESS_TRANSACTION,
|
|
192
|
+
connectionUri,
|
|
193
|
+
res
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
socket.subscribe({
|
|
197
|
+
..._blockbookApi.subscribeAddressesMessage.call(void 0, addresses, asAddress),
|
|
198
|
+
cb: socketCb,
|
|
199
|
+
deferred: deferredAddressSub,
|
|
200
|
+
subscribed: false
|
|
201
|
+
})
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
async watchBlocks(deferredBlockSub) {
|
|
205
|
+
const socketCb = async (
|
|
206
|
+
res
|
|
207
|
+
) => {
|
|
208
|
+
engineEmitter.emit(
|
|
209
|
+
_EngineEmitter.EngineEvent.BLOCK_HEIGHT_CHANGED,
|
|
210
|
+
connectionUri,
|
|
211
|
+
res.height
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
socket.subscribe({
|
|
215
|
+
..._blockbookApi.subscribeNewBlockMessage.call(void 0, ),
|
|
216
|
+
cb: socketCb,
|
|
217
|
+
deferred: deferredBlockSub,
|
|
218
|
+
subscribed: false
|
|
219
|
+
})
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
//
|
|
223
|
+
// Task Methods:
|
|
224
|
+
//
|
|
225
|
+
|
|
226
|
+
addressQueryTask(address, params, deferred) {
|
|
227
|
+
return {
|
|
228
|
+
..._blockbookApi.addressMessage.call(void 0, address, params.asBlockbookAddress, {
|
|
229
|
+
details: 'txs',
|
|
230
|
+
from: params.lastQueriedBlockHeight,
|
|
231
|
+
pageSize: _constants.BLOCKBOOK_TXS_PER_PAGE,
|
|
232
|
+
page: params.page
|
|
233
|
+
}),
|
|
234
|
+
deferred
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
transactionQueryTask(txId, deferred) {
|
|
239
|
+
return {
|
|
240
|
+
..._blockbookApi.transactionMessage.call(void 0, txId),
|
|
241
|
+
deferred
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
transactionSpecialQueryTask(
|
|
246
|
+
txId,
|
|
247
|
+
deferred
|
|
248
|
+
) {
|
|
249
|
+
return {
|
|
250
|
+
..._blockbookApi.transactionMessageSpecific.call(void 0, txId),
|
|
251
|
+
deferred
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
utxoListQueryTask(address, params, deferred) {
|
|
256
|
+
return {
|
|
257
|
+
..._blockbookApi.addressUtxosMessage.call(void 0, address, params.asBlockbookAddress),
|
|
258
|
+
deferred
|
|
259
|
+
}
|
|
260
|
+
}
|
|
97
261
|
}
|
|
98
262
|
|
|
99
263
|
const socket = _Socket.makeSocket.call(void 0, connectionUri, {
|
|
100
|
-
|
|
264
|
+
asResponse,
|
|
265
|
+
healthCheck: _nullishCoalesce(config.ping, () => ( ping)),
|
|
101
266
|
onQueueSpaceCB,
|
|
102
267
|
log,
|
|
103
268
|
emitter: socketEmitter,
|
|
104
269
|
walletId
|
|
105
270
|
})
|
|
106
271
|
|
|
107
|
-
async function connect() {
|
|
108
|
-
log(`connecting to blockbook socket with uri ${connectionUri}`)
|
|
109
|
-
if (instance.isConnected) return
|
|
110
|
-
|
|
111
|
-
await socket.connect()
|
|
112
|
-
instance.isConnected = socket.isConnected()
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async function disconnect() {
|
|
116
|
-
log(
|
|
117
|
-
`disconnecting from blockbook socket with uri ${connectionUri}, currently connected: ${instance.isConnected}`
|
|
118
|
-
)
|
|
119
|
-
if (!instance.isConnected) return
|
|
120
|
-
|
|
121
|
-
socket.disconnect()
|
|
122
|
-
instance.isConnected = false
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function onQueueSpace(cb) {
|
|
126
|
-
socket.onQueueSpace(cb)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async function promisifyWsMessage(message) {
|
|
130
|
-
const deferred = new _Deferred2.default()
|
|
131
|
-
socket.submitTask({ ...message, deferred })
|
|
132
|
-
return await deferred.promise
|
|
133
|
-
}
|
|
134
|
-
|
|
135
272
|
async function ping() {
|
|
136
|
-
await promisifyWsMessage(_blockbookApi.pingMessage.call(void 0, ))
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async function fetchInfo() {
|
|
140
|
-
return await promisifyWsMessage(_blockbookApi.infoMessage.call(void 0, ))
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
async function fetchAddressUtxos(
|
|
144
|
-
account
|
|
145
|
-
) {
|
|
146
|
-
return await promisifyWsMessage(_blockbookApi.addressUtxosMessage.call(void 0, account))
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async function fetchTransaction(hash) {
|
|
150
|
-
return await promisifyWsMessage(_blockbookApi.transactionMessage.call(void 0, hash))
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async function fetchAddress(
|
|
154
|
-
address,
|
|
155
|
-
params = {}
|
|
156
|
-
) {
|
|
157
|
-
return await promisifyWsMessage(_blockbookApi.addressMessage.call(void 0, address, asAddress, params))
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async function watchBlocks(
|
|
161
|
-
deferredBlockSub
|
|
162
|
-
) {
|
|
163
|
-
const socketCb = async (res) => {
|
|
164
|
-
engineEmitter.emit(
|
|
165
|
-
_EngineEmitter.EngineEvent.BLOCK_HEIGHT_CHANGED,
|
|
166
|
-
connectionUri,
|
|
167
|
-
res.height
|
|
168
|
-
)
|
|
169
|
-
}
|
|
170
|
-
socket.subscribe({
|
|
171
|
-
..._blockbookApi.subscribeNewBlockMessage.call(void 0, ),
|
|
172
|
-
cb: socketCb,
|
|
173
|
-
deferred: deferredBlockSub,
|
|
174
|
-
subscribed: false
|
|
175
|
-
})
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function watchAddresses(
|
|
179
|
-
addresses,
|
|
180
|
-
deferredAddressSub
|
|
181
|
-
) {
|
|
182
|
-
const socketCb = async (res) => {
|
|
183
|
-
engineEmitter.emit(
|
|
184
|
-
_EngineEmitter.EngineEvent.NEW_ADDRESS_TRANSACTION,
|
|
185
|
-
connectionUri,
|
|
186
|
-
res
|
|
187
|
-
)
|
|
188
|
-
}
|
|
189
|
-
socket.subscribe({
|
|
190
|
-
..._blockbookApi.subscribeAddressesMessage.call(void 0, addresses, asAddress),
|
|
191
|
-
cb: socketCb,
|
|
192
|
-
deferred: deferredAddressSub,
|
|
193
|
-
subscribed: false
|
|
194
|
-
})
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async function broadcastTx(
|
|
198
|
-
transaction
|
|
199
|
-
) {
|
|
200
|
-
return await promisifyWsMessage(_blockbookApi.broadcastTxMessage.call(void 0, transaction))
|
|
273
|
+
await instance.promisifyWsMessage(_blockbookApi.pingMessage.call(void 0, ))
|
|
201
274
|
}
|
|
202
275
|
|
|
203
276
|
return instance
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _altcoinjs = require('altcoin-js');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _cleaners = require('cleaners');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _keymanager = require('../keymanager/keymanager');
|
|
16
|
+
var _Blockbook = require('./Blockbook');
|
|
17
|
+
|
|
18
|
+
var _Deferred = require('./Deferred'); var _Deferred2 = _interopRequireDefault(_Deferred);
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
var _electrumApi = require('./electrumApi');
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const asResponseMessage = (raw) => {
|
|
47
|
+
const message = _cleaners.asJSON.call(void 0,
|
|
48
|
+
_cleaners.asObject.call(void 0, {
|
|
49
|
+
id: _cleaners.asString,
|
|
50
|
+
result: _cleaners.asUnknown,
|
|
51
|
+
error: _cleaners.asOptional.call(void 0,
|
|
52
|
+
_cleaners.asEither.call(void 0,
|
|
53
|
+
_cleaners.asObject.call(void 0, { message: _cleaners.asString }),
|
|
54
|
+
_cleaners.asObject.call(void 0, { connected: _cleaners.asString })
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
})
|
|
58
|
+
)(raw)
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
id: message.id,
|
|
62
|
+
data: message.result,
|
|
63
|
+
error: message.error
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const asResponse = (raw) => {
|
|
68
|
+
const payloadString = _cleaners.asString.call(void 0, raw).trimEnd()
|
|
69
|
+
const messageStrings = payloadString.split('\n')
|
|
70
|
+
const messages = messageStrings.map(asResponseMessage)
|
|
71
|
+
return messages
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function makeBlockbookElectrum(
|
|
75
|
+
config
|
|
76
|
+
) {
|
|
77
|
+
const {
|
|
78
|
+
asAddress,
|
|
79
|
+
connectionUri,
|
|
80
|
+
engineEmitter,
|
|
81
|
+
log,
|
|
82
|
+
onQueueSpaceCB,
|
|
83
|
+
pluginInfo,
|
|
84
|
+
socketEmitter,
|
|
85
|
+
walletId
|
|
86
|
+
} = config
|
|
87
|
+
log(`makeBlockbookElectrum with uri ${connectionUri}`)
|
|
88
|
+
|
|
89
|
+
const addressToScriptHash = (address) => {
|
|
90
|
+
const scriptPubkey = _keymanager.addressToScriptPubkey.call(void 0, {
|
|
91
|
+
address,
|
|
92
|
+
coin: pluginInfo.coinInfo.name
|
|
93
|
+
})
|
|
94
|
+
const scriptHashBuffer = _altcoinjs.crypto.sha256(Buffer.from(scriptPubkey, 'hex'))
|
|
95
|
+
const scriptHash = scriptHashBuffer.reverse().toString('hex')
|
|
96
|
+
return scriptHash
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const instance = _Blockbook.makeBlockbook.call(void 0, {
|
|
100
|
+
asAddress,
|
|
101
|
+
asResponse,
|
|
102
|
+
connectionUri,
|
|
103
|
+
engineEmitter,
|
|
104
|
+
log,
|
|
105
|
+
onQueueSpaceCB: async (
|
|
106
|
+
uri
|
|
107
|
+
) => {
|
|
108
|
+
const task = await onQueueSpaceCB(uri)
|
|
109
|
+
if (task == null || typeof task === 'boolean') return task
|
|
110
|
+
|
|
111
|
+
// Translate getAccountUtxo to blockchain.scripthash.listunspent:
|
|
112
|
+
if (task.method === 'getAccountUtxo') {
|
|
113
|
+
const params = task.params
|
|
114
|
+
const address =
|
|
115
|
+
asAddress != null ? asAddress(params.descriptor) : params.descriptor
|
|
116
|
+
const scriptHash = addressToScriptHash(address)
|
|
117
|
+
|
|
118
|
+
const deferred = new _Deferred2.default()
|
|
119
|
+
deferred.promise
|
|
120
|
+
.then((electrumUtxos) => {
|
|
121
|
+
const blockbookUtxos = electrumUtxos.map(
|
|
122
|
+
utxo => ({
|
|
123
|
+
txid: utxo.tx_hash,
|
|
124
|
+
vout: utxo.tx_pos,
|
|
125
|
+
value: utxo.value.toString(),
|
|
126
|
+
height: utxo.height
|
|
127
|
+
})
|
|
128
|
+
)
|
|
129
|
+
task.deferred.resolve(blockbookUtxos)
|
|
130
|
+
})
|
|
131
|
+
.catch((e) => {
|
|
132
|
+
task.deferred.reject(e)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
const translatedTask = {
|
|
136
|
+
..._electrumApi.listUnspentMessage.call(void 0, scriptHash),
|
|
137
|
+
deferred
|
|
138
|
+
}
|
|
139
|
+
return translatedTask
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Get Address Transactions:
|
|
143
|
+
if (task.method === 'getAccountInfo') {
|
|
144
|
+
const params = task.params
|
|
145
|
+
const address =
|
|
146
|
+
asAddress != null ? asAddress(params.descriptor) : params.descriptor
|
|
147
|
+
const scriptHash = addressToScriptHash(address)
|
|
148
|
+
|
|
149
|
+
const deferred = new _Deferred2.default()
|
|
150
|
+
deferred.promise
|
|
151
|
+
.then((electrumUtxos) => {
|
|
152
|
+
const blockbookUtxos = {
|
|
153
|
+
address, // unused
|
|
154
|
+
balance: '0', // unused
|
|
155
|
+
totalReceived: '0', // unused
|
|
156
|
+
totalSent: '0', // unused
|
|
157
|
+
txs: electrumUtxos.length,
|
|
158
|
+
unconfirmedBalance: '0', // unused
|
|
159
|
+
unconfirmedTxs: electrumUtxos.reduce(
|
|
160
|
+
(sum, tx) => (sum + tx.height >= 0 ? 1 : 0),
|
|
161
|
+
0
|
|
162
|
+
),
|
|
163
|
+
txids: [], // unused
|
|
164
|
+
transactions: [], // TODO: this requires an extra query per txid
|
|
165
|
+
page: 0, // unused
|
|
166
|
+
totalPages: 1,
|
|
167
|
+
itemsOnPage: 0 // unused
|
|
168
|
+
}
|
|
169
|
+
task.deferred.resolve(blockbookUtxos)
|
|
170
|
+
})
|
|
171
|
+
.catch((e) => {
|
|
172
|
+
task.deferred.reject(e)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
const translatedTask = {
|
|
176
|
+
..._electrumApi.addressTransactionsMessage.call(void 0, scriptHash),
|
|
177
|
+
deferred
|
|
178
|
+
}
|
|
179
|
+
return translatedTask
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Skip unsupported task and continue with the next one:
|
|
183
|
+
return true
|
|
184
|
+
},
|
|
185
|
+
ping: async () => {
|
|
186
|
+
return await instance.promisifyWsMessage(_electrumApi.pingMessage.call(void 0, ))
|
|
187
|
+
},
|
|
188
|
+
socketEmitter,
|
|
189
|
+
walletId
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
instance.broadcastTx = async () => {
|
|
193
|
+
throw new Error('broadcastTx not supported for Electrum connections')
|
|
194
|
+
}
|
|
195
|
+
instance.fetchAddress = async () => {
|
|
196
|
+
throw new Error('fetchAddress not supported for Electrum connections')
|
|
197
|
+
}
|
|
198
|
+
instance.fetchAddressUtxos = async () => {
|
|
199
|
+
throw new Error('fetchAddressUtxos not supported for Electrum connections')
|
|
200
|
+
}
|
|
201
|
+
instance.fetchInfo = async () => {
|
|
202
|
+
throw new Error('fetchInfo not supported for Electrum connections')
|
|
203
|
+
}
|
|
204
|
+
instance.fetchTransaction = async () => {
|
|
205
|
+
throw new Error('fetchTransaction not supported for Electrum connections')
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
instance.watchAddresses = async () => {
|
|
209
|
+
return // Fail gracefully
|
|
210
|
+
}
|
|
211
|
+
instance.watchBlocks = async () => {
|
|
212
|
+
return // Fail gracefully
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return instance
|
|
216
|
+
} exports.makeBlockbookElectrum = makeBlockbookElectrum;
|