示例#1
0
func NewStateObjectFromBytes(address common.Address, data []byte, db common.Database) *StateObject {
	// TODO clean me up
	var extobject struct {
		Nonce    uint64
		Balance  *big.Int
		Root     common.Hash
		CodeHash []byte
	}
	err := rlp.Decode(bytes.NewReader(data), &extobject)
	if err != nil {
		fmt.Println(err)
		return nil
	}

	object := &StateObject{address: address, db: db}
	object.nonce = extobject.Nonce
	object.balance = extobject.Balance
	object.codeHash = extobject.CodeHash
	object.trie = trie.NewSecure(extobject.Root[:], db)
	object.storage = make(map[string]common.Hash)
	object.gasPool = new(big.Int)
	object.code, _ = db.Get(extobject.CodeHash)

	return object
}
示例#2
0
func NewStateObject(address common.Address, db common.Database) *StateObject {
	object := &StateObject{db: db, address: address, balance: new(big.Int), gasPool: new(big.Int), dirty: true}
	object.trie = trie.NewSecure((common.Hash{}).Bytes(), db)
	object.storage = make(Storage)
	object.gasPool = new(big.Int)

	return object
}
示例#3
0
func (c *StateObject) RlpDecode(data []byte) {
	decoder := common.NewValueFromBytes(data)
	c.nonce = decoder.Get(0).Uint()
	c.balance = decoder.Get(1).BigInt()
	c.trie = trie.NewSecure(decoder.Get(2).Bytes(), c.db)
	c.storage = make(map[string]common.Hash)
	c.gasPool = new(big.Int)

	c.codeHash = decoder.Get(3).Bytes()

	c.code, _ = c.db.Get(c.codeHash)
}
示例#4
0
// SyncObjects syncs the changed objects to the trie
func (self *StateDB) SyncObjects() {
	self.trie = trie.NewSecure(self.root[:], self.db)

	self.refund = new(big.Int)

	for _, stateObject := range self.stateObjects {
		if stateObject.remove {
			self.DeleteStateObject(stateObject)
		} else {
			stateObject.Update()

			self.UpdateStateObject(stateObject)
		}
		stateObject.dirty = false
	}
}
示例#5
0
// Create a new state from a given trie
func New(root common.Hash, db common.Database) *StateDB {
	trie := trie.NewSecure(root[:], db)
	return &StateDB{root: root, db: db, trie: trie, stateObjects: make(map[string]*StateObject), refund: new(big.Int), logs: make(map[common.Hash]Logs)}
}