edge-currency-plugins 1.0.0-rc.5 → 1.1.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.
@@ -1,4 +1,6 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }
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(); } } 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 _altcoinjs = require('altcoin-js');
2
+ var _bnjs = require('bn.js'); var _bnjs2 = _interopRequireDefault(_bnjs);
3
+
2
4
 
3
5
 
4
6
 
@@ -56,12 +58,11 @@ var _keymanager = require('../../keymanager/keymanager');
56
58
 
57
59
 
58
60
 
59
-
60
61
  const toEdgeTransaction = async (
61
62
  args
62
63
  ) => {
63
- const { tx, processor, walletTools, engineInfo } = args
64
-
64
+ const { tx, processor, walletTools, pluginInfo } = args
65
+ const { engineInfo, currencyInfo } = pluginInfo
65
66
  const ourReceiveAddresses = []
66
67
  for (const out of tx.ourOuts) {
67
68
  const { scriptPubkey } = tx.outputs[parseInt(out)]
@@ -95,14 +96,32 @@ var _keymanager = require('../../keymanager/keymanager');
95
96
  }
96
97
  }
97
98
 
99
+ const feeRes = {}
100
+
101
+ try {
102
+ const altcoinTx = _altcoinjs.Transaction.fromHex(tx.hex)
103
+ const vBytes = altcoinTx.virtualSize()
104
+ // feeRate must be of a number type (limited to 53 bits)
105
+ const feeRate = new (0, _bnjs2.default)(tx.fees, 10)
106
+ .div(new (0, _bnjs2.default)(vBytes, 10))
107
+ .toNumber()
108
+ Object.assign(feeRes, {
109
+ feeRateUsed: {
110
+ // GUI repo uses satPerVByte rather than satPerByte defined in customFeeTemplate
111
+ satPerVByte: feeRate
112
+ }
113
+ })
114
+ } catch (e) {}
115
+
98
116
  return {
99
- currencyCode: args.currencyCode,
100
- txid: args.tx.txid,
101
- blockHeight: args.tx.blockHeight,
102
- date: args.tx.date,
103
- nativeAmount: args.tx.ourAmount,
104
- networkFee: args.tx.fees,
105
- signedTx: args.tx.hex,
106
- ourReceiveAddresses
117
+ currencyCode: currencyInfo.currencyCode,
118
+ txid: tx.txid,
119
+ blockHeight: tx.blockHeight,
120
+ date: tx.date,
121
+ nativeAmount: tx.ourAmount,
122
+ networkFee: tx.fees,
123
+ signedTx: tx.hex,
124
+ ourReceiveAddresses,
125
+ ...feeRes
107
126
  }
108
127
  }; exports.toEdgeTransaction = toEdgeTransaction
@@ -253,10 +253,9 @@ var _utils = require('./utils');
253
253
  async (tx) =>
254
254
  await _ProcessorTransaction.toEdgeTransaction.call(void 0, {
255
255
  tx,
256
- currencyCode: currencyInfo.currencyCode,
257
256
  walletTools,
258
257
  processor,
259
- engineInfo
258
+ pluginInfo
260
259
  })
261
260
  )
262
261
  )
@@ -450,7 +450,7 @@ var _utils3 = require('./utils');
450
450
  const utxoMap = new Map()
451
451
  for (const utxo of utxos) {
452
452
  const utxoSet = _nullishCoalesce(utxoMap.get(utxo.scriptPubkey), () => ( new Set()))
453
- if (utxoMap.has(utxo.scriptPubkey) == null)
453
+ if (!utxoMap.has(utxo.scriptPubkey))
454
454
  utxoMap.set(utxo.scriptPubkey, utxoSet)
455
455
  utxoSet.add(utxo)
456
456
  }
@@ -647,20 +647,13 @@ const addToAddressTransactionCache = async (
647
647
  const transactionChanged = async (
648
648
  args
649
649
  ) => {
650
- const {
651
- emitter,
652
- walletTools,
653
- processor,
654
- pluginInfo: { currencyInfo, engineInfo },
655
- tx
656
- } = args
650
+ const { emitter, walletTools, processor, pluginInfo, tx } = args
657
651
  emitter.emit(_makeEngineEmitter.EngineEvent.TRANSACTIONS_CHANGED, [
658
652
  await _ProcessorTransaction.toEdgeTransaction.call(void 0, {
659
653
  tx,
660
- currencyCode: currencyInfo.currencyCode,
661
654
  walletTools,
662
655
  processor,
663
- engineInfo
656
+ pluginInfo
664
657
  })
665
658
  ])
666
659
  }; exports.transactionChanged = transactionChanged
@@ -52,7 +52,7 @@ const currencyInfo = {
52
52
 
53
53
  const engineInfo = {
54
54
  formats: ['bip44', 'bip32'],
55
- forks: ['bitcoinsv'],
55
+ // forks: ['bitcoinsv'],
56
56
  gapLimit: 10,
57
57
  defaultFee: 10000,
58
58
  feeUpdateInterval: 60000,
@@ -41,9 +41,9 @@ const currencyInfo = {
41
41
  metaTokens: [],
42
42
 
43
43
  // Explorers:
44
- blockExplorer: 'https://blockchair.com/bitcoin-sv/block/%s',
45
- addressExplorer: 'https://blockchair.com/bitcoin-sv/address/%s',
46
- transactionExplorer: 'https://blockchair.com/bitcoin-sv/transaction/%s',
44
+ blockExplorer: 'https://whatsonchain.com/block/%s',
45
+ addressExplorer: 'https://whatsonchain.com/address/%s',
46
+ transactionExplorer: 'https://whatsonchain.com/tx/%s',
47
47
 
48
48
  // Images:
49
49
  symbolImage: `${_constants.IMAGE_SERVER_URL}/bitcoinsv-logo-solo-64.png`,
@@ -47,6 +47,6 @@ var _utils = require('./utils'); var utils = _interopRequireWildcard(_utils);
47
47
 
48
48
  return {
49
49
  changeUsed: false,
50
- fee: feeRate * utils.transactionBytes(inputs, outputs)
50
+ fee: Math.ceil(feeRate * utils.transactionBytes(inputs, outputs))
51
51
  }
52
52
  } exports.accumulative = accumulative;
@@ -54,6 +54,6 @@ var _utils = require('./utils'); var utils = _interopRequireWildcard(_utils);
54
54
 
55
55
  return {
56
56
  changeUsed: false,
57
- fee: feeRate * utils.transactionBytes(inputs, outputs)
57
+ fee: Math.ceil(feeRate * utils.transactionBytes(inputs, outputs))
58
58
  }
59
59
  } exports.forceUseUtxo = forceUseUtxo;
@@ -10,7 +10,7 @@ var _utils = require('./utils'); var utils = _interopRequireWildcard(_utils);
10
10
  scriptPubkey: Buffer.from(target.script, 'hex')
11
11
  }))
12
12
 
13
- const fee = feeRate * utils.transactionBytes(utxos, outputs)
13
+ const fee = Math.ceil(feeRate * utils.transactionBytes(utxos, outputs))
14
14
  targets[0].value -= fee
15
15
  outputs[0].value -= fee
16
16
  return { inputs: utxos, outputs, fee, changeUsed: false }
@@ -275,7 +275,12 @@ const WAKE_UP_MS = 5000 // interval at which we wakeUp and potentially onQueueSp
275
275
  if (!subscription.subscribed) {
276
276
  subscription.deferred.reject()
277
277
  }
278
- subscription.cb(subscription.cleaner(json.data))
278
+ try {
279
+ subscription.cb(subscription.cleaner(json.data))
280
+ } catch (error) {
281
+ console.log({ uri, error, json, subscription })
282
+ throw error
283
+ }
279
284
  return
280
285
  }
281
286
  }
@@ -296,9 +301,9 @@ const WAKE_UP_MS = 5000 // interval at which we wakeUp and potentially onQueueSp
296
301
  } else {
297
302
  message.task.deferred.resolve(json.data)
298
303
  }
299
- } catch (e) {
300
- if (e instanceof TypeError) console.log({ json, message })
301
- message.task.deferred.reject(e)
304
+ } catch (error) {
305
+ console.log({ uri, error, json, message })
306
+ message.task.deferred.reject(error)
302
307
  }
303
308
  }
304
309
  } catch (e) {
@@ -1,15 +1,14 @@
1
1
  import { EdgeTransaction } from 'edge-core-js/types';
2
- import { EngineInfo } from '../../../plugin/types';
2
+ import { PluginInfo } from '../../../plugin/types';
3
3
  import { UTXOPluginWalletTools } from '../../engine/makeUtxoWalletTools';
4
4
  import { Processor } from '../makeProcessor';
5
5
  import { IProcessorTransaction } from '../types';
6
6
  export declare const fromEdgeTransaction: (tx: EdgeTransaction) => IProcessorTransaction;
7
7
  interface ToEdgeTransactionArgs {
8
8
  tx: IProcessorTransaction;
9
- currencyCode: string;
10
9
  walletTools: UTXOPluginWalletTools;
11
10
  processor: Processor;
12
- engineInfo: EngineInfo;
11
+ pluginInfo: PluginInfo;
13
12
  }
14
13
  export declare const toEdgeTransaction: (args: ToEdgeTransactionArgs) => Promise<EdgeTransaction>;
15
14
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-plugins",
3
- "version": "1.0.0-rc.5",
3
+ "version": "1.1.0",
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",
@@ -48,7 +48,7 @@
48
48
  "bs58smartcheck": "^2.0.4",
49
49
  "cleaners": "^0.3.12",
50
50
  "disklet": "^0.4.5",
51
- "edge-core-js": "^0.19.19",
51
+ "edge-core-js": "^0.19.20",
52
52
  "memlet": "^0.1.6",
53
53
  "uri-js": "^4.4.0",
54
54
  "url-parse": "^1.5.2",