From 429dd2a100f3b9e2b612b59bcb48f79a805cd6f9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 7 Nov 2014 12:18:48 +0100 Subject: Implemented new miner w/ ui interface for merged mining. Closes #177 * Miner has been rewritten * Added new miner pane * Added option for local txs * Added option to read from MergeMining contract and list them for merged mining --- xeth/config.go | 2 ++ xeth/hexface.go | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'xeth') diff --git a/xeth/config.go b/xeth/config.go index 34aa9e32d..ad0660d75 100644 --- a/xeth/config.go +++ b/xeth/config.go @@ -19,6 +19,8 @@ func (self *Config) Get(name string) *Object { objectAddr := configCtrl.GetStorage(ethutil.BigD([]byte{0})) domainAddr := (&Object{self.pipe.World().safeGet(objectAddr.Bytes())}).StorageString("DnsReg").Bytes() return &Object{self.pipe.World().safeGet(domainAddr)} + case "MergeMining": + addr = []byte{4} default: addr = ethutil.RightPadBytes([]byte(name), 32) } diff --git a/xeth/hexface.go b/xeth/hexface.go index 21e82e37d..5ef3eaf1a 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -254,6 +254,10 @@ func (self *JSXEth) CompileMutan(code string) string { return ethutil.Bytes2Hex(data) } +func (self *JSXEth) FindInConfig(str string) string { + return ethutil.Bytes2Hex(self.World().Config().Get(str).Address()) +} + func ToJSMessages(messages state.Messages) *ethutil.List { var msgs []JSMessage for _, m := range messages { -- cgit v1.2.3 From cbeebcd47da846e1b8990313f1ff1ffe7d0bf00f Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 10 Nov 2014 01:17:31 +0100 Subject: Fixed bloom, updated mining & block processing * Reverted back to process blocks in batches method * Bloom generation and lookup fix * Minor UI changed (mainly debug) --- xeth/js_types.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'xeth') diff --git a/xeth/js_types.go b/xeth/js_types.go index 1a1938648..ff240e21c 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -26,6 +26,8 @@ type JSBlock struct { GasLimit string `json:"gasLimit"` GasUsed string `json:"gasUsed"` PrevHash string `json:"prevHash"` + Bloom string `json:"bloom"` + Raw string `json:"raw"` } // Creates a new QML Block from a chain block @@ -54,6 +56,8 @@ func NewJSBlock(block *chain.Block) *JSBlock { Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase), PrevHash: ethutil.Bytes2Hex(block.PrevHash), + Bloom: ethutil.Bytes2Hex(block.LogsBloom), + Raw: block.String(), } } -- cgit v1.2.3 From 6c9e503eb8d41d331d6a74e69539a06590072190 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 11 Nov 2014 22:51:26 +0100 Subject: Removed all implicit logging. Fixed gas issues and jump errors --- xeth/vm_env.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xeth') diff --git a/xeth/vm_env.go b/xeth/vm_env.go index 2c36444e9..68b13e5a8 100644 --- a/xeth/vm_env.go +++ b/xeth/vm_env.go @@ -34,7 +34,7 @@ func (self *VMEnv) BlockHash() []byte { return self.block.Hash() } func (self *VMEnv) Value() *big.Int { return self.value } func (self *VMEnv) State() *state.State { return self.state } func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit } -func (self *VMEnv) AddLog(state.Log) {} +func (self *VMEnv) AddLog(*state.Log) {} func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error { return vm.Transfer(from, to, amount) } -- cgit v1.2.3 From a1b6a9ac29d0aa8d29a2c0535bafdb5fe4d4830b Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 18 Nov 2014 16:58:22 +0100 Subject: Begin of moving objects to types package * Block(s) * Transaction(s) --- xeth/hexface.go | 9 +++++---- xeth/js_types.go | 9 +++++---- xeth/pipe.go | 11 ++++++----- xeth/vm_env.go | 7 +++---- 4 files changed, 19 insertions(+), 17 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index 5ef3eaf1a..5bf9845d4 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -6,6 +6,7 @@ import ( "sync/atomic" "github.com/ethereum/go-ethereum/chain" + "github.com/ethereum/go-ethereum/chain/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/state" @@ -209,7 +210,7 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr gas = ethutil.Big(gasStr) gasPrice = ethutil.Big(gasPriceStr) data []byte - tx *chain.Transaction + tx *types.Transaction ) if ethutil.IsHex(codeStr) { @@ -219,9 +220,9 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr } if contractCreation { - tx = chain.NewContractCreationTx(value, gas, gasPrice, data) + tx = types.NewContractCreationTx(value, gas, gasPrice, data) } else { - tx = chain.NewTransactionMessage(hash, value, gas, gasPrice, data) + tx = types.NewTransactionMessage(hash, value, gas, gasPrice, data) } acc := self.obj.BlockManager().TransState().GetOrNewStateObject(keyPair.Address()) @@ -240,7 +241,7 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr } func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) { - tx := chain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) + tx := types.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) self.obj.TxPool().QueueTransaction(tx) return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(self.World().State()), tx.Hash(), tx.Sender()), nil } diff --git a/xeth/js_types.go b/xeth/js_types.go index ff240e21c..cba674416 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/ethereum/go-ethereum/chain" + "github.com/ethereum/go-ethereum/chain/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/state" @@ -14,7 +15,7 @@ import ( // Block interface exposed to QML type JSBlock struct { //Transactions string `json:"transactions"` - ref *chain.Block + ref *types.Block Size string `json:"size"` Number int `json:"number"` Hash string `json:"hash"` @@ -31,7 +32,7 @@ type JSBlock struct { } // Creates a new QML Block from a chain block -func NewJSBlock(block *chain.Block) *JSBlock { +func NewJSBlock(block *types.Block) *JSBlock { if block == nil { return &JSBlock{} } @@ -79,7 +80,7 @@ func (self *JSBlock) GetTransaction(hash string) *JSTransaction { } type JSTransaction struct { - ref *chain.Transaction + ref *types.Transaction Value string `json:"value"` Gas string `json:"gas"` @@ -94,7 +95,7 @@ type JSTransaction struct { Confirmations int `json:"confirmations"` } -func NewJSTx(tx *chain.Transaction, state *state.State) *JSTransaction { +func NewJSTx(tx *types.Transaction, state *state.State) *JSTransaction { hash := ethutil.Bytes2Hex(tx.Hash()) receiver := ethutil.Bytes2Hex(tx.Recipient) if receiver == "0000000000000000000000000000000000000000" { diff --git a/xeth/pipe.go b/xeth/pipe.go index abed8ef9a..8130ab72e 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/ethereum/go-ethereum/chain" + "github.com/ethereum/go-ethereum/chain/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/logger" @@ -72,7 +73,7 @@ func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price * return ret, err } -func (self *XEth) Block(hash []byte) *chain.Block { +func (self *XEth) Block(hash []byte) *types.Block { return self.blockChain.GetBlock(hash) } @@ -115,7 +116,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, rec []byte, value, gas, price *e contractCreation = true } - var tx *chain.Transaction + var tx *types.Transaction // Compile and assemble the given data if contractCreation { script, err := ethutil.Compile(string(data), false) @@ -123,7 +124,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, rec []byte, value, gas, price *e return nil, err } - tx = chain.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), script) + tx = types.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), script) } else { data := ethutil.StringToByteFunc(string(data), func(s string) (ret []byte) { slice := strings.Split(s, "\n") @@ -134,7 +135,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, rec []byte, value, gas, price *e return }) - tx = chain.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data) + tx = types.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data) } acc := self.blockManager.TransState().GetOrNewStateObject(key.Address()) @@ -155,7 +156,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, rec []byte, value, gas, price *e return tx.Hash(), nil } -func (self *XEth) PushTx(tx *chain.Transaction) ([]byte, error) { +func (self *XEth) PushTx(tx *types.Transaction) ([]byte, error) { self.obj.TxPool().QueueTransaction(tx) if tx.Recipient == nil { addr := tx.CreationAddress(self.World().State()) diff --git a/xeth/vm_env.go b/xeth/vm_env.go index 68b13e5a8..10575ad79 100644 --- a/xeth/vm_env.go +++ b/xeth/vm_env.go @@ -2,20 +2,19 @@ package xeth import ( "math/big" - - "github.com/ethereum/go-ethereum/chain" + "github.com/ethereum/go-ethereum/chain/types" "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/vm" ) type VMEnv struct { state *state.State - block *chain.Block + block *types.Block value *big.Int sender []byte } -func NewEnv(state *state.State, block *chain.Block, value *big.Int, sender []byte) *VMEnv { +func NewEnv(state *state.State, block *types.Block, value *big.Int, sender []byte) *VMEnv { return &VMEnv{ state: state, block: block, -- cgit v1.2.3 From 6dc46d3341dc5fa25bd005f9606de258874139be Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 1 Dec 2014 20:18:09 +0100 Subject: Changed the way transactions are being added to the transaction pool --- xeth/hexface.go | 118 ++++++++++++++++++++++++++++++++++++-------------------- xeth/pipe.go | 64 ++++++++++++++++-------------- 2 files changed, 112 insertions(+), 70 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index 5ef3eaf1a..31685403d 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -177,19 +177,25 @@ func (self *JSXEth) FromNumber(str string) string { return ethutil.BigD(ethutil.Hex2Bytes(str)).String() } -func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (*JSReceipt, error) { - var hash []byte - var contractCreation bool - if len(toStr) == 0 { - contractCreation = true +func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { + var ( + to []byte + value = ethutil.NewValue(valueStr) + gas = ethutil.NewValue(gasStr) + gasPrice = ethutil.NewValue(gasPriceStr) + data []byte + ) + + if ethutil.IsHex(codeStr) { + data = ethutil.Hex2Bytes(codeStr[2:]) } else { - // Check if an address is stored by this address - addr := self.World().Config().Get("NameReg").StorageString(toStr).Bytes() - if len(addr) > 0 { - hash = addr - } else { - hash = ethutil.Hex2Bytes(toStr) - } + data = ethutil.Hex2Bytes(codeStr) + } + + if ethutil.IsHex(toStr) { + to = ethutil.Hex2Bytes(toStr[2:]) + } else { + to = ethutil.Hex2Bytes(toStr) } var keyPair *crypto.KeyPair @@ -201,47 +207,77 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr } if err != nil { - return nil, err + return "", err } - var ( - value = ethutil.Big(valueStr) - gas = ethutil.Big(gasStr) - gasPrice = ethutil.Big(gasPriceStr) - data []byte - tx *chain.Transaction - ) - - if ethutil.IsHex(codeStr) { - data = ethutil.Hex2Bytes(codeStr[2:]) - } else { - data = ethutil.Hex2Bytes(codeStr) + tx, err := self.XEth.Transact(keyPair, to, value, gas, gasPrice, data) + if err != nil { + return "", err } - - if contractCreation { - tx = chain.NewContractCreationTx(value, gas, gasPrice, data) - } else { - tx = chain.NewTransactionMessage(hash, value, gas, gasPrice, data) + if chain.IsContractAddr(to) { + return ethutil.Bytes2Hex(tx.CreationAddress(nil)), nil } - acc := self.obj.BlockManager().TransState().GetOrNewStateObject(keyPair.Address()) - tx.Nonce = acc.Nonce - acc.Nonce += 1 - self.obj.BlockManager().TransState().UpdateStateObject(acc) + return ethutil.Bytes2Hex(tx.Hash()), nil + + /* + var hash []byte + var contractCreation bool + if len(toStr) == 0 { + contractCreation = true + } else { + // Check if an address is stored by this address + addr := self.World().Config().Get("NameReg").StorageString(toStr).Bytes() + if len(addr) > 0 { + hash = addr + } else { + hash = ethutil.Hex2Bytes(toStr) + } + } + - tx.Sign(keyPair.PrivateKey) - self.obj.TxPool().QueueTransaction(tx) + var ( + value = ethutil.Big(valueStr) + gas = ethutil.Big(gasStr) + gasPrice = ethutil.Big(gasPriceStr) + data []byte + tx *chain.Transaction + ) - if contractCreation { - pipelogger.Infof("Contract addr %x", tx.CreationAddress(self.World().State())) - } + if ethutil.IsHex(codeStr) { + data = ethutil.Hex2Bytes(codeStr[2:]) + } else { + data = ethutil.Hex2Bytes(codeStr) + } - return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil + if contractCreation { + tx = chain.NewContractCreationTx(value, gas, gasPrice, data) + } else { + tx = chain.NewTransactionMessage(hash, value, gas, gasPrice, data) + } + + acc := self.obj.BlockManager().TransState().GetOrNewStateObject(keyPair.Address()) + tx.Nonce = acc.Nonce + acc.Nonce += 1 + self.obj.BlockManager().TransState().UpdateStateObject(acc) + + tx.Sign(keyPair.PrivateKey) + self.obj.TxPool().QueueTransaction(tx) + + if contractCreation { + pipelogger.Infof("Contract addr %x", tx.CreationAddress(self.World().State())) + } + + return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil + */ } func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) { tx := chain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) - self.obj.TxPool().QueueTransaction(tx) + err := self.obj.TxPool().Add(tx) + if err != nil { + return nil, err + } return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(self.World().State()), tx.Hash(), tx.Sender()), nil } diff --git a/xeth/pipe.go b/xeth/pipe.go index abed8ef9a..6e2f325c5 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -6,7 +6,6 @@ package xeth import ( "fmt" - "strings" "github.com/ethereum/go-ethereum/chain" "github.com/ethereum/go-ethereum/crypto" @@ -93,7 +92,7 @@ func (self *XEth) Exists(addr []byte) bool { return self.World().Get(addr) != nil } -func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) ([]byte, error) { +func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) (*chain.Transaction, error) { // Check if an address is stored by this address var hash []byte addr := self.World().Config().Get("NameReg").StorageString(rec).Bytes() @@ -108,55 +107,62 @@ func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, pr return self.Transact(key, hash, value, gas, price, data) } -func (self *XEth) Transact(key *crypto.KeyPair, rec []byte, value, gas, price *ethutil.Value, data []byte) ([]byte, error) { +func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *ethutil.Value, data []byte) (*chain.Transaction, error) { var hash []byte var contractCreation bool - if rec == nil { + if chain.IsContractAddr(to) { contractCreation = true + } else { + // Check if an address is stored by this address + addr := self.World().Config().Get("NameReg").Storage(to).Bytes() + if len(addr) > 0 { + hash = addr + } else { + hash = to + } } var tx *chain.Transaction - // Compile and assemble the given data if contractCreation { - script, err := ethutil.Compile(string(data), false) - if err != nil { - return nil, err - } - - tx = chain.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), script) + tx = chain.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), data) } else { - data := ethutil.StringToByteFunc(string(data), func(s string) (ret []byte) { - slice := strings.Split(s, "\n") - for _, dataItem := range slice { - d := ethutil.FormatData(dataItem) - ret = append(ret, d...) - } - return - }) - tx = chain.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data) } - acc := self.blockManager.TransState().GetOrNewStateObject(key.Address()) - tx.Nonce = acc.Nonce - acc.Nonce += 1 - self.blockManager.TransState().UpdateStateObject(acc) + state := self.blockManager.TransState() + nonce := state.GetNonce(key.Address()) + tx.Nonce = nonce tx.Sign(key.PrivateKey) - self.obj.TxPool().QueueTransaction(tx) + err := self.obj.TxPool().Add(tx) + if err != nil { + return nil, err + } + + state.SetNonce(key.Address(), nonce+1) if contractCreation { addr := tx.CreationAddress(self.World().State()) pipelogger.Infof("Contract addr %x\n", addr) - - return addr, nil } - return tx.Hash(), nil + return tx, nil + + //acc := self.blockManager.TransState().GetOrNewStateObject(key.Address()) + //self.obj.TxPool().QueueTransaction(tx) + + //acc.Nonce += 1 + //self.blockManager.TransState().UpdateStateObject(acc) + } func (self *XEth) PushTx(tx *chain.Transaction) ([]byte, error) { - self.obj.TxPool().QueueTransaction(tx) + err := self.obj.TxPool().Add(tx) + if err != nil { + return nil, err + } + + //self.obj.TxPool().QueueTransaction(tx) if tx.Recipient == nil { addr := tx.CreationAddress(self.World().State()) pipelogger.Infof("Contract addr %x\n", addr) -- cgit v1.2.3 From 82405501872385b240012070bad2f0eda643d423 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 3 Dec 2014 14:05:19 +0100 Subject: updated to types --- xeth/hexface.go | 2 +- xeth/pipe.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index 9b7aa6b9c..6360c7675 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -215,7 +215,7 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr if err != nil { return "", err } - if chain.IsContractAddr(to) { + if types.IsContractAddr(to) { return ethutil.Bytes2Hex(tx.CreationAddress(nil)), nil } diff --git a/xeth/pipe.go b/xeth/pipe.go index 9cc163a81..c96c6efc0 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -93,7 +93,7 @@ func (self *XEth) Exists(addr []byte) bool { return self.World().Get(addr) != nil } -func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) (*chain.Transaction, error) { +func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) (*types.Transaction, error) { // Check if an address is stored by this address var hash []byte addr := self.World().Config().Get("NameReg").StorageString(rec).Bytes() @@ -108,10 +108,10 @@ func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, pr return self.Transact(key, hash, value, gas, price, data) } -func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *ethutil.Value, data []byte) (*chain.Transaction, error) { +func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *ethutil.Value, data []byte) (*types.Transaction, error) { var hash []byte var contractCreation bool - if chain.IsContractAddr(to) { + if types.IsContractAddr(to) { contractCreation = true } else { // Check if an address is stored by this address @@ -125,9 +125,9 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et var tx *types.Transaction if contractCreation { - tx = chain.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), data) + tx = types.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), data) } else { - tx = chain.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data) + tx = types.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data) } state := self.blockManager.TransState() -- cgit v1.2.3 From 6d99c03d915789c445c2d40579419a16fde2b7c8 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 3 Dec 2014 17:22:26 +0100 Subject: Updated environments according to the new interface set --- xeth/pipe.go | 17 +++++++++-------- xeth/vm_env.go | 30 +++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 9 deletions(-) (limited to 'xeth') diff --git a/xeth/pipe.go b/xeth/pipe.go index c96c6efc0..2dfb91b7f 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -5,15 +5,12 @@ package xeth */ import ( - "fmt" - "github.com/ethereum/go-ethereum/chain" "github.com/ethereum/go-ethereum/chain/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/state" - "github.com/ethereum/go-ethereum/vm" ) var pipelogger = logger.NewLogger("XETH") @@ -62,14 +59,18 @@ func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price * self.Vm.State = self.World().State().Copy() - evm := vm.New(NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address()), vm.Type(ethutil.Config.VmType)) + vmenv := NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address()) + return vmenv.Call(initiator, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) + /* + evm := vm.New(, vm.Type(ethutil.Config.VmType)) - msg := vm.NewExecution(evm, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) - ret, err := msg.Exec(object.Address(), initiator) + msg := vm.NewExecution(evm, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) + ret, err := msg.Exec(object.Address(), initiator) - fmt.Println("returned from call", ret, err) + fmt.Println("returned from call", ret, err) - return ret, err + return ret, err + */ } func (self *XEth) Block(hash []byte) *types.Block { diff --git a/xeth/vm_env.go b/xeth/vm_env.go index 10575ad79..d11459626 100644 --- a/xeth/vm_env.go +++ b/xeth/vm_env.go @@ -2,6 +2,8 @@ package xeth import ( "math/big" + + "github.com/ethereum/go-ethereum/chain" "github.com/ethereum/go-ethereum/chain/types" "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/vm" @@ -12,6 +14,8 @@ type VMEnv struct { block *types.Block value *big.Int sender []byte + + depth int } func NewEnv(state *state.State, block *types.Block, value *big.Int, sender []byte) *VMEnv { @@ -33,7 +37,31 @@ func (self *VMEnv) BlockHash() []byte { return self.block.Hash() } func (self *VMEnv) Value() *big.Int { return self.value } func (self *VMEnv) State() *state.State { return self.state } func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit } -func (self *VMEnv) AddLog(*state.Log) {} +func (self *VMEnv) Depth() int { return self.depth } +func (self *VMEnv) SetDepth(i int) { self.depth = i } +func (self *VMEnv) AddLog(log *state.Log) { + self.state.AddLog(log) +} func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error { return vm.Transfer(from, to, amount) } + +func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *chain.Execution { + evm := vm.New(self, vm.DebugVmTy) + + return chain.NewExecution(evm, addr, data, gas, price, value) +} + +func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) { + exe := self.vm(addr, data, gas, price, value) + return exe.Call(addr, me) +} +func (self *VMEnv) CallCode(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) { + exe := self.vm(me.Address(), data, gas, price, value) + return exe.Call(addr, me) +} + +func (self *VMEnv) Create(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ClosureRef) { + exe := self.vm(addr, data, gas, price, value) + return exe.Create(me) +} -- cgit v1.2.3 From 9008b155d3c8d2a32c4c8945f1174243d48d4e90 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 4 Dec 2014 10:28:02 +0100 Subject: Renamed `chain` => `core` --- xeth/hexface.go | 59 ++++---------------------------------------------------- xeth/js_types.go | 10 +++++----- xeth/pipe.go | 12 ++++++------ xeth/vm_env.go | 8 ++++---- 4 files changed, 19 insertions(+), 70 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index 6360c7675..c1f49453d 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -5,8 +5,8 @@ import ( "encoding/json" "sync/atomic" - "github.com/ethereum/go-ethereum/chain" - "github.com/ethereum/go-ethereum/chain/types" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/state" @@ -16,7 +16,7 @@ type JSXEth struct { *XEth } -func NewJSXEth(eth chain.EthManager) *JSXEth { +func NewJSXEth(eth core.EthManager) *JSXEth { return &JSXEth{New(eth)} } @@ -64,7 +64,7 @@ func (self *JSXEth) PeerCount() int { func (self *JSXEth) Peers() []JSPeer { var peers []JSPeer for peer := self.obj.Peers().Front(); peer != nil; peer = peer.Next() { - p := peer.Value.(chain.Peer) + p := peer.Value.(core.Peer) // we only want connected peers if atomic.LoadInt32(p.Connected()) != 0 { peers = append(peers, *NewJSPeer(p)) @@ -220,57 +220,6 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr } return ethutil.Bytes2Hex(tx.Hash()), nil - - /* - var hash []byte - var contractCreation bool - if len(toStr) == 0 { - contractCreation = true - } else { - // Check if an address is stored by this address - addr := self.World().Config().Get("NameReg").StorageString(toStr).Bytes() - if len(addr) > 0 { - hash = addr - } else { - hash = ethutil.Hex2Bytes(toStr) - } - } - - - var ( - value = ethutil.Big(valueStr) - gas = ethutil.Big(gasStr) - gasPrice = ethutil.Big(gasPriceStr) - data []byte - tx *chain.Transaction - ) - - if ethutil.IsHex(codeStr) { - data = ethutil.Hex2Bytes(codeStr[2:]) - } else { - data = ethutil.Hex2Bytes(codeStr) - } - - if contractCreation { - tx = chain.NewContractCreationTx(value, gas, gasPrice, data) - } else { - tx = chain.NewTransactionMessage(hash, value, gas, gasPrice, data) - } - - acc := self.obj.BlockManager().TransState().GetOrNewStateObject(keyPair.Address()) - tx.Nonce = acc.Nonce - acc.Nonce += 1 - self.obj.BlockManager().TransState().UpdateStateObject(acc) - - tx.Sign(keyPair.PrivateKey) - self.obj.TxPool().QueueTransaction(tx) - - if contractCreation { - pipelogger.Infof("Contract addr %x", tx.CreationAddress(self.World().State())) - } - - return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil - */ } func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) { diff --git a/xeth/js_types.go b/xeth/js_types.go index cba674416..6aba3d993 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -5,8 +5,8 @@ import ( "strconv" "strings" - "github.com/ethereum/go-ethereum/chain" - "github.com/ethereum/go-ethereum/chain/types" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/state" @@ -106,7 +106,7 @@ func NewJSTx(tx *types.Transaction, state *state.State) *JSTransaction { var data string if tx.CreatesContract() { - data = strings.Join(chain.Disassemble(tx.Data), "\n") + data = strings.Join(core.Disassemble(tx.Data), "\n") } else { data = ethutil.Bytes2Hex(tx.Data) } @@ -155,7 +155,7 @@ func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) * // Peer interface exposed to QML type JSPeer struct { - ref *chain.Peer + ref *core.Peer Inbound bool `json:"isInbound"` LastSend int64 `json:"lastSend"` LastPong int64 `json:"lastPong"` @@ -167,7 +167,7 @@ type JSPeer struct { Caps string `json:"caps"` } -func NewJSPeer(peer chain.Peer) *JSPeer { +func NewJSPeer(peer core.Peer) *JSPeer { if peer == nil { return nil } diff --git a/xeth/pipe.go b/xeth/pipe.go index 2dfb91b7f..cabcc1cbe 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -5,8 +5,8 @@ package xeth */ import ( - "github.com/ethereum/go-ethereum/chain" - "github.com/ethereum/go-ethereum/chain/types" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/logger" @@ -20,15 +20,15 @@ type VmVars struct { } type XEth struct { - obj chain.EthManager - blockManager *chain.BlockManager - blockChain *chain.ChainManager + obj core.EthManager + blockManager *core.BlockManager + blockChain *core.ChainManager world *World Vm VmVars } -func New(obj chain.EthManager) *XEth { +func New(obj core.EthManager) *XEth { pipe := &XEth{ obj: obj, blockManager: obj.BlockManager(), diff --git a/xeth/vm_env.go b/xeth/vm_env.go index d11459626..831a310cc 100644 --- a/xeth/vm_env.go +++ b/xeth/vm_env.go @@ -3,8 +3,8 @@ package xeth import ( "math/big" - "github.com/ethereum/go-ethereum/chain" - "github.com/ethereum/go-ethereum/chain/types" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/vm" ) @@ -46,10 +46,10 @@ func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error { return vm.Transfer(from, to, amount) } -func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *chain.Execution { +func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution { evm := vm.New(self, vm.DebugVmTy) - return chain.NewExecution(evm, addr, data, gas, price, value) + return core.NewExecution(evm, addr, data, gas, price, value) } func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) { -- cgit v1.2.3 From 83663ed4b01480c628ce2c849e4e881ac04b5120 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 4 Dec 2014 10:53:49 +0100 Subject: Renames for chain, updated VM, moved methods * Renamed a couple more chain => core * Updated VM `pc` to be uint64 rather than big int * XEth interface cleanup --- xeth/pipe.go | 63 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 35 deletions(-) (limited to 'xeth') diff --git a/xeth/pipe.go b/xeth/pipe.go index cabcc1cbe..f1ecd19d5 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -39,6 +39,9 @@ func New(obj core.EthManager) *XEth { return pipe } +/* + * State / Account accessors + */ func (self *XEth) Balance(addr []byte) *ethutil.Value { return ethutil.NewValue(self.World().safeGet(addr).Balance) } @@ -47,32 +50,6 @@ func (self *XEth) Nonce(addr []byte) uint64 { return self.World().safeGet(addr).Nonce } -func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { - return self.ExecuteObject(&Object{self.World().safeGet(addr)}, data, value, gas, price) -} - -func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { - var ( - initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address()) - block = self.blockChain.CurrentBlock - ) - - self.Vm.State = self.World().State().Copy() - - vmenv := NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address()) - return vmenv.Call(initiator, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) - /* - evm := vm.New(, vm.Type(ethutil.Config.VmType)) - - msg := vm.NewExecution(evm, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) - ret, err := msg.Exec(object.Address(), initiator) - - fmt.Println("returned from call", ret, err) - - return ret, err - */ -} - func (self *XEth) Block(hash []byte) *types.Block { return self.blockChain.GetBlock(hash) } @@ -81,6 +58,11 @@ func (self *XEth) Storage(addr, storageAddr []byte) *ethutil.Value { return self.World().safeGet(addr).GetStorage(ethutil.BigD(storageAddr)) } +func (self *XEth) Exists(addr []byte) bool { + return self.World().Get(addr) != nil +} + +// Converts the given private key to an address func (self *XEth) ToAddress(priv []byte) []byte { pair, err := crypto.NewKeyPairFromSec(priv) if err != nil { @@ -90,10 +72,28 @@ func (self *XEth) ToAddress(priv []byte) []byte { return pair.Address() } -func (self *XEth) Exists(addr []byte) bool { - return self.World().Get(addr) != nil +/* + * Execution helpers + */ +func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { + return self.ExecuteObject(&Object{self.World().safeGet(addr)}, data, value, gas, price) +} + +func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { + var ( + initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address()) + block = self.blockChain.CurrentBlock + ) + + self.Vm.State = self.World().State().Copy() + + vmenv := NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address()) + return vmenv.Call(initiator, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) } +/* + * Transactional methods + */ func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) (*types.Transaction, error) { // Check if an address is stored by this address var hash []byte @@ -149,13 +149,6 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et } return tx, nil - - //acc := self.blockManager.TransState().GetOrNewStateObject(key.Address()) - //self.obj.TxPool().QueueTransaction(tx) - - //acc.Nonce += 1 - //self.blockManager.TransState().UpdateStateObject(acc) - } func (self *XEth) PushTx(tx *types.Transaction) ([]byte, error) { -- cgit v1.2.3 From f298ffdbb8ec2b14f254e880a65f22f4d7c66305 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 4 Dec 2014 11:40:20 +0100 Subject: Renamed State => StateDB --- xeth/js_types.go | 2 +- xeth/pipe.go | 2 +- xeth/vm_env.go | 6 +++--- xeth/world.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'xeth') diff --git a/xeth/js_types.go b/xeth/js_types.go index 6aba3d993..da26439cf 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -95,7 +95,7 @@ type JSTransaction struct { Confirmations int `json:"confirmations"` } -func NewJSTx(tx *types.Transaction, state *state.State) *JSTransaction { +func NewJSTx(tx *types.Transaction, state *state.StateDB) *JSTransaction { hash := ethutil.Bytes2Hex(tx.Hash()) receiver := ethutil.Bytes2Hex(tx.Recipient) if receiver == "0000000000000000000000000000000000000000" { diff --git a/xeth/pipe.go b/xeth/pipe.go index f1ecd19d5..6da92cd23 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -16,7 +16,7 @@ import ( var pipelogger = logger.NewLogger("XETH") type VmVars struct { - State *state.State + State *state.StateDB } type XEth struct { diff --git a/xeth/vm_env.go b/xeth/vm_env.go index 831a310cc..4a2827ff4 100644 --- a/xeth/vm_env.go +++ b/xeth/vm_env.go @@ -10,7 +10,7 @@ import ( ) type VMEnv struct { - state *state.State + state *state.StateDB block *types.Block value *big.Int sender []byte @@ -18,7 +18,7 @@ type VMEnv struct { depth int } -func NewEnv(state *state.State, block *types.Block, value *big.Int, sender []byte) *VMEnv { +func NewEnv(state *state.StateDB, block *types.Block, value *big.Int, sender []byte) *VMEnv { return &VMEnv{ state: state, block: block, @@ -35,7 +35,7 @@ func (self *VMEnv) Time() int64 { return self.block.Time } func (self *VMEnv) Difficulty() *big.Int { return self.block.Difficulty } func (self *VMEnv) BlockHash() []byte { return self.block.Hash() } func (self *VMEnv) Value() *big.Int { return self.value } -func (self *VMEnv) State() *state.State { return self.state } +func (self *VMEnv) State() *state.StateDB { return self.state } func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit } func (self *VMEnv) Depth() int { return self.depth } func (self *VMEnv) SetDepth(i int) { self.depth = i } diff --git a/xeth/world.go b/xeth/world.go index 6fb757d67..c5c20c224 100644 --- a/xeth/world.go +++ b/xeth/world.go @@ -22,7 +22,7 @@ func (self *XEth) World() *World { return self.world } -func (self *World) State() *state.State { +func (self *World) State() *state.StateDB { return self.pipe.blockManager.CurrentState() } -- cgit v1.2.3 From 3043b233ea4df9b630638d75f3589b94653ccfa9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 4 Dec 2014 12:35:23 +0100 Subject: Log is now interface --- xeth/vm_env.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xeth') diff --git a/xeth/vm_env.go b/xeth/vm_env.go index 4a2827ff4..ce53e9a30 100644 --- a/xeth/vm_env.go +++ b/xeth/vm_env.go @@ -39,7 +39,7 @@ func (self *VMEnv) State() *state.StateDB { return self.state } func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit } func (self *VMEnv) Depth() int { return self.depth } func (self *VMEnv) SetDepth(i int) { self.depth = i } -func (self *VMEnv) AddLog(log *state.Log) { +func (self *VMEnv) AddLog(log state.Log) { self.state.AddLog(log) } func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error { -- cgit v1.2.3 From 8c7e4b290fbdfe2c0da451aef03b94bec3c95e4c Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 4 Dec 2014 16:44:14 +0100 Subject: Added pre processing of transaction on the transient state --- xeth/pipe.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'xeth') diff --git a/xeth/pipe.go b/xeth/pipe.go index 6da92cd23..2ca8134ce 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -136,11 +136,17 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et tx.Nonce = nonce tx.Sign(key.PrivateKey) + + // Do some pre processing for our "pre" events and hooks + block := self.blockChain.NewBlock(key.Address()) + coinbase := state.GetStateObject(key.Address()) + coinbase.SetGasPool(block.GasLimit) + self.blockManager.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true) + err := self.obj.TxPool().Add(tx) if err != nil { return nil, err } - state.SetNonce(key.Address(), nonce+1) if contractCreation { -- cgit v1.2.3 From 5553e5aaed5c3f4e303b7d6671d2c92a45aa487e Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 10 Dec 2014 19:59:12 +0100 Subject: states moved to chain --- xeth/pipe.go | 12 ++++++------ xeth/world.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'xeth') diff --git a/xeth/pipe.go b/xeth/pipe.go index 2ca8134ce..a8d8ed999 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -22,7 +22,7 @@ type VmVars struct { type XEth struct { obj core.EthManager blockManager *core.BlockManager - blockChain *core.ChainManager + chainManager *core.ChainManager world *World Vm VmVars @@ -32,7 +32,7 @@ func New(obj core.EthManager) *XEth { pipe := &XEth{ obj: obj, blockManager: obj.BlockManager(), - blockChain: obj.ChainManager(), + chainManager: obj.ChainManager(), } pipe.world = NewWorld(pipe) @@ -51,7 +51,7 @@ func (self *XEth) Nonce(addr []byte) uint64 { } func (self *XEth) Block(hash []byte) *types.Block { - return self.blockChain.GetBlock(hash) + return self.chainManager.GetBlock(hash) } func (self *XEth) Storage(addr, storageAddr []byte) *ethutil.Value { @@ -82,7 +82,7 @@ func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.V func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { var ( initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address()) - block = self.blockChain.CurrentBlock + block = self.chainManager.CurrentBlock ) self.Vm.State = self.World().State().Copy() @@ -131,14 +131,14 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et tx = types.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data) } - state := self.blockManager.TransState() + state := self.chainManager.TransState() nonce := state.GetNonce(key.Address()) tx.Nonce = nonce tx.Sign(key.PrivateKey) // Do some pre processing for our "pre" events and hooks - block := self.blockChain.NewBlock(key.Address()) + block := self.chainManager.NewBlock(key.Address()) coinbase := state.GetStateObject(key.Address()) coinbase.SetGasPool(block.GasLimit) self.blockManager.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true) diff --git a/xeth/world.go b/xeth/world.go index c5c20c224..956ef1e15 100644 --- a/xeth/world.go +++ b/xeth/world.go @@ -23,7 +23,7 @@ func (self *XEth) World() *World { } func (self *World) State() *state.StateDB { - return self.pipe.blockManager.CurrentState() + return self.pipe.chainManager.State() } func (self *World) Get(addr []byte) *Object { -- cgit v1.2.3 From 148de1c8757413f171dbf2fd3e8e5a5976eb7dc9 Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 14 Dec 2014 18:09:33 +0000 Subject: adapt xeth pkg to new backend. FIXME JSPeer peer info --- xeth/hexface.go | 9 ++------ xeth/js_types.go | 65 +++++++++++++++++++++++++++----------------------------- xeth/world.go | 5 ++--- 3 files changed, 35 insertions(+), 44 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index c1f49453d..524b68210 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -3,7 +3,6 @@ package xeth import ( "bytes" "encoding/json" - "sync/atomic" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" @@ -63,12 +62,8 @@ func (self *JSXEth) PeerCount() int { func (self *JSXEth) Peers() []JSPeer { var peers []JSPeer - for peer := self.obj.Peers().Front(); peer != nil; peer = peer.Next() { - p := peer.Value.(core.Peer) - // we only want connected peers - if atomic.LoadInt32(p.Connected()) != 0 { - peers = append(peers, *NewJSPeer(p)) - } + for _, peer := range self.obj.Peers() { + peers = append(peers, *NewJSPeer(peer)) } return peers diff --git a/xeth/js_types.go b/xeth/js_types.go index da26439cf..1d9faa190 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -1,14 +1,13 @@ package xeth import ( - "fmt" - "strconv" "strings" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/state" ) @@ -155,38 +154,36 @@ func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) * // Peer interface exposed to QML type JSPeer struct { - ref *core.Peer - Inbound bool `json:"isInbound"` - LastSend int64 `json:"lastSend"` - LastPong int64 `json:"lastPong"` - Ip string `json:"ip"` - Port int `json:"port"` - Version string `json:"version"` - LastResponse string `json:"lastResponse"` - Latency string `json:"latency"` - Caps string `json:"caps"` -} - -func NewJSPeer(peer core.Peer) *JSPeer { - if peer == nil { - return nil - } - - var ip []string - for _, i := range peer.Host() { - ip = append(ip, strconv.Itoa(int(i))) - } - ipAddress := strings.Join(ip, ".") - - var caps []string - capsIt := peer.Caps().NewIterator() - for capsIt.Next() { - cap := capsIt.Value().Get(0).Str() - ver := capsIt.Value().Get(1).Uint() - caps = append(caps, fmt.Sprintf("%s/%d", cap, ver)) - } - - return &JSPeer{ref: &peer, Inbound: peer.Inbound(), LastSend: peer.LastSend().Unix(), LastPong: peer.LastPong(), Version: peer.Version(), Ip: ipAddress, Port: int(peer.Port()), Latency: peer.PingTime(), Caps: "[" + strings.Join(caps, ", ") + "]"} + ref *p2p.Peer + // Inbound bool `json:"isInbound"` + // LastSend int64 `json:"lastSend"` + // LastPong int64 `json:"lastPong"` + // Ip string `json:"ip"` + // Port int `json:"port"` + // Version string `json:"version"` + // LastResponse string `json:"lastResponse"` + // Latency string `json:"latency"` + // Caps string `json:"caps"` +} + +func NewJSPeer(peer *p2p.Peer) *JSPeer { + + // var ip []string + // for _, i := range peer.Host() { + // ip = append(ip, strconv.Itoa(int(i))) + // } + // ipAddress := strings.Join(ip, ".") + + // var caps []string + // capsIt := peer.Caps().NewIterator() + // for capsIt.Next() { + // cap := capsIt.Value().Get(0).Str() + // ver := capsIt.Value().Get(1).Uint() + // caps = append(caps, fmt.Sprintf("%s/%d", cap, ver)) + // } + + return &JSPeer{ref: peer} + // return &JSPeer{ref: &peer, Inbound: peer.Inbound(), LastSend: peer.LastSend().Unix(), LastPong: peer.LastPong(), Version: peer.Version(), Ip: ipAddress, Port: int(peer.Port()), Latency: peer.PingTime(), Caps: "[" + strings.Join(caps, ", ") + "]"} } type JSReceipt struct { diff --git a/xeth/world.go b/xeth/world.go index 956ef1e15..008a08423 100644 --- a/xeth/world.go +++ b/xeth/world.go @@ -1,8 +1,7 @@ package xeth import ( - "container/list" - + "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/state" ) @@ -55,7 +54,7 @@ func (self *World) IsListening() bool { return self.pipe.obj.IsListening() } -func (self *World) Peers() *list.List { +func (self *World) Peers() []*p2p.Peer { return self.pipe.obj.Peers() } -- cgit v1.2.3 From 2d09e67713757e2a80eb614562c97f962af36cf7 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 13:17:24 +0100 Subject: Updated to new methods --- xeth/hexface.go | 2 +- xeth/pipe.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index c1f49453d..75ec5f43d 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -29,7 +29,7 @@ func (self *JSXEth) BlockByHash(strHash string) *JSBlock { func (self *JSXEth) BlockByNumber(num int32) *JSBlock { if num == -1 { - return NewJSBlock(self.obj.ChainManager().CurrentBlock) + return NewJSBlock(self.obj.ChainManager().CurrentBlock()) } return NewJSBlock(self.obj.ChainManager().GetBlockByNumber(uint64(num))) diff --git a/xeth/pipe.go b/xeth/pipe.go index a8d8ed999..1e4d0ec60 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -82,7 +82,7 @@ func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.V func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { var ( initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address()) - block = self.chainManager.CurrentBlock + block = self.chainManager.CurrentBlock() ) self.Vm.State = self.World().State().Copy() -- cgit v1.2.3 From db494170dc819b1eb0d267b6e1ab36c6cfb63569 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 15:18:13 +0100 Subject: Created generic message (easy for testing) --- xeth/hexface.go | 4 ++-- xeth/js_types.go | 10 +++++----- xeth/pipe.go | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index 75ec5f43d..8fb42b4db 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -216,7 +216,7 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr return "", err } if types.IsContractAddr(to) { - return ethutil.Bytes2Hex(tx.CreationAddress(nil)), nil + return ethutil.Bytes2Hex(core.AddressFromMessage(tx)), nil } return ethutil.Bytes2Hex(tx.Hash()), nil @@ -229,7 +229,7 @@ func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) { return nil, err } - return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(self.World().State()), tx.Hash(), tx.Sender()), nil + return NewJSReciept(tx.CreatesContract(), core.AddressFromMessage(tx), tx.Hash(), tx.From()), nil } func (self *JSXEth) CompileMutan(code string) string { diff --git a/xeth/js_types.go b/xeth/js_types.go index da26439cf..2d6ee91bc 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -97,21 +97,21 @@ type JSTransaction struct { func NewJSTx(tx *types.Transaction, state *state.StateDB) *JSTransaction { hash := ethutil.Bytes2Hex(tx.Hash()) - receiver := ethutil.Bytes2Hex(tx.Recipient) + receiver := ethutil.Bytes2Hex(tx.To()) if receiver == "0000000000000000000000000000000000000000" { - receiver = ethutil.Bytes2Hex(tx.CreationAddress(state)) + receiver = ethutil.Bytes2Hex(core.AddressFromMessage(tx)) } sender := ethutil.Bytes2Hex(tx.Sender()) createsContract := tx.CreatesContract() var data string if tx.CreatesContract() { - data = strings.Join(core.Disassemble(tx.Data), "\n") + data = strings.Join(core.Disassemble(tx.Data()), "\n") } else { - data = ethutil.Bytes2Hex(tx.Data) + data = ethutil.Bytes2Hex(tx.Data()) } - return &JSTransaction{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value), Address: receiver, Contract: tx.CreatesContract(), Gas: tx.Gas.String(), GasPrice: tx.GasPrice.String(), Data: data, Sender: sender, CreatesContract: createsContract, RawData: ethutil.Bytes2Hex(tx.Data)} + return &JSTransaction{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value()), Address: receiver, Contract: tx.CreatesContract(), Gas: tx.Gas().String(), GasPrice: tx.GasPrice().String(), Data: data, Sender: sender, CreatesContract: createsContract, RawData: ethutil.Bytes2Hex(tx.Data())} } func (self *JSTransaction) ToString() string { diff --git a/xeth/pipe.go b/xeth/pipe.go index 1e4d0ec60..06820cc86 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -134,7 +134,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et state := self.chainManager.TransState() nonce := state.GetNonce(key.Address()) - tx.Nonce = nonce + tx.SetNonce(nonce) tx.Sign(key.PrivateKey) // Do some pre processing for our "pre" events and hooks @@ -150,7 +150,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et state.SetNonce(key.Address(), nonce+1) if contractCreation { - addr := tx.CreationAddress(self.World().State()) + addr := core.AddressFromMessage(tx) pipelogger.Infof("Contract addr %x\n", addr) } @@ -163,8 +163,8 @@ func (self *XEth) PushTx(tx *types.Transaction) ([]byte, error) { return nil, err } - if tx.Recipient == nil { - addr := tx.CreationAddress(self.World().State()) + if tx.To() == nil { + addr := core.AddressFromMessage(tx) pipelogger.Infof("Contract addr %x\n", addr) return addr, nil } -- cgit v1.2.3 From 5ad473d7581b92811c3a3e035274a82fc5568f57 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 15:33:22 +0100 Subject: Moved methods to messages --- xeth/hexface.go | 2 +- xeth/js_types.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index 8fb42b4db..bfd2dddd9 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -229,7 +229,7 @@ func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) { return nil, err } - return NewJSReciept(tx.CreatesContract(), core.AddressFromMessage(tx), tx.Hash(), tx.From()), nil + return NewJSReciept(core.MessageCreatesContract(tx), core.AddressFromMessage(tx), tx.Hash(), tx.From()), nil } func (self *JSXEth) CompileMutan(code string) string { diff --git a/xeth/js_types.go b/xeth/js_types.go index 2d6ee91bc..62867d6a9 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -102,16 +102,16 @@ func NewJSTx(tx *types.Transaction, state *state.StateDB) *JSTransaction { receiver = ethutil.Bytes2Hex(core.AddressFromMessage(tx)) } sender := ethutil.Bytes2Hex(tx.Sender()) - createsContract := tx.CreatesContract() + createsContract := core.MessageCreatesContract(tx) var data string - if tx.CreatesContract() { + if createsContract { data = strings.Join(core.Disassemble(tx.Data()), "\n") } else { data = ethutil.Bytes2Hex(tx.Data()) } - return &JSTransaction{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value()), Address: receiver, Contract: tx.CreatesContract(), Gas: tx.Gas().String(), GasPrice: tx.GasPrice().String(), Data: data, Sender: sender, CreatesContract: createsContract, RawData: ethutil.Bytes2Hex(tx.Data())} + return &JSTransaction{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value()), Address: receiver, Contract: createsContract, Gas: tx.Gas().String(), GasPrice: tx.GasPrice().String(), Data: data, Sender: sender, CreatesContract: createsContract, RawData: ethutil.Bytes2Hex(tx.Data())} } func (self *JSTransaction) ToString() string { -- cgit v1.2.3 From 59ef6e36931c980ba15babfb3680514635faebf6 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 19 Dec 2014 00:18:52 +0100 Subject: Cleaned up objects --- xeth/vm_env.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'xeth') diff --git a/xeth/vm_env.go b/xeth/vm_env.go index ce53e9a30..7fb674a94 100644 --- a/xeth/vm_env.go +++ b/xeth/vm_env.go @@ -47,9 +47,7 @@ func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error { } func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution { - evm := vm.New(self, vm.DebugVmTy) - - return core.NewExecution(evm, addr, data, gas, price, value) + return core.NewExecution(self, addr, data, gas, price, value) } func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) { -- cgit v1.2.3 From 4cd79d8ddd7608d60344b13fe4bda7315429d1d9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 23 Dec 2014 13:48:44 +0100 Subject: Refactored block & Transaction * Includes new rlp decoder --- xeth/js_types.go | 20 ++++++++++---------- xeth/pipe.go | 2 +- xeth/vm_env.go | 12 ++++++------ 3 files changed, 17 insertions(+), 17 deletions(-) (limited to 'xeth') diff --git a/xeth/js_types.go b/xeth/js_types.go index 04018f6a5..4bb1f4e7d 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -42,21 +42,21 @@ func NewJSBlock(block *types.Block) *JSBlock { } txlist := ethutil.NewList(ptxs) - puncles := make([]*JSBlock, len(block.Uncles)) - for i, uncle := range block.Uncles { - puncles[i] = NewJSBlock(uncle) + puncles := make([]*JSBlock, len(block.Uncles())) + for i, uncle := range block.Uncles() { + puncles[i] = NewJSBlock(types.NewBlockWithHeader(uncle)) } ulist := ethutil.NewList(puncles) return &JSBlock{ ref: block, Size: block.Size().String(), - Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), - GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), + Number: int(block.NumberU64()), GasUsed: block.GasUsed().String(), + GasLimit: block.GasLimit().String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: txlist, Uncles: ulist, - Time: block.Time, - Coinbase: ethutil.Bytes2Hex(block.Coinbase), - PrevHash: ethutil.Bytes2Hex(block.PrevHash), - Bloom: ethutil.Bytes2Hex(block.LogsBloom), + Time: block.Time(), + Coinbase: ethutil.Bytes2Hex(block.Coinbase()), + PrevHash: ethutil.Bytes2Hex(block.ParentHash()), + Bloom: ethutil.Bytes2Hex(block.Bloom()), Raw: block.String(), } } @@ -70,7 +70,7 @@ func (self *JSBlock) ToString() string { } func (self *JSBlock) GetTransaction(hash string) *JSTransaction { - tx := self.ref.GetTransaction(ethutil.Hex2Bytes(hash)) + tx := self.ref.Transaction(ethutil.Hex2Bytes(hash)) if tx == nil { return nil } diff --git a/xeth/pipe.go b/xeth/pipe.go index 06820cc86..775d5cfc5 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -140,7 +140,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et // Do some pre processing for our "pre" events and hooks block := self.chainManager.NewBlock(key.Address()) coinbase := state.GetStateObject(key.Address()) - coinbase.SetGasPool(block.GasLimit) + coinbase.SetGasPool(block.GasLimit()) self.blockManager.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true) err := self.obj.TxPool().Add(tx) diff --git a/xeth/vm_env.go b/xeth/vm_env.go index 7fb674a94..7633e0640 100644 --- a/xeth/vm_env.go +++ b/xeth/vm_env.go @@ -28,15 +28,15 @@ func NewEnv(state *state.StateDB, block *types.Block, value *big.Int, sender []b } func (self *VMEnv) Origin() []byte { return self.sender } -func (self *VMEnv) BlockNumber() *big.Int { return self.block.Number } -func (self *VMEnv) PrevHash() []byte { return self.block.PrevHash } -func (self *VMEnv) Coinbase() []byte { return self.block.Coinbase } -func (self *VMEnv) Time() int64 { return self.block.Time } -func (self *VMEnv) Difficulty() *big.Int { return self.block.Difficulty } +func (self *VMEnv) BlockNumber() *big.Int { return self.block.Number() } +func (self *VMEnv) PrevHash() []byte { return self.block.ParentHash() } +func (self *VMEnv) Coinbase() []byte { return self.block.Coinbase() } +func (self *VMEnv) Time() int64 { return self.block.Time() } +func (self *VMEnv) Difficulty() *big.Int { return self.block.Difficulty() } func (self *VMEnv) BlockHash() []byte { return self.block.Hash() } +func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit() } func (self *VMEnv) Value() *big.Int { return self.value } func (self *VMEnv) State() *state.StateDB { return self.state } -func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit } func (self *VMEnv) Depth() int { return self.depth } func (self *VMEnv) SetDepth(i int) { self.depth = i } func (self *VMEnv) AddLog(log state.Log) { -- cgit v1.2.3 From 780abaec988df302e0c98f1a35e9af35b5623746 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 23 Dec 2014 18:35:36 +0100 Subject: Switched to new trie --- xeth/hexface.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index 6c084f947..c3d8cef86 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -138,10 +138,10 @@ type KeyVal struct { func (self *JSXEth) EachStorage(addr string) string { var values []KeyVal object := self.World().SafeGet(ethutil.Hex2Bytes(addr)) - object.EachStorage(func(name string, value *ethutil.Value) { - value.Decode() - values = append(values, KeyVal{ethutil.Bytes2Hex([]byte(name)), ethutil.Bytes2Hex(value.Bytes())}) - }) + it := object.Trie().Iterator() + for it.Next() { + values = append(values, KeyVal{ethutil.Bytes2Hex(it.Key), ethutil.Bytes2Hex(it.Value)}) + } valuesJson, err := json.Marshal(values) if err != nil { -- cgit v1.2.3 From 4dc7ee90879d7146c9e5004c04992c90ad78f632 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 2 Jan 2015 16:14:12 +0100 Subject: Closure => Context --- xeth/vm_env.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'xeth') diff --git a/xeth/vm_env.go b/xeth/vm_env.go index 7633e0640..d2a21afd5 100644 --- a/xeth/vm_env.go +++ b/xeth/vm_env.go @@ -50,16 +50,16 @@ func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execu return core.NewExecution(self, addr, data, gas, price, value) } -func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) { +func (self *VMEnv) Call(me vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) { exe := self.vm(addr, data, gas, price, value) return exe.Call(addr, me) } -func (self *VMEnv) CallCode(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) { +func (self *VMEnv) CallCode(me vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) { exe := self.vm(me.Address(), data, gas, price, value) return exe.Call(addr, me) } -func (self *VMEnv) Create(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ClosureRef) { +func (self *VMEnv) Create(me vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) { exe := self.vm(addr, data, gas, price, value) return exe.Create(me) } -- cgit v1.2.3 From 5c82fdc2434c302a2b65a4c7f25fe91b22cd43df Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 2 Jan 2015 22:18:23 +0100 Subject: Make sure that the object exists --- xeth/pipe.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'xeth') diff --git a/xeth/pipe.go b/xeth/pipe.go index 775d5cfc5..cae6ee1de 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -139,7 +139,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et // Do some pre processing for our "pre" events and hooks block := self.chainManager.NewBlock(key.Address()) - coinbase := state.GetStateObject(key.Address()) + coinbase := state.GetOrNewStateObject(key.Address()) coinbase.SetGasPool(block.GasLimit()) self.blockManager.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true) -- cgit v1.2.3 From ca1b2a1a91401255ab4e26cec7eb575b99ecb8da Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 3 Jan 2015 17:18:43 +0100 Subject: Changed prev_hash to block_hash, state transition now uses vm env * PREVHASH => BLOCKHASH( N ) * State transition object uses VMEnv as it's query interface * Updated vm.Enviroment has GetHash( n ) for BLOCKHASH instruction * Added GetHash to xeth, core, utils & test environments --- xeth/pipe.go | 2 +- xeth/vm_env.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'xeth') diff --git a/xeth/pipe.go b/xeth/pipe.go index cae6ee1de..05cefd8ad 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -87,7 +87,7 @@ func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price * self.Vm.State = self.World().State().Copy() - vmenv := NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address()) + vmenv := NewEnv(self.chainManager, self.Vm.State, block, value.BigInt(), initiator.Address()) return vmenv.Call(initiator, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) } diff --git a/xeth/vm_env.go b/xeth/vm_env.go index d2a21afd5..1470b9eaa 100644 --- a/xeth/vm_env.go +++ b/xeth/vm_env.go @@ -10,6 +10,7 @@ import ( ) type VMEnv struct { + chain *core.ChainManager state *state.StateDB block *types.Block value *big.Int @@ -18,7 +19,7 @@ type VMEnv struct { depth int } -func NewEnv(state *state.StateDB, block *types.Block, value *big.Int, sender []byte) *VMEnv { +func NewEnv(chain *core.ChainManager, state *state.StateDB, block *types.Block, value *big.Int, sender []byte) *VMEnv { return &VMEnv{ state: state, block: block, @@ -33,12 +34,18 @@ func (self *VMEnv) PrevHash() []byte { return self.block.ParentHash() } func (self *VMEnv) Coinbase() []byte { return self.block.Coinbase() } func (self *VMEnv) Time() int64 { return self.block.Time() } func (self *VMEnv) Difficulty() *big.Int { return self.block.Difficulty() } -func (self *VMEnv) BlockHash() []byte { return self.block.Hash() } func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit() } func (self *VMEnv) Value() *big.Int { return self.value } func (self *VMEnv) State() *state.StateDB { return self.state } func (self *VMEnv) Depth() int { return self.depth } func (self *VMEnv) SetDepth(i int) { self.depth = i } +func (self *VMEnv) GetHash(n uint64) []byte { + if block := self.chain.GetBlockByNumber(n); block != nil { + return block.Hash() + } + + return nil +} func (self *VMEnv) AddLog(log state.Log) { self.state.AddLog(log) } -- cgit v1.2.3 From c1dee151445d1d9700e0c623916299370868490c Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 5 Jan 2015 00:18:44 +0100 Subject: BlockManager => BlockProcessor --- xeth/pipe.go | 181 ----------------------------------------------------------- xeth/xeth.go | 181 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+), 181 deletions(-) delete mode 100644 xeth/pipe.go create mode 100644 xeth/xeth.go (limited to 'xeth') diff --git a/xeth/pipe.go b/xeth/pipe.go deleted file mode 100644 index 05cefd8ad..000000000 --- a/xeth/pipe.go +++ /dev/null @@ -1,181 +0,0 @@ -package xeth - -/* - * eXtended ETHereum - */ - -import ( - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/ethutil" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/state" -) - -var pipelogger = logger.NewLogger("XETH") - -type VmVars struct { - State *state.StateDB -} - -type XEth struct { - obj core.EthManager - blockManager *core.BlockManager - chainManager *core.ChainManager - world *World - - Vm VmVars -} - -func New(obj core.EthManager) *XEth { - pipe := &XEth{ - obj: obj, - blockManager: obj.BlockManager(), - chainManager: obj.ChainManager(), - } - pipe.world = NewWorld(pipe) - - return pipe -} - -/* - * State / Account accessors - */ -func (self *XEth) Balance(addr []byte) *ethutil.Value { - return ethutil.NewValue(self.World().safeGet(addr).Balance) -} - -func (self *XEth) Nonce(addr []byte) uint64 { - return self.World().safeGet(addr).Nonce -} - -func (self *XEth) Block(hash []byte) *types.Block { - return self.chainManager.GetBlock(hash) -} - -func (self *XEth) Storage(addr, storageAddr []byte) *ethutil.Value { - return self.World().safeGet(addr).GetStorage(ethutil.BigD(storageAddr)) -} - -func (self *XEth) Exists(addr []byte) bool { - return self.World().Get(addr) != nil -} - -// Converts the given private key to an address -func (self *XEth) ToAddress(priv []byte) []byte { - pair, err := crypto.NewKeyPairFromSec(priv) - if err != nil { - return nil - } - - return pair.Address() -} - -/* - * Execution helpers - */ -func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { - return self.ExecuteObject(&Object{self.World().safeGet(addr)}, data, value, gas, price) -} - -func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { - var ( - initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address()) - block = self.chainManager.CurrentBlock() - ) - - self.Vm.State = self.World().State().Copy() - - vmenv := NewEnv(self.chainManager, self.Vm.State, block, value.BigInt(), initiator.Address()) - return vmenv.Call(initiator, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) -} - -/* - * Transactional methods - */ -func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) (*types.Transaction, error) { - // Check if an address is stored by this address - var hash []byte - addr := self.World().Config().Get("NameReg").StorageString(rec).Bytes() - if len(addr) > 0 { - hash = addr - } else if ethutil.IsHex(rec) { - hash = ethutil.Hex2Bytes(rec[2:]) - } else { - hash = ethutil.Hex2Bytes(rec) - } - - return self.Transact(key, hash, value, gas, price, data) -} - -func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *ethutil.Value, data []byte) (*types.Transaction, error) { - var hash []byte - var contractCreation bool - if types.IsContractAddr(to) { - contractCreation = true - } else { - // Check if an address is stored by this address - addr := self.World().Config().Get("NameReg").Storage(to).Bytes() - if len(addr) > 0 { - hash = addr - } else { - hash = to - } - } - - var tx *types.Transaction - if contractCreation { - tx = types.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), data) - } else { - tx = types.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data) - } - - state := self.chainManager.TransState() - nonce := state.GetNonce(key.Address()) - - tx.SetNonce(nonce) - tx.Sign(key.PrivateKey) - - // Do some pre processing for our "pre" events and hooks - block := self.chainManager.NewBlock(key.Address()) - coinbase := state.GetOrNewStateObject(key.Address()) - coinbase.SetGasPool(block.GasLimit()) - self.blockManager.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true) - - err := self.obj.TxPool().Add(tx) - if err != nil { - return nil, err - } - state.SetNonce(key.Address(), nonce+1) - - if contractCreation { - addr := core.AddressFromMessage(tx) - pipelogger.Infof("Contract addr %x\n", addr) - } - - return tx, nil -} - -func (self *XEth) PushTx(tx *types.Transaction) ([]byte, error) { - err := self.obj.TxPool().Add(tx) - if err != nil { - return nil, err - } - - if tx.To() == nil { - addr := core.AddressFromMessage(tx) - pipelogger.Infof("Contract addr %x\n", addr) - return addr, nil - } - return tx.Hash(), nil -} - -func (self *XEth) CompileMutan(code string) ([]byte, error) { - data, err := ethutil.Compile(code, false) - if err != nil { - return nil, err - } - - return data, nil -} diff --git a/xeth/xeth.go b/xeth/xeth.go new file mode 100644 index 000000000..a10ccfc8b --- /dev/null +++ b/xeth/xeth.go @@ -0,0 +1,181 @@ +package xeth + +/* + * eXtended ETHereum + */ + +import ( + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/state" +) + +var pipelogger = logger.NewLogger("XETH") + +type VmVars struct { + State *state.StateDB +} + +type XEth struct { + obj core.EthManager + blockProcessor *core.BlockProcessor + chainManager *core.ChainManager + world *World + + Vm VmVars +} + +func New(obj core.EthManager) *XEth { + pipe := &XEth{ + obj: obj, + blockProcessor: obj.BlockProcessor(), + chainManager: obj.ChainManager(), + } + pipe.world = NewWorld(pipe) + + return pipe +} + +/* + * State / Account accessors + */ +func (self *XEth) Balance(addr []byte) *ethutil.Value { + return ethutil.NewValue(self.World().safeGet(addr).Balance) +} + +func (self *XEth) Nonce(addr []byte) uint64 { + return self.World().safeGet(addr).Nonce +} + +func (self *XEth) Block(hash []byte) *types.Block { + return self.chainManager.GetBlock(hash) +} + +func (self *XEth) Storage(addr, storageAddr []byte) *ethutil.Value { + return self.World().safeGet(addr).GetStorage(ethutil.BigD(storageAddr)) +} + +func (self *XEth) Exists(addr []byte) bool { + return self.World().Get(addr) != nil +} + +// Converts the given private key to an address +func (self *XEth) ToAddress(priv []byte) []byte { + pair, err := crypto.NewKeyPairFromSec(priv) + if err != nil { + return nil + } + + return pair.Address() +} + +/* + * Execution helpers + */ +func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { + return self.ExecuteObject(&Object{self.World().safeGet(addr)}, data, value, gas, price) +} + +func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { + var ( + initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address()) + block = self.chainManager.CurrentBlock() + ) + + self.Vm.State = self.World().State().Copy() + + vmenv := NewEnv(self.chainManager, self.Vm.State, block, value.BigInt(), initiator.Address()) + return vmenv.Call(initiator, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) +} + +/* + * Transactional methods + */ +func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) (*types.Transaction, error) { + // Check if an address is stored by this address + var hash []byte + addr := self.World().Config().Get("NameReg").StorageString(rec).Bytes() + if len(addr) > 0 { + hash = addr + } else if ethutil.IsHex(rec) { + hash = ethutil.Hex2Bytes(rec[2:]) + } else { + hash = ethutil.Hex2Bytes(rec) + } + + return self.Transact(key, hash, value, gas, price, data) +} + +func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *ethutil.Value, data []byte) (*types.Transaction, error) { + var hash []byte + var contractCreation bool + if types.IsContractAddr(to) { + contractCreation = true + } else { + // Check if an address is stored by this address + addr := self.World().Config().Get("NameReg").Storage(to).Bytes() + if len(addr) > 0 { + hash = addr + } else { + hash = to + } + } + + var tx *types.Transaction + if contractCreation { + tx = types.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), data) + } else { + tx = types.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data) + } + + state := self.chainManager.TransState() + nonce := state.GetNonce(key.Address()) + + tx.SetNonce(nonce) + tx.Sign(key.PrivateKey) + + // Do some pre processing for our "pre" events and hooks + block := self.chainManager.NewBlock(key.Address()) + coinbase := state.GetOrNewStateObject(key.Address()) + coinbase.SetGasPool(block.GasLimit()) + self.blockProcessor.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true) + + err := self.obj.TxPool().Add(tx) + if err != nil { + return nil, err + } + state.SetNonce(key.Address(), nonce+1) + + if contractCreation { + addr := core.AddressFromMessage(tx) + pipelogger.Infof("Contract addr %x\n", addr) + } + + return tx, nil +} + +func (self *XEth) PushTx(tx *types.Transaction) ([]byte, error) { + err := self.obj.TxPool().Add(tx) + if err != nil { + return nil, err + } + + if tx.To() == nil { + addr := core.AddressFromMessage(tx) + pipelogger.Infof("Contract addr %x\n", addr) + return addr, nil + } + return tx.Hash(), nil +} + +func (self *XEth) CompileMutan(code string) ([]byte, error) { + data, err := ethutil.Compile(code, false) + if err != nil { + return nil, err + } + + return data, nil +} -- cgit v1.2.3 From c9985bf563888d5f346408d2ff174167e8b65880 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 5 Jan 2015 19:53:53 +0100 Subject: Fixed peer window. Minor tweaks and fixes --- xeth/js_types.go | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) (limited to 'xeth') diff --git a/xeth/js_types.go b/xeth/js_types.go index 4bb1f4e7d..dbddcb7a3 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -1,6 +1,7 @@ package xeth import ( + "fmt" "strings" "github.com/ethereum/go-ethereum/core" @@ -154,36 +155,24 @@ func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) * // Peer interface exposed to QML type JSPeer struct { - ref *p2p.Peer - // Inbound bool `json:"isInbound"` - // LastSend int64 `json:"lastSend"` - // LastPong int64 `json:"lastPong"` - // Ip string `json:"ip"` - // Port int `json:"port"` - // Version string `json:"version"` - // LastResponse string `json:"lastResponse"` - // Latency string `json:"latency"` - // Caps string `json:"caps"` + ref *p2p.Peer + Ip string `json:"ip"` + Version string `json:"version"` + Caps string `json:"caps"` } func NewJSPeer(peer *p2p.Peer) *JSPeer { + var caps []string + for _, cap := range peer.Caps() { + caps = append(caps, fmt.Sprintf("%s/%d", cap.Name, cap.Version)) + } - // var ip []string - // for _, i := range peer.Host() { - // ip = append(ip, strconv.Itoa(int(i))) - // } - // ipAddress := strings.Join(ip, ".") - - // var caps []string - // capsIt := peer.Caps().NewIterator() - // for capsIt.Next() { - // cap := capsIt.Value().Get(0).Str() - // ver := capsIt.Value().Get(1).Uint() - // caps = append(caps, fmt.Sprintf("%s/%d", cap, ver)) - // } - - return &JSPeer{ref: peer} - // return &JSPeer{ref: &peer, Inbound: peer.Inbound(), LastSend: peer.LastSend().Unix(), LastPong: peer.LastPong(), Version: peer.Version(), Ip: ipAddress, Port: int(peer.Port()), Latency: peer.PingTime(), Caps: "[" + strings.Join(caps, ", ") + "]"} + return &JSPeer{ + ref: peer, + Ip: peer.RemoteAddr().String(), + Version: peer.Identity().String(), + Caps: fmt.Sprintf("%v", caps), + } } type JSReceipt struct { -- cgit v1.2.3 From 564f02aa2b1188a2a736a9345f2afaa13e50ef45 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 6 Jan 2015 13:18:09 +0100 Subject: Fixed tests --- xeth/js_types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'xeth') diff --git a/xeth/js_types.go b/xeth/js_types.go index dbddcb7a3..e7a1e95e9 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -169,8 +169,8 @@ func NewJSPeer(peer *p2p.Peer) *JSPeer { return &JSPeer{ ref: peer, - Ip: peer.RemoteAddr().String(), - Version: peer.Identity().String(), + Ip: fmt.Sprintf("%v", peer.RemoteAddr()), + Version: fmt.Sprintf("%v", peer.Identity()), Caps: fmt.Sprintf("%v", caps), } } -- cgit v1.2.3 From fed3e6a808921fb8274b50043c5c39a24a1bbccf Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 7 Jan 2015 13:17:48 +0100 Subject: Refactored ethutil.Config.Db out --- xeth/js_types.go | 6 +++--- xeth/world.go | 2 +- xeth/xeth.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'xeth') diff --git a/xeth/js_types.go b/xeth/js_types.go index e7a1e95e9..5fe5946b1 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -39,7 +39,7 @@ func NewJSBlock(block *types.Block) *JSBlock { ptxs := make([]*JSTransaction, len(block.Transactions())) for i, tx := range block.Transactions() { - ptxs[i] = NewJSTx(tx, block.State()) + ptxs[i] = NewJSTx(tx) } txlist := ethutil.NewList(ptxs) @@ -76,7 +76,7 @@ func (self *JSBlock) GetTransaction(hash string) *JSTransaction { return nil } - return NewJSTx(tx, self.ref.State()) + return NewJSTx(tx) } type JSTransaction struct { @@ -95,7 +95,7 @@ type JSTransaction struct { Confirmations int `json:"confirmations"` } -func NewJSTx(tx *types.Transaction, state *state.StateDB) *JSTransaction { +func NewJSTx(tx *types.Transaction) *JSTransaction { hash := ethutil.Bytes2Hex(tx.Hash()) receiver := ethutil.Bytes2Hex(tx.To()) if receiver == "0000000000000000000000000000000000000000" { diff --git a/xeth/world.go b/xeth/world.go index 008a08423..25c2f3eb8 100644 --- a/xeth/world.go +++ b/xeth/world.go @@ -36,7 +36,7 @@ func (self *World) SafeGet(addr []byte) *Object { func (self *World) safeGet(addr []byte) *state.StateObject { object := self.State().GetStateObject(addr) if object == nil { - object = state.NewStateObject(addr) + object = state.NewStateObject(addr, self.pipe.obj.Db()) } return object diff --git a/xeth/xeth.go b/xeth/xeth.go index a10ccfc8b..34d8ffd0a 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -81,7 +81,7 @@ func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.V func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { var ( - initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address()) + initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address(), self.obj.Db()) block = self.chainManager.CurrentBlock() ) -- cgit v1.2.3 From e3da85faedf21a3ddb73a0fa29decf65364e6c39 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 10 Jan 2015 00:51:56 +0100 Subject: Implemented filter for ws + fixes * proper 0xhex * filters fixed * start of filter manager * accounts for ws. Closes #246 --- xeth/hexface.go | 73 ++++++++++++++++++++++++-------------------------------- xeth/js_types.go | 63 +++++++++++++++++++++++++++++------------------- 2 files changed, 69 insertions(+), 67 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index c3d8cef86..808ae7d39 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -20,7 +20,7 @@ func NewJSXEth(eth core.EthManager) *JSXEth { } func (self *JSXEth) BlockByHash(strHash string) *JSBlock { - hash := ethutil.Hex2Bytes(strHash) + hash := fromHex(strHash) block := self.obj.ChainManager().GetBlock(hash) return NewJSBlock(block) @@ -50,8 +50,12 @@ func (self *JSXEth) Key() *JSKey { return NewJSKey(self.obj.KeyManager().KeyPair()) } +func (self *JSXEth) Accounts() []string { + return []string{toHex(self.obj.KeyManager().Address())} +} + func (self *JSXEth) StateObject(addr string) *JSObject { - object := &Object{self.World().safeGet(ethutil.Hex2Bytes(addr))} + object := &Object{self.World().safeGet(fromHex(addr))} return NewJSObject(object) } @@ -78,7 +82,7 @@ func (self *JSXEth) IsListening() bool { } func (self *JSXEth) CoinBase() string { - return ethutil.Bytes2Hex(self.obj.KeyManager().Address()) + return toHex(self.obj.KeyManager().Address()) } func (self *JSXEth) NumberToHuman(balance string) string { @@ -88,46 +92,46 @@ func (self *JSXEth) NumberToHuman(balance string) string { } func (self *JSXEth) StorageAt(addr, storageAddr string) string { - storage := self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr)) + storage := self.World().SafeGet(fromHex(addr)).Storage(fromHex(storageAddr)) - return ethutil.Bytes2Hex(storage.Bytes()) + return toHex(storage.Bytes()) } func (self *JSXEth) BalanceAt(addr string) string { - return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Balance().String() + return self.World().SafeGet(fromHex(addr)).Balance().String() } func (self *JSXEth) TxCountAt(address string) int { - return int(self.World().SafeGet(ethutil.Hex2Bytes(address)).Nonce) + return int(self.World().SafeGet(fromHex(address)).Nonce) } func (self *JSXEth) CodeAt(address string) string { - return ethutil.Bytes2Hex(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code) + return toHex(self.World().SafeGet(fromHex(address)).Code) } func (self *JSXEth) IsContract(address string) bool { - return len(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code) > 0 + return len(self.World().SafeGet(fromHex(address)).Code) > 0 } func (self *JSXEth) SecretToAddress(key string) string { - pair, err := crypto.NewKeyPairFromSec(ethutil.Hex2Bytes(key)) + pair, err := crypto.NewKeyPairFromSec(fromHex(key)) if err != nil { return "" } - return ethutil.Bytes2Hex(pair.Address()) + return toHex(pair.Address()) } func (self *JSXEth) Execute(addr, value, gas, price, data string) (string, error) { ret, err := self.ExecuteObject(&Object{ - self.World().safeGet(ethutil.Hex2Bytes(addr))}, - ethutil.Hex2Bytes(data), + self.World().safeGet(fromHex(addr))}, + fromHex(data), ethutil.NewValue(value), ethutil.NewValue(gas), ethutil.NewValue(price), ) - return ethutil.Bytes2Hex(ret), err + return toHex(ret), err } type KeyVal struct { @@ -137,10 +141,10 @@ type KeyVal struct { func (self *JSXEth) EachStorage(addr string) string { var values []KeyVal - object := self.World().SafeGet(ethutil.Hex2Bytes(addr)) + object := self.World().SafeGet(fromHex(addr)) it := object.Trie().Iterator() for it.Next() { - values = append(values, KeyVal{ethutil.Bytes2Hex(it.Key), ethutil.Bytes2Hex(it.Value)}) + values = append(values, KeyVal{toHex(it.Key), toHex(it.Value)}) } valuesJson, err := json.Marshal(values) @@ -154,7 +158,7 @@ func (self *JSXEth) EachStorage(addr string) string { func (self *JSXEth) ToAscii(str string) string { padded := ethutil.RightPadBytes([]byte(str), 32) - return "0x" + ethutil.Bytes2Hex(padded) + return "0x" + toHex(padded) } func (self *JSXEth) FromAscii(str string) string { @@ -162,7 +166,7 @@ func (self *JSXEth) FromAscii(str string) string { str = str[2:] } - return string(bytes.Trim(ethutil.Hex2Bytes(str), "\x00")) + return string(bytes.Trim(fromHex(str), "\x00")) } func (self *JSXEth) FromNumber(str string) string { @@ -170,7 +174,7 @@ func (self *JSXEth) FromNumber(str string) string { str = str[2:] } - return ethutil.BigD(ethutil.Hex2Bytes(str)).String() + return ethutil.BigD(fromHex(str)).String() } func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { @@ -182,26 +186,11 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr data []byte ) - if ethutil.IsHex(codeStr) { - data = ethutil.Hex2Bytes(codeStr[2:]) - } else { - data = ethutil.Hex2Bytes(codeStr) - } - - if ethutil.IsHex(toStr) { - to = ethutil.Hex2Bytes(toStr[2:]) - } else { - to = ethutil.Hex2Bytes(toStr) - } + data = fromHex(codeStr) - var keyPair *crypto.KeyPair - var err error - if ethutil.IsHex(key) { - keyPair, err = crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(key[2:]))) - } else { - keyPair, err = crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(key))) - } + to = fromHex(toStr) + keyPair, err := crypto.NewKeyPairFromSec([]byte(fromHex(key))) if err != nil { return "", err } @@ -211,14 +200,14 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr return "", err } if types.IsContractAddr(to) { - return ethutil.Bytes2Hex(core.AddressFromMessage(tx)), nil + return toHex(core.AddressFromMessage(tx)), nil } - return ethutil.Bytes2Hex(tx.Hash()), nil + return toHex(tx.Hash()), nil } func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) { - tx := types.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) + tx := types.NewTransactionFromBytes(fromHex(txStr)) err := self.obj.TxPool().Add(tx) if err != nil { return nil, err @@ -233,11 +222,11 @@ func (self *JSXEth) CompileMutan(code string) string { return err.Error() } - return ethutil.Bytes2Hex(data) + return toHex(data) } func (self *JSXEth) FindInConfig(str string) string { - return ethutil.Bytes2Hex(self.World().Config().Get(str).Address()) + return toHex(self.World().Config().Get(str).Address()) } func ToJSMessages(messages state.Messages) *ethutil.List { diff --git a/xeth/js_types.go b/xeth/js_types.go index 5fe5946b1..a0be996ff 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -12,6 +12,19 @@ import ( "github.com/ethereum/go-ethereum/state" ) +func toHex(b []byte) string { + return "0x" + ethutil.Bytes2Hex(b) +} +func fromHex(s string) []byte { + if len(s) > 1 { + if s[0:2] == "0x" { + s = s[2:] + } + return ethutil.Hex2Bytes(s) + } + return nil +} + // Block interface exposed to QML type JSBlock struct { //Transactions string `json:"transactions"` @@ -52,12 +65,12 @@ func NewJSBlock(block *types.Block) *JSBlock { return &JSBlock{ ref: block, Size: block.Size().String(), Number: int(block.NumberU64()), GasUsed: block.GasUsed().String(), - GasLimit: block.GasLimit().String(), Hash: ethutil.Bytes2Hex(block.Hash()), + GasLimit: block.GasLimit().String(), Hash: toHex(block.Hash()), Transactions: txlist, Uncles: ulist, Time: block.Time(), - Coinbase: ethutil.Bytes2Hex(block.Coinbase()), - PrevHash: ethutil.Bytes2Hex(block.ParentHash()), - Bloom: ethutil.Bytes2Hex(block.Bloom()), + Coinbase: toHex(block.Coinbase()), + PrevHash: toHex(block.ParentHash()), + Bloom: toHex(block.Bloom()), Raw: block.String(), } } @@ -71,7 +84,7 @@ func (self *JSBlock) ToString() string { } func (self *JSBlock) GetTransaction(hash string) *JSTransaction { - tx := self.ref.Transaction(ethutil.Hex2Bytes(hash)) + tx := self.ref.Transaction(fromHex(hash)) if tx == nil { return nil } @@ -96,22 +109,22 @@ type JSTransaction struct { } func NewJSTx(tx *types.Transaction) *JSTransaction { - hash := ethutil.Bytes2Hex(tx.Hash()) - receiver := ethutil.Bytes2Hex(tx.To()) + hash := toHex(tx.Hash()) + receiver := toHex(tx.To()) if receiver == "0000000000000000000000000000000000000000" { - receiver = ethutil.Bytes2Hex(core.AddressFromMessage(tx)) + receiver = toHex(core.AddressFromMessage(tx)) } - sender := ethutil.Bytes2Hex(tx.From()) + sender := toHex(tx.From()) createsContract := core.MessageCreatesContract(tx) var data string if createsContract { data = strings.Join(core.Disassemble(tx.Data()), "\n") } else { - data = ethutil.Bytes2Hex(tx.Data()) + data = toHex(tx.Data()) } - return &JSTransaction{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value()), Address: receiver, Contract: createsContract, Gas: tx.Gas().String(), GasPrice: tx.GasPrice().String(), Data: data, Sender: sender, CreatesContract: createsContract, RawData: ethutil.Bytes2Hex(tx.Data())} + return &JSTransaction{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value()), Address: receiver, Contract: createsContract, Gas: tx.Gas().String(), GasPrice: tx.GasPrice().String(), Data: data, Sender: sender, CreatesContract: createsContract, RawData: toHex(tx.Data())} } func (self *JSTransaction) ToString() string { @@ -125,7 +138,7 @@ type JSKey struct { } func NewJSKey(key *crypto.KeyPair) *JSKey { - return &JSKey{ethutil.Bytes2Hex(key.Address()), ethutil.Bytes2Hex(key.PrivateKey), ethutil.Bytes2Hex(key.PublicKey)} + return &JSKey{toHex(key.Address()), toHex(key.PrivateKey), toHex(key.PublicKey)} } type JSObject struct { @@ -146,9 +159,9 @@ type PReceipt struct { func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) *PReceipt { return &PReceipt{ contractCreation, - ethutil.Bytes2Hex(creationAddress), - ethutil.Bytes2Hex(hash), - ethutil.Bytes2Hex(address), + toHex(creationAddress), + toHex(hash), + toHex(address), } } @@ -185,9 +198,9 @@ type JSReceipt struct { func NewJSReciept(contractCreation bool, creationAddress, hash, address []byte) *JSReceipt { return &JSReceipt{ contractCreation, - ethutil.Bytes2Hex(creationAddress), - ethutil.Bytes2Hex(hash), - ethutil.Bytes2Hex(address), + toHex(creationAddress), + toHex(hash), + toHex(address), } } @@ -207,15 +220,15 @@ type JSMessage struct { func NewJSMessage(message *state.Message) JSMessage { return JSMessage{ - To: ethutil.Bytes2Hex(message.To), - From: ethutil.Bytes2Hex(message.From), - Input: ethutil.Bytes2Hex(message.Input), - Output: ethutil.Bytes2Hex(message.Output), + To: toHex(message.To), + From: toHex(message.From), + Input: toHex(message.Input), + Output: toHex(message.Output), Path: int32(message.Path), - Origin: ethutil.Bytes2Hex(message.Origin), + Origin: toHex(message.Origin), Timestamp: int32(message.Timestamp), - Coinbase: ethutil.Bytes2Hex(message.Origin), - Block: ethutil.Bytes2Hex(message.Block), + Coinbase: toHex(message.Origin), + Block: toHex(message.Block), Number: int32(message.Number.Int64()), Value: message.Value.String(), } -- cgit v1.2.3 From 7f638f0b2d8d989be25e660178d79df3278e4c84 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 28 Jan 2015 18:14:28 +0100 Subject: moving to a better xeth --- xeth/config.go | 2 + xeth/hexface.go | 150 ++++++++++++++++++++---------------------------- xeth/world.go | 57 +++++-------------- xeth/xeth.go | 174 +------------------------------------------------------- 4 files changed, 77 insertions(+), 306 deletions(-) (limited to 'xeth') diff --git a/xeth/config.go b/xeth/config.go index ad0660d75..db6cce3bd 100644 --- a/xeth/config.go +++ b/xeth/config.go @@ -1,5 +1,6 @@ package xeth +/* import "github.com/ethereum/go-ethereum/ethutil" var cnfCtr = ethutil.Hex2Bytes("661005d2720d855f1d9976f88bb10c1a3398c77f") @@ -33,3 +34,4 @@ func (self *Config) Get(name string) *Object { func (self *Config) Exist() bool { return self.pipe.World().Get(cnfCtr) != nil } +*/ diff --git a/xeth/hexface.go b/xeth/hexface.go index 808ae7d39..3eb535724 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -11,27 +11,52 @@ import ( "github.com/ethereum/go-ethereum/state" ) +// to resolve the import cycle +type Backend interface { + BlockProcessor() *core.BlockProcessor + ChainManager() *core.ChainManager + Coinbase() []byte + KeyManager() *crypto.KeyManager + IsMining() bool + IsListening() bool + PeerCount() int + Db() ethutil.Database + TxPool() *core.TxPool +} + type JSXEth struct { - *XEth + eth Backend + blockProcessor *core.BlockProcessor + chainManager *core.ChainManager + world *State } -func NewJSXEth(eth core.EthManager) *JSXEth { - return &JSXEth{New(eth)} +func NewJSXEth(eth Backend) *JSXEth { + xeth := &JSXEth{ + eth: eth, + blockProcessor: eth.BlockProcessor(), + chainManager: eth.ChainManager(), + } + xeth.world = NewState(xeth) + + return xeth } +func (self *JSXEth) State() *State { return self.world } + func (self *JSXEth) BlockByHash(strHash string) *JSBlock { hash := fromHex(strHash) - block := self.obj.ChainManager().GetBlock(hash) + block := self.chainManager.GetBlock(hash) return NewJSBlock(block) } func (self *JSXEth) BlockByNumber(num int32) *JSBlock { if num == -1 { - return NewJSBlock(self.obj.ChainManager().CurrentBlock()) + return NewJSBlock(self.chainManager.CurrentBlock()) } - return NewJSBlock(self.obj.ChainManager().GetBlockByNumber(uint64(num))) + return NewJSBlock(self.chainManager.GetBlockByNumber(uint64(num))) } func (self *JSXEth) Block(v interface{}) *JSBlock { @@ -46,43 +71,32 @@ func (self *JSXEth) Block(v interface{}) *JSBlock { return nil } -func (self *JSXEth) Key() *JSKey { - return NewJSKey(self.obj.KeyManager().KeyPair()) -} - func (self *JSXEth) Accounts() []string { - return []string{toHex(self.obj.KeyManager().Address())} + return []string{toHex(self.eth.KeyManager().Address())} } +/* func (self *JSXEth) StateObject(addr string) *JSObject { - object := &Object{self.World().safeGet(fromHex(addr))} + object := &Object{self.State().safeGet(fromHex(addr))} return NewJSObject(object) } +*/ func (self *JSXEth) PeerCount() int { - return self.obj.PeerCount() -} - -func (self *JSXEth) Peers() []JSPeer { - var peers []JSPeer - for _, peer := range self.obj.Peers() { - peers = append(peers, *NewJSPeer(peer)) - } - - return peers + return self.eth.PeerCount() } func (self *JSXEth) IsMining() bool { - return self.obj.IsMining() + return self.eth.IsMining() } func (self *JSXEth) IsListening() bool { - return self.obj.IsListening() + return self.eth.IsListening() } -func (self *JSXEth) CoinBase() string { - return toHex(self.obj.KeyManager().Address()) +func (self *JSXEth) Coinbase() string { + return toHex(self.eth.KeyManager().Address()) } func (self *JSXEth) NumberToHuman(balance string) string { @@ -92,25 +106,25 @@ func (self *JSXEth) NumberToHuman(balance string) string { } func (self *JSXEth) StorageAt(addr, storageAddr string) string { - storage := self.World().SafeGet(fromHex(addr)).Storage(fromHex(storageAddr)) + storage := self.State().SafeGet(addr).StorageString(storageAddr) return toHex(storage.Bytes()) } func (self *JSXEth) BalanceAt(addr string) string { - return self.World().SafeGet(fromHex(addr)).Balance().String() + return self.State().SafeGet(addr).Balance().String() } func (self *JSXEth) TxCountAt(address string) int { - return int(self.World().SafeGet(fromHex(address)).Nonce) + return int(self.State().SafeGet(address).Nonce) } func (self *JSXEth) CodeAt(address string) string { - return toHex(self.World().SafeGet(fromHex(address)).Code) + return toHex(self.State().SafeGet(address).Code) } func (self *JSXEth) IsContract(address string) bool { - return len(self.World().SafeGet(fromHex(address)).Code) > 0 + return len(self.State().SafeGet(address).Code) > 0 } func (self *JSXEth) SecretToAddress(key string) string { @@ -123,15 +137,7 @@ func (self *JSXEth) SecretToAddress(key string) string { } func (self *JSXEth) Execute(addr, value, gas, price, data string) (string, error) { - ret, err := self.ExecuteObject(&Object{ - self.World().safeGet(fromHex(addr))}, - fromHex(data), - ethutil.NewValue(value), - ethutil.NewValue(gas), - ethutil.NewValue(price), - ) - - return toHex(ret), err + return "", nil } type KeyVal struct { @@ -141,7 +147,7 @@ type KeyVal struct { func (self *JSXEth) EachStorage(addr string) string { var values []KeyVal - object := self.World().SafeGet(fromHex(addr)) + object := self.State().SafeGet(addr) it := object.Trie().Iterator() for it.Next() { values = append(values, KeyVal{toHex(it.Key), toHex(it.Value)}) @@ -178,62 +184,28 @@ func (self *JSXEth) FromNumber(str string) string { } func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { - var ( - to []byte - value = ethutil.NewValue(valueStr) - gas = ethutil.NewValue(gasStr) - gasPrice = ethutil.NewValue(gasPriceStr) - data []byte - ) - - data = fromHex(codeStr) - - to = fromHex(toStr) - - keyPair, err := crypto.NewKeyPairFromSec([]byte(fromHex(key))) - if err != nil { - return "", err - } - - tx, err := self.XEth.Transact(keyPair, to, value, gas, gasPrice, data) - if err != nil { - return "", err - } - if types.IsContractAddr(to) { - return toHex(core.AddressFromMessage(tx)), nil - } - - return toHex(tx.Hash()), nil + return "", nil } -func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) { - tx := types.NewTransactionFromBytes(fromHex(txStr)) - err := self.obj.TxPool().Add(tx) - if err != nil { - return nil, err +func ToJSMessages(messages state.Messages) *ethutil.List { + var msgs []JSMessage + for _, m := range messages { + msgs = append(msgs, NewJSMessage(m)) } - return NewJSReciept(core.MessageCreatesContract(tx), core.AddressFromMessage(tx), tx.Hash(), tx.From()), nil + return ethutil.NewList(msgs) } -func (self *JSXEth) CompileMutan(code string) string { - data, err := self.XEth.CompileMutan(code) +func (self *JSXEth) PushTx(encodedTx string) (string, error) { + tx := types.NewTransactionFromBytes(fromHex(encodedTx)) + err := self.eth.TxPool().Add(tx) if err != nil { - return err.Error() + return "", err } - return toHex(data) -} - -func (self *JSXEth) FindInConfig(str string) string { - return toHex(self.World().Config().Get(str).Address()) -} - -func ToJSMessages(messages state.Messages) *ethutil.List { - var msgs []JSMessage - for _, m := range messages { - msgs = append(msgs, NewJSMessage(m)) + if tx.To() == nil { + addr := core.AddressFromMessage(tx) + return toHex(addr), nil } - - return ethutil.NewList(msgs) + return toHex(tx.Hash()), nil } diff --git a/xeth/world.go b/xeth/world.go index 25c2f3eb8..60d4bbb57 100644 --- a/xeth/world.go +++ b/xeth/world.go @@ -1,63 +1,32 @@ package xeth -import ( - "github.com/ethereum/go-ethereum/p2p" - "github.com/ethereum/go-ethereum/state" -) - -type World struct { - pipe *XEth - cfg *Config -} - -func NewWorld(pipe *XEth) *World { - world := &World{pipe, nil} - world.cfg = &Config{pipe} +import "github.com/ethereum/go-ethereum/state" - return world +type State struct { + xeth *JSXEth } -func (self *XEth) World() *World { - return self.world +func NewState(xeth *JSXEth) *State { + return &State{xeth} } -func (self *World) State() *state.StateDB { - return self.pipe.chainManager.State() +func (self *State) State() *state.StateDB { + return self.xeth.chainManager.State() } -func (self *World) Get(addr []byte) *Object { - return &Object{self.State().GetStateObject(addr)} +func (self *State) Get(addr string) *Object { + return &Object{self.State().GetStateObject(fromHex(addr))} } -func (self *World) SafeGet(addr []byte) *Object { +func (self *State) SafeGet(addr string) *Object { return &Object{self.safeGet(addr)} } -func (self *World) safeGet(addr []byte) *state.StateObject { - object := self.State().GetStateObject(addr) +func (self *State) safeGet(addr string) *state.StateObject { + object := self.State().GetStateObject(fromHex(addr)) if object == nil { - object = state.NewStateObject(addr, self.pipe.obj.Db()) + object = state.NewStateObject(fromHex(addr), self.xeth.eth.Db()) } return object } - -func (self *World) Coinbase() *state.StateObject { - return nil -} - -func (self *World) IsMining() bool { - return self.pipe.obj.IsMining() -} - -func (self *World) IsListening() bool { - return self.pipe.obj.IsListening() -} - -func (self *World) Peers() []*p2p.Peer { - return self.pipe.obj.Peers() -} - -func (self *World) Config() *Config { - return self.cfg -} diff --git a/xeth/xeth.go b/xeth/xeth.go index 34d8ffd0a..92b9bc995 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -4,178 +4,6 @@ package xeth * eXtended ETHereum */ -import ( - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/ethutil" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/state" -) +import "github.com/ethereum/go-ethereum/logger" var pipelogger = logger.NewLogger("XETH") - -type VmVars struct { - State *state.StateDB -} - -type XEth struct { - obj core.EthManager - blockProcessor *core.BlockProcessor - chainManager *core.ChainManager - world *World - - Vm VmVars -} - -func New(obj core.EthManager) *XEth { - pipe := &XEth{ - obj: obj, - blockProcessor: obj.BlockProcessor(), - chainManager: obj.ChainManager(), - } - pipe.world = NewWorld(pipe) - - return pipe -} - -/* - * State / Account accessors - */ -func (self *XEth) Balance(addr []byte) *ethutil.Value { - return ethutil.NewValue(self.World().safeGet(addr).Balance) -} - -func (self *XEth) Nonce(addr []byte) uint64 { - return self.World().safeGet(addr).Nonce -} - -func (self *XEth) Block(hash []byte) *types.Block { - return self.chainManager.GetBlock(hash) -} - -func (self *XEth) Storage(addr, storageAddr []byte) *ethutil.Value { - return self.World().safeGet(addr).GetStorage(ethutil.BigD(storageAddr)) -} - -func (self *XEth) Exists(addr []byte) bool { - return self.World().Get(addr) != nil -} - -// Converts the given private key to an address -func (self *XEth) ToAddress(priv []byte) []byte { - pair, err := crypto.NewKeyPairFromSec(priv) - if err != nil { - return nil - } - - return pair.Address() -} - -/* - * Execution helpers - */ -func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { - return self.ExecuteObject(&Object{self.World().safeGet(addr)}, data, value, gas, price) -} - -func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { - var ( - initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address(), self.obj.Db()) - block = self.chainManager.CurrentBlock() - ) - - self.Vm.State = self.World().State().Copy() - - vmenv := NewEnv(self.chainManager, self.Vm.State, block, value.BigInt(), initiator.Address()) - return vmenv.Call(initiator, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) -} - -/* - * Transactional methods - */ -func (self *XEth) TransactString(key *crypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) (*types.Transaction, error) { - // Check if an address is stored by this address - var hash []byte - addr := self.World().Config().Get("NameReg").StorageString(rec).Bytes() - if len(addr) > 0 { - hash = addr - } else if ethutil.IsHex(rec) { - hash = ethutil.Hex2Bytes(rec[2:]) - } else { - hash = ethutil.Hex2Bytes(rec) - } - - return self.Transact(key, hash, value, gas, price, data) -} - -func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *ethutil.Value, data []byte) (*types.Transaction, error) { - var hash []byte - var contractCreation bool - if types.IsContractAddr(to) { - contractCreation = true - } else { - // Check if an address is stored by this address - addr := self.World().Config().Get("NameReg").Storage(to).Bytes() - if len(addr) > 0 { - hash = addr - } else { - hash = to - } - } - - var tx *types.Transaction - if contractCreation { - tx = types.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), data) - } else { - tx = types.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data) - } - - state := self.chainManager.TransState() - nonce := state.GetNonce(key.Address()) - - tx.SetNonce(nonce) - tx.Sign(key.PrivateKey) - - // Do some pre processing for our "pre" events and hooks - block := self.chainManager.NewBlock(key.Address()) - coinbase := state.GetOrNewStateObject(key.Address()) - coinbase.SetGasPool(block.GasLimit()) - self.blockProcessor.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true) - - err := self.obj.TxPool().Add(tx) - if err != nil { - return nil, err - } - state.SetNonce(key.Address(), nonce+1) - - if contractCreation { - addr := core.AddressFromMessage(tx) - pipelogger.Infof("Contract addr %x\n", addr) - } - - return tx, nil -} - -func (self *XEth) PushTx(tx *types.Transaction) ([]byte, error) { - err := self.obj.TxPool().Add(tx) - if err != nil { - return nil, err - } - - if tx.To() == nil { - addr := core.AddressFromMessage(tx) - pipelogger.Infof("Contract addr %x\n", addr) - return addr, nil - } - return tx.Hash(), nil -} - -func (self *XEth) CompileMutan(code string) ([]byte, error) { - data, err := ethutil.Compile(code, false) - if err != nil { - return nil, err - } - - return data, nil -} -- cgit v1.2.3 From 1146f25015b6d84072b71c490aba246e3010bd87 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 28 Jan 2015 18:25:50 +0100 Subject: clean up of xeth --- xeth/config.go | 37 ---------- xeth/hexface.go | 211 -------------------------------------------------------- xeth/xeth.go | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 210 insertions(+), 249 deletions(-) delete mode 100644 xeth/config.go delete mode 100644 xeth/hexface.go (limited to 'xeth') diff --git a/xeth/config.go b/xeth/config.go deleted file mode 100644 index db6cce3bd..000000000 --- a/xeth/config.go +++ /dev/null @@ -1,37 +0,0 @@ -package xeth - -/* -import "github.com/ethereum/go-ethereum/ethutil" - -var cnfCtr = ethutil.Hex2Bytes("661005d2720d855f1d9976f88bb10c1a3398c77f") - -type Config struct { - pipe *XEth -} - -func (self *Config) Get(name string) *Object { - configCtrl := self.pipe.World().safeGet(cnfCtr) - var addr []byte - - switch name { - case "NameReg": - addr = []byte{0} - case "DnsReg": - objectAddr := configCtrl.GetStorage(ethutil.BigD([]byte{0})) - domainAddr := (&Object{self.pipe.World().safeGet(objectAddr.Bytes())}).StorageString("DnsReg").Bytes() - return &Object{self.pipe.World().safeGet(domainAddr)} - case "MergeMining": - addr = []byte{4} - default: - addr = ethutil.RightPadBytes([]byte(name), 32) - } - - objectAddr := configCtrl.GetStorage(ethutil.BigD(addr)) - - return &Object{self.pipe.World().safeGet(objectAddr.Bytes())} -} - -func (self *Config) Exist() bool { - return self.pipe.World().Get(cnfCtr) != nil -} -*/ diff --git a/xeth/hexface.go b/xeth/hexface.go deleted file mode 100644 index 3eb535724..000000000 --- a/xeth/hexface.go +++ /dev/null @@ -1,211 +0,0 @@ -package xeth - -import ( - "bytes" - "encoding/json" - - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/ethutil" - "github.com/ethereum/go-ethereum/state" -) - -// to resolve the import cycle -type Backend interface { - BlockProcessor() *core.BlockProcessor - ChainManager() *core.ChainManager - Coinbase() []byte - KeyManager() *crypto.KeyManager - IsMining() bool - IsListening() bool - PeerCount() int - Db() ethutil.Database - TxPool() *core.TxPool -} - -type JSXEth struct { - eth Backend - blockProcessor *core.BlockProcessor - chainManager *core.ChainManager - world *State -} - -func NewJSXEth(eth Backend) *JSXEth { - xeth := &JSXEth{ - eth: eth, - blockProcessor: eth.BlockProcessor(), - chainManager: eth.ChainManager(), - } - xeth.world = NewState(xeth) - - return xeth -} - -func (self *JSXEth) State() *State { return self.world } - -func (self *JSXEth) BlockByHash(strHash string) *JSBlock { - hash := fromHex(strHash) - block := self.chainManager.GetBlock(hash) - - return NewJSBlock(block) -} - -func (self *JSXEth) BlockByNumber(num int32) *JSBlock { - if num == -1 { - return NewJSBlock(self.chainManager.CurrentBlock()) - } - - return NewJSBlock(self.chainManager.GetBlockByNumber(uint64(num))) -} - -func (self *JSXEth) Block(v interface{}) *JSBlock { - if n, ok := v.(int32); ok { - return self.BlockByNumber(n) - } else if str, ok := v.(string); ok { - return self.BlockByHash(str) - } else if f, ok := v.(float64); ok { // Don't ask ... - return self.BlockByNumber(int32(f)) - } - - return nil -} - -func (self *JSXEth) Accounts() []string { - return []string{toHex(self.eth.KeyManager().Address())} -} - -/* -func (self *JSXEth) StateObject(addr string) *JSObject { - object := &Object{self.State().safeGet(fromHex(addr))} - - return NewJSObject(object) -} -*/ - -func (self *JSXEth) PeerCount() int { - return self.eth.PeerCount() -} - -func (self *JSXEth) IsMining() bool { - return self.eth.IsMining() -} - -func (self *JSXEth) IsListening() bool { - return self.eth.IsListening() -} - -func (self *JSXEth) Coinbase() string { - return toHex(self.eth.KeyManager().Address()) -} - -func (self *JSXEth) NumberToHuman(balance string) string { - b := ethutil.Big(balance) - - return ethutil.CurrencyToString(b) -} - -func (self *JSXEth) StorageAt(addr, storageAddr string) string { - storage := self.State().SafeGet(addr).StorageString(storageAddr) - - return toHex(storage.Bytes()) -} - -func (self *JSXEth) BalanceAt(addr string) string { - return self.State().SafeGet(addr).Balance().String() -} - -func (self *JSXEth) TxCountAt(address string) int { - return int(self.State().SafeGet(address).Nonce) -} - -func (self *JSXEth) CodeAt(address string) string { - return toHex(self.State().SafeGet(address).Code) -} - -func (self *JSXEth) IsContract(address string) bool { - return len(self.State().SafeGet(address).Code) > 0 -} - -func (self *JSXEth) SecretToAddress(key string) string { - pair, err := crypto.NewKeyPairFromSec(fromHex(key)) - if err != nil { - return "" - } - - return toHex(pair.Address()) -} - -func (self *JSXEth) Execute(addr, value, gas, price, data string) (string, error) { - return "", nil -} - -type KeyVal struct { - Key string `json:"key"` - Value string `json:"value"` -} - -func (self *JSXEth) EachStorage(addr string) string { - var values []KeyVal - object := self.State().SafeGet(addr) - it := object.Trie().Iterator() - for it.Next() { - values = append(values, KeyVal{toHex(it.Key), toHex(it.Value)}) - } - - valuesJson, err := json.Marshal(values) - if err != nil { - return "" - } - - return string(valuesJson) -} - -func (self *JSXEth) ToAscii(str string) string { - padded := ethutil.RightPadBytes([]byte(str), 32) - - return "0x" + toHex(padded) -} - -func (self *JSXEth) FromAscii(str string) string { - if ethutil.IsHex(str) { - str = str[2:] - } - - return string(bytes.Trim(fromHex(str), "\x00")) -} - -func (self *JSXEth) FromNumber(str string) string { - if ethutil.IsHex(str) { - str = str[2:] - } - - return ethutil.BigD(fromHex(str)).String() -} - -func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { - return "", nil -} - -func ToJSMessages(messages state.Messages) *ethutil.List { - var msgs []JSMessage - for _, m := range messages { - msgs = append(msgs, NewJSMessage(m)) - } - - return ethutil.NewList(msgs) -} - -func (self *JSXEth) PushTx(encodedTx string) (string, error) { - tx := types.NewTransactionFromBytes(fromHex(encodedTx)) - err := self.eth.TxPool().Add(tx) - if err != nil { - return "", err - } - - if tx.To() == nil { - addr := core.AddressFromMessage(tx) - return toHex(addr), nil - } - return toHex(tx.Hash()), nil -} diff --git a/xeth/xeth.go b/xeth/xeth.go index 92b9bc995..6b491b0fe 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -4,6 +4,215 @@ package xeth * eXtended ETHereum */ -import "github.com/ethereum/go-ethereum/logger" +import ( + "bytes" + "encoding/json" + + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/state" +) var pipelogger = logger.NewLogger("XETH") + +// to resolve the import cycle +type Backend interface { + BlockProcessor() *core.BlockProcessor + ChainManager() *core.ChainManager + Coinbase() []byte + KeyManager() *crypto.KeyManager + IsMining() bool + IsListening() bool + PeerCount() int + Db() ethutil.Database + TxPool() *core.TxPool +} + +type JSXEth struct { + eth Backend + blockProcessor *core.BlockProcessor + chainManager *core.ChainManager + world *State +} + +func NewJSXEth(eth Backend) *JSXEth { + xeth := &JSXEth{ + eth: eth, + blockProcessor: eth.BlockProcessor(), + chainManager: eth.ChainManager(), + } + xeth.world = NewState(xeth) + + return xeth +} + +func (self *JSXEth) State() *State { return self.world } + +func (self *JSXEth) BlockByHash(strHash string) *JSBlock { + hash := fromHex(strHash) + block := self.chainManager.GetBlock(hash) + + return NewJSBlock(block) +} + +func (self *JSXEth) BlockByNumber(num int32) *JSBlock { + if num == -1 { + return NewJSBlock(self.chainManager.CurrentBlock()) + } + + return NewJSBlock(self.chainManager.GetBlockByNumber(uint64(num))) +} + +func (self *JSXEth) Block(v interface{}) *JSBlock { + if n, ok := v.(int32); ok { + return self.BlockByNumber(n) + } else if str, ok := v.(string); ok { + return self.BlockByHash(str) + } else if f, ok := v.(float64); ok { // Don't ask ... + return self.BlockByNumber(int32(f)) + } + + return nil +} + +func (self *JSXEth) Accounts() []string { + return []string{toHex(self.eth.KeyManager().Address())} +} + +/* +func (self *JSXEth) StateObject(addr string) *JSObject { + object := &Object{self.State().safeGet(fromHex(addr))} + + return NewJSObject(object) +} +*/ + +func (self *JSXEth) PeerCount() int { + return self.eth.PeerCount() +} + +func (self *JSXEth) IsMining() bool { + return self.eth.IsMining() +} + +func (self *JSXEth) IsListening() bool { + return self.eth.IsListening() +} + +func (self *JSXEth) Coinbase() string { + return toHex(self.eth.KeyManager().Address()) +} + +func (self *JSXEth) NumberToHuman(balance string) string { + b := ethutil.Big(balance) + + return ethutil.CurrencyToString(b) +} + +func (self *JSXEth) StorageAt(addr, storageAddr string) string { + storage := self.State().SafeGet(addr).StorageString(storageAddr) + + return toHex(storage.Bytes()) +} + +func (self *JSXEth) BalanceAt(addr string) string { + return self.State().SafeGet(addr).Balance().String() +} + +func (self *JSXEth) TxCountAt(address string) int { + return int(self.State().SafeGet(address).Nonce) +} + +func (self *JSXEth) CodeAt(address string) string { + return toHex(self.State().SafeGet(address).Code) +} + +func (self *JSXEth) IsContract(address string) bool { + return len(self.State().SafeGet(address).Code) > 0 +} + +func (self *JSXEth) SecretToAddress(key string) string { + pair, err := crypto.NewKeyPairFromSec(fromHex(key)) + if err != nil { + return "" + } + + return toHex(pair.Address()) +} + +func (self *JSXEth) Execute(addr, value, gas, price, data string) (string, error) { + return "", nil +} + +type KeyVal struct { + Key string `json:"key"` + Value string `json:"value"` +} + +func (self *JSXEth) EachStorage(addr string) string { + var values []KeyVal + object := self.State().SafeGet(addr) + it := object.Trie().Iterator() + for it.Next() { + values = append(values, KeyVal{toHex(it.Key), toHex(it.Value)}) + } + + valuesJson, err := json.Marshal(values) + if err != nil { + return "" + } + + return string(valuesJson) +} + +func (self *JSXEth) ToAscii(str string) string { + padded := ethutil.RightPadBytes([]byte(str), 32) + + return "0x" + toHex(padded) +} + +func (self *JSXEth) FromAscii(str string) string { + if ethutil.IsHex(str) { + str = str[2:] + } + + return string(bytes.Trim(fromHex(str), "\x00")) +} + +func (self *JSXEth) FromNumber(str string) string { + if ethutil.IsHex(str) { + str = str[2:] + } + + return ethutil.BigD(fromHex(str)).String() +} + +func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { + return "", nil +} + +func ToJSMessages(messages state.Messages) *ethutil.List { + var msgs []JSMessage + for _, m := range messages { + msgs = append(msgs, NewJSMessage(m)) + } + + return ethutil.NewList(msgs) +} + +func (self *JSXEth) PushTx(encodedTx string) (string, error) { + tx := types.NewTransactionFromBytes(fromHex(encodedTx)) + err := self.eth.TxPool().Add(tx) + if err != nil { + return "", err + } + + if tx.To() == nil { + addr := core.AddressFromMessage(tx) + return toHex(addr), nil + } + return toHex(tx.Hash()), nil +} -- cgit v1.2.3 From 872b2497114209119becf2e8a4d4a5818e2084ee Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 28 Jan 2015 18:35:49 +0100 Subject: further cleaned up xeth interface --- xeth/js_types.go | 235 --------------------------------------------------- xeth/object.go | 26 ------ xeth/types.go | 251 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ xeth/world.go | 4 +- xeth/xeth.go | 68 +++++++-------- 5 files changed, 287 insertions(+), 297 deletions(-) delete mode 100644 xeth/js_types.go delete mode 100644 xeth/object.go create mode 100644 xeth/types.go (limited to 'xeth') diff --git a/xeth/js_types.go b/xeth/js_types.go deleted file mode 100644 index a0be996ff..000000000 --- a/xeth/js_types.go +++ /dev/null @@ -1,235 +0,0 @@ -package xeth - -import ( - "fmt" - "strings" - - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/ethutil" - "github.com/ethereum/go-ethereum/p2p" - "github.com/ethereum/go-ethereum/state" -) - -func toHex(b []byte) string { - return "0x" + ethutil.Bytes2Hex(b) -} -func fromHex(s string) []byte { - if len(s) > 1 { - if s[0:2] == "0x" { - s = s[2:] - } - return ethutil.Hex2Bytes(s) - } - return nil -} - -// Block interface exposed to QML -type JSBlock struct { - //Transactions string `json:"transactions"` - ref *types.Block - Size string `json:"size"` - Number int `json:"number"` - Hash string `json:"hash"` - Transactions *ethutil.List `json:"transactions"` - Uncles *ethutil.List `json:"uncles"` - Time int64 `json:"time"` - Coinbase string `json:"coinbase"` - Name string `json:"name"` - GasLimit string `json:"gasLimit"` - GasUsed string `json:"gasUsed"` - PrevHash string `json:"prevHash"` - Bloom string `json:"bloom"` - Raw string `json:"raw"` -} - -// Creates a new QML Block from a chain block -func NewJSBlock(block *types.Block) *JSBlock { - if block == nil { - return &JSBlock{} - } - - ptxs := make([]*JSTransaction, len(block.Transactions())) - for i, tx := range block.Transactions() { - ptxs[i] = NewJSTx(tx) - } - txlist := ethutil.NewList(ptxs) - - puncles := make([]*JSBlock, len(block.Uncles())) - for i, uncle := range block.Uncles() { - puncles[i] = NewJSBlock(types.NewBlockWithHeader(uncle)) - } - ulist := ethutil.NewList(puncles) - - return &JSBlock{ - ref: block, Size: block.Size().String(), - Number: int(block.NumberU64()), GasUsed: block.GasUsed().String(), - GasLimit: block.GasLimit().String(), Hash: toHex(block.Hash()), - Transactions: txlist, Uncles: ulist, - Time: block.Time(), - Coinbase: toHex(block.Coinbase()), - PrevHash: toHex(block.ParentHash()), - Bloom: toHex(block.Bloom()), - Raw: block.String(), - } -} - -func (self *JSBlock) ToString() string { - if self.ref != nil { - return self.ref.String() - } - - return "" -} - -func (self *JSBlock) GetTransaction(hash string) *JSTransaction { - tx := self.ref.Transaction(fromHex(hash)) - if tx == nil { - return nil - } - - return NewJSTx(tx) -} - -type JSTransaction struct { - ref *types.Transaction - - Value string `json:"value"` - Gas string `json:"gas"` - GasPrice string `json:"gasPrice"` - Hash string `json:"hash"` - Address string `json:"address"` - Sender string `json:"sender"` - RawData string `json:"rawData"` - Data string `json:"data"` - Contract bool `json:"isContract"` - CreatesContract bool `json:"createsContract"` - Confirmations int `json:"confirmations"` -} - -func NewJSTx(tx *types.Transaction) *JSTransaction { - hash := toHex(tx.Hash()) - receiver := toHex(tx.To()) - if receiver == "0000000000000000000000000000000000000000" { - receiver = toHex(core.AddressFromMessage(tx)) - } - sender := toHex(tx.From()) - createsContract := core.MessageCreatesContract(tx) - - var data string - if createsContract { - data = strings.Join(core.Disassemble(tx.Data()), "\n") - } else { - data = toHex(tx.Data()) - } - - return &JSTransaction{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value()), Address: receiver, Contract: createsContract, Gas: tx.Gas().String(), GasPrice: tx.GasPrice().String(), Data: data, Sender: sender, CreatesContract: createsContract, RawData: toHex(tx.Data())} -} - -func (self *JSTransaction) ToString() string { - return self.ref.String() -} - -type JSKey struct { - Address string `json:"address"` - PrivateKey string `json:"privateKey"` - PublicKey string `json:"publicKey"` -} - -func NewJSKey(key *crypto.KeyPair) *JSKey { - return &JSKey{toHex(key.Address()), toHex(key.PrivateKey), toHex(key.PublicKey)} -} - -type JSObject struct { - *Object -} - -func NewJSObject(object *Object) *JSObject { - return &JSObject{object} -} - -type PReceipt struct { - CreatedContract bool `json:"createdContract"` - Address string `json:"address"` - Hash string `json:"hash"` - Sender string `json:"sender"` -} - -func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) *PReceipt { - return &PReceipt{ - contractCreation, - toHex(creationAddress), - toHex(hash), - toHex(address), - } -} - -// Peer interface exposed to QML - -type JSPeer struct { - ref *p2p.Peer - Ip string `json:"ip"` - Version string `json:"version"` - Caps string `json:"caps"` -} - -func NewJSPeer(peer *p2p.Peer) *JSPeer { - var caps []string - for _, cap := range peer.Caps() { - caps = append(caps, fmt.Sprintf("%s/%d", cap.Name, cap.Version)) - } - - return &JSPeer{ - ref: peer, - Ip: fmt.Sprintf("%v", peer.RemoteAddr()), - Version: fmt.Sprintf("%v", peer.Identity()), - Caps: fmt.Sprintf("%v", caps), - } -} - -type JSReceipt struct { - CreatedContract bool `json:"createdContract"` - Address string `json:"address"` - Hash string `json:"hash"` - Sender string `json:"sender"` -} - -func NewJSReciept(contractCreation bool, creationAddress, hash, address []byte) *JSReceipt { - return &JSReceipt{ - contractCreation, - toHex(creationAddress), - toHex(hash), - toHex(address), - } -} - -type JSMessage struct { - To string `json:"to"` - From string `json:"from"` - Input string `json:"input"` - Output string `json:"output"` - Path int32 `json:"path"` - Origin string `json:"origin"` - Timestamp int32 `json:"timestamp"` - Coinbase string `json:"coinbase"` - Block string `json:"block"` - Number int32 `json:"number"` - Value string `json:"value"` -} - -func NewJSMessage(message *state.Message) JSMessage { - return JSMessage{ - To: toHex(message.To), - From: toHex(message.From), - Input: toHex(message.Input), - Output: toHex(message.Output), - Path: int32(message.Path), - Origin: toHex(message.Origin), - Timestamp: int32(message.Timestamp), - Coinbase: toHex(message.Origin), - Block: toHex(message.Block), - Number: int32(message.Number.Int64()), - Value: message.Value.String(), - } -} diff --git a/xeth/object.go b/xeth/object.go deleted file mode 100644 index a4ac41e89..000000000 --- a/xeth/object.go +++ /dev/null @@ -1,26 +0,0 @@ -package xeth - -import ( - "github.com/ethereum/go-ethereum/ethutil" - "github.com/ethereum/go-ethereum/state" -) - -type Object struct { - *state.StateObject -} - -func (self *Object) StorageString(str string) *ethutil.Value { - if ethutil.IsHex(str) { - return self.Storage(ethutil.Hex2Bytes(str[2:])) - } else { - return self.Storage(ethutil.RightPadBytes([]byte(str), 32)) - } -} - -func (self *Object) StorageValue(addr *ethutil.Value) *ethutil.Value { - return self.Storage(addr.Bytes()) -} - -func (self *Object) Storage(addr []byte) *ethutil.Value { - return self.StateObject.GetStorage(ethutil.BigD(addr)) -} diff --git a/xeth/types.go b/xeth/types.go new file mode 100644 index 000000000..4d8543eb1 --- /dev/null +++ b/xeth/types.go @@ -0,0 +1,251 @@ +package xeth + +import ( + "fmt" + "strings" + + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/p2p" + "github.com/ethereum/go-ethereum/state" +) + +func toHex(b []byte) string { + return "0x" + ethutil.Bytes2Hex(b) +} +func fromHex(s string) []byte { + if len(s) > 1 { + if s[0:2] == "0x" { + s = s[2:] + } + return ethutil.Hex2Bytes(s) + } + return nil +} + +type Object struct { + *state.StateObject +} + +func NewObject(state *state.StateObject) *Object { + return &Object{state} +} + +func (self *Object) StorageString(str string) *ethutil.Value { + if ethutil.IsHex(str) { + return self.Storage(ethutil.Hex2Bytes(str[2:])) + } else { + return self.Storage(ethutil.RightPadBytes([]byte(str), 32)) + } +} + +func (self *Object) StorageValue(addr *ethutil.Value) *ethutil.Value { + return self.Storage(addr.Bytes()) +} + +func (self *Object) Storage(addr []byte) *ethutil.Value { + return self.StateObject.GetStorage(ethutil.BigD(addr)) +} + +// Block interface exposed to QML +type Block struct { + //Transactions string `json:"transactions"` + ref *types.Block + Size string `json:"size"` + Number int `json:"number"` + Hash string `json:"hash"` + Transactions *ethutil.List `json:"transactions"` + Uncles *ethutil.List `json:"uncles"` + Time int64 `json:"time"` + Coinbase string `json:"coinbase"` + Name string `json:"name"` + GasLimit string `json:"gasLimit"` + GasUsed string `json:"gasUsed"` + PrevHash string `json:"prevHash"` + Bloom string `json:"bloom"` + Raw string `json:"raw"` +} + +// Creates a new QML Block from a chain block +func NewBlock(block *types.Block) *Block { + if block == nil { + return &Block{} + } + + ptxs := make([]*Transaction, len(block.Transactions())) + for i, tx := range block.Transactions() { + ptxs[i] = NewTx(tx) + } + txlist := ethutil.NewList(ptxs) + + puncles := make([]*Block, len(block.Uncles())) + for i, uncle := range block.Uncles() { + puncles[i] = NewBlock(types.NewBlockWithHeader(uncle)) + } + ulist := ethutil.NewList(puncles) + + return &Block{ + ref: block, Size: block.Size().String(), + Number: int(block.NumberU64()), GasUsed: block.GasUsed().String(), + GasLimit: block.GasLimit().String(), Hash: toHex(block.Hash()), + Transactions: txlist, Uncles: ulist, + Time: block.Time(), + Coinbase: toHex(block.Coinbase()), + PrevHash: toHex(block.ParentHash()), + Bloom: toHex(block.Bloom()), + Raw: block.String(), + } +} + +func (self *Block) ToString() string { + if self.ref != nil { + return self.ref.String() + } + + return "" +} + +func (self *Block) GetTransaction(hash string) *Transaction { + tx := self.ref.Transaction(fromHex(hash)) + if tx == nil { + return nil + } + + return NewTx(tx) +} + +type Transaction struct { + ref *types.Transaction + + Value string `json:"value"` + Gas string `json:"gas"` + GasPrice string `json:"gasPrice"` + Hash string `json:"hash"` + Address string `json:"address"` + Sender string `json:"sender"` + RawData string `json:"rawData"` + Data string `json:"data"` + Contract bool `json:"isContract"` + CreatesContract bool `json:"createsContract"` + Confirmations int `json:"confirmations"` +} + +func NewTx(tx *types.Transaction) *Transaction { + hash := toHex(tx.Hash()) + receiver := toHex(tx.To()) + if receiver == "0000000000000000000000000000000000000000" { + receiver = toHex(core.AddressFromMessage(tx)) + } + sender := toHex(tx.From()) + createsContract := core.MessageCreatesContract(tx) + + var data string + if createsContract { + data = strings.Join(core.Disassemble(tx.Data()), "\n") + } else { + data = toHex(tx.Data()) + } + + return &Transaction{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value()), Address: receiver, Contract: createsContract, Gas: tx.Gas().String(), GasPrice: tx.GasPrice().String(), Data: data, Sender: sender, CreatesContract: createsContract, RawData: toHex(tx.Data())} +} + +func (self *Transaction) ToString() string { + return self.ref.String() +} + +type Key struct { + Address string `json:"address"` + PrivateKey string `json:"privateKey"` + PublicKey string `json:"publicKey"` +} + +func NewKey(key *crypto.KeyPair) *Key { + return &Key{toHex(key.Address()), toHex(key.PrivateKey), toHex(key.PublicKey)} +} + +type PReceipt struct { + CreatedContract bool `json:"createdContract"` + Address string `json:"address"` + Hash string `json:"hash"` + Sender string `json:"sender"` +} + +func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) *PReceipt { + return &PReceipt{ + contractCreation, + toHex(creationAddress), + toHex(hash), + toHex(address), + } +} + +// Peer interface exposed to QML + +type Peer struct { + ref *p2p.Peer + Ip string `json:"ip"` + Version string `json:"version"` + Caps string `json:"caps"` +} + +func NewPeer(peer *p2p.Peer) *Peer { + var caps []string + for _, cap := range peer.Caps() { + caps = append(caps, fmt.Sprintf("%s/%d", cap.Name, cap.Version)) + } + + return &Peer{ + ref: peer, + Ip: fmt.Sprintf("%v", peer.RemoteAddr()), + Version: fmt.Sprintf("%v", peer.Identity()), + Caps: fmt.Sprintf("%v", caps), + } +} + +type Receipt struct { + CreatedContract bool `json:"createdContract"` + Address string `json:"address"` + Hash string `json:"hash"` + Sender string `json:"sender"` +} + +func NewReciept(contractCreation bool, creationAddress, hash, address []byte) *Receipt { + return &Receipt{ + contractCreation, + toHex(creationAddress), + toHex(hash), + toHex(address), + } +} + +type Message struct { + To string `json:"to"` + From string `json:"from"` + Input string `json:"input"` + Output string `json:"output"` + Path int32 `json:"path"` + Origin string `json:"origin"` + Timestamp int32 `json:"timestamp"` + Coinbase string `json:"coinbase"` + Block string `json:"block"` + Number int32 `json:"number"` + Value string `json:"value"` +} + +func NewMessage(message *state.Message) Message { + return Message{ + To: toHex(message.To), + From: toHex(message.From), + Input: toHex(message.Input), + Output: toHex(message.Output), + Path: int32(message.Path), + Origin: toHex(message.Origin), + Timestamp: int32(message.Timestamp), + Coinbase: toHex(message.Origin), + Block: toHex(message.Block), + Number: int32(message.Number.Int64()), + Value: message.Value.String(), + } +} diff --git a/xeth/world.go b/xeth/world.go index 60d4bbb57..cdceec50d 100644 --- a/xeth/world.go +++ b/xeth/world.go @@ -3,10 +3,10 @@ package xeth import "github.com/ethereum/go-ethereum/state" type State struct { - xeth *JSXEth + xeth *XEth } -func NewState(xeth *JSXEth) *State { +func NewState(xeth *XEth) *State { return &State{xeth} } diff --git a/xeth/xeth.go b/xeth/xeth.go index 6b491b0fe..96e545b35 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -31,15 +31,15 @@ type Backend interface { TxPool() *core.TxPool } -type JSXEth struct { +type XEth struct { eth Backend blockProcessor *core.BlockProcessor chainManager *core.ChainManager world *State } -func NewJSXEth(eth Backend) *JSXEth { - xeth := &JSXEth{ +func New(eth Backend) *XEth { + xeth := &XEth{ eth: eth, blockProcessor: eth.BlockProcessor(), chainManager: eth.ChainManager(), @@ -49,24 +49,24 @@ func NewJSXEth(eth Backend) *JSXEth { return xeth } -func (self *JSXEth) State() *State { return self.world } +func (self *XEth) State() *State { return self.world } -func (self *JSXEth) BlockByHash(strHash string) *JSBlock { +func (self *XEth) BlockByHash(strHash string) *Block { hash := fromHex(strHash) block := self.chainManager.GetBlock(hash) - return NewJSBlock(block) + return NewBlock(block) } -func (self *JSXEth) BlockByNumber(num int32) *JSBlock { +func (self *XEth) BlockByNumber(num int32) *Block { if num == -1 { - return NewJSBlock(self.chainManager.CurrentBlock()) + return NewBlock(self.chainManager.CurrentBlock()) } - return NewJSBlock(self.chainManager.GetBlockByNumber(uint64(num))) + return NewBlock(self.chainManager.GetBlockByNumber(uint64(num))) } -func (self *JSXEth) Block(v interface{}) *JSBlock { +func (self *XEth) Block(v interface{}) *Block { if n, ok := v.(int32); ok { return self.BlockByNumber(n) } else if str, ok := v.(string); ok { @@ -78,63 +78,63 @@ func (self *JSXEth) Block(v interface{}) *JSBlock { return nil } -func (self *JSXEth) Accounts() []string { +func (self *XEth) Accounts() []string { return []string{toHex(self.eth.KeyManager().Address())} } /* -func (self *JSXEth) StateObject(addr string) *JSObject { +func (self *XEth) StateObject(addr string) *Object { object := &Object{self.State().safeGet(fromHex(addr))} - return NewJSObject(object) + return NewObject(object) } */ -func (self *JSXEth) PeerCount() int { +func (self *XEth) PeerCount() int { return self.eth.PeerCount() } -func (self *JSXEth) IsMining() bool { +func (self *XEth) IsMining() bool { return self.eth.IsMining() } -func (self *JSXEth) IsListening() bool { +func (self *XEth) IsListening() bool { return self.eth.IsListening() } -func (self *JSXEth) Coinbase() string { +func (self *XEth) Coinbase() string { return toHex(self.eth.KeyManager().Address()) } -func (self *JSXEth) NumberToHuman(balance string) string { +func (self *XEth) NumberToHuman(balance string) string { b := ethutil.Big(balance) return ethutil.CurrencyToString(b) } -func (self *JSXEth) StorageAt(addr, storageAddr string) string { +func (self *XEth) StorageAt(addr, storageAddr string) string { storage := self.State().SafeGet(addr).StorageString(storageAddr) return toHex(storage.Bytes()) } -func (self *JSXEth) BalanceAt(addr string) string { +func (self *XEth) BalanceAt(addr string) string { return self.State().SafeGet(addr).Balance().String() } -func (self *JSXEth) TxCountAt(address string) int { +func (self *XEth) TxCountAt(address string) int { return int(self.State().SafeGet(address).Nonce) } -func (self *JSXEth) CodeAt(address string) string { +func (self *XEth) CodeAt(address string) string { return toHex(self.State().SafeGet(address).Code) } -func (self *JSXEth) IsContract(address string) bool { +func (self *XEth) IsContract(address string) bool { return len(self.State().SafeGet(address).Code) > 0 } -func (self *JSXEth) SecretToAddress(key string) string { +func (self *XEth) SecretToAddress(key string) string { pair, err := crypto.NewKeyPairFromSec(fromHex(key)) if err != nil { return "" @@ -143,7 +143,7 @@ func (self *JSXEth) SecretToAddress(key string) string { return toHex(pair.Address()) } -func (self *JSXEth) Execute(addr, value, gas, price, data string) (string, error) { +func (self *XEth) Execute(addr, value, gas, price, data string) (string, error) { return "", nil } @@ -152,7 +152,7 @@ type KeyVal struct { Value string `json:"value"` } -func (self *JSXEth) EachStorage(addr string) string { +func (self *XEth) EachStorage(addr string) string { var values []KeyVal object := self.State().SafeGet(addr) it := object.Trie().Iterator() @@ -168,13 +168,13 @@ func (self *JSXEth) EachStorage(addr string) string { return string(valuesJson) } -func (self *JSXEth) ToAscii(str string) string { +func (self *XEth) ToAscii(str string) string { padded := ethutil.RightPadBytes([]byte(str), 32) return "0x" + toHex(padded) } -func (self *JSXEth) FromAscii(str string) string { +func (self *XEth) FromAscii(str string) string { if ethutil.IsHex(str) { str = str[2:] } @@ -182,7 +182,7 @@ func (self *JSXEth) FromAscii(str string) string { return string(bytes.Trim(fromHex(str), "\x00")) } -func (self *JSXEth) FromNumber(str string) string { +func (self *XEth) FromNumber(str string) string { if ethutil.IsHex(str) { str = str[2:] } @@ -190,20 +190,20 @@ func (self *JSXEth) FromNumber(str string) string { return ethutil.BigD(fromHex(str)).String() } -func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { +func (self *XEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { return "", nil } -func ToJSMessages(messages state.Messages) *ethutil.List { - var msgs []JSMessage +func ToMessages(messages state.Messages) *ethutil.List { + var msgs []Message for _, m := range messages { - msgs = append(msgs, NewJSMessage(m)) + msgs = append(msgs, NewMessage(m)) } return ethutil.NewList(msgs) } -func (self *JSXEth) PushTx(encodedTx string) (string, error) { +func (self *XEth) PushTx(encodedTx string) (string, error) { tx := types.NewTransactionFromBytes(fromHex(encodedTx)) err := self.eth.TxPool().Add(tx) if err != nil { -- cgit v1.2.3 From cebb149f5cfaf008240d7069fd220401950cc7ee Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 28 Jan 2015 20:50:09 +0100 Subject: removed key while in the process of moving to the new key storage --- xeth/xeth.go | 68 ++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 13 deletions(-) (limited to 'xeth') diff --git a/xeth/xeth.go b/xeth/xeth.go index 96e545b35..89b2459b0 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -22,7 +22,6 @@ var pipelogger = logger.NewLogger("XETH") type Backend interface { BlockProcessor() *core.BlockProcessor ChainManager() *core.ChainManager - Coinbase() []byte KeyManager() *crypto.KeyManager IsMining() bool IsListening() bool @@ -82,14 +81,6 @@ func (self *XEth) Accounts() []string { return []string{toHex(self.eth.KeyManager().Address())} } -/* -func (self *XEth) StateObject(addr string) *Object { - object := &Object{self.State().safeGet(fromHex(addr))} - - return NewObject(object) -} -*/ - func (self *XEth) PeerCount() int { return self.eth.PeerCount() } @@ -190,10 +181,6 @@ func (self *XEth) FromNumber(str string) string { return ethutil.BigD(fromHex(str)).String() } -func (self *XEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { - return "", nil -} - func ToMessages(messages state.Messages) *ethutil.List { var msgs []Message for _, m := range messages { @@ -216,3 +203,58 @@ func (self *XEth) PushTx(encodedTx string) (string, error) { } return toHex(tx.Hash()), nil } + +func (self *XEth) Transact(toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { + + var ( + to []byte + value = ethutil.NewValue(valueStr) + gas = ethutil.NewValue(gasStr) + price = ethutil.NewValue(gasPriceStr) + data []byte + key = self.eth.KeyManager().KeyPair() + contractCreation bool + ) + + data = fromHex(codeStr) + to = fromHex(toStr) + if len(to) == 0 { + contractCreation = true + } + + var tx *types.Transaction + if contractCreation { + tx = types.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), data) + } else { + tx = types.NewTransactionMessage(to, value.BigInt(), gas.BigInt(), price.BigInt(), data) + } + + state := self.chainManager.TransState() + nonce := state.GetNonce(key.Address()) + + tx.SetNonce(nonce) + tx.Sign(key.PrivateKey) + + // Do some pre processing for our "pre" events and hooks + block := self.chainManager.NewBlock(key.Address()) + coinbase := state.GetOrNewStateObject(key.Address()) + coinbase.SetGasPool(block.GasLimit()) + self.blockProcessor.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true) + + err := self.eth.TxPool().Add(tx) + if err != nil { + return "", err + } + state.SetNonce(key.Address(), nonce+1) + + if contractCreation { + addr := core.AddressFromMessage(tx) + pipelogger.Infof("Contract addr %x\n", addr) + } + + if types.IsContractAddr(to) { + return toHex(core.AddressFromMessage(tx)), nil + } + + return toHex(tx.Hash()), nil +} -- cgit v1.2.3 From 84adf77bf3492351de82f0ec820a1d280e85a5cd Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 29 Jan 2015 13:10:34 +0100 Subject: Added RPC "Call" for JS calls to contracts --- xeth/xeth.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'xeth') diff --git a/xeth/xeth.go b/xeth/xeth.go index 89b2459b0..382a1f285 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -204,6 +204,34 @@ func (self *XEth) PushTx(encodedTx string) (string, error) { return toHex(tx.Hash()), nil } +func (self *XEth) Call(toStr, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { + if len(gasStr) == 0 { + gasStr = "100000" + } + if len(gasPriceStr) == 0 { + gasPriceStr = "1" + } + + var ( + statedb = self.chainManager.TransState() + initiator = state.NewStateObject(self.eth.KeyManager().KeyPair().Address(), self.eth.Db()) + block = self.chainManager.CurrentBlock() + to = statedb.GetOrNewStateObject(fromHex(toStr)) + data = fromHex(dataStr) + gas = ethutil.Big(gasStr) + price = ethutil.Big(gasPriceStr) + value = ethutil.Big(valueStr) + ) + + vmenv := NewEnv(self.chainManager, statedb, block, value, initiator.Address()) + res, err := vmenv.Call(initiator, to.Address(), data, gas, price, value) + if err != nil { + return "", err + } + + return toHex(res), nil +} + func (self *XEth) Transact(toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { var ( -- cgit v1.2.3 From 6488a392a347d0d47212fdc78386e3e0e5841d7d Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 29 Jan 2015 16:52:00 +0100 Subject: Reimplemented message filters for rpc calls --- xeth/xeth.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'xeth') diff --git a/xeth/xeth.go b/xeth/xeth.go index 382a1f285..4cfa104d0 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -12,7 +12,9 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/state" ) @@ -22,19 +24,22 @@ var pipelogger = logger.NewLogger("XETH") type Backend interface { BlockProcessor() *core.BlockProcessor ChainManager() *core.ChainManager - KeyManager() *crypto.KeyManager + TxPool() *core.TxPool + PeerCount() int IsMining() bool IsListening() bool - PeerCount() int + Peers() []*p2p.Peer + KeyManager() *crypto.KeyManager + ClientIdentity() p2p.ClientIdentity Db() ethutil.Database - TxPool() *core.TxPool + EventMux() *event.TypeMux } type XEth struct { eth Backend blockProcessor *core.BlockProcessor chainManager *core.ChainManager - world *State + state *State } func New(eth Backend) *XEth { @@ -43,12 +48,16 @@ func New(eth Backend) *XEth { blockProcessor: eth.BlockProcessor(), chainManager: eth.ChainManager(), } - xeth.world = NewState(xeth) + xeth.state = NewState(xeth) return xeth } -func (self *XEth) State() *State { return self.world } +func (self *XEth) Backend() Backend { + return self.eth +} + +func (self *XEth) State() *State { return self.state } func (self *XEth) BlockByHash(strHash string) *Block { hash := fromHex(strHash) -- cgit v1.2.3 From 0031f388ac1f6f4a23c5c75e5eeb4a007f0b2f31 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 29 Jan 2015 20:39:26 +0100 Subject: More dapp samples * Info DApp, coin DApp * Additional rpc methods --- xeth/types.go | 19 +++++++++++++++---- xeth/world.go | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'xeth') diff --git a/xeth/types.go b/xeth/types.go index 4d8543eb1..bee730ba1 100644 --- a/xeth/types.go +++ b/xeth/types.go @@ -35,20 +35,31 @@ func NewObject(state *state.StateObject) *Object { func (self *Object) StorageString(str string) *ethutil.Value { if ethutil.IsHex(str) { - return self.Storage(ethutil.Hex2Bytes(str[2:])) + return self.storage(ethutil.Hex2Bytes(str[2:])) } else { - return self.Storage(ethutil.RightPadBytes([]byte(str), 32)) + return self.storage(ethutil.RightPadBytes([]byte(str), 32)) } } func (self *Object) StorageValue(addr *ethutil.Value) *ethutil.Value { - return self.Storage(addr.Bytes()) + return self.storage(addr.Bytes()) } -func (self *Object) Storage(addr []byte) *ethutil.Value { +func (self *Object) storage(addr []byte) *ethutil.Value { return self.StateObject.GetStorage(ethutil.BigD(addr)) } +func (self *Object) Storage() (storage map[string]string) { + storage = make(map[string]string) + + it := self.StateObject.Trie().Iterator() + for it.Next() { + storage[toHex(it.Key)] = toHex(it.Value) + } + + return +} + // Block interface exposed to QML type Block struct { //Transactions string `json:"transactions"` diff --git a/xeth/world.go b/xeth/world.go index cdceec50d..9cbdd9461 100644 --- a/xeth/world.go +++ b/xeth/world.go @@ -11,7 +11,7 @@ func NewState(xeth *XEth) *State { } func (self *State) State() *state.StateDB { - return self.xeth.chainManager.State() + return self.xeth.chainManager.TransState() } func (self *State) Get(addr string) *Object { -- cgit v1.2.3 From 54927dc0e0b99009f92fbb7b28d71ae20179ce1e Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 29 Jan 2015 23:58:43 +0100 Subject: Fixed issue with Storage() * Storage() returned encoded values. They are now decode prior to hexing * Removed old code from state object * Updated coin --- xeth/types.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'xeth') diff --git a/xeth/types.go b/xeth/types.go index bee730ba1..34caf5cbc 100644 --- a/xeth/types.go +++ b/xeth/types.go @@ -1,6 +1,7 @@ package xeth import ( + "bytes" "fmt" "strings" @@ -9,6 +10,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/p2p" + "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/state" ) @@ -54,8 +56,11 @@ func (self *Object) Storage() (storage map[string]string) { it := self.StateObject.Trie().Iterator() for it.Next() { - storage[toHex(it.Key)] = toHex(it.Value) + var data []byte + rlp.Decode(bytes.NewReader(it.Value), &data) + storage[toHex(it.Key)] = toHex(data) } + self.StateObject.Trie().PrintRoot() return } -- cgit v1.2.3 From c03d403437c20584bcbf3cf3fa9d79ac7a0a8ca7 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 30 Jan 2015 13:25:12 +0100 Subject: Added whisper interface for xeth, added examples, updated RPC * Added RPC methods for whisper * Added whisper example --- xeth/whisper.go | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xeth/xeth.go | 12 +++--- 2 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 xeth/whisper.go (limited to 'xeth') diff --git a/xeth/whisper.go b/xeth/whisper.go new file mode 100644 index 000000000..31201271b --- /dev/null +++ b/xeth/whisper.go @@ -0,0 +1,116 @@ +package xeth + +import ( + "errors" + "fmt" + "time" + + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/whisper" +) + +var qlogger = logger.NewLogger("XSHH") + +type Whisper struct { + *whisper.Whisper +} + +func NewWhisper(w *whisper.Whisper) *Whisper { + return &Whisper{w} +} + +func (self *Whisper) Post(payload string, to, from string, topics []string, priority, ttl uint32) error { + if priority == 0 { + priority = 1000 + } + + if ttl == 0 { + ttl = 100 + } + + pk := crypto.ToECDSAPub(fromHex(from)) + if key := self.Whisper.GetIdentity(pk); key != nil || len(from) == 0 { + msg := whisper.NewMessage(fromHex(payload)) + envelope, err := msg.Seal(time.Duration(priority*100000), whisper.Opts{ + Ttl: time.Duration(ttl) * time.Second, + To: crypto.ToECDSAPub(fromHex(to)), + From: key, + Topics: whisper.TopicsFromString(topics...), + }) + + if err != nil { + return err + } + + if err := self.Whisper.Send(envelope); err != nil { + return err + } + } else { + return errors.New("unmatched pub / priv for seal") + } + + return nil +} + +func (self *Whisper) NewIdentity() string { + key := self.Whisper.NewIdentity() + + return toHex(crypto.FromECDSAPub(&key.PublicKey)) +} + +func (self *Whisper) HasIdentity(key string) bool { + return self.Whisper.HasIdentity(crypto.ToECDSAPub(fromHex(key))) +} + +func (self *Whisper) Watch(opts *Options) int { + filter := whisper.Filter{ + To: crypto.ToECDSA(fromHex(opts.To)), + From: crypto.ToECDSAPub(fromHex(opts.From)), + Topics: whisper.TopicsFromString(opts.Topics...), + } + + var i int + filter.Fn = func(msg *whisper.Message) { + opts.Fn(NewWhisperMessage(msg)) + } + fmt.Println("new filter", filter) + + i = self.Whisper.Watch(filter) + + return i +} + +func (self *Whisper) Messages(id int) (messages []WhisperMessage) { + msgs := self.Whisper.Messages(id) + messages = make([]WhisperMessage, len(msgs)) + for i, message := range msgs { + messages[i] = NewWhisperMessage(message) + } + + return +} + +type Options struct { + To string + From string + Topics []string + Fn func(msg WhisperMessage) +} + +type WhisperMessage struct { + ref *whisper.Message + Flags int32 `json:"flags"` + Payload string `json:"payload"` + From string `json:"from"` +} + +func NewWhisperMessage(msg *whisper.Message) WhisperMessage { + return WhisperMessage{ + ref: msg, + Flags: int32(msg.Flags), + Payload: "0x" + ethutil.Bytes2Hex(msg.Payload), + From: "0x" + ethutil.Bytes2Hex(crypto.FromECDSAPub(msg.Recover())), + } +} diff --git a/xeth/xeth.go b/xeth/xeth.go index 4cfa104d0..a65fa1331 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -16,6 +16,7 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/state" + "github.com/ethereum/go-ethereum/whisper" ) var pipelogger = logger.NewLogger("XETH") @@ -33,6 +34,7 @@ type Backend interface { ClientIdentity() p2p.ClientIdentity Db() ethutil.Database EventMux() *event.TypeMux + Whisper() *whisper.Whisper } type XEth struct { @@ -40,6 +42,7 @@ type XEth struct { blockProcessor *core.BlockProcessor chainManager *core.ChainManager state *State + whisper *Whisper } func New(eth Backend) *XEth { @@ -47,17 +50,16 @@ func New(eth Backend) *XEth { eth: eth, blockProcessor: eth.BlockProcessor(), chainManager: eth.ChainManager(), + whisper: NewWhisper(eth.Whisper()), } xeth.state = NewState(xeth) return xeth } -func (self *XEth) Backend() Backend { - return self.eth -} - -func (self *XEth) State() *State { return self.state } +func (self *XEth) Backend() Backend { return self.eth } +func (self *XEth) State() *State { return self.state } +func (self *XEth) Whisper() *Whisper { return self.whisper } func (self *XEth) BlockByHash(strHash string) *Block { hash := fromHex(strHash) -- cgit v1.2.3 From 2d9b3aa537a901d9b5b3aa951d71d9977c6e4703 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 30 Jan 2015 17:00:33 +0100 Subject: Removed debug log --- xeth/whisper.go | 2 -- 1 file changed, 2 deletions(-) (limited to 'xeth') diff --git a/xeth/whisper.go b/xeth/whisper.go index 31201271b..32ad1332b 100644 --- a/xeth/whisper.go +++ b/xeth/whisper.go @@ -2,7 +2,6 @@ package xeth import ( "errors" - "fmt" "time" "github.com/ethereum/go-ethereum/crypto" @@ -75,7 +74,6 @@ func (self *Whisper) Watch(opts *Options) int { filter.Fn = func(msg *whisper.Message) { opts.Fn(NewWhisperMessage(msg)) } - fmt.Println("new filter", filter) i = self.Whisper.Watch(filter) -- cgit v1.2.3