edge-currency-plugins 1.1.3 → 1.1.6
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,5 @@
|
|
|
1
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(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await 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 _biggystring = require('biggystring');
|
|
2
|
+
var _cleaners = require('cleaners');
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
|
|
@@ -1109,6 +1110,42 @@ const processTransactionResponse = (
|
|
|
1109
1110
|
txResponse,
|
|
1110
1111
|
pluginInfo: { coinInfo }
|
|
1111
1112
|
} = args
|
|
1113
|
+
const inputs = txResponse.vin.map(vin => {
|
|
1114
|
+
const scriptPubkey =
|
|
1115
|
+
// Note: Blockbook has empirically not sent a hex value as the
|
|
1116
|
+
// scriptPubkey for vins. If we discover this to be changed for some
|
|
1117
|
+
// cases, we may want to use the `hex` field as an optimization.
|
|
1118
|
+
_cleaners.asMaybe.call(void 0,
|
|
1119
|
+
raw => _utils3.validScriptPubkeyFromAddress.call(void 0, raw),
|
|
1120
|
+
'unknown'
|
|
1121
|
+
)({
|
|
1122
|
+
address: vin.addresses[0],
|
|
1123
|
+
coin: coinInfo.name
|
|
1124
|
+
})
|
|
1125
|
+
return {
|
|
1126
|
+
txId: vin.txid,
|
|
1127
|
+
outputIndex: vin.vout, // case for tx `fefac8c22ba1178df5d7c90b78cc1c203d1a9f5f5506f7b8f6f469fa821c2674` no `vout` for input
|
|
1128
|
+
n: vin.n,
|
|
1129
|
+
scriptPubkey,
|
|
1130
|
+
amount: vin.value
|
|
1131
|
+
}
|
|
1132
|
+
})
|
|
1133
|
+
const outputs = txResponse.vout.map(vout => {
|
|
1134
|
+
const scriptPubkey =
|
|
1135
|
+
_nullishCoalesce(vout.hex, () => (
|
|
1136
|
+
_cleaners.asMaybe.call(void 0,
|
|
1137
|
+
raw => _utils3.validScriptPubkeyFromAddress.call(void 0, raw),
|
|
1138
|
+
'unknown'
|
|
1139
|
+
)({
|
|
1140
|
+
address: vout.addresses[0],
|
|
1141
|
+
coin: coinInfo.name
|
|
1142
|
+
})))
|
|
1143
|
+
return {
|
|
1144
|
+
n: vout.n,
|
|
1145
|
+
scriptPubkey,
|
|
1146
|
+
amount: vout.value
|
|
1147
|
+
}
|
|
1148
|
+
})
|
|
1112
1149
|
return {
|
|
1113
1150
|
txid: txResponse.txid,
|
|
1114
1151
|
hex: txResponse.hex,
|
|
@@ -1116,26 +1153,8 @@ const processTransactionResponse = (
|
|
|
1116
1153
|
blockHeight: txResponse.blockHeight > 0 ? txResponse.blockHeight : 0,
|
|
1117
1154
|
date: txResponse.blockTime,
|
|
1118
1155
|
fees: txResponse.fees,
|
|
1119
|
-
inputs
|
|
1120
|
-
|
|
1121
|
-
outputIndex: input.vout, // case for tx `fefac8c22ba1178df5d7c90b78cc1c203d1a9f5f5506f7b8f6f469fa821c2674` no `vout` for input
|
|
1122
|
-
n: input.n,
|
|
1123
|
-
scriptPubkey: _utils3.validScriptPubkeyFromAddress.call(void 0, {
|
|
1124
|
-
address: input.addresses[0],
|
|
1125
|
-
coin: coinInfo.name
|
|
1126
|
-
}),
|
|
1127
|
-
amount: input.value
|
|
1128
|
-
})),
|
|
1129
|
-
outputs: txResponse.vout.map(output => ({
|
|
1130
|
-
n: output.n,
|
|
1131
|
-
scriptPubkey:
|
|
1132
|
-
_nullishCoalesce(output.hex, () => (
|
|
1133
|
-
_utils3.validScriptPubkeyFromAddress.call(void 0, {
|
|
1134
|
-
address: output.addresses[0],
|
|
1135
|
-
coin: coinInfo.name
|
|
1136
|
-
}))),
|
|
1137
|
-
amount: output.value
|
|
1138
|
-
})),
|
|
1156
|
+
inputs,
|
|
1157
|
+
outputs,
|
|
1139
1158
|
ourIns: [],
|
|
1140
1159
|
ourOuts: [],
|
|
1141
1160
|
ourAmount: '0'
|
|
@@ -1244,25 +1263,10 @@ const processProcessorUtxos = async (
|
|
|
1244
1263
|
oldBalance = _biggystring.add.call(void 0, utxo.value, oldBalance)
|
|
1245
1264
|
}
|
|
1246
1265
|
|
|
1247
|
-
// If the UTXO isn't present in the update UTXO set, then it is spent.
|
|
1266
|
+
// If the UTXO isn't present in the update UTXO set, then it is spent or dropped.
|
|
1267
|
+
// Remove it from the database if so
|
|
1248
1268
|
if (updatedUtxos[utxo.id] == null) {
|
|
1249
|
-
|
|
1250
|
-
// Delete the UTXO from the database if it's spent and confirmed
|
|
1251
|
-
utxoIdsToRemove.push(utxo.id)
|
|
1252
|
-
} else {
|
|
1253
|
-
// Otherwise just mark it as spent.
|
|
1254
|
-
updatedUtxos[utxo.id] = { ...utxo, spent: true }
|
|
1255
|
-
}
|
|
1256
|
-
} else {
|
|
1257
|
-
/*
|
|
1258
|
-
If the UTXO is present in the updated UTXO set, enforce that the UTXO
|
|
1259
|
-
remains spent in the new UTXO set. This means, we will never mark a UTXO
|
|
1260
|
-
as unspent again. UTXOs only become unspent again if the tx is dropped
|
|
1261
|
-
which shall be affected by another routine.
|
|
1262
|
-
*/
|
|
1263
|
-
// TODO: To fix this logic for dropped-tx, add a condition which uses the
|
|
1264
|
-
// network's block-height to determine whether to set it back as unspend
|
|
1265
|
-
updatedUtxos[utxo.id].spent = utxo.spent || updatedUtxos[utxo.id].spent
|
|
1269
|
+
utxoIdsToRemove.push(utxo.id)
|
|
1266
1270
|
}
|
|
1267
1271
|
}
|
|
1268
1272
|
|
|
@@ -232,6 +232,7 @@ var VerifyAddressEnum; (function (VerifyAddressEnum) {
|
|
|
232
232
|
|
|
233
233
|
|
|
234
234
|
|
|
235
|
+
|
|
235
236
|
|
|
236
237
|
|
|
237
238
|
function bip43PurposeNumberToTypeEnum(
|
|
@@ -828,6 +829,7 @@ const wifToPrivateKeyInternal = (
|
|
|
828
829
|
} exports.signMessageBase64 = signMessageBase64;
|
|
829
830
|
|
|
830
831
|
function makeTx(args) {
|
|
832
|
+
const { log } = args
|
|
831
833
|
let sequence = 0xffffffff
|
|
832
834
|
if (args.setRBF) {
|
|
833
835
|
sequence -= 2
|
|
@@ -918,7 +920,7 @@ const wifToPrivateKeyInternal = (
|
|
|
918
920
|
})
|
|
919
921
|
}
|
|
920
922
|
|
|
921
|
-
if (target.memo != null) {
|
|
923
|
+
if (target.memo != null && target.memo !== '') {
|
|
922
924
|
const memoHex = Buffer.from(target.memo, 'utf8').toString('hex')
|
|
923
925
|
// check if hex string is within 80 bytes
|
|
924
926
|
const validatedMemo = _utils.validateMemo.call(void 0, memoHex)
|
|
@@ -963,8 +965,13 @@ const wifToPrivateKeyInternal = (
|
|
|
963
965
|
const sortedOutputs = _bip69.sortOutputs.call(void 0, result.outputs)
|
|
964
966
|
|
|
965
967
|
const psbt = new bitcoin.Psbt()
|
|
966
|
-
|
|
967
|
-
|
|
968
|
+
try {
|
|
969
|
+
psbt.addInputs(sortedInputs)
|
|
970
|
+
psbt.addOutputs(sortedOutputs)
|
|
971
|
+
} catch (error) {
|
|
972
|
+
_optionalChain([log, 'optionalAccess', _16 => _16.error, 'call', _17 => _17(`Failed makeTx: ${String(error)}`)])
|
|
973
|
+
throw error
|
|
974
|
+
}
|
|
968
975
|
|
|
969
976
|
return {
|
|
970
977
|
inputs: sortedInputs,
|
|
@@ -972,7 +979,7 @@ const wifToPrivateKeyInternal = (
|
|
|
972
979
|
changeUsed: result.changeUsed,
|
|
973
980
|
fee: result.fee,
|
|
974
981
|
psbtBase64: psbt.toBase64(),
|
|
975
|
-
hex: _optionalChain([psbt, 'access',
|
|
982
|
+
hex: _optionalChain([psbt, 'access', _18 => _18.data, 'optionalAccess', _19 => _19.globalMap, 'optionalAccess', _20 => _20.unsignedTx, 'optionalAccess', _21 => _21.toBuffer, 'call', _22 => _22(), 'optionalAccess', _23 => _23.toString, 'call', _24 => _24('hex')])
|
|
976
983
|
}
|
|
977
984
|
} exports.makeTx = makeTx;
|
|
978
985
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EdgeLog } from 'edge-core-js/types';
|
|
1
2
|
import { AddressPath } from '../../plugin/types';
|
|
2
3
|
import { IUTXO } from '../db/types';
|
|
3
4
|
import { ScriptTemplate } from '../info/scriptTemplates/types';
|
|
@@ -131,6 +132,7 @@ export interface MakeTxArgs {
|
|
|
131
132
|
currencyCode: string;
|
|
132
133
|
freshChangeAddress: string;
|
|
133
134
|
subtractFee?: boolean;
|
|
135
|
+
log?: EdgeLog;
|
|
134
136
|
}
|
|
135
137
|
export interface MakeTxTarget {
|
|
136
138
|
address?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edge-currency-plugins",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
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",
|