Cryptocurrency Ethereum Mastering Development

Gnosis multisig Wallet

This is a function that returns an array of addresses that confirmed for a transactionId.

    mapping (uint => Transaction) public transactions;
    mapping (uint => mapping (address => bool)) public confirmations; 
    address[] public ownersArr;

    /// @dev Returns array with owner addresses, which confirmed transaction.
    /// @param transactionId Transaction ID.
    /// @return Returns array of owner addresses.
    function getConfirmations(uint transactionId)
        returns (address[] _confirmations)
        address[] memory confirmationsTemp = new address[](ownersArr.length);
        uint count = 0;
        uint i;
        for (i=0; i<ownersArr.length; i++)
            if (confirmations[transactionId][ownersArr[i]]) {
                confirmationsTemp[count] = ownersArr[i];
                count += 1;
        _confirmations = new address[](count);
        for (i=0; i<count; i++)
            _confirmations[i] = confirmationsTemp[i];

I could understand whats the point of running two loops inside this function when only one loop is sufficient to get all the addresses that confirmed for a transactioId.

    function getConfirmations(uint _transactionId) public view returns (address[] _confirmations)
        for (uint i=0; i < ownersArr.length; i++){
            if (confirmations[_transactionId][ownersArr[i]]){



Leave an answer

Your email address will not be published. Required fields are marked *