change all modified calls to ethtrie, ethutil and ethcrypto functions
This commit is contained in:
@ -3,6 +3,8 @@ package ethchain
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/ethereum/eth-go/ethcrypto"
|
||||
"github.com/ethereum/eth-go/ethtrie"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"math/big"
|
||||
"strconv"
|
||||
@ -102,18 +104,18 @@ func CreateBlock(root interface{},
|
||||
}
|
||||
block.SetUncles([]*Block{})
|
||||
|
||||
block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, root))
|
||||
block.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, root))
|
||||
|
||||
return block
|
||||
}
|
||||
|
||||
// Returns a hash of the block
|
||||
func (block *Block) Hash() []byte {
|
||||
return ethutil.Sha3Bin(block.Value().Encode())
|
||||
return ethcrypto.Sha3Bin(block.Value().Encode())
|
||||
}
|
||||
|
||||
func (block *Block) HashNoNonce() []byte {
|
||||
return ethutil.Sha3Bin(ethutil.Encode([]interface{}{block.PrevHash,
|
||||
return ethcrypto.Sha3Bin(ethutil.Encode([]interface{}{block.PrevHash,
|
||||
block.UncleSha, block.Coinbase, block.state.trie.Root,
|
||||
block.TxSha, block.Difficulty, block.Number, block.MinGasPrice,
|
||||
block.GasLimit, block.GasUsed, block.Time, block.Extra}))
|
||||
@ -239,7 +241,7 @@ func (block *Block) SetUncles(uncles []*Block) {
|
||||
block.Uncles = uncles
|
||||
|
||||
// Sha of the concatenated uncles
|
||||
block.UncleSha = ethutil.Sha3Bin(ethutil.Encode(block.rlpUncles()))
|
||||
block.UncleSha = ethcrypto.Sha3Bin(ethutil.Encode(block.rlpUncles()))
|
||||
}
|
||||
|
||||
func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) {
|
||||
@ -250,7 +252,7 @@ func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) {
|
||||
func (block *Block) setTransactions(txs []*Transaction) {
|
||||
block.transactions = txs
|
||||
|
||||
trie := ethutil.NewTrie(ethutil.Config.Db, "")
|
||||
trie := ethtrie.NewTrie(ethutil.Config.Db, "")
|
||||
for i, tx := range txs {
|
||||
trie.Update(strconv.Itoa(i), string(tx.RlpEncode()))
|
||||
}
|
||||
@ -287,7 +289,7 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) {
|
||||
block.PrevHash = header.Get(0).Bytes()
|
||||
block.UncleSha = header.Get(1).Bytes()
|
||||
block.Coinbase = header.Get(2).Bytes()
|
||||
block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, header.Get(3).Val))
|
||||
block.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, header.Get(3).Val))
|
||||
block.TxSha = header.Get(4).Bytes()
|
||||
block.Difficulty = header.Get(5).BigInt()
|
||||
block.Number = header.Get(6).BigInt()
|
||||
@ -329,7 +331,7 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block {
|
||||
block.PrevHash = header.Get(0).Bytes()
|
||||
block.UncleSha = header.Get(1).Bytes()
|
||||
block.Coinbase = header.Get(2).Bytes()
|
||||
block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, header.Get(3).Val))
|
||||
block.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, header.Get(3).Val))
|
||||
block.TxSha = header.Get(4).Bytes()
|
||||
block.Difficulty = header.Get(5).BigInt()
|
||||
block.Number = header.Get(6).BigInt()
|
||||
|
@ -278,7 +278,7 @@ func AddTestNetFunds(block *Block) {
|
||||
"e6716f9544a56c530d868e4bfbacb172315bdead",
|
||||
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4",
|
||||
} {
|
||||
codedAddr := ethutil.FromHex(addr)
|
||||
codedAddr := ethutil.Hex2Bytes(addr)
|
||||
account := block.state.GetAccount(codedAddr)
|
||||
account.Amount = ethutil.Big("1606938044258990275541962092341162602522202993782792835301376") //ethutil.BigPow(2, 200)
|
||||
block.state.UpdateStateObject(account)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ethchain
|
||||
|
||||
import (
|
||||
"github.com/ethereum/eth-go/ethcrypto"
|
||||
"github.com/ethereum/eth-go/ethlog"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"github.com/obscuren/sha3"
|
||||
@ -40,7 +41,7 @@ func (pow *EasyPow) Search(block *Block, reactChan chan ethutil.React) []byte {
|
||||
powlogger.Infoln("Hashing @", int64(hashes), "khash")
|
||||
}
|
||||
|
||||
sha := ethutil.Sha3Bin(big.NewInt(r.Int63()).Bytes())
|
||||
sha := ethcrypto.Sha3Bin(big.NewInt(r.Int63()).Bytes())
|
||||
if pow.Verify(hash, diff, sha) {
|
||||
return sha
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ethchain
|
||||
|
||||
import (
|
||||
"github.com/ethereum/eth-go/ethcrypto"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"math/big"
|
||||
)
|
||||
@ -11,13 +12,13 @@ import (
|
||||
|
||||
var ZeroHash256 = make([]byte, 32)
|
||||
var ZeroHash160 = make([]byte, 20)
|
||||
var EmptyShaList = ethutil.Sha3Bin(ethutil.Encode([]interface{}{}))
|
||||
var EmptyShaList = ethcrypto.Sha3Bin(ethutil.Encode([]interface{}{}))
|
||||
|
||||
var GenesisHeader = []interface{}{
|
||||
// Previous hash (none)
|
||||
ZeroHash256,
|
||||
// Sha of uncles
|
||||
ethutil.Sha3Bin(ethutil.Encode([]interface{}{})),
|
||||
ethcrypto.Sha3Bin(ethutil.Encode([]interface{}{})),
|
||||
// Coinbase
|
||||
ZeroHash160,
|
||||
// Root state
|
||||
@ -39,7 +40,7 @@ var GenesisHeader = []interface{}{
|
||||
// Extra
|
||||
nil,
|
||||
// Nonce
|
||||
ethutil.Sha3Bin(big.NewInt(42).Bytes()),
|
||||
ethcrypto.Sha3Bin(big.NewInt(42).Bytes()),
|
||||
}
|
||||
|
||||
var Genesis = []interface{}{GenesisHeader, []interface{}{}, []interface{}{}}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ethchain
|
||||
|
||||
import (
|
||||
"github.com/ethereum/eth-go/ethcrypto"
|
||||
"github.com/ethereum/eth-go/ethtrie"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"math/big"
|
||||
@ -74,7 +75,7 @@ func (s *State) Purge() int {
|
||||
return s.trie.NewIterator().Purge()
|
||||
}
|
||||
|
||||
func (s *State) EachStorage(cb ethutil.EachCallback) {
|
||||
func (s *State) EachStorage(cb ethtrie.EachCallback) {
|
||||
it := s.trie.NewIterator()
|
||||
it.Each(cb)
|
||||
}
|
||||
@ -92,7 +93,7 @@ func (self *State) UpdateStateObject(stateObject *StateObject) {
|
||||
self.stateObjects[string(addr)] = stateObject
|
||||
}
|
||||
|
||||
ethutil.Config.Db.Put(ethutil.Sha3Bin(stateObject.Script()), stateObject.Script())
|
||||
ethutil.Config.Db.Put(ethcrypto.Sha3Bin(stateObject.Script()), stateObject.Script())
|
||||
|
||||
self.trie.Update(string(addr), string(stateObject.RlpEncode()))
|
||||
|
||||
|
@ -3,6 +3,7 @@ package ethchain
|
||||
import (
|
||||
"bytes"
|
||||
"container/list"
|
||||
"github.com/ethereum/eth-go/ethcrypto"
|
||||
"github.com/ethereum/eth-go/ethlog"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"github.com/ethereum/eth-go/ethwire"
|
||||
@ -38,6 +39,7 @@ type EthManager interface {
|
||||
IsMining() bool
|
||||
IsListening() bool
|
||||
Peers() *list.List
|
||||
KeyManager() *ethcrypto.KeyManager
|
||||
}
|
||||
|
||||
type StateManager struct {
|
||||
@ -293,7 +295,7 @@ func (sm *StateManager) ValidateBlock(block *Block) error {
|
||||
|
||||
// Verify the nonce of the block. Return an error if it's not valid
|
||||
if !sm.Pow.Verify(block.HashNoNonce(), block.Difficulty, block.Nonce) {
|
||||
return ValidationError("Block's nonce is invalid (= %v)", ethutil.Hex(block.Nonce))
|
||||
return ValidationError("Block's nonce is invalid (= %v)", ethutil.Bytes2Hex(block.Nonce))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -2,6 +2,8 @@ package ethchain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ethereum/eth-go/ethcrypto"
|
||||
"github.com/ethereum/eth-go/ethtrie"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"math/big"
|
||||
"strings"
|
||||
@ -39,7 +41,7 @@ func MakeContract(tx *Transaction, state *State) *StateObject {
|
||||
|
||||
contract := state.NewStateObject(addr)
|
||||
contract.initScript = tx.Data
|
||||
contract.state = NewState(ethutil.NewTrie(ethutil.Config.Db, ""))
|
||||
contract.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, ""))
|
||||
|
||||
return contract
|
||||
}
|
||||
@ -53,7 +55,7 @@ func NewStateObject(addr []byte) *StateObject {
|
||||
|
||||
func NewContract(address []byte, Amount *big.Int, root []byte) *StateObject {
|
||||
contract := &StateObject{address: address, Amount: Amount, Nonce: 0}
|
||||
contract.state = NewState(ethutil.NewTrie(ethutil.Config.Db, string(root)))
|
||||
contract.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, string(root)))
|
||||
|
||||
return contract
|
||||
}
|
||||
@ -246,7 +248,7 @@ func (c *StateObject) RlpEncode() []byte {
|
||||
root = ""
|
||||
}
|
||||
|
||||
return ethutil.Encode([]interface{}{c.Nonce, c.Amount, root, ethutil.Sha3Bin(c.script)})
|
||||
return ethutil.Encode([]interface{}{c.Nonce, c.Amount, root, ethcrypto.Sha3Bin(c.script)})
|
||||
}
|
||||
|
||||
func (c *StateObject) RlpDecode(data []byte) {
|
||||
@ -254,7 +256,8 @@ func (c *StateObject) RlpDecode(data []byte) {
|
||||
|
||||
c.Nonce = decoder.Get(0).Uint()
|
||||
c.Amount = decoder.Get(1).BigInt()
|
||||
c.state = NewState(ethutil.NewTrie(ethutil.Config.Db, decoder.Get(2).Interface()))
|
||||
c.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, decoder.Get(2).Interface()))
|
||||
c.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, decoder.Get(2).Interface()))
|
||||
|
||||
c.ScriptHash = decoder.Get(3).Bytes()
|
||||
|
||||
|
@ -3,6 +3,7 @@ package ethchain
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/ethereum/eth-go/ethcrypto"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"github.com/obscuren/secp256k1-go"
|
||||
"math/big"
|
||||
@ -62,7 +63,7 @@ func (self *Transaction) TotalValue() *big.Int {
|
||||
func (tx *Transaction) Hash() []byte {
|
||||
data := []interface{}{tx.Nonce, tx.GasPrice, tx.Gas, tx.Recipient, tx.Value, tx.Data}
|
||||
|
||||
return ethutil.Sha3Bin(ethutil.NewValue(data).Encode())
|
||||
return ethcrypto.Sha3Bin(ethutil.NewValue(data).Encode())
|
||||
}
|
||||
|
||||
func (tx *Transaction) CreatesContract() bool {
|
||||
@ -75,7 +76,7 @@ func (tx *Transaction) IsContract() bool {
|
||||
}
|
||||
|
||||
func (tx *Transaction) CreationAddress() []byte {
|
||||
return ethutil.Sha3Bin(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
|
||||
return ethcrypto.Sha3Bin(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
|
||||
}
|
||||
|
||||
func (tx *Transaction) Signature(key []byte) []byte {
|
||||
@ -111,7 +112,7 @@ func (tx *Transaction) Sender() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
return ethutil.Sha3Bin(pubkey[1:])[12:]
|
||||
return ethcrypto.Sha3Bin(pubkey[1:])[12:]
|
||||
}
|
||||
|
||||
func (tx *Transaction) Sign(privk []byte) error {
|
||||
|
@ -2,6 +2,7 @@ package ethchain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ethereum/eth-go/ethcrypto"
|
||||
"github.com/ethereum/eth-go/ethlog"
|
||||
"github.com/ethereum/eth-go/ethutil"
|
||||
"math"
|
||||
@ -398,7 +399,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
|
||||
case SHA3:
|
||||
require(2)
|
||||
size, offset := stack.Popn()
|
||||
data := ethutil.Sha3Bin(mem.Get(offset.Int64(), size.Int64()))
|
||||
data := ethcrypto.Sha3Bin(mem.Get(offset.Int64(), size.Int64()))
|
||||
|
||||
stack.Push(ethutil.BigD(data))
|
||||
// 0x30 range
|
||||
@ -594,7 +595,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
|
||||
snapshot := vm.state.Copy()
|
||||
|
||||
// Generate a new address
|
||||
addr := ethutil.CreateAddress(closure.caller.Address(), closure.caller.N())
|
||||
addr := ethcrypto.CreateAddress(closure.caller.Address(), closure.caller.N())
|
||||
|
||||
vm.Printf(" (*) %x", addr).Endl()
|
||||
|
||||
|
Reference in New Issue
Block a user