From d91357d00ca080c63d81570504e5c45fb15e3841 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 8 Sep 2014 00:50:04 +0200 Subject: Added GetCode method --- ethstate/state.go | 9 +++++++++ ethstate/state_object.go | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ethstate/state.go b/ethstate/state.go index 2f7f00a32..42bbf021b 100644 --- a/ethstate/state.go +++ b/ethstate/state.go @@ -49,6 +49,15 @@ func (self *State) GetNonce(addr []byte) uint64 { return 0 } +func (self *State) GetCode(addr []byte) []byte { + stateObject := self.GetStateObject(addr) + if stateObject != nil { + return stateObject.Code + } + + return nil +} + // // Setting, updating & deleting state object methods // diff --git a/ethstate/state_object.go b/ethstate/state_object.go index bf4e92583..6fc0696a8 100644 --- a/ethstate/state_object.go +++ b/ethstate/state_object.go @@ -297,8 +297,12 @@ func (c *StateObject) RlpEncode() []byte { } else { root = "" } + var codeHash []byte + if len(c.Code) > 0 { + codeHash = ethcrypto.Sha3Bin(c.Code) + } - return ethutil.Encode([]interface{}{c.Nonce, c.Balance, root, ethcrypto.Sha3Bin(c.Code)}) + return ethutil.Encode([]interface{}{c.Nonce, c.Balance, root, codeHash}) } func (c *StateObject) RlpDecode(data []byte) { -- cgit