aboutsummaryrefslogtreecommitdiffstats
path: root/xeth/xeth.go
diff options
context:
space:
mode:
Diffstat (limited to 'xeth/xeth.go')
-rw-r--r--xeth/xeth.go49
1 files changed, 43 insertions, 6 deletions
diff --git a/xeth/xeth.go b/xeth/xeth.go
index 89b2459b0..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)
@@ -204,6 +213,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 (