diff options
author | obscuren <geffobscura@gmail.com> | 2014-07-17 20:53:27 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-07-17 20:53:27 +0800 |
commit | 0415e4a637296539e7a5c09282b7aee19268e599 (patch) | |
tree | c403eac0c3d4cda7aef003bba658f7b39881cdb5 /ethchain/state_transition.go | |
parent | ed3424ff75b396360990725afc124326dea4ab45 (diff) | |
download | dexon-0415e4a637296539e7a5c09282b7aee19268e599.tar dexon-0415e4a637296539e7a5c09282b7aee19268e599.tar.gz dexon-0415e4a637296539e7a5c09282b7aee19268e599.tar.bz2 dexon-0415e4a637296539e7a5c09282b7aee19268e599.tar.lz dexon-0415e4a637296539e7a5c09282b7aee19268e599.tar.xz dexon-0415e4a637296539e7a5c09282b7aee19268e599.tar.zst dexon-0415e4a637296539e7a5c09282b7aee19268e599.zip |
Fixed coinbase copy in state
Diffstat (limited to 'ethchain/state_transition.go')
-rw-r--r-- | ethchain/state_transition.go | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/ethchain/state_transition.go b/ethchain/state_transition.go index 8cface9e8..8ed528c9f 100644 --- a/ethchain/state_transition.go +++ b/ethchain/state_transition.go @@ -42,7 +42,7 @@ func (self *StateTransition) Coinbase() *StateObject { return self.cb } - self.cb = self.state.GetAccount(self.coinbase) + self.cb = self.state.GetOrNewStateObject(self.coinbase) return self.cb } func (self *StateTransition) Sender() *StateObject { @@ -50,7 +50,7 @@ func (self *StateTransition) Sender() *StateObject { return self.sen } - self.sen = self.state.GetAccount(self.tx.Sender()) + self.sen = self.state.GetOrNewStateObject(self.tx.Sender()) return self.sen } @@ -63,7 +63,7 @@ func (self *StateTransition) Receiver() *StateObject { return self.rec } - self.rec = self.state.GetAccount(self.tx.Recipient) + self.rec = self.state.GetOrNewStateObject(self.tx.Recipient) return self.rec } @@ -174,13 +174,16 @@ func (self *StateTransition) TransitionState() (err error) { return } - /* FIXME - * If tx goes TO "0", goes OOG during init, reverse changes, but initial endowment should happen. The ether is lost forever - */ - var snapshot *State + if sender.Amount.Cmp(self.value) < 0 { + return fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", self.value, sender.Amount) + } + var snapshot *State // If the receiver is nil it's a contract (\0*32). if tx.CreatesContract() { + // Subtract the (irreversible) amount from the senders account + sender.SubAmount(self.value) + snapshot = self.state.Copy() // Create a new state object for the contract @@ -189,16 +192,17 @@ func (self *StateTransition) TransitionState() (err error) { if receiver == nil { return fmt.Errorf("Unable to create contract") } + + // Add the amount to receivers account which should conclude this transaction + receiver.AddAmount(self.value) } else { receiver = self.Receiver() - } - // Transfer value from sender to receiver - if err = self.transferValue(sender, receiver); err != nil { - return - } + // Subtract the amount from the senders account + sender.SubAmount(self.value) + // Add the amount to receivers account which should conclude this transaction + receiver.AddAmount(self.value) - if snapshot == nil { snapshot = self.state.Copy() } |