2

we all know that we can write smart contract with solidity in ethereum such as:

 mapping(bytes32 => bytes32) private  userPasswds ;
    event RecordReturnResult(bool res);

    /// @dev new the pair of user and password to the array here
    function newPair(string user, string password)  returns (bool) {      
        bytes32  sha3_user = sha3(user);
        bytes32  sha3_password = sha3(password);
        bool res = true;
        if (userPasswds[sha3_user] > 0) {
            res = false;
            RecordReturnResult(res);
            return res;
        }           
        else{
            userPasswds[sha3_user] = sha3_password;
            res = true;
            RecordReturnResult(res);
            return res;
        }      
    }

Where are the variables stored? For example:

    mapping(bytes32 => bytes32) private  userPasswds ;
    event RecordReturnResult(bool res);bytes32  sha3_user = sha3(user);
    bytes32  sha3_password = sha3(password);
    bool res = true;

are they stored in block chain or leveldb or other places? thank you.

  • 1
    thank you very much for your reply. but I can only choose one to be the winner. – jiebang Jun 28 '17 at 3:21
2

these states are stored in the Contract's storage. Each contract has its own storage and memory space and both are in the blockchain(leveldb physically).

look at the diagram below to get an idea :

enter image description here

2

Contracts variables (state) are stored by the Ethereum virtual machine in a Merkle Tree. The hash of the tree is stored in a block and the block is persisted to disk via leveldb.

  • thank you, you said the tree is stored in EVM not in block,so if the electric is cut off, will the data does missing? – jiebang Jul 6 '17 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.