func TestReset(t *testing.T) { trie := NewEmpty() vals := []struct{ k, v string }{ {"do", "verb"}, {"ether", "wookiedoo"}, {"horse", "stallion"}, } for _, val := range vals { trie.UpdateString(val.k, val.v) } trie.Commit() before := common.CopyBytes(trie.roothash) trie.UpdateString("should", "revert") trie.Hash() // Should have no effect trie.Hash() trie.Hash() // ### trie.Reset() after := common.CopyBytes(trie.roothash) if !bytes.Equal(before, after) { t.Errorf("expected roots to be equal. %x - %x", before, after) } }
func (self *StateObject) Copy() *StateObject { stateObject := NewStateObject(self.Address(), self.db) stateObject.balance.Set(self.balance) stateObject.codeHash = common.CopyBytes(self.codeHash) stateObject.nonce = self.nonce stateObject.trie = self.trie stateObject.code = common.CopyBytes(self.code) stateObject.initCode = common.CopyBytes(self.initCode) stateObject.storage = self.storage.Copy() stateObject.gasPool.Set(self.gasPool) stateObject.remove = self.remove stateObject.dirty = self.dirty stateObject.deleted = self.deleted return stateObject }
func NewTransaction(nonce uint64, to common.Address, amount, gasLimit, gasPrice *big.Int, data []byte) *Transaction { if len(data) > 0 { data = common.CopyBytes(data) } d := txdata{ AccountNonce: nonce, Recipient: &to, Payload: data, Amount: new(big.Int), GasLimit: new(big.Int), Price: new(big.Int), R: new(big.Int), S: new(big.Int), } if amount != nil { d.Amount.Set(amount) } if gasLimit != nil { d.GasLimit.Set(gasLimit) } if gasPrice != nil { d.Price.Set(gasPrice) } return &Transaction{data: d} }
func NewContractCreation(nonce uint64, amount, gasLimit, gasPrice *big.Int, data []byte) *Transaction { if len(data) > 0 { data = common.CopyBytes(data) } return &Transaction{data: txdata{ AccountNonce: nonce, Recipient: nil, Amount: new(big.Int).Set(amount), GasLimit: new(big.Int).Set(gasLimit), Price: new(big.Int).Set(gasPrice), Payload: data, R: new(big.Int), S: new(big.Int), }} }
func NewReceipt(root []byte, cumalativeGasUsed *big.Int) *Receipt { return &Receipt{PostState: common.CopyBytes(root), CumulativeGasUsed: new(big.Int).Set(cumalativeGasUsed)} }
func (b *Block) Extra() []byte { return common.CopyBytes(b.header.Extra) }
func (tx *Transaction) Data() []byte { return common.CopyBytes(tx.data.Payload) }
func (self *ValueNode) Copy(t *Trie) Node { return &ValueNode{t, common.CopyBytes(self.data), self.dirty} }
func (self *ShortNode) Copy(t *Trie) Node { node := &ShortNode{t, nil, self.value.Copy(t), self.dirty} node.key = common.CopyBytes(self.key) node.dirty = true return node }
func (self *HashNode) Copy(t *Trie) Node { return NewHash(common.CopyBytes(self.key), t) }