Commit 85423394 authored by Karl Floersch's avatar Karl Floersch Committed by GitHub

Add getPendingQueueElements (#38)

parent fa5a2598
......@@ -167,6 +167,20 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
});
}
/**
* @inheritdoc iOVM_CanonicalTransactionChain
*/
function getNumPendingQueueElements()
override
public
view
returns (
uint40
)
{
return _getQueueLength() - getNextQueueIndex();
}
/**
* @inheritdoc iOVM_CanonicalTransactionChain
*/
......@@ -248,15 +262,14 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
override
public
{
uint40 nextQueueIndex = getNextQueueIndex();
uint40 queueLength = _getQueueLength();
_numQueuedTransactions = Math.min(_numQueuedTransactions, queueLength - nextQueueIndex);
_numQueuedTransactions = Math.min(_numQueuedTransactions, getNumPendingQueueElements());
require(
_numQueuedTransactions > 0,
"Must append more than zero transactions."
);
bytes32[] memory leaves = new bytes32[](_numQueuedTransactions);
uint40 nextQueueIndex = getNextQueueIndex();
for (uint256 i = 0; i < _numQueuedTransactions; i++) {
if (msg.sender != sequencer) {
......@@ -683,7 +696,7 @@ contract OVM_CanonicalTransactionChain is iOVM_CanonicalTransactionChain, Lib_Ad
internal
view
{
if (queue.getLength() == 0) {
if (getNumPendingQueueElements() == 0) {
return;
}
......
......@@ -85,6 +85,17 @@ interface iOVM_CanonicalTransactionChain {
uint40
);
/**
* Get the number of queue elements which have not yet been included.
* @return Length of the queue.
*/
function getNumPendingQueueElements()
external
view
returns (
uint40
);
/**
* Gets the queue element at a particular index.
* @param _index Index of the queue element to access.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment