The move white paper says an account consists of module and resource. Let’s say if I wanna to persist a non-resource value (e.g., the number of users in my dapp), where will this value go to physically? I didn’t find the explanation in the white paper yet.
Everything in an account is a resource. However, resources are themselves composed of plain data values (e.g., integers) and other resources. So if you want to store a plain data value like a user count, it must live inside some resource.
LibraCoin module contains a
MarketCap resource containing a
total_value integer that tracks the combined value all the of Libra in the system. This might be a useful example to look at when thinking about how to implement your use-case.
@sam, thanks for the explanation.I wonder if it makes sense that every states under an account are resources, where I don’t have the need of linear logic. Or is the overhead of storing resource physically is so cheap that we don’t care?
Or is the overhead of storing resource physically is so cheap that we don’t care?
Good question. Resources have no runtime or storage overhead, so you should use them as often as you like! Only the bytecode verifier understands the distinction between resources, structs, and ordinary values like ints.
So, basically, following the example of mint(), resources deemed “global” are assgined to account 0x0?
To publish a resource under address A, you need to be able to send a transaction from address A. The only command for publishing resources is
move_to_sender. So you can publish your own “global” resource under any address that you can send a transaction from.
In the mint example, 0x0 is used as a placeholder for the address of the Association account. It does not have any special status.