ethpipe => xeth (eXtended ETHereum)

This commit is contained in:
obscuren 2014-10-31 14:30:08 +01:00
parent 8826e9694c
commit 0ed1a8b50a
19 changed files with 112 additions and 108 deletions

@ -24,9 +24,9 @@ import (
"github.com/ethereum/go-ethereum/chain" "github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/ethpipe"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/xeth"
) )
type plugin struct { type plugin struct {
@ -46,7 +46,7 @@ func (gui *Gui) LogPrint(level logger.LogLevel, msg string) {
} }
*/ */
} }
func (gui *Gui) Transact(recipient, value, gas, gasPrice, d string) (*ethpipe.JSReceipt, error) { func (gui *Gui) Transact(recipient, value, gas, gasPrice, d string) (*xeth.JSReceipt, error) {
var data string var data string
if len(recipient) == 0 { if len(recipient) == 0 {
code, err := ethutil.Compile(d, false) code, err := ethutil.Compile(d, false)

@ -21,11 +21,11 @@ import (
"encoding/json" "encoding/json"
"github.com/ethereum/go-ethereum/chain" "github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/ethpipe"
"github.com/ethereum/go-ethereum/ethstate" "github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/javascript" "github.com/ethereum/go-ethereum/javascript"
"github.com/ethereum/go-ethereum/ui/qt" "github.com/ethereum/go-ethereum/ui/qt"
"github.com/ethereum/go-ethereum/xeth"
"gopkg.in/qml.v1" "gopkg.in/qml.v1"
) )
@ -43,7 +43,7 @@ type AppContainer interface {
} }
type ExtApplication struct { type ExtApplication struct {
*ethpipe.JSPipe *xeth.JSXEth
eth chain.EthManager eth chain.EthManager
events event.Subscription events event.Subscription
@ -57,7 +57,7 @@ type ExtApplication struct {
func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication { func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication {
return &ExtApplication{ return &ExtApplication{
JSPipe: ethpipe.NewJSPipe(lib.eth), JSXEth: xeth.NewJSXEth(lib.eth),
eth: lib.eth, eth: lib.eth,
watcherQuitChan: make(chan bool), watcherQuitChan: make(chan bool),
filters: make(map[string]*chain.Filter), filters: make(map[string]*chain.Filter),

@ -34,10 +34,10 @@ import (
"github.com/ethereum/go-ethereum/chain" "github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethminer" "github.com/ethereum/go-ethereum/ethminer"
"github.com/ethereum/go-ethereum/ethpipe"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethwire" "github.com/ethereum/go-ethereum/ethwire"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/xeth"
"gopkg.in/qml.v1" "gopkg.in/qml.v1"
) )
@ -84,7 +84,7 @@ type Gui struct {
logLevel logger.LogLevel logLevel logger.LogLevel
open bool open bool
pipe *ethpipe.JSPipe pipe *xeth.JSXEth
Session string Session string
clientIdentity *ethwire.SimpleClientIdentity clientIdentity *ethwire.SimpleClientIdentity
@ -103,7 +103,7 @@ func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIden
panic(err) panic(err)
} }
pipe := ethpipe.NewJSPipe(ethereum) pipe := xeth.NewJSXEth(ethereum)
gui := &Gui{eth: ethereum, txDb: db, pipe: pipe, logLevel: logger.LogLevel(logLevel), Session: session, open: false, clientIdentity: clientIdentity, config: config, plugins: make(map[string]plugin)} gui := &Gui{eth: ethereum, txDb: db, pipe: pipe, logLevel: logger.LogLevel(logLevel), Session: session, open: false, clientIdentity: clientIdentity, config: config, plugins: make(map[string]plugin)}
data, _ := ethutil.ReadAllFile(path.Join(ethutil.Config.ExecPath, "plugins.json")) data, _ := ethutil.ReadAllFile(path.Join(ethutil.Config.ExecPath, "plugins.json"))
json.Unmarshal([]byte(data), &gui.plugins) json.Unmarshal([]byte(data), &gui.plugins)
@ -117,11 +117,11 @@ func (gui *Gui) Start(assetPath string) {
// Register ethereum functions // Register ethereum functions
qml.RegisterTypes("Ethereum", 1, 0, []qml.TypeSpec{{ qml.RegisterTypes("Ethereum", 1, 0, []qml.TypeSpec{{
Init: func(p *ethpipe.JSBlock, obj qml.Object) { p.Number = 0; p.Hash = "" }, Init: func(p *xeth.JSBlock, obj qml.Object) { p.Number = 0; p.Hash = "" },
}, { }, {
Init: func(p *ethpipe.JSTransaction, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, Init: func(p *xeth.JSTransaction, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" },
}, { }, {
Init: func(p *ethpipe.KeyVal, obj qml.Object) { p.Key = ""; p.Value = "" }, Init: func(p *xeth.KeyVal, obj qml.Object) { p.Key = ""; p.Value = "" },
}}) }})
// Create a new QML engine // Create a new QML engine
gui.engine = qml.NewEngine() gui.engine = qml.NewEngine()
@ -287,7 +287,7 @@ func (gui *Gui) loadAddressBook() {
} }
func (gui *Gui) insertTransaction(window string, tx *chain.Transaction) { func (gui *Gui) insertTransaction(window string, tx *chain.Transaction) {
pipe := ethpipe.New(gui.eth) pipe := xeth.New(gui.eth)
nameReg := pipe.World().Config().Get("NameReg") nameReg := pipe.World().Config().Get("NameReg")
addr := gui.address() addr := gui.address()
@ -299,7 +299,7 @@ func (gui *Gui) insertTransaction(window string, tx *chain.Transaction) {
} }
var ( var (
ptx = ethpipe.NewJSTx(tx, pipe.World().State()) ptx = xeth.NewJSTx(tx, pipe.World().State())
send = nameReg.Storage(tx.Sender()) send = nameReg.Storage(tx.Sender())
rec = nameReg.Storage(tx.Recipient) rec = nameReg.Storage(tx.Recipient)
s, r string s, r string
@ -346,7 +346,7 @@ func (gui *Gui) readPreviousTransactions() {
func (gui *Gui) processBlock(block *chain.Block, initial bool) { func (gui *Gui) processBlock(block *chain.Block, initial bool) {
name := strings.Trim(gui.pipe.World().Config().Get("NameReg").Storage(block.Coinbase).Str(), "\x00") name := strings.Trim(gui.pipe.World().Config().Get("NameReg").Storage(block.Coinbase).Str(), "\x00")
b := ethpipe.NewJSBlock(block) b := xeth.NewJSBlock(block)
b.Name = name b.Name = name
gui.getObjectByName("chainView").Call("addBlock", b, initial) gui.getObjectByName("chainView").Call("addBlock", b, initial)
@ -451,12 +451,12 @@ func (gui *Gui) update() {
if bytes.Compare(tx.Sender(), gui.address()) == 0 { if bytes.Compare(tx.Sender(), gui.address()) == 0 {
object.SubAmount(tx.Value) object.SubAmount(tx.Value)
//gui.getObjectByName("transactionView").Call("addTx", ethpipe.NewJSTx(tx), "send") //gui.getObjectByName("transactionView").Call("addTx", xeth.NewJSTx(tx), "send")
gui.txDb.Put(tx.Hash(), tx.RlpEncode()) gui.txDb.Put(tx.Hash(), tx.RlpEncode())
} else if bytes.Compare(tx.Recipient, gui.address()) == 0 { } else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
object.AddAmount(tx.Value) object.AddAmount(tx.Value)
//gui.getObjectByName("transactionView").Call("addTx", ethpipe.NewJSTx(tx), "recv") //gui.getObjectByName("transactionView").Call("addTx", xeth.NewJSTx(tx), "recv")
gui.txDb.Put(tx.Hash(), tx.RlpEncode()) gui.txDb.Put(tx.Hash(), tx.RlpEncode())
} }

@ -28,10 +28,10 @@ import (
"path/filepath" "path/filepath"
"github.com/ethereum/go-ethereum/chain" "github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/ethpipe"
"github.com/ethereum/go-ethereum/ethstate" "github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/javascript" "github.com/ethereum/go-ethereum/javascript"
"github.com/ethereum/go-ethereum/xeth"
"github.com/howeyc/fsnotify" "github.com/howeyc/fsnotify"
"gopkg.in/qml.v1" "gopkg.in/qml.v1"
) )
@ -139,7 +139,7 @@ func (app *HtmlApplication) Window() *qml.Window {
} }
func (app *HtmlApplication) NewBlock(block *chain.Block) { func (app *HtmlApplication) NewBlock(block *chain.Block) {
b := &ethpipe.JSBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Bytes2Hex(block.Hash())} b := &xeth.JSBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Bytes2Hex(block.Hash())}
app.webView.Call("onNewBlockCb", b) app.webView.Call("onNewBlockCb", b)
} }

@ -22,9 +22,9 @@ import (
"runtime" "runtime"
"github.com/ethereum/go-ethereum/chain" "github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/ethpipe"
"github.com/ethereum/go-ethereum/ethstate" "github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/xeth"
"gopkg.in/qml.v1" "gopkg.in/qml.v1"
) )
@ -66,7 +66,7 @@ func (app *QmlApplication) NewWatcher(quitChan chan bool) {
// Events // Events
func (app *QmlApplication) NewBlock(block *chain.Block) { func (app *QmlApplication) NewBlock(block *chain.Block) {
pblock := &ethpipe.JSBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Bytes2Hex(block.Hash())} pblock := &xeth.JSBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Bytes2Hex(block.Hash())}
app.win.Call("onNewBlockCb", pblock) app.win.Call("onNewBlockCb", pblock)
} }

@ -27,11 +27,11 @@ import (
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/chain" "github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethpipe"
"github.com/ethereum/go-ethereum/ethstate" "github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/javascript" "github.com/ethereum/go-ethereum/javascript"
"github.com/ethereum/go-ethereum/ui/qt" "github.com/ethereum/go-ethereum/ui/qt"
"github.com/ethereum/go-ethereum/xeth"
"gopkg.in/qml.v1" "gopkg.in/qml.v1"
) )
@ -42,7 +42,7 @@ type memAddr struct {
// UI Library that has some basic functionality exposed // UI Library that has some basic functionality exposed
type UiLib struct { type UiLib struct {
*ethpipe.JSPipe *xeth.JSXEth
engine *qml.Engine engine *qml.Engine
eth *eth.Ethereum eth *eth.Ethereum
connected bool connected bool
@ -58,7 +58,7 @@ type UiLib struct {
} }
func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib {
return &UiLib{JSPipe: ethpipe.NewJSPipe(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*ethpipe.JSFilter)} return &UiLib{JSXEth: xeth.NewJSXEth(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)}
} }
func (self *UiLib) Notef(args []interface{}) { func (self *UiLib) Notef(args []interface{}) {
@ -214,7 +214,7 @@ func (self *UiLib) StartDebugger() {
func (self *UiLib) NewFilter(object map[string]interface{}) (id int) { func (self *UiLib) NewFilter(object map[string]interface{}) (id int) {
filter := qt.NewFilterFromMap(object, self.eth) filter := qt.NewFilterFromMap(object, self.eth)
filter.MessageCallback = func(messages ethstate.Messages) { filter.MessageCallback = func(messages ethstate.Messages) {
self.win.Root().Call("invokeFilterCallback", ethpipe.ToJSMessages(messages), id) self.win.Root().Call("invokeFilterCallback", xeth.ToJSMessages(messages), id)
} }
id = self.eth.InstallFilter(filter) id = self.eth.InstallFilter(filter)
return id return id
@ -232,7 +232,7 @@ func (self *UiLib) NewFilterString(typ string) (id int) {
func (self *UiLib) Messages(id int) *ethutil.List { func (self *UiLib) Messages(id int) *ethutil.List {
filter := self.eth.GetFilter(id) filter := self.eth.GetFilter(id)
if filter != nil { if filter != nil {
messages := ethpipe.ToJSMessages(filter.Find()) messages := xeth.ToJSMessages(filter.Find())
return messages return messages
} }
@ -295,10 +295,10 @@ func mapToTxParams(object map[string]interface{}) map[string]string {
return conv return conv
} }
func (self *UiLib) Transact(params map[string]interface{}) (*ethpipe.JSReceipt, error) { func (self *UiLib) Transact(params map[string]interface{}) (*xeth.JSReceipt, error) {
object := mapToTxParams(params) object := mapToTxParams(params)
return self.JSPipe.Transact( return self.JSXEth.Transact(
object["from"], object["from"],
object["to"], object["to"],
object["value"], object["value"],
@ -320,7 +320,7 @@ func (self *UiLib) Compile(code string) (string, error) {
func (self *UiLib) Call(params map[string]interface{}) (string, error) { func (self *UiLib) Call(params map[string]interface{}) (string, error) {
object := mapToTxParams(params) object := mapToTxParams(params)
return self.JSPipe.Execute( return self.JSXEth.Execute(
object["to"], object["to"],
object["value"], object["value"],
object["gas"], object["gas"],

@ -17,11 +17,11 @@ import (
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethminer" "github.com/ethereum/go-ethereum/ethminer"
"github.com/ethereum/go-ethereum/ethpipe"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethwire" "github.com/ethereum/go-ethereum/ethwire"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/xeth"
) )
var clilogger = logger.NewLogger("CLI") var clilogger = logger.NewLogger("CLI")
@ -244,7 +244,7 @@ func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, Secre
func StartRpc(ethereum *eth.Ethereum, RpcPort int) { func StartRpc(ethereum *eth.Ethereum, RpcPort int) {
var err error var err error
ethereum.RpcServer, err = rpc.NewJsonRpcServer(ethpipe.NewJSPipe(ethereum), RpcPort) ethereum.RpcServer, err = rpc.NewJsonRpcServer(xeth.NewJSXEth(ethereum), RpcPort)
if err != nil { if err != nil {
clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err) clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
} else { } else {

@ -2,9 +2,9 @@ package utils
import ( import (
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/ethpipe"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/websocket" "github.com/ethereum/go-ethereum/websocket"
"github.com/ethereum/go-ethereum/xeth"
) )
func args(v ...interface{}) []interface{} { func args(v ...interface{}) []interface{} {
@ -21,7 +21,7 @@ func NewWebSocketServer(eth *eth.Ethereum) *WebSocketServer {
} }
func (self *WebSocketServer) Serv() { func (self *WebSocketServer) Serv() {
pipe := ethpipe.NewJSPipe(self.ethereum) pipe := xeth.NewJSXEth(self.ethereum)
wsServ := websocket.NewServer("/eth", ":40404") wsServ := websocket.NewServer("/eth", ":40404")
wsServ.MessageFunc(func(c *websocket.Client, msg *websocket.Message) { wsServ.MessageFunc(func(c *websocket.Client, msg *websocket.Message) {

@ -10,11 +10,11 @@ import (
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/chain" "github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/ethpipe"
"github.com/ethereum/go-ethereum/ethstate" "github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/xeth"
"github.com/obscuren/otto" "github.com/obscuren/otto"
) )
@ -23,7 +23,7 @@ var jsrelogger = logger.NewLogger("JSRE")
type JSRE struct { type JSRE struct {
ethereum *eth.Ethereum ethereum *eth.Ethereum
Vm *otto.Otto Vm *otto.Otto
pipe *ethpipe.JSPipe pipe *xeth.JSXEth
events event.Subscription events event.Subscription
@ -48,7 +48,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
re := &JSRE{ re := &JSRE{
ethereum, ethereum,
otto.New(), otto.New(),
ethpipe.NewJSPipe(ethereum), xeth.NewJSXEth(ethereum),
nil, nil,
make(map[string][]otto.Value), make(map[string][]otto.Value),
} }

@ -4,15 +4,15 @@ import (
"fmt" "fmt"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/ethpipe"
"github.com/ethereum/go-ethereum/ethstate" "github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ui" "github.com/ethereum/go-ethereum/ui"
"github.com/ethereum/go-ethereum/xeth"
"github.com/obscuren/otto" "github.com/obscuren/otto"
) )
type JSStateObject struct { type JSStateObject struct {
*ethpipe.JSObject *xeth.JSObject
eth *JSEthereum eth *JSEthereum
} }
@ -30,7 +30,7 @@ func (self *JSStateObject) EachStorage(call otto.FunctionCall) otto.Value {
// The JSEthereum object attempts to wrap the PEthereum object and returns // The JSEthereum object attempts to wrap the PEthereum object and returns
// meaningful javascript objects // meaningful javascript objects
type JSBlock struct { type JSBlock struct {
*ethpipe.JSBlock *xeth.JSBlock
eth *JSEthereum eth *JSEthereum
} }
@ -67,33 +67,33 @@ func NewJSMessage(message *ethstate.Message) JSMessage {
} }
type JSEthereum struct { type JSEthereum struct {
*ethpipe.JSPipe *xeth.JSXEth
vm *otto.Otto vm *otto.Otto
ethereum *eth.Ethereum ethereum *eth.Ethereum
} }
func (self *JSEthereum) GetBlock(hash string) otto.Value { func (self *JSEthereum) GetBlock(hash string) otto.Value {
return self.toVal(&JSBlock{self.JSPipe.BlockByHash(hash), self}) return self.toVal(&JSBlock{self.JSXEth.BlockByHash(hash), self})
} }
func (self *JSEthereum) GetPeers() otto.Value { func (self *JSEthereum) GetPeers() otto.Value {
return self.toVal(self.JSPipe.Peers()) return self.toVal(self.JSXEth.Peers())
} }
func (self *JSEthereum) GetKey() otto.Value { func (self *JSEthereum) GetKey() otto.Value {
return self.toVal(self.JSPipe.Key()) return self.toVal(self.JSXEth.Key())
} }
func (self *JSEthereum) GetStateObject(addr string) otto.Value { func (self *JSEthereum) GetStateObject(addr string) otto.Value {
return self.toVal(&JSStateObject{ethpipe.NewJSObject(self.JSPipe.World().SafeGet(ethutil.Hex2Bytes(addr))), self}) return self.toVal(&JSStateObject{xeth.NewJSObject(self.JSXEth.World().SafeGet(ethutil.Hex2Bytes(addr))), self})
} }
func (self *JSEthereum) Peers() otto.Value { func (self *JSEthereum) Peers() otto.Value {
return self.toVal(self.JSPipe.Peers()) return self.toVal(self.JSXEth.Peers())
} }
func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) otto.Value { func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) otto.Value {
r, err := self.JSPipe.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr) r, err := self.JSXEth.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -104,7 +104,7 @@ func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr,
} }
func (self *JSEthereum) Create(key, valueStr, gasStr, gasPriceStr, scriptStr string) otto.Value { func (self *JSEthereum) Create(key, valueStr, gasStr, gasPriceStr, scriptStr string) otto.Value {
r, err := self.JSPipe.Transact(key, "", valueStr, gasStr, gasPriceStr, scriptStr) r, err := self.JSXEth.Transact(key, "", valueStr, gasStr, gasPriceStr, scriptStr)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)

@ -6,12 +6,12 @@ import (
"math/big" "math/big"
"strings" "strings"
"github.com/ethereum/go-ethereum/ethpipe"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/xeth"
) )
type EthereumApi struct { type EthereumApi struct {
pipe *ethpipe.JSPipe pipe *xeth.JSXEth
} }
type JsonArgs interface { type JsonArgs interface {

@ -6,8 +6,8 @@ import (
"net/rpc" "net/rpc"
"net/rpc/jsonrpc" "net/rpc/jsonrpc"
"github.com/ethereum/go-ethereum/ethpipe"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/xeth"
) )
var jsonlogger = logger.NewLogger("JSON") var jsonlogger = logger.NewLogger("JSON")
@ -15,7 +15,7 @@ var jsonlogger = logger.NewLogger("JSON")
type JsonRpcServer struct { type JsonRpcServer struct {
quit chan bool quit chan bool
listener net.Listener listener net.Listener
pipe *ethpipe.JSPipe pipe *xeth.JSXEth
} }
func (s *JsonRpcServer) exitHandler() { func (s *JsonRpcServer) exitHandler() {
@ -52,7 +52,7 @@ func (s *JsonRpcServer) Start() {
} }
} }
func NewJsonRpcServer(pipe *ethpipe.JSPipe, port int) (*JsonRpcServer, error) { func NewJsonRpcServer(pipe *xeth.JSXEth, port int) (*JsonRpcServer, error) {
sport := fmt.Sprintf(":%d", port) sport := fmt.Sprintf(":%d", port)
l, err := net.Listen("tcp", sport) l, err := net.Listen("tcp", sport)
if err != nil { if err != nil {

@ -1,11 +1,11 @@
package ethpipe package xeth
import "github.com/ethereum/go-ethereum/ethutil" import "github.com/ethereum/go-ethereum/ethutil"
var cnfCtr = ethutil.Hex2Bytes("661005d2720d855f1d9976f88bb10c1a3398c77f") var cnfCtr = ethutil.Hex2Bytes("661005d2720d855f1d9976f88bb10c1a3398c77f")
type Config struct { type Config struct {
pipe *Pipe pipe *XEth
} }
func (self *Config) Get(name string) *Object { func (self *Config) Get(name string) *Object {

@ -1,4 +1,4 @@
package ethpipe package xeth
import ( import (
"bytes" "bytes"
@ -11,22 +11,22 @@ import (
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
) )
type JSPipe struct { type JSXEth struct {
*Pipe *XEth
} }
func NewJSPipe(eth chain.EthManager) *JSPipe { func NewJSXEth(eth chain.EthManager) *JSXEth {
return &JSPipe{New(eth)} return &JSXEth{New(eth)}
} }
func (self *JSPipe) BlockByHash(strHash string) *JSBlock { func (self *JSXEth) BlockByHash(strHash string) *JSBlock {
hash := ethutil.Hex2Bytes(strHash) hash := ethutil.Hex2Bytes(strHash)
block := self.obj.ChainManager().GetBlock(hash) block := self.obj.ChainManager().GetBlock(hash)
return NewJSBlock(block) return NewJSBlock(block)
} }
func (self *JSPipe) BlockByNumber(num int32) *JSBlock { func (self *JSXEth) BlockByNumber(num int32) *JSBlock {
if num == -1 { if num == -1 {
return NewJSBlock(self.obj.ChainManager().CurrentBlock) return NewJSBlock(self.obj.ChainManager().CurrentBlock)
} }
@ -34,7 +34,7 @@ func (self *JSPipe) BlockByNumber(num int32) *JSBlock {
return NewJSBlock(self.obj.ChainManager().GetBlockByNumber(uint64(num))) return NewJSBlock(self.obj.ChainManager().GetBlockByNumber(uint64(num)))
} }
func (self *JSPipe) Block(v interface{}) *JSBlock { func (self *JSXEth) Block(v interface{}) *JSBlock {
if n, ok := v.(int32); ok { if n, ok := v.(int32); ok {
return self.BlockByNumber(n) return self.BlockByNumber(n)
} else if str, ok := v.(string); ok { } else if str, ok := v.(string); ok {
@ -46,21 +46,21 @@ func (self *JSPipe) Block(v interface{}) *JSBlock {
return nil return nil
} }
func (self *JSPipe) Key() *JSKey { func (self *JSXEth) Key() *JSKey {
return NewJSKey(self.obj.KeyManager().KeyPair()) return NewJSKey(self.obj.KeyManager().KeyPair())
} }
func (self *JSPipe) StateObject(addr string) *JSObject { func (self *JSXEth) StateObject(addr string) *JSObject {
object := &Object{self.World().safeGet(ethutil.Hex2Bytes(addr))} object := &Object{self.World().safeGet(ethutil.Hex2Bytes(addr))}
return NewJSObject(object) return NewJSObject(object)
} }
func (self *JSPipe) PeerCount() int { func (self *JSXEth) PeerCount() int {
return self.obj.PeerCount() return self.obj.PeerCount()
} }
func (self *JSPipe) Peers() []JSPeer { func (self *JSXEth) Peers() []JSPeer {
var peers []JSPeer var peers []JSPeer
for peer := self.obj.Peers().Front(); peer != nil; peer = peer.Next() { for peer := self.obj.Peers().Front(); peer != nil; peer = peer.Next() {
p := peer.Value.(chain.Peer) p := peer.Value.(chain.Peer)
@ -73,47 +73,47 @@ func (self *JSPipe) Peers() []JSPeer {
return peers return peers
} }
func (self *JSPipe) IsMining() bool { func (self *JSXEth) IsMining() bool {
return self.obj.IsMining() return self.obj.IsMining()
} }
func (self *JSPipe) IsListening() bool { func (self *JSXEth) IsListening() bool {
return self.obj.IsListening() return self.obj.IsListening()
} }
func (self *JSPipe) CoinBase() string { func (self *JSXEth) CoinBase() string {
return ethutil.Bytes2Hex(self.obj.KeyManager().Address()) return ethutil.Bytes2Hex(self.obj.KeyManager().Address())
} }
func (self *JSPipe) NumberToHuman(balance string) string { func (self *JSXEth) NumberToHuman(balance string) string {
b := ethutil.Big(balance) b := ethutil.Big(balance)
return ethutil.CurrencyToString(b) return ethutil.CurrencyToString(b)
} }
func (self *JSPipe) StorageAt(addr, storageAddr 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(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr))
return ethutil.Bytes2Hex(storage.Bytes()) return ethutil.Bytes2Hex(storage.Bytes())
} }
func (self *JSPipe) BalanceAt(addr string) string { func (self *JSXEth) BalanceAt(addr string) string {
return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Balance().String() return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Balance().String()
} }
func (self *JSPipe) TxCountAt(address string) int { func (self *JSXEth) TxCountAt(address string) int {
return int(self.World().SafeGet(ethutil.Hex2Bytes(address)).Nonce) return int(self.World().SafeGet(ethutil.Hex2Bytes(address)).Nonce)
} }
func (self *JSPipe) CodeAt(address string) string { func (self *JSXEth) CodeAt(address string) string {
return ethutil.Bytes2Hex(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code) return ethutil.Bytes2Hex(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code)
} }
func (self *JSPipe) IsContract(address string) bool { func (self *JSXEth) IsContract(address string) bool {
return len(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code) > 0 return len(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code) > 0
} }
func (self *JSPipe) SecretToAddress(key string) string { func (self *JSXEth) SecretToAddress(key string) string {
pair, err := crypto.NewKeyPairFromSec(ethutil.Hex2Bytes(key)) pair, err := crypto.NewKeyPairFromSec(ethutil.Hex2Bytes(key))
if err != nil { if err != nil {
return "" return ""
@ -122,7 +122,7 @@ func (self *JSPipe) SecretToAddress(key string) string {
return ethutil.Bytes2Hex(pair.Address()) return ethutil.Bytes2Hex(pair.Address())
} }
func (self *JSPipe) Execute(addr, value, gas, price, data string) (string, error) { func (self *JSXEth) Execute(addr, value, gas, price, data string) (string, error) {
ret, err := self.ExecuteObject(&Object{ ret, err := self.ExecuteObject(&Object{
self.World().safeGet(ethutil.Hex2Bytes(addr))}, self.World().safeGet(ethutil.Hex2Bytes(addr))},
ethutil.Hex2Bytes(data), ethutil.Hex2Bytes(data),
@ -139,7 +139,7 @@ type KeyVal struct {
Value string `json:"value"` Value string `json:"value"`
} }
func (self *JSPipe) EachStorage(addr string) string { func (self *JSXEth) EachStorage(addr string) string {
var values []KeyVal var values []KeyVal
object := self.World().SafeGet(ethutil.Hex2Bytes(addr)) object := self.World().SafeGet(ethutil.Hex2Bytes(addr))
object.EachStorage(func(name string, value *ethutil.Value) { object.EachStorage(func(name string, value *ethutil.Value) {
@ -155,13 +155,13 @@ func (self *JSPipe) EachStorage(addr string) string {
return string(valuesJson) return string(valuesJson)
} }
func (self *JSPipe) ToAscii(str string) string { func (self *JSXEth) ToAscii(str string) string {
padded := ethutil.RightPadBytes([]byte(str), 32) padded := ethutil.RightPadBytes([]byte(str), 32)
return "0x" + ethutil.Bytes2Hex(padded) return "0x" + ethutil.Bytes2Hex(padded)
} }
func (self *JSPipe) FromAscii(str string) string { func (self *JSXEth) FromAscii(str string) string {
if ethutil.IsHex(str) { if ethutil.IsHex(str) {
str = str[2:] str = str[2:]
} }
@ -169,7 +169,7 @@ func (self *JSPipe) FromAscii(str string) string {
return string(bytes.Trim(ethutil.Hex2Bytes(str), "\x00")) return string(bytes.Trim(ethutil.Hex2Bytes(str), "\x00"))
} }
func (self *JSPipe) FromNumber(str string) string { func (self *JSXEth) FromNumber(str string) string {
if ethutil.IsHex(str) { if ethutil.IsHex(str) {
str = str[2:] str = str[2:]
} }
@ -177,7 +177,7 @@ func (self *JSPipe) FromNumber(str string) string {
return ethutil.BigD(ethutil.Hex2Bytes(str)).String() return ethutil.BigD(ethutil.Hex2Bytes(str)).String()
} }
func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (*JSReceipt, error) { func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (*JSReceipt, error) {
var hash []byte var hash []byte
var contractCreation bool var contractCreation bool
if len(toStr) == 0 { if len(toStr) == 0 {
@ -239,14 +239,14 @@ func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil
} }
func (self *JSPipe) PushTx(txStr string) (*JSReceipt, error) { func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) {
tx := chain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) tx := chain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr))
self.obj.TxPool().QueueTransaction(tx) self.obj.TxPool().QueueTransaction(tx)
return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(self.World().State()), tx.Hash(), tx.Sender()), nil return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(self.World().State()), tx.Hash(), tx.Sender()), nil
} }
func (self *JSPipe) CompileMutan(code string) string { func (self *JSXEth) CompileMutan(code string) string {
data, err := self.Pipe.CompileMutan(code) data, err := self.XEth.CompileMutan(code)
if err != nil { if err != nil {
return err.Error() return err.Error()
} }

@ -1,4 +1,4 @@
package ethpipe package xeth
import ( import (
"fmt" "fmt"

@ -1,4 +1,4 @@
package ethpipe package xeth
import ( import (
"github.com/ethereum/go-ethereum/ethstate" "github.com/ethereum/go-ethereum/ethstate"

@ -1,4 +1,8 @@
package ethpipe package xeth
/*
* eXtended ETHereum
*/
import ( import (
"fmt" "fmt"
@ -12,13 +16,13 @@ import (
"github.com/ethereum/go-ethereum/vm" "github.com/ethereum/go-ethereum/vm"
) )
var pipelogger = logger.NewLogger("PIPE") var pipelogger = logger.NewLogger("XETH")
type VmVars struct { type VmVars struct {
State *ethstate.State State *ethstate.State
} }
type Pipe struct { type XEth struct {
obj chain.EthManager obj chain.EthManager
stateManager *chain.StateManager stateManager *chain.StateManager
blockChain *chain.ChainManager blockChain *chain.ChainManager
@ -27,8 +31,8 @@ type Pipe struct {
Vm VmVars Vm VmVars
} }
func New(obj chain.EthManager) *Pipe { func New(obj chain.EthManager) *XEth {
pipe := &Pipe{ pipe := &XEth{
obj: obj, obj: obj,
stateManager: obj.StateManager(), stateManager: obj.StateManager(),
blockChain: obj.ChainManager(), blockChain: obj.ChainManager(),
@ -38,19 +42,19 @@ func New(obj chain.EthManager) *Pipe {
return pipe return pipe
} }
func (self *Pipe) Balance(addr []byte) *ethutil.Value { func (self *XEth) Balance(addr []byte) *ethutil.Value {
return ethutil.NewValue(self.World().safeGet(addr).Balance) return ethutil.NewValue(self.World().safeGet(addr).Balance)
} }
func (self *Pipe) Nonce(addr []byte) uint64 { func (self *XEth) Nonce(addr []byte) uint64 {
return self.World().safeGet(addr).Nonce return self.World().safeGet(addr).Nonce
} }
func (self *Pipe) Execute(addr []byte, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { 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) return self.ExecuteObject(&Object{self.World().safeGet(addr)}, data, value, gas, price)
} }
func (self *Pipe) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
var ( var (
initiator = ethstate.NewStateObject(self.obj.KeyManager().KeyPair().Address()) initiator = ethstate.NewStateObject(self.obj.KeyManager().KeyPair().Address())
block = self.blockChain.CurrentBlock block = self.blockChain.CurrentBlock
@ -68,15 +72,15 @@ func (self *Pipe) ExecuteObject(object *Object, data []byte, value, gas, price *
return ret, err return ret, err
} }
func (self *Pipe) Block(hash []byte) *chain.Block { func (self *XEth) Block(hash []byte) *chain.Block {
return self.blockChain.GetBlock(hash) return self.blockChain.GetBlock(hash)
} }
func (self *Pipe) Storage(addr, storageAddr []byte) *ethutil.Value { func (self *XEth) Storage(addr, storageAddr []byte) *ethutil.Value {
return self.World().safeGet(addr).GetStorage(ethutil.BigD(storageAddr)) return self.World().safeGet(addr).GetStorage(ethutil.BigD(storageAddr))
} }
func (self *Pipe) ToAddress(priv []byte) []byte { func (self *XEth) ToAddress(priv []byte) []byte {
pair, err := crypto.NewKeyPairFromSec(priv) pair, err := crypto.NewKeyPairFromSec(priv)
if err != nil { if err != nil {
return nil return nil
@ -85,11 +89,11 @@ func (self *Pipe) ToAddress(priv []byte) []byte {
return pair.Address() return pair.Address()
} }
func (self *Pipe) Exists(addr []byte) bool { func (self *XEth) Exists(addr []byte) bool {
return self.World().Get(addr) != nil return self.World().Get(addr) != nil
} }
func (self *Pipe) 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) ([]byte, error) {
// Check if an address is stored by this address // Check if an address is stored by this address
var hash []byte var hash []byte
addr := self.World().Config().Get("NameReg").StorageString(rec).Bytes() addr := self.World().Config().Get("NameReg").StorageString(rec).Bytes()
@ -104,7 +108,7 @@ func (self *Pipe) TransactString(key *crypto.KeyPair, rec string, value, gas, pr
return self.Transact(key, hash, value, gas, price, data) return self.Transact(key, hash, value, gas, price, data)
} }
func (self *Pipe) Transact(key *crypto.KeyPair, rec []byte, value, gas, price *ethutil.Value, data []byte) ([]byte, error) { func (self *XEth) Transact(key *crypto.KeyPair, rec []byte, value, gas, price *ethutil.Value, data []byte) ([]byte, error) {
var hash []byte var hash []byte
var contractCreation bool var contractCreation bool
if rec == nil { if rec == nil {
@ -151,7 +155,7 @@ func (self *Pipe) Transact(key *crypto.KeyPair, rec []byte, value, gas, price *e
return tx.Hash(), nil return tx.Hash(), nil
} }
func (self *Pipe) PushTx(tx *chain.Transaction) ([]byte, error) { func (self *XEth) PushTx(tx *chain.Transaction) ([]byte, error) {
self.obj.TxPool().QueueTransaction(tx) self.obj.TxPool().QueueTransaction(tx)
if tx.Recipient == nil { if tx.Recipient == nil {
addr := tx.CreationAddress(self.World().State()) addr := tx.CreationAddress(self.World().State())
@ -161,7 +165,7 @@ func (self *Pipe) PushTx(tx *chain.Transaction) ([]byte, error) {
return tx.Hash(), nil return tx.Hash(), nil
} }
func (self *Pipe) CompileMutan(code string) ([]byte, error) { func (self *XEth) CompileMutan(code string) ([]byte, error) {
data, err := ethutil.Compile(code, false) data, err := ethutil.Compile(code, false)
if err != nil { if err != nil {
return nil, err return nil, err

@ -1,4 +1,4 @@
package ethpipe package xeth
import ( import (
"math/big" "math/big"

@ -1,4 +1,4 @@
package ethpipe package xeth
import ( import (
"container/list" "container/list"
@ -7,18 +7,18 @@ import (
) )
type World struct { type World struct {
pipe *Pipe pipe *XEth
cfg *Config cfg *Config
} }
func NewWorld(pipe *Pipe) *World { func NewWorld(pipe *XEth) *World {
world := &World{pipe, nil} world := &World{pipe, nil}
world.cfg = &Config{pipe} world.cfg = &Config{pipe}
return world return world
} }
func (self *Pipe) World() *World { func (self *XEth) World() *World {
return self.world return self.world
} }