struct buyer{ uint amount; Status status; } mapping(address=>buyer) public buyers; mapping(uint=>address) buyerIndex; uint public buyerNum; //Order a product. function(){ uint doubleValue=value*2; uint amount=msg.value/doubleValue; if(buyers[msg.sender]==null){ //Error in this line buyer abuyer=buyer({amount:amount,status:Status.Created}); //Error in this line buyerNum++; buyerIndex[buyerNum]=msg.sender; buyers[msg.sender]=abuyer; }else{ buyers[msg.sender].amount+=amount; } Order(msg.sender,amount*doubleValue,amount); }
If a buyer is not recorded in the buyer mapping, then buyerNum++; but I don't know how to tell whether a buyer is in the mapping
Unlike other languages(java, javascript), There is null or undefined in solidity. Values are assigned to zero bytes if there is no object.
Within an Ethereum transaction, the zero-account is just a special case used to indicate that a new contract is being deployed. It is literally '0x0' set to the to field in the raw transaction.
Boolean: This data type accepts only two values True or False. Integer: This data type is used to store integer values, int and uint are used to declare signed and unsigned integers respectively. Fixed Point Numbers: These data types are not fully supported in solidity yet, as per the Solidity documentation.
In solidity every variable is set to 0
by default.
You should think of mappings
as all possible combinations are set to 0
by default.
In your specific case I would use the following:
if (buyers[msg.sender].amount == 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With