SOCI4L

More than one fact

Step 1 of 4
0 of 2 goals

Group the facts

You now want a second number per member: how many times they deposited.

The tempting move is a second mapping. Two mappings that must always be written together is a bug waiting to happen, because one day only one of them gets updated.

Declare a record instead:

struct Member {
    uint256 amount;
    uint256 deposits;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract Registry {
    mapping(address => uint256) public amounts;

    function join(uint256 amount) external {
        amounts[msg.sender] += amount;
    }

    function amountOf(address who) external view returns (uint256) {
        return amounts[who];
    }

    function depositsOf(address who) external view returns (uint256) {
        return 0;
    }
}

Goals

The contract compiles
nothing to compile yet
Declare `struct Member`
no state variables yet

Contract storage

Write a contract and it will deploy itself here.