2

I am having trouble understanding the function confirmAndCheck (line 149 in the Wallet contract). Pasting the code below, with my addition in the last line:

function confirmAndCheck(bytes32 _operation) internal returns (bool) {
        // determine what index the present sender is:
        uint ownerIndex = m_ownerIndex[uint(msg.sender)];
        // make sure they're an owner
        if (ownerIndex == 0) return;

        var pending = m_pending[_operation];
        // if we're not yet working on this operation, switch over and reset the confirmation status.
        if (pending.yetNeeded == 0) {
            // reset count of confirmations needed.
            pending.yetNeeded = m_required;
            // reset which owners have confirmed (none) - set our bitmap to 0.
            pending.ownersDone = 0;
            pending.index = m_pendingIndex.length++;
            m_pendingIndex[pending.index] = _operation;
        }
        // determine the bit to set for this owner.
        uint ownerIndexBit = 2**ownerIndex;
        // make sure we (the message sender) haven't confirmed this operation previously.
        if (pending.ownersDone & ownerIndexBit == 0) {
            Confirmation(msg.sender, _operation);
            // ok - check if count is enough to go ahead.
            if (pending.yetNeeded <= 1) {
                // enough confirmations: reset and run interior.
                delete m_pendingIndex[m_pending[_operation].index];
                delete m_pending[_operation];
                return true;
            }
            else
            {
                // not enough: record that this owner in particular confirmed.
                pending.yetNeeded--;
                pending.ownersDone |= ownerIndexBit;
                // m_pending[_operation] = pending; // ?
            }
        }
    }

In case of multiple confirmations, shouldn't we save the local variable pending inside m_pending, since it will be accessed again later in line 155?

Thanks,

1 Answer 1

1

It’s a reference type, so we shouldn’t.

On the other hand, assignments from a memory stored reference type to another memory-stored reference type does not create a copy.

Since the variable pending is reference, all changes applied to this variable are also applied to the origin. Therefore we don’t have to assign its value back to m_pending.

6
  • 1
    This answer has severe formatting or content problems. This answer is unlikely to be salvageable through editing, and might need to be removed.
    – niksmac
    Jan 26, 2017 at 2:08
  • @niksmac What’s the problem? Jan 26, 2017 at 9:38
  • Link only answers are generally not welcome, will get removed eventually.
    – niksmac
    Jan 26, 2017 at 9:40
  • Consider adding some information the link into this answer.
    – niksmac
    Jan 26, 2017 at 9:41
  • @niksmac Is it ok now? Jan 26, 2017 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.