aboutsummaryrefslogtreecommitdiffstats
path: root/xeth
diff options
context:
space:
mode:
Diffstat (limited to 'xeth')
-rw-r--r--xeth/frontend.go10
-rw-r--r--xeth/state.go12
-rw-r--r--xeth/types.go10
-rw-r--r--xeth/whisper.go10
-rw-r--r--xeth/whisper_filter.go10
-rw-r--r--xeth/whisper_message.go10
-rw-r--r--xeth/xeth.go72
-rw-r--r--xeth/xeth_test.go26
8 files changed, 107 insertions, 53 deletions
diff --git a/xeth/frontend.go b/xeth/frontend.go
index 967ccbaf5..e89282242 100644
--- a/xeth/frontend.go
+++ b/xeth/frontend.go
@@ -1,18 +1,18 @@
// Copyright 2015 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package xeth
diff --git a/xeth/state.go b/xeth/state.go
index 434c4aae9..981fe63b7 100644
--- a/xeth/state.go
+++ b/xeth/state.go
@@ -1,18 +1,18 @@
// Copyright 2015 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package xeth
@@ -45,7 +45,7 @@ func (self *State) SafeGet(addr string) *Object {
func (self *State) safeGet(addr string) *state.StateObject {
object := self.state.GetStateObject(common.HexToAddress(addr))
if object == nil {
- object = state.NewStateObject(common.HexToAddress(addr), self.xeth.backend.StateDb())
+ object = state.NewStateObject(common.HexToAddress(addr), self.xeth.backend.ChainDb())
}
return object
diff --git a/xeth/types.go b/xeth/types.go
index f584b69ba..ad5101d61 100644
--- a/xeth/types.go
+++ b/xeth/types.go
@@ -1,18 +1,18 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package xeth
diff --git a/xeth/whisper.go b/xeth/whisper.go
index 6deae4e5c..e7130978f 100644
--- a/xeth/whisper.go
+++ b/xeth/whisper.go
@@ -1,18 +1,18 @@
// Copyright 2015 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Contains the external API to the whisper sub-protocol.
diff --git a/xeth/whisper_filter.go b/xeth/whisper_filter.go
index b6c94ef83..fdf5cebae 100644
--- a/xeth/whisper_filter.go
+++ b/xeth/whisper_filter.go
@@ -1,18 +1,18 @@
// Copyright 2015 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Contains the external API side message filter for watching, pooling and polling
// matched whisper messages, also serializing data access to avoid duplications.
diff --git a/xeth/whisper_message.go b/xeth/whisper_message.go
index 3c48561ec..b3014a697 100644
--- a/xeth/whisper_message.go
+++ b/xeth/whisper_message.go
@@ -1,18 +1,18 @@
// Copyright 2015 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Contains the external API representation of a whisper message.
diff --git a/xeth/xeth.go b/xeth/xeth.go
index 2781c67c9..5110aa62c 100644
--- a/xeth/xeth.go
+++ b/xeth/xeth.go
@@ -1,18 +1,18 @@
// Copyright 2014 The go-ethereum Authors
-// This file is part of go-ethereum.
+// This file is part of the go-ethereum library.
//
-// go-ethereum is free software: you can redistribute it and/or modify
+// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
-// go-ethereum is distributed in the hope that it will be useful,
+// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Package xeth is the interface to all Ethereum functionality.
package xeth
@@ -20,8 +20,10 @@ package xeth
import (
"bytes"
"encoding/json"
+ "errors"
"fmt"
"math/big"
+ "regexp"
"sync"
"time"
@@ -45,6 +47,7 @@ var (
defaultGasPrice = big.NewInt(10000000000000) //150000000000
defaultGas = big.NewInt(90000) //500000
dappStorePre = []byte("dapp-")
+ addrReg = regexp.MustCompile(`^(0x)?[a-fA-F0-9]{40}$`)
)
// byte will be inferred
@@ -123,7 +126,7 @@ func New(ethereum *eth.Ethereum, frontend Frontend) *XEth {
if frontend == nil {
xeth.frontend = dummyFrontend{}
}
- xeth.state = NewState(xeth, xeth.backend.ChainManager().TransState())
+ xeth.state = NewState(xeth, xeth.backend.ChainManager().State())
go xeth.start()
go xeth.filterManager.Start()
@@ -210,9 +213,9 @@ func (self *XEth) AtStateNum(num int64) *XEth {
st = self.backend.Miner().PendingState().Copy()
default:
if block := self.getBlockByHeight(num); block != nil {
- st = state.New(block.Root(), self.backend.StateDb())
+ st = state.New(block.Root(), self.backend.ChainDb())
} else {
- st = state.New(self.backend.ChainManager().GetBlockByNumber(0).Root(), self.backend.StateDb())
+ st = state.New(self.backend.ChainManager().GetBlockByNumber(0).Root(), self.backend.ChainDb())
}
}
@@ -256,7 +259,7 @@ func (self *XEth) UpdateState() (wait chan *big.Int) {
wait <- n
n = nil
}
- statedb := state.New(ev.Block.Root(), self.backend.StateDb())
+ statedb := state.New(ev.Block.Root(), self.backend.ChainDb())
self.state = NewState(self, statedb)
}
case n, ok = <-wait:
@@ -308,9 +311,14 @@ func (self *XEth) EthBlockByHash(strHash string) *types.Block {
func (self *XEth) EthTransactionByHash(hash string) (tx *types.Transaction, blhash common.Hash, blnum *big.Int, txi uint64) {
// Due to increasing return params and need to determine if this is from transaction pool or
// some chain, this probably needs to be refactored for more expressiveness
- data, _ := self.backend.ExtraDb().Get(common.FromHex(hash))
+ data, _ := self.backend.ChainDb().Get(common.FromHex(hash))
if len(data) != 0 {
- tx = types.NewTransactionFromBytes(data)
+ dtx := new(types.Transaction)
+ if err := rlp.DecodeBytes(data, dtx); err != nil {
+ glog.V(logger.Error).Infoln(err)
+ return
+ }
+ tx = dtx
} else { // check pending transactions
tx = self.backend.TxPool().GetTransaction(common.HexToHash(hash))
}
@@ -322,7 +330,7 @@ func (self *XEth) EthTransactionByHash(hash string) (tx *types.Transaction, blha
Index uint64
}
- v, dberr := self.backend.ExtraDb().Get(append(common.FromHex(hash), 0x0001))
+ v, dberr := self.backend.ChainDb().Get(append(common.FromHex(hash), 0x0001))
// TODO check specifically for ErrNotFound
if dberr != nil {
return
@@ -357,7 +365,7 @@ func (self *XEth) GetBlockReceipts(bhash common.Hash) types.Receipts {
}
func (self *XEth) GetTxReceipt(txhash common.Hash) *types.Receipt {
- return core.GetReceipt(self.backend.ExtraDb(), txhash)
+ return core.GetReceipt(self.backend.ChainDb(), txhash)
}
func (self *XEth) GasLimit() *big.Int {
@@ -400,13 +408,13 @@ func (self *XEth) SetSolc(solcPath string) (*compiler.Solidity, error) {
// store DApp value in extra database
func (self *XEth) DbPut(key, val []byte) bool {
- self.backend.ExtraDb().Put(append(dappStorePre, key...), val)
+ self.backend.DappDb().Put(append(dappStorePre, key...), val)
return true
}
// retrieve DApp value from extra database
func (self *XEth) DbGet(key []byte) ([]byte, error) {
- val, err := self.backend.ExtraDb().Get(append(dappStorePre, key...))
+ val, err := self.backend.DappDb().Get(append(dappStorePre, key...))
return val, err
}
@@ -518,6 +526,9 @@ func (self *XEth) UninstallFilter(id int) bool {
}
func (self *XEth) NewLogFilter(earliest, latest int64, skip, max int, address []string, topics [][]string) int {
+ self.logMu.Lock()
+ defer self.logMu.Unlock()
+
var id int
filter := core.NewFilter(self.backend)
filter.SetEarliestBlock(earliest)
@@ -539,6 +550,9 @@ func (self *XEth) NewLogFilter(earliest, latest int64, skip, max int, address []
}
func (self *XEth) NewTransactionFilter() int {
+ self.transactionMu.Lock()
+ defer self.transactionMu.Unlock()
+
var id int
filter := core.NewFilter(self.backend)
filter.TransactionCallback = func(tx *types.Transaction) {
@@ -553,6 +567,9 @@ func (self *XEth) NewTransactionFilter() int {
}
func (self *XEth) NewBlockFilter() int {
+ self.blockMu.Lock()
+ defer self.blockMu.Unlock()
+
var id int
filter := core.NewFilter(self.backend)
filter.BlockCallback = func(block *types.Block, logs state.Logs) {
@@ -609,9 +626,6 @@ func (self *XEth) TransactionFilterChanged(id int) []common.Hash {
}
func (self *XEth) Logs(id int) state.Logs {
- self.logMu.Lock()
- defer self.logMu.Unlock()
-
filter := self.filterManager.GetFilter(id)
if filter != nil {
return filter.Find()
@@ -767,8 +781,14 @@ func (self *XEth) FromNumber(str string) string {
}
func (self *XEth) PushTx(encodedTx string) (string, error) {
- tx := types.NewTransactionFromBytes(common.FromHex(encodedTx))
- err := self.backend.TxPool().Add(tx)
+ tx := new(types.Transaction)
+ err := rlp.DecodeBytes(common.FromHex(encodedTx), tx)
+ if err != nil {
+ glog.V(logger.Error).Infoln(err)
+ return "", err
+ }
+
+ err = self.backend.TxPool().Add(tx)
if err != nil {
return "", err
}
@@ -861,6 +881,10 @@ func (self *XEth) Sign(fromStr, hashStr string, didUnlock bool) (string, error)
return common.ToHex(sig), nil
}
+func isAddress(addr string) bool {
+ return addrReg.MatchString(addr)
+}
+
func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
// this minimalistic recoding is enough (works for natspec.js)
@@ -870,6 +894,10 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS
return "", err
}
+ if len(toStr) > 0 && toStr != "0x" && !isAddress(toStr) {
+ return "", errors.New("Invalid address")
+ }
+
var (
from = common.HexToAddress(fromStr)
to = common.HexToAddress(toStr)
@@ -946,9 +974,9 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS
if contractCreation {
addr := crypto.CreateAddress(from, nonce)
- glog.V(logger.Info).Infof("Tx(%x) created: %x\n", tx.Hash(), addr)
+ glog.V(logger.Info).Infof("Tx(%s) created: %s\n", signed.Hash().Hex(), addr.Hex())
} else {
- glog.V(logger.Info).Infof("Tx(%x) to: %x\n", tx.Hash(), tx.To())
+ glog.V(logger.Info).Infof("Tx(%s) to: %s\n", signed.Hash().Hex(), tx.To().Hex())
}
return signed.Hash().Hex(), nil
diff --git a/xeth/xeth_test.go b/xeth/xeth_test.go
new file mode 100644
index 000000000..e649d20ef
--- /dev/null
+++ b/xeth/xeth_test.go
@@ -0,0 +1,26 @@
+package xeth
+
+import "testing"
+
+func TestIsAddress(t *testing.T) {
+ for _, invalid := range []string{
+ "0x00",
+ "0xNN",
+ "0x00000000000000000000000000000000000000NN",
+ "0xAAar000000000000000000000000000000000000",
+ } {
+ if isAddress(invalid) {
+ t.Error("Expected", invalid, "to be invalid")
+ }
+ }
+
+ for _, valid := range []string{
+ "0x0000000000000000000000000000000000000000",
+ "0xAABBbbCCccff9900000000000000000000000000",
+ "AABBbbCCccff9900000000000000000000000000",
+ } {
+ if !isAddress(valid) {
+ t.Error("Expected", valid, "to be valid")
+ }
+ }
+}