Skip to content

Commit

Permalink
methods to get pending transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
bencxr committed Jun 14, 2016
1 parent 0aeff24 commit c992080
Showing 1 changed file with 60 additions and 4 deletions.
64 changes: 60 additions & 4 deletions wallet/wallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,13 @@ contract multiowned {
uint ownerIndexBit = 2**ownerIndex;
return !(pending.ownersDone & ownerIndexBit == 0);
}

// INTERNAL METHODS

// Given an operation hash, get the number of confirmations needed
function getPendingConfirmationsNeeded(bytes32 _operation) returns (uint) {
return m_pending[_operation].yetNeeded;
}

// INTERNAL METHODS
function confirmAndCheck(bytes32 _operation) internal returns (bool) {
// determine what index the present sender is:
uint ownerIndex = m_ownerIndex[uint(msg.sender)];
Expand Down Expand Up @@ -363,16 +367,68 @@ contract Wallet is multisig, multiowned, daylimit {
return true;
}
}


// Gets the number of pending transactions
function numPendingTransactions() returns (uint) {
var pendingTransactionsCount = 0;
// Use m_pendingIndex.length to get all hashes, then count how many of the
// operations are transactions, because we don't want to store hashes twice
// and this is a local call anyway
for (uint i = 0; i < m_pendingIndex.length; i++) {
if (isPendingTransaction(i)) {
pendingTransactionsCount++;
}
}

return pendingTransactionsCount;
}

// Gets the hash of a pending operation at the specified index
function getPendingTransaction(uint _index) returns (bytes32) {
var pendingTransactionsCount = 0;
// Seek through all of m_pendingIndex (used in the multiowned contract)
// But only count transactions
for (uint i = 0; i < m_pendingIndex.length; i++) {
if (isPendingTransaction(i)) {
if (_index == pendingTransactionsCount) {
return m_pendingIndex[i];
}
pendingTransactionsCount++;
}
}
}

// Gets the destination address of a pending transaction by the operation hash
function getPendingTransactionToAddress(bytes32 _operation) returns (address) {
return address(m_txs[_operation].to);
}

// Gets the value in wei of a pending transaction by the operation hash
function getPendingTransactionValue(bytes32 _operation) returns (uint) {
return m_txs[_operation].value;
}

// Gets the proposed data of a pending transaction by the operation hash
function getPendingTransactionData(bytes32 _operation) returns (bytes) {
return m_txs[_operation].data;
}

// INTERNAL METHODS

function clearPending() internal {
uint length = m_pendingIndex.length;
for (uint i = 0; i < length; ++i)
delete m_txs[m_pendingIndex[i]];
super.clearPending();
}

// Determine if a pending operation index is a pending transaction
function isPendingTransaction(uint _index) internal returns (bool) {
if (m_txs[m_pendingIndex[_index]].to != 0 || m_txs[m_pendingIndex[_index]].data.length != 0) {
return true;
}
return false;
}

// FIELDS

// pending transactions we have at present.
Expand Down

0 comments on commit c992080

Please sign in to comment.