Hi @benj,
You’ve done a great job at explaining these concepts to @Flippy
Your terminology is actually very good. The term used in the Solidity documentation for attributes or properties is members, but it is clear what you mean by attributes, and that’s the main thing.
Just a couple of observations …
This is correct if our mapping is defined with an address data type as the key…
mapping(
address
=> User) users;
… and not with an unsigned integer data type …
From your explanation, I think this is actually how you meant to define your mapping, but I just wanted to clarify this.
With the mapping defined as User
instances (created from the struct) mapped to addresses (and not unsigned integers), users[msg.sender]
will reference a User
instance, and not an address, and so instead of…
… the local activeUser variable should be defined with the custom data type User
(and not as an address)…
User activeUser = users[msg.sender];
uint activeUserBalance = activeUser.balance;
I think it’s important to make clear that, when we are referencing a specific “entry” in a mapping, the value within the square brackets is the key the entry is mapped to, and the data type of the key (the data type declared before the arrow in the mapping definition) is usually not the same as the data type of the value that is mapped to it (the data type declared after the arrow in the mapping definition).
Your explanation breaking down msg.sender.transfer(amount);
is really quite excellent
Strictly speaking, msg
is not a data type, but instead we can consider msg.sender
as representing one value with an address data type (the address calling the function). Address data types in Solidity have many available members
, some of which are what you have described as methods — which I think is a really good term to use to describe how these particular members operate.
Here is a link to the full list of Members of Address Types in the documentation:
https://docs.soliditylang.org/en/latest/units-and-global-variables.html#members-of-address-types
Just let me know if either of you have any further questions