Spec:
- Wallets have sums paid to them for different tokens.
Design
- Wallet address maps to totalpaid by token.
Implementation
- Two mappings, one for wallet address, one for a token label (designed to be an integer based on a second struct)
Error
- Integer constant expected
This line fails –
uint _TotalPaid = PaymentDetail[_TokenIndex][_Wallet].TotalPaid;
Has anyone any ideas about how to solve this error?
Here is the code –
struct PaymentDetail { uint TotalPaid; } mapping (bytes32 => mapping (uint => PaymentDetail[]) ) public PaymentDetails; function addPaymentDetail (bytes32 _Wallet, uint _TokenIndex, uint _Payment) public { uint _TotalPaid = PaymentDetail[_TokenIndex][_Wallet].TotalPaid; _TotalPaid=_TotalPaid+_Payment; PaymentDetail[_Wallet][_TokenIndex].TotalPaid=_TotalPaid; }
Best Answer
As per Documentation . Mapping types are declared as
mapping(_KeyType => _ValueType)
. Here_KeyType
can be almost any type except for a mapping, adynamically sized array
, a contract, an enum and a struct._ValueType
can actually be any type, including mappings. It not possible directly make an array of struct as value type. But it is possible for other data types, like :Here I changed the code as solidity support for struct as value type in mapping.