|
|
|
@ -10,25 +10,21 @@ type Contract struct { |
|
|
|
|
Nonce uint64 |
|
|
|
|
//state *ethutil.Trie
|
|
|
|
|
state *State |
|
|
|
|
address []byte |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func NewContract(Amount *big.Int, root []byte) *Contract { |
|
|
|
|
contract := &Contract{Amount: Amount, Nonce: 0} |
|
|
|
|
func NewContract(address []byte, Amount *big.Int, root []byte) *Contract { |
|
|
|
|
contract := &Contract{address: address, Amount: Amount, Nonce: 0} |
|
|
|
|
contract.state = NewState(ethutil.NewTrie(ethutil.Config.Db, string(root))) |
|
|
|
|
|
|
|
|
|
return contract |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *Contract) RlpEncode() []byte { |
|
|
|
|
return ethutil.Encode([]interface{}{c.Amount, c.Nonce, c.state.trie.Root}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *Contract) RlpDecode(data []byte) { |
|
|
|
|
decoder := ethutil.NewValueFromBytes(data) |
|
|
|
|
func NewContractFromBytes(address, data []byte) *Contract { |
|
|
|
|
contract := &Contract{address: address} |
|
|
|
|
contract.RlpDecode(data) |
|
|
|
|
|
|
|
|
|
c.Amount = decoder.Get(0).BigInt() |
|
|
|
|
c.Nonce = decoder.Get(1).Uint() |
|
|
|
|
c.state = NewState(ethutil.NewTrie(ethutil.Config.Db, decoder.Get(2).Interface())) |
|
|
|
|
return contract |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *Contract) Addr(addr []byte) *ethutil.Value { |
|
|
|
@ -54,13 +50,29 @@ func (c *Contract) ReturnGas(val *big.Int, state *State) { |
|
|
|
|
c.Amount.Add(c.Amount, val) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *Contract) Address() []byte { |
|
|
|
|
return c.address |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *Contract) RlpEncode() []byte { |
|
|
|
|
return ethutil.Encode([]interface{}{c.Amount, c.Nonce, c.state.trie.Root}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (c *Contract) RlpDecode(data []byte) { |
|
|
|
|
decoder := ethutil.NewValueFromBytes(data) |
|
|
|
|
|
|
|
|
|
c.Amount = decoder.Get(0).BigInt() |
|
|
|
|
c.Nonce = decoder.Get(1).Uint() |
|
|
|
|
c.state = NewState(ethutil.NewTrie(ethutil.Config.Db, decoder.Get(2).Interface())) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func MakeContract(tx *Transaction, state *State) *Contract { |
|
|
|
|
// Create contract if there's no recipient
|
|
|
|
|
if tx.IsContract() { |
|
|
|
|
addr := tx.Hash()[12:] |
|
|
|
|
|
|
|
|
|
value := tx.Value |
|
|
|
|
contract := NewContract(value, []byte("")) |
|
|
|
|
contract := NewContract(addr, value, []byte("")) |
|
|
|
|
state.trie.Update(string(addr), string(contract.RlpEncode())) |
|
|
|
|
for i, val := range tx.Data { |
|
|
|
|
if len(val) > 0 { |
|
|
|
|