2

I have the following questions:

1.From a LevelDB perspective, where are tokens stored? Is it part of account info? Or is it only part of the smart contract?

  1. If it is only part of the contract, how does block explorer know what tokens each account has?

  2. Anyone can point me to the relevant implementation files in aleth impl?

1 Answer 1

3
  1. From a LevelDB perspective, where are tokens stored? Is it part of account info? Or is it only part of the smart contract?

LevelDB is key/value storage then the key will depends on the smart contract address and the address of the token holder in the balance mapping. We can say that token balance is part of smart contract's state and the account is only the key in the smart contract balance mapping.

For detail you can refer to this link

https://medium.com/aigang-network/how-to-read-ethereum-contract-storage-44252c8af925

  1. If it is only part of the contract, how does block explorer know what tokens each account has?

Blockexplorer will watch events or reading tnx's receipt/logs of relevant token smart contract's transactions to record the token balance of each account/address.

  1. Anyone can point me to the relevant implementation files in aleth impl?

This is the implement code to read the data by specific key

// GetState returns a value in account storage.
func (self *stateObject) GetState(db Database, key common.Hash) common.Hash {
    value, exists := self.cachedStorage[key]
    if exists {
        return value
    }
    // Load from DB in case it is missing.
    enc, err := self.getTrie(db).TryGet(key[:])
    if err != nil {
        self.setError(err)
        return common.Hash{}
    }
    if len(enc) > 0 {
        _, content, _, err := rlp.Split(enc)
        if err != nil {
            self.setError(err)
        }
        value.SetBytes(content)
    }
    self.cachedStorage[key] = value
    return value
}
9
  • i dont think you are answering my question at all Sep 3, 2018 at 14:57
  • okay, I updated my answer base on my understanding, PTAL!
    – Tony Dang
    Sep 3, 2018 at 15:22
  • great! Would you be interested in working on a start up blockchian project? we pay competitively. give me your email! Sep 3, 2018 at 16:10
  • Cool, drop me an email on [email protected]; thanks in advance.
    – Tony Dang
    Sep 3, 2018 at 16:15
  • @user2584960 I am also interested in working on your blockchain project, put your email on your profile and I will contact you.
    – Nulik
    Sep 3, 2018 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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