bitcore-node
Advanced tools
Comparing version 10.0.25 to 10.0.26
@@ -496,4 +496,5 @@ "use strict"; | ||
return [2 /*return*/, Promise.all([ | ||
this.transactionModel.collection.deleteMany({ chain: chain, network: network, txid: { $in: txids }, blockHeight: -1 }), | ||
this.coinModel.collection.deleteMany({ chain: chain, network: network, mintTxid: { $in: txids }, mintHeight: -1 }) | ||
this.transactionModel.collection.deleteMany({ chain: chain, network: network, txid: { $in: txids }, blockHeight: -1 /* SpentHeightIndicators.pending */ }), | ||
this.coinModel.collection.deleteMany({ chain: chain, network: network, mintTxid: { $in: txids }, mintHeight: -1 /* SpentHeightIndicators.pending */ }), | ||
this.coinModel.collection.updateMany({ chain: chain, network: network, spentTxid: { $in: txids }, spentHeight: -1 /* SpentHeightIndicators.pending */ }, { $set: { spentTxid: null, spentHeight: -2 /* SpentHeightIndicators.unspent */ } }) | ||
])]; | ||
@@ -500,0 +501,0 @@ }); |
@@ -133,3 +133,3 @@ "use strict"; | ||
}; | ||
var oldMempoolCoin = { | ||
var oldMempoolTxOutput = { | ||
chain: 'BTC', | ||
@@ -141,3 +141,3 @@ network: 'mainnet', | ||
}; | ||
var oldMempoolCoin2 = { | ||
var oldMempoolTx2Output = { | ||
chain: 'BTC', | ||
@@ -149,2 +149,18 @@ network: 'mainnet', | ||
}; | ||
var parentTxOutput1 = { | ||
chain: 'BTC', | ||
network: 'mainnet', | ||
mintHeight: 1234, | ||
mintTxid: 'parentTx', | ||
spentHeight: -1, | ||
spentTxid: 'oldMempoolTx' // this output is an input for oldMempoolTx | ||
}; | ||
var parentTxOutput2 = { | ||
chain: 'BTC', | ||
network: 'mainnet', | ||
mintHeight: 1234, | ||
mintTxid: 'parentTx', | ||
spentHeight: -1, | ||
spentTxid: 'imaginaryTx' // another imaginary tx spent this output. This is here to make sure we don't mark this output as unspent | ||
}; | ||
function modTxid(orig, i) { | ||
@@ -179,11 +195,17 @@ return orig + (i ? '_' + i : ''); | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, transaction_1.TransactionStorage.collection.insertOne(__assign(__assign({}, oldMempoolTx), { txid: modTxid(oldMempoolTx.txid, i) }))]; | ||
case 0: return [4 /*yield*/, coin_1.CoinStorage.collection.insertOne(__assign(__assign({}, parentTxOutput1), { spentTxid: modTxid(parentTxOutput1.spentTxid, i) }))]; | ||
case 1: | ||
_a.sent(); | ||
return [4 /*yield*/, coin_1.CoinStorage.collection.insertOne(__assign(__assign({}, oldMempoolCoin), { mintTxid: modTxid(oldMempoolCoin.mintTxid, i), spentTxid: modTxid(oldMempoolCoin.spentTxid, i) }))]; | ||
return [4 /*yield*/, coin_1.CoinStorage.collection.insertOne(__assign(__assign({}, parentTxOutput2), { spentTxid: modTxid(parentTxOutput2.spentTxid, i) }))]; | ||
case 2: | ||
_a.sent(); | ||
return [4 /*yield*/, coin_1.CoinStorage.collection.insertOne(__assign(__assign({}, oldMempoolCoin2), { mintTxid: modTxid(oldMempoolCoin2.mintTxid, i) }))]; | ||
return [4 /*yield*/, transaction_1.TransactionStorage.collection.insertOne(__assign(__assign({}, oldMempoolTx), { txid: modTxid(oldMempoolTx.txid, i) }))]; | ||
case 3: | ||
_a.sent(); | ||
return [4 /*yield*/, coin_1.CoinStorage.collection.insertOne(__assign(__assign({}, oldMempoolTxOutput), { mintTxid: modTxid(oldMempoolTxOutput.mintTxid, i), spentTxid: modTxid(oldMempoolTxOutput.spentTxid, i) }))]; | ||
case 4: | ||
_a.sent(); | ||
return [4 /*yield*/, coin_1.CoinStorage.collection.insertOne(__assign(__assign({}, oldMempoolTx2Output), { mintTxid: modTxid(oldMempoolTx2Output.mintTxid, i) }))]; | ||
case 5: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
@@ -265,3 +287,3 @@ } | ||
it('should remove old transactions', function () { return __awaiter(_this, void 0, void 0, function () { | ||
var chain, network, count, shouldBeGoneTx, shouldBeGoneCoins; | ||
var chain, network, count, shouldBeGoneTx, shouldBeGoneCoins, parentTxOutputs; | ||
return __generator(this, function (_a) { | ||
@@ -293,8 +315,15 @@ switch (_a.label) { | ||
return [4 /*yield*/, coin_1.CoinStorage.collection | ||
.find({ chain: chain, network: network, mintTxid: { $in: [oldMempoolCoin.mintTxid, oldMempoolCoin2.mintTxid] } }) | ||
.find({ chain: chain, network: network, mintTxid: { $in: [oldMempoolTxOutput.mintTxid, oldMempoolTx2Output.mintTxid] } }) | ||
.toArray()]; | ||
case 5: | ||
shouldBeGoneCoins = _a.sent(); | ||
return [4 /*yield*/, coin_1.CoinStorage.collection | ||
.find({ chain: chain, network: network, mintTxid: parentTxOutput1.mintTxid }) | ||
.toArray()]; | ||
case 6: | ||
parentTxOutputs = _a.sent(); | ||
(0, chai_1.expect)(shouldBeGoneTx.length).eq(0); | ||
(0, chai_1.expect)(shouldBeGoneCoins.length).eq(0); | ||
(0, chai_1.expect)(parentTxOutputs.length).eq(2); | ||
(0, chai_1.expect)(parentTxOutputs.filter(function (coin) { return coin.spentHeight === -2; }).length).to.equal(1); | ||
return [2 /*return*/]; | ||
@@ -341,3 +370,3 @@ } | ||
return [4 /*yield*/, coin_1.CoinStorage.collection | ||
.find({ chain: chain, network: network, mintTxid: { $in: [modTxid(oldMempoolCoin.mintTxid, 0), modTxid(oldMempoolCoin2.mintTxid, 0), modTxid(oldMempoolCoin.mintTxid, 1), modTxid(oldMempoolCoin2.mintTxid, 1), modTxid(oldMempoolCoin.mintTxid, 2), modTxid(oldMempoolCoin2.mintTxid, 2)] } }) | ||
.find({ chain: chain, network: network, mintTxid: { $in: [modTxid(oldMempoolTxOutput.mintTxid, 0), modTxid(oldMempoolTx2Output.mintTxid, 0), modTxid(oldMempoolTxOutput.mintTxid, 1), modTxid(oldMempoolTx2Output.mintTxid, 1), modTxid(oldMempoolTxOutput.mintTxid, 2), modTxid(oldMempoolTx2Output.mintTxid, 2)] } }) | ||
.toArray()]; | ||
@@ -381,3 +410,3 @@ case 7: | ||
return [4 /*yield*/, coin_1.CoinStorage.collection | ||
.find({ chain: chain, network: network, mintTxid: { $in: [oldMempoolCoin.mintTxid, oldMempoolCoin2.mintTxid] } }) | ||
.find({ chain: chain, network: network, mintTxid: { $in: [oldMempoolTxOutput.mintTxid, oldMempoolTx2Output.mintTxid] } }) | ||
.toArray()]; | ||
@@ -393,3 +422,3 @@ case 5: | ||
it('should skip removing transactions if coin has >0 confs', function () { return __awaiter(_this, void 0, void 0, function () { | ||
var rpcStub, oldMempoolCoin2Height, chain, network, count, shouldBeGoneTx, shouldBeGoneCoins; | ||
var rpcStub, oldMempoolTx2OutputHeight, chain, network, count, shouldBeGoneTx, shouldBeGoneCoins; | ||
return __generator(this, function (_a) { | ||
@@ -400,8 +429,8 @@ switch (_a.label) { | ||
rpcStub.onCall(0).rejects({ code: -5, message: 'already exists' }); | ||
oldMempoolCoin2Height = oldMempoolCoin2.mintHeight; | ||
oldMempoolCoin2.mintHeight = 1; | ||
oldMempoolTx2OutputHeight = oldMempoolTx2Output.mintHeight; | ||
oldMempoolTx2Output.mintHeight = 1; | ||
return [4 /*yield*/, insertOldTx()]; | ||
case 1: | ||
_a.sent(); | ||
oldMempoolCoin2.mintHeight = oldMempoolCoin2Height; // reset | ||
oldMempoolTx2Output.mintHeight = oldMempoolTx2OutputHeight; // reset | ||
chain = oldMempoolTx.chain, network = oldMempoolTx.network; | ||
@@ -426,3 +455,3 @@ return [4 /*yield*/, transaction_1.TransactionStorage.collection.countDocuments({ | ||
return [4 /*yield*/, coin_1.CoinStorage.collection | ||
.find({ chain: chain, network: network, mintTxid: { $in: [oldMempoolCoin.mintTxid, oldMempoolCoin2.mintTxid] } }) | ||
.find({ chain: chain, network: network, mintTxid: { $in: [oldMempoolTxOutput.mintTxid, oldMempoolTx2Output.mintTxid] } }) | ||
.toArray()]; | ||
@@ -429,0 +458,0 @@ case 5: |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "10.0.25", | ||
"version": "10.0.26", | ||
"author": "Justin Langston <nitsujlangston@gmail.com>", | ||
@@ -102,3 +102,3 @@ "contributors": [ | ||
"bitcore-p2p-doge": "^10.0.21", | ||
"bitcore-wallet-client": "^10.0.24", | ||
"bitcore-wallet-client": "^10.0.26", | ||
"body-parser": "1.18.3", | ||
@@ -122,3 +122,3 @@ "cors": "2.8.4", | ||
}, | ||
"gitHead": "8ecf3f81146163bc065f79f803117b51eb6395c6" | ||
"gitHead": "090a156b91bb62f3a77f951fcae227e5b08d7277" | ||
} |
@@ -259,4 +259,8 @@ import { Transform } from 'stream'; | ||
return Promise.all([ | ||
this.transactionModel.collection.deleteMany({ chain, network, txid: { $in: txids }, blockHeight: -1 }), | ||
this.coinModel.collection.deleteMany({ chain, network, mintTxid: { $in: txids }, mintHeight: -1 }) | ||
this.transactionModel.collection.deleteMany({ chain, network, txid: { $in: txids }, blockHeight: SpentHeightIndicators.pending }), | ||
this.coinModel.collection.deleteMany({ chain, network, mintTxid: { $in: txids }, mintHeight: SpentHeightIndicators.pending }), | ||
this.coinModel.collection.updateMany( | ||
{ chain, network, spentTxid: { $in: txids }, spentHeight: SpentHeightIndicators.pending }, | ||
{ $set: { spentTxid: null, spentHeight: SpentHeightIndicators.unspent } } | ||
) | ||
]); | ||
@@ -263,0 +267,0 @@ } |
@@ -68,3 +68,3 @@ import { expect } from 'chai'; | ||
const oldMempoolCoin = { | ||
const oldMempoolTxOutput = { | ||
chain: 'BTC', | ||
@@ -77,3 +77,3 @@ network: 'mainnet', | ||
const oldMempoolCoin2 = { | ||
const oldMempoolTx2Output = { // output that spends oldMempoolTxOutput | ||
chain: 'BTC', | ||
@@ -86,2 +86,20 @@ network: 'mainnet', | ||
const parentTxOutput1 = { | ||
chain: 'BTC', | ||
network: 'mainnet', | ||
mintHeight: 1234, | ||
mintTxid: 'parentTx', | ||
spentHeight: -1, | ||
spentTxid: 'oldMempoolTx' // this output is an input for oldMempoolTx | ||
} as ICoin; | ||
const parentTxOutput2 = { | ||
chain: 'BTC', | ||
network: 'mainnet', | ||
mintHeight: 1234, | ||
mintTxid: 'parentTx', | ||
spentHeight: -1, | ||
spentTxid: 'imaginaryTx' // another imaginary tx spent this output. This is here to make sure we don't mark this output as unspent | ||
} as ICoin; | ||
function modTxid(orig, i) { | ||
@@ -101,5 +119,7 @@ return orig + (i ? '_' + i : ''); | ||
async function insertOldTx(i: any = 0) { | ||
await CoinStorage.collection.insertOne({ ...parentTxOutput1, spentTxid: modTxid(parentTxOutput1.spentTxid, i) }); | ||
await CoinStorage.collection.insertOne({ ...parentTxOutput2, spentTxid: modTxid(parentTxOutput2.spentTxid, i) }); | ||
await TransactionStorage.collection.insertOne({ ...oldMempoolTx, txid: modTxid(oldMempoolTx.txid, i) }); | ||
await CoinStorage.collection.insertOne({ ...oldMempoolCoin, mintTxid: modTxid(oldMempoolCoin.mintTxid, i), spentTxid: modTxid(oldMempoolCoin.spentTxid, i) }); | ||
await CoinStorage.collection.insertOne({ ...oldMempoolCoin2, mintTxid: modTxid(oldMempoolCoin2.mintTxid, i) }); | ||
await CoinStorage.collection.insertOne({ ...oldMempoolTxOutput, mintTxid: modTxid(oldMempoolTxOutput.mintTxid, i), spentTxid: modTxid(oldMempoolTxOutput.spentTxid, i) }); | ||
await CoinStorage.collection.insertOne({ ...oldMempoolTx2Output, mintTxid: modTxid(oldMempoolTx2Output.mintTxid, i) }); | ||
} | ||
@@ -151,7 +171,12 @@ | ||
const shouldBeGoneCoins = await CoinStorage.collection | ||
.find({ chain, network, mintTxid: { $in: [oldMempoolCoin.mintTxid, oldMempoolCoin2.mintTxid] } }) | ||
.find({ chain, network, mintTxid: { $in: [oldMempoolTxOutput.mintTxid, oldMempoolTx2Output.mintTxid] } }) | ||
.toArray(); | ||
const parentTxOutputs = await CoinStorage.collection | ||
.find({ chain, network, mintTxid: parentTxOutput1.mintTxid }) | ||
.toArray(); | ||
expect(shouldBeGoneTx.length).eq(0); | ||
expect(shouldBeGoneCoins.length).eq(0); | ||
expect(parentTxOutputs.length).eq(2); | ||
expect(parentTxOutputs.filter(coin => coin.spentHeight === -2).length).to.equal(1); | ||
}); | ||
@@ -182,3 +207,3 @@ | ||
const shouldBeGoneCoins = await CoinStorage.collection | ||
.find({ chain, network, mintTxid: { $in: [modTxid(oldMempoolCoin.mintTxid, 0), modTxid(oldMempoolCoin2.mintTxid, 0), modTxid(oldMempoolCoin.mintTxid, 1), modTxid(oldMempoolCoin2.mintTxid, 1), modTxid(oldMempoolCoin.mintTxid, 2), modTxid(oldMempoolCoin2.mintTxid, 2)] } }) | ||
.find({ chain, network, mintTxid: { $in: [modTxid(oldMempoolTxOutput.mintTxid, 0), modTxid(oldMempoolTx2Output.mintTxid, 0), modTxid(oldMempoolTxOutput.mintTxid, 1), modTxid(oldMempoolTx2Output.mintTxid, 1), modTxid(oldMempoolTxOutput.mintTxid, 2), modTxid(oldMempoolTx2Output.mintTxid, 2)] } }) | ||
.toArray(); | ||
@@ -209,3 +234,3 @@ | ||
const shouldBeGoneCoins = await CoinStorage.collection | ||
.find({ chain, network, mintTxid: { $in: [oldMempoolCoin.mintTxid, oldMempoolCoin2.mintTxid] } }) | ||
.find({ chain, network, mintTxid: { $in: [oldMempoolTxOutput.mintTxid, oldMempoolTx2Output.mintTxid] } }) | ||
.toArray(); | ||
@@ -220,6 +245,6 @@ | ||
rpcStub.onCall(0).rejects({ code: -5, message: 'already exists' }); | ||
const oldMempoolCoin2Height = oldMempoolCoin2.mintHeight; | ||
oldMempoolCoin2.mintHeight = 1; | ||
const oldMempoolTx2OutputHeight = oldMempoolTx2Output.mintHeight; | ||
oldMempoolTx2Output.mintHeight = 1; | ||
await insertOldTx(); | ||
oldMempoolCoin2.mintHeight = oldMempoolCoin2Height; // reset | ||
oldMempoolTx2Output.mintHeight = oldMempoolTx2OutputHeight; // reset | ||
const { chain, network } = oldMempoolTx; | ||
@@ -240,3 +265,3 @@ | ||
const shouldBeGoneCoins = await CoinStorage.collection | ||
.find({ chain, network, mintTxid: { $in: [oldMempoolCoin.mintTxid, oldMempoolCoin2.mintTxid] } }) | ||
.find({ chain, network, mintTxid: { $in: [oldMempoolTxOutput.mintTxid, oldMempoolTx2Output.mintTxid] } }) | ||
.toArray(); | ||
@@ -243,0 +268,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
7605757
129743
4
+ Addedbitcore-client@10.0.36(transitive)
+ Addedbitcore-wallet-client@10.0.36(transitive)
+ Addedcrypto-wallet-core@10.0.36(transitive)
- Removedbitcore-client@10.0.37(transitive)
- Removedbitcore-wallet-client@10.0.37(transitive)
- Removedcrypto-wallet-core@10.0.37(transitive)