2016-06-16 17 views
9
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); 

} 

Se un acquirente non è registrato nella mappatura dell'acquirente, quindi acquirenteNum ++; ma non so dire se un acquirente è nella mappaturaEsistono cose simili in solidità

+0

Forse come [Come posso verificare se una variabile o una matrice è impostato o vuoto o null] (http://ethereum.stackexchange.com/a/2134/87), [Verifica valore zero della struttura] (http://ethereum.stackexchange.com/q/2502/87) o [Qual è il valore zero per una stringa] (http: // ethereum. stackexchange.com/q/5683/87) a Ethereum Stack Exchange? – default

risposta

3

Si potrebbe creare Nessuno variabile da utilizzare come un NULL:

uint80 constant None = uint80(0); 
2

In solidità ogni variabile è impostata su 0 per impostazione predefinita.

Si dovrebbe pensare a mappingspoiché tutte le combinazioni possibili di sono impostate su 0 per impostazione predefinita.

Nel vostro caso specifico Vorrei utilizzare il seguente:

if (buyers[msg.sender].amount == 0)