@liskhq/lisk-transaction-pool
Advanced tools
Comparing version 0.1.0-alpha.0 to 0.1.0-alpha.1
@@ -14,3 +14,3 @@ import { Transaction } from './transaction_pool'; | ||
enqueueOne(transaction: Transaction): void; | ||
exists(transaction: Transaction): boolean; | ||
exists(id: string): boolean; | ||
filter(condition: (transaction: Transaction) => boolean): ReadonlyArray<Transaction>; | ||
@@ -17,0 +17,0 @@ peekUntil(condition: (transaction: Transaction) => boolean): ReadonlyArray<Transaction>; |
@@ -25,3 +25,3 @@ "use strict"; | ||
return { | ||
affected: [transaction, ...affected], | ||
affected: [...affected, transaction], | ||
unaffected, | ||
@@ -48,4 +48,4 @@ conditionFailedOnce: false, | ||
} | ||
exists(transaction) { | ||
return !!this._index[transaction.id]; | ||
exists(id) { | ||
return !!this._index[id]; | ||
} | ||
@@ -65,3 +65,3 @@ filter(condition) { | ||
return { | ||
affected: [transaction, ...affected], | ||
affected: [...affected, transaction], | ||
unaffected, | ||
@@ -68,0 +68,0 @@ conditionFailedOnce: false, |
@@ -39,2 +39,3 @@ import { EventEmitter } from 'events'; | ||
readonly isFull: boolean; | ||
readonly queueName: QueueNames; | ||
} | ||
@@ -82,6 +83,7 @@ interface TransactionPoolDependencies { | ||
addTransaction(transaction: Transaction): AddTransactionResult; | ||
addPendingTransaction(transaction: Transaction): AddTransactionResult; | ||
addVerifiedTransaction(transaction: Transaction): AddTransactionResult; | ||
addVerifiedRemovedTransactions(transactions: ReadonlyArray<Transaction>): void; | ||
addVerifiedSignature(signatureObject: SignatureObject): TransactionResponse; | ||
existsInTransactionPool(transaction: Transaction): boolean; | ||
existsInTransactionPool(id: string): boolean; | ||
findInTransactionPool(id: string): Transaction | undefined; | ||
@@ -88,0 +90,0 @@ readonly queues: Queues; |
@@ -77,2 +77,6 @@ "use strict"; | ||
} | ||
addPendingTransaction(transaction) { | ||
const pendingQueue = 'pending'; | ||
return this.addTransactionToQueue(pendingQueue, transaction); | ||
} | ||
addVerifiedTransaction(transaction) { | ||
@@ -106,4 +110,4 @@ const verifiedQueue = 'verified'; | ||
} | ||
existsInTransactionPool(transaction) { | ||
return Object.keys(this._queues).reduce((previousValue, queueName) => previousValue || this._queues[queueName].exists(transaction), false); | ||
existsInTransactionPool(id) { | ||
return Object.keys(this._queues).reduce((previousValue, queueName) => previousValue || this._queues[queueName].exists(id), false); | ||
} | ||
@@ -156,6 +160,7 @@ findInTransactionPool(id) { | ||
addTransactionToQueue(queueName, transaction) { | ||
if (this.existsInTransactionPool(transaction)) { | ||
if (this.existsInTransactionPool(transaction.id)) { | ||
return { | ||
isFull: false, | ||
alreadyExists: true, | ||
queueName, | ||
}; | ||
@@ -167,2 +172,3 @@ } | ||
alreadyExists: false, | ||
queueName, | ||
}; | ||
@@ -180,2 +186,3 @@ } | ||
alreadyExists: false, | ||
queueName, | ||
}; | ||
@@ -182,0 +189,0 @@ } |
{ | ||
"name": "@liskhq/lisk-transaction-pool", | ||
"version": "0.1.0-alpha.0", | ||
"version": "0.1.0-alpha.1", | ||
"description": "Transaction pool library for use with Lisk-related software", | ||
@@ -5,0 +5,0 @@ "author": "Lisk Foundation <admin@lisk.io>, lightcurve GmbH <admin@lightcurve.io>", |
@@ -57,3 +57,3 @@ import { Transaction } from './transaction_pool'; | ||
return { | ||
affected: [transaction, ...affected], | ||
affected: [...affected, transaction], | ||
unaffected, | ||
@@ -88,4 +88,4 @@ conditionFailedOnce: false, | ||
public exists(transaction: Transaction): boolean { | ||
return !!this._index[transaction.id]; | ||
public exists(id: string): boolean { | ||
return !!this._index[id]; | ||
} | ||
@@ -117,3 +117,3 @@ | ||
return { | ||
affected: [transaction, ...affected], | ||
affected: [...affected, transaction], | ||
unaffected, | ||
@@ -120,0 +120,0 @@ conditionFailedOnce: false, |
@@ -70,2 +70,3 @@ /* | ||
readonly isFull: boolean; | ||
readonly queueName: QueueNames; | ||
} | ||
@@ -230,2 +231,8 @@ | ||
public addPendingTransaction(transaction: Transaction): AddTransactionResult { | ||
const pendingQueue: QueueNames = 'pending'; | ||
return this.addTransactionToQueue(pendingQueue, transaction); | ||
} | ||
public addVerifiedTransaction( | ||
@@ -292,6 +299,6 @@ transaction: Transaction, | ||
public existsInTransactionPool(transaction: Transaction): boolean { | ||
public existsInTransactionPool(id: string): boolean { | ||
return Object.keys(this._queues).reduce( | ||
(previousValue, queueName) => | ||
previousValue || this._queues[queueName].exists(transaction), | ||
previousValue || this._queues[queueName].exists(id), | ||
false, | ||
@@ -428,6 +435,7 @@ ); | ||
): AddTransactionResult { | ||
if (this.existsInTransactionPool(transaction)) { | ||
if (this.existsInTransactionPool(transaction.id)) { | ||
return { | ||
isFull: false, | ||
alreadyExists: true, | ||
queueName, | ||
}; | ||
@@ -440,2 +448,3 @@ } | ||
alreadyExists: false, | ||
queueName, | ||
}; | ||
@@ -457,2 +466,3 @@ } | ||
alreadyExists: false, | ||
queueName, | ||
}; | ||
@@ -459,0 +469,0 @@ } |
@@ -89,3 +89,3 @@ import { | ||
transactionsToValidate.forEach(transaction => { | ||
expect(transactionPool.queues.received.exists(transaction)).to.be | ||
expect(transactionPool.queues.received.exists(transaction.id)).to.be | ||
.false; | ||
@@ -99,3 +99,3 @@ }); | ||
validTransactions.forEach(transaction => { | ||
expect(transactionPool.queues.validated.exists(transaction)).to.be | ||
expect(transactionPool.queues.validated.exists(transaction.id)).to.be | ||
.true; | ||
@@ -112,3 +112,3 @@ }); | ||
invalidTransactions.forEach(transaction => { | ||
expect(transactionPool.existsInTransactionPool(transaction)).to.be | ||
expect(transactionPool.existsInTransactionPool(transaction.id)).to.be | ||
.false; | ||
@@ -139,4 +139,4 @@ }); | ||
transactionsToVerify.forEach(transaction => { | ||
expect(transactionPool.queues.validated.exists(transaction)).to.be | ||
.false; | ||
expect(transactionPool.queues.validated.exists(transaction.id)).to | ||
.be.false; | ||
}); | ||
@@ -149,3 +149,3 @@ }); | ||
verifiableTransactions.forEach(transaction => { | ||
expect(transactionPool.queues.verified.exists(transaction)).to.be | ||
expect(transactionPool.queues.verified.exists(transaction.id)).to.be | ||
.true; | ||
@@ -162,4 +162,4 @@ }); | ||
unverifiableTransactions.forEach(transaction => { | ||
expect(transactionPool.existsInTransactionPool(transaction)).to.be | ||
.false; | ||
expect(transactionPool.existsInTransactionPool(transaction.id)).to | ||
.be.false; | ||
}); | ||
@@ -189,4 +189,4 @@ }); | ||
transactionsToProcess.forEach(transaction => { | ||
expect(transactionPool.queues.verified.exists(transaction)).to.be | ||
.false; | ||
expect(transactionPool.queues.verified.exists(transaction.id)).to | ||
.be.false; | ||
}); | ||
@@ -199,3 +199,3 @@ }); | ||
processableTransactions.forEach(transaction => { | ||
expect(transactionPool.queues.ready.exists(transaction)).to.be | ||
expect(transactionPool.queues.ready.exists(transaction.id)).to.be | ||
.true; | ||
@@ -212,4 +212,4 @@ }); | ||
unprocessableTransactions.forEach(transaction => { | ||
expect(transactionPool.existsInTransactionPool(transaction)).to.be | ||
.false; | ||
expect(transactionPool.existsInTransactionPool(transaction.id)).to | ||
.be.false; | ||
}); | ||
@@ -229,3 +229,3 @@ }); | ||
transactionsInReadyQueue.forEach(transaction => { | ||
expect(transactionPool.queues.ready.exists(transaction)).to.be | ||
expect(transactionPool.queues.ready.exists(transaction.id)).to.be | ||
.true; | ||
@@ -232,0 +232,0 @@ }); |
@@ -140,4 +140,5 @@ import { | ||
transactionsToMoveToValidatedQueue.forEach(affectedTransaction => { | ||
expect(transactionPool.queues.validated.exists(affectedTransaction)) | ||
.to.be.true; | ||
expect( | ||
transactionPool.queues.validated.exists(affectedTransaction.id), | ||
).to.be.true; | ||
}); | ||
@@ -148,4 +149,4 @@ }); | ||
transactionsToMoveToReceivedQueue.forEach(affectedTransaction => { | ||
expect(transactionPool.queues.received.exists(affectedTransaction)).to | ||
.be.true; | ||
expect(transactionPool.queues.received.exists(affectedTransaction.id)) | ||
.to.be.true; | ||
}); | ||
@@ -157,7 +158,8 @@ }); | ||
transaction => | ||
expect(transactionPool.queues.ready.exists(transaction)).to.be.true, | ||
expect(transactionPool.queues.ready.exists(transaction.id)).to.be | ||
.true, | ||
); | ||
unaffectedTransactionsInVerifiedQueue.forEach( | ||
transaction => | ||
expect(transactionPool.queues.verified.exists(transaction)).to.be | ||
expect(transactionPool.queues.verified.exists(transaction.id)).to.be | ||
.true, | ||
@@ -167,3 +169,3 @@ ); | ||
transaction => | ||
expect(transactionPool.queues.pending.exists(transaction)).to.be | ||
expect(transactionPool.queues.pending.exists(transaction.id)).to.be | ||
.true, | ||
@@ -173,4 +175,4 @@ ); | ||
transaction => | ||
expect(transactionPool.queues.validated.exists(transaction)).to.be | ||
.true, | ||
expect(transactionPool.queues.validated.exists(transaction.id)).to | ||
.be.true, | ||
); | ||
@@ -182,3 +184,3 @@ }); | ||
transaction => | ||
expect(transactionPool.queues.verified.exists(transaction)).to.be | ||
expect(transactionPool.queues.verified.exists(transaction.id)).to.be | ||
.true, | ||
@@ -263,3 +265,3 @@ ); | ||
confirmedTransactions.forEach(transaction => { | ||
expect(transactionPool.existsInTransactionPool(transaction)).to.be | ||
expect(transactionPool.existsInTransactionPool(transaction.id)).to.be | ||
.false; | ||
@@ -271,3 +273,3 @@ }); | ||
transactionsToMoveToValidatedQueue.forEach(transaction => { | ||
expect(transactionPool.queues.validated.exists(transaction)).to.be | ||
expect(transactionPool.queues.validated.exists(transaction.id)).to.be | ||
.true; | ||
@@ -279,3 +281,3 @@ }); | ||
transactionsToMoveToReceivedQueue.forEach(transaction => { | ||
expect(transactionPool.queues.received.exists(transaction)).to.be | ||
expect(transactionPool.queues.received.exists(transaction.id)).to.be | ||
.true; | ||
@@ -315,3 +317,3 @@ }); | ||
transactionsToMoveToReceivedQueue.forEach(transaction => { | ||
expect(transactionPool.queues.received.exists(transaction)).to.be | ||
expect(transactionPool.queues.received.exists(transaction.id)).to.be | ||
.true; | ||
@@ -323,3 +325,3 @@ }); | ||
transactionsToMoveToValidatedQueue.forEach(transaction => { | ||
expect(transactionPool.queues.validated.exists(transaction)).to.be | ||
expect(transactionPool.queues.validated.exists(transaction.id)).to.be | ||
.true; | ||
@@ -326,0 +328,0 @@ }); |
@@ -65,3 +65,3 @@ /* | ||
queue.enqueueOne(transaction); | ||
expect(queue.exists(transaction)).to.be.true; | ||
expect(queue.exists(transaction.id)).to.be.true; | ||
}); | ||
@@ -71,3 +71,3 @@ | ||
const transaction = transactions[0]; | ||
expect(queue.exists(transaction)).to.be.false; | ||
expect(queue.exists(transaction.id)).to.be.false; | ||
}); | ||
@@ -175,4 +175,4 @@ }); | ||
expect(peekedTransactions).to.deep.equal([ | ||
lastTransaction, | ||
secondToLastTransaciton, | ||
lastTransaction, | ||
]); | ||
@@ -208,4 +208,4 @@ }); | ||
expect(dequeuedTransactions).to.deep.equal([ | ||
lastTransaction, | ||
secondToLastTransaciton, | ||
lastTransaction, | ||
]); | ||
@@ -212,0 +212,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
880720
19676