From c9920809a0a22aec86f636847181a75e6c75e568 Mon Sep 17 00:00:00 2001 From: Ben Chan Date: Tue, 14 Jun 2016 13:26:49 -0700 Subject: [PATCH] methods to get pending transactions --- wallet/wallet.sol | 64 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/wallet/wallet.sol b/wallet/wallet.sol index c522a9b..15d5780 100644 --- a/wallet/wallet.sol +++ b/wallet/wallet.sol @@ -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)]; @@ -363,9 +367,53 @@ 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) @@ -373,6 +421,14 @@ contract Wallet is multisig, multiowned, daylimit { 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.