mirror of https://github.com/status-im/op-geth.git
ethpipe => xeth (eXtended ETHereum)
This commit is contained in:
parent
8826e9694c
commit
0ed1a8b50a
|
@ -24,9 +24,9 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/chain"
|
||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||
"github.com/ethereum/go-ethereum/ethpipe"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
)
|
||||
|
||||
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
|
||||
if len(recipient) == 0 {
|
||||
code, err := ethutil.Compile(d, false)
|
||||
|
|
|
@ -21,11 +21,11 @@ import (
|
|||
"encoding/json"
|
||||
|
||||
"github.com/ethereum/go-ethereum/chain"
|
||||
"github.com/ethereum/go-ethereum/ethpipe"
|
||||
"github.com/ethereum/go-ethereum/ethstate"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/javascript"
|
||||
"github.com/ethereum/go-ethereum/ui/qt"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
"gopkg.in/qml.v1"
|
||||
)
|
||||
|
||||
|
@ -43,7 +43,7 @@ type AppContainer interface {
|
|||
}
|
||||
|
||||
type ExtApplication struct {
|
||||
*ethpipe.JSPipe
|
||||
*xeth.JSXEth
|
||||
eth chain.EthManager
|
||||
|
||||
events event.Subscription
|
||||
|
@ -57,7 +57,7 @@ type ExtApplication struct {
|
|||
|
||||
func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication {
|
||||
return &ExtApplication{
|
||||
JSPipe: ethpipe.NewJSPipe(lib.eth),
|
||||
JSXEth: xeth.NewJSXEth(lib.eth),
|
||||
eth: lib.eth,
|
||||
watcherQuitChan: make(chan bool),
|
||||
filters: make(map[string]*chain.Filter),
|
||||
|
|
|
@ -34,10 +34,10 @@ import (
|
|||
"github.com/ethereum/go-ethereum/chain"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/ethminer"
|
||||
"github.com/ethereum/go-ethereum/ethpipe"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/ethwire"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
"gopkg.in/qml.v1"
|
||||
)
|
||||
|
||||
|
@ -84,7 +84,7 @@ type Gui struct {
|
|||
logLevel logger.LogLevel
|
||||
open bool
|
||||
|
||||
pipe *ethpipe.JSPipe
|
||||
pipe *xeth.JSXEth
|
||||
|
||||
Session string
|
||||
clientIdentity *ethwire.SimpleClientIdentity
|
||||
|
@ -103,7 +103,7 @@ func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIden
|
|||
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)}
|
||||
data, _ := ethutil.ReadAllFile(path.Join(ethutil.Config.ExecPath, "plugins.json"))
|
||||
json.Unmarshal([]byte(data), &gui.plugins)
|
||||
|
@ -117,11 +117,11 @@ func (gui *Gui) Start(assetPath string) {
|
|||
|
||||
// Register ethereum functions
|
||||
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
|
||||
gui.engine = qml.NewEngine()
|
||||
|
@ -287,7 +287,7 @@ func (gui *Gui) loadAddressBook() {
|
|||
}
|
||||
|
||||
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")
|
||||
addr := gui.address()
|
||||
|
||||
|
@ -299,7 +299,7 @@ func (gui *Gui) insertTransaction(window string, tx *chain.Transaction) {
|
|||
}
|
||||
|
||||
var (
|
||||
ptx = ethpipe.NewJSTx(tx, pipe.World().State())
|
||||
ptx = xeth.NewJSTx(tx, pipe.World().State())
|
||||
send = nameReg.Storage(tx.Sender())
|
||||
rec = nameReg.Storage(tx.Recipient)
|
||||
s, r string
|
||||
|
@ -346,7 +346,7 @@ func (gui *Gui) readPreviousTransactions() {
|
|||
|
||||
func (gui *Gui) processBlock(block *chain.Block, initial bool) {
|
||||
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
|
||||
|
||||
gui.getObjectByName("chainView").Call("addBlock", b, initial)
|
||||
|
@ -451,12 +451,12 @@ func (gui *Gui) update() {
|
|||
if bytes.Compare(tx.Sender(), gui.address()) == 0 {
|
||||
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())
|
||||
} else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
|
||||
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())
|
||||
}
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/ethereum/go-ethereum/chain"
|
||||
"github.com/ethereum/go-ethereum/ethpipe"
|
||||
"github.com/ethereum/go-ethereum/ethstate"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/javascript"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
"github.com/howeyc/fsnotify"
|
||||
"gopkg.in/qml.v1"
|
||||
)
|
||||
|
@ -139,7 +139,7 @@ func (app *HtmlApplication) Window() *qml.Window {
|
|||
}
|
||||
|
||||
func (app *HtmlApplication) NewBlock(block *chain.Block) {
|
||||
b := ðpipe.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)
|
||||
}
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ import (
|
|||
"runtime"
|
||||
|
||||
"github.com/ethereum/go-ethereum/chain"
|
||||
"github.com/ethereum/go-ethereum/ethpipe"
|
||||
"github.com/ethereum/go-ethereum/ethstate"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
"gopkg.in/qml.v1"
|
||||
)
|
||||
|
||||
|
@ -66,7 +66,7 @@ func (app *QmlApplication) NewWatcher(quitChan chan bool) {
|
|||
|
||||
// Events
|
||||
func (app *QmlApplication) NewBlock(block *chain.Block) {
|
||||
pblock := ðpipe.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)
|
||||
}
|
||||
|
||||
|
|
|
@ -27,11 +27,11 @@ import (
|
|||
"github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/chain"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethpipe"
|
||||
"github.com/ethereum/go-ethereum/ethstate"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/javascript"
|
||||
"github.com/ethereum/go-ethereum/ui/qt"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
"gopkg.in/qml.v1"
|
||||
)
|
||||
|
||||
|
@ -42,7 +42,7 @@ type memAddr struct {
|
|||
|
||||
// UI Library that has some basic functionality exposed
|
||||
type UiLib struct {
|
||||
*ethpipe.JSPipe
|
||||
*xeth.JSXEth
|
||||
engine *qml.Engine
|
||||
eth *eth.Ethereum
|
||||
connected bool
|
||||
|
@ -58,7 +58,7 @@ type UiLib struct {
|
|||
}
|
||||
|
||||
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{}) {
|
||||
|
@ -214,7 +214,7 @@ func (self *UiLib) StartDebugger() {
|
|||
func (self *UiLib) NewFilter(object map[string]interface{}) (id int) {
|
||||
filter := qt.NewFilterFromMap(object, self.eth)
|
||||
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)
|
||||
return id
|
||||
|
@ -232,7 +232,7 @@ func (self *UiLib) NewFilterString(typ string) (id int) {
|
|||
func (self *UiLib) Messages(id int) *ethutil.List {
|
||||
filter := self.eth.GetFilter(id)
|
||||
if filter != nil {
|
||||
messages := ethpipe.ToJSMessages(filter.Find())
|
||||
messages := xeth.ToJSMessages(filter.Find())
|
||||
|
||||
return messages
|
||||
}
|
||||
|
@ -295,10 +295,10 @@ func mapToTxParams(object map[string]interface{}) map[string]string {
|
|||
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)
|
||||
|
||||
return self.JSPipe.Transact(
|
||||
return self.JSXEth.Transact(
|
||||
object["from"],
|
||||
object["to"],
|
||||
object["value"],
|
||||
|
@ -320,7 +320,7 @@ func (self *UiLib) Compile(code string) (string, error) {
|
|||
func (self *UiLib) Call(params map[string]interface{}) (string, error) {
|
||||
object := mapToTxParams(params)
|
||||
|
||||
return self.JSPipe.Execute(
|
||||
return self.JSXEth.Execute(
|
||||
object["to"],
|
||||
object["value"],
|
||||
object["gas"],
|
||||
|
|
|
@ -17,11 +17,11 @@ import (
|
|||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/ethminer"
|
||||
"github.com/ethereum/go-ethereum/ethpipe"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/ethwire"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
)
|
||||
|
||||
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) {
|
||||
var err error
|
||||
ethereum.RpcServer, err = rpc.NewJsonRpcServer(ethpipe.NewJSPipe(ethereum), RpcPort)
|
||||
ethereum.RpcServer, err = rpc.NewJsonRpcServer(xeth.NewJSXEth(ethereum), RpcPort)
|
||||
if err != nil {
|
||||
clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
|
||||
} else {
|
||||
|
|
|
@ -2,9 +2,9 @@ package utils
|
|||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/ethpipe"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/websocket"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
)
|
||||
|
||||
func args(v ...interface{}) []interface{} {
|
||||
|
@ -21,7 +21,7 @@ func NewWebSocketServer(eth *eth.Ethereum) *WebSocketServer {
|
|||
}
|
||||
|
||||
func (self *WebSocketServer) Serv() {
|
||||
pipe := ethpipe.NewJSPipe(self.ethereum)
|
||||
pipe := xeth.NewJSXEth(self.ethereum)
|
||||
|
||||
wsServ := websocket.NewServer("/eth", ":40404")
|
||||
wsServ.MessageFunc(func(c *websocket.Client, msg *websocket.Message) {
|
||||
|
|
|
@ -10,11 +10,11 @@ import (
|
|||
"github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/chain"
|
||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||
"github.com/ethereum/go-ethereum/ethpipe"
|
||||
"github.com/ethereum/go-ethereum/ethstate"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
"github.com/obscuren/otto"
|
||||
)
|
||||
|
||||
|
@ -23,7 +23,7 @@ var jsrelogger = logger.NewLogger("JSRE")
|
|||
type JSRE struct {
|
||||
ethereum *eth.Ethereum
|
||||
Vm *otto.Otto
|
||||
pipe *ethpipe.JSPipe
|
||||
pipe *xeth.JSXEth
|
||||
|
||||
events event.Subscription
|
||||
|
||||
|
@ -48,7 +48,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
|
|||
re := &JSRE{
|
||||
ethereum,
|
||||
otto.New(),
|
||||
ethpipe.NewJSPipe(ethereum),
|
||||
xeth.NewJSXEth(ethereum),
|
||||
nil,
|
||||
make(map[string][]otto.Value),
|
||||
}
|
||||
|
|
|
@ -4,15 +4,15 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/ethpipe"
|
||||
"github.com/ethereum/go-ethereum/ethstate"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/ui"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
"github.com/obscuren/otto"
|
||||
)
|
||||
|
||||
type JSStateObject struct {
|
||||
*ethpipe.JSObject
|
||||
*xeth.JSObject
|
||||
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
|
||||
// meaningful javascript objects
|
||||
type JSBlock struct {
|
||||
*ethpipe.JSBlock
|
||||
*xeth.JSBlock
|
||||
eth *JSEthereum
|
||||
}
|
||||
|
||||
|
@ -67,33 +67,33 @@ func NewJSMessage(message *ethstate.Message) JSMessage {
|
|||
}
|
||||
|
||||
type JSEthereum struct {
|
||||
*ethpipe.JSPipe
|
||||
*xeth.JSXEth
|
||||
vm *otto.Otto
|
||||
ethereum *eth.Ethereum
|
||||
}
|
||||
|
||||
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 {
|
||||
return self.toVal(self.JSPipe.Peers())
|
||||
return self.toVal(self.JSXEth.Peers())
|
||||
}
|
||||
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
r, err := self.JSPipe.Transact(key, "", valueStr, gasStr, gasPriceStr, scriptStr)
|
||||
r, err := self.JSXEth.Transact(key, "", valueStr, gasStr, gasPriceStr, scriptStr)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
|
|
@ -6,12 +6,12 @@ import (
|
|||
"math/big"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/ethpipe"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
)
|
||||
|
||||
type EthereumApi struct {
|
||||
pipe *ethpipe.JSPipe
|
||||
pipe *xeth.JSXEth
|
||||
}
|
||||
|
||||
type JsonArgs interface {
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
|
||||
"github.com/ethereum/go-ethereum/ethpipe"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
)
|
||||
|
||||
var jsonlogger = logger.NewLogger("JSON")
|
||||
|
@ -15,7 +15,7 @@ var jsonlogger = logger.NewLogger("JSON")
|
|||
type JsonRpcServer struct {
|
||||
quit chan bool
|
||||
listener net.Listener
|
||||
pipe *ethpipe.JSPipe
|
||||
pipe *xeth.JSXEth
|
||||
}
|
||||
|
||||
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)
|
||||
l, err := net.Listen("tcp", sport)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package ethpipe
|
||||
package xeth
|
||||
|
||||
import "github.com/ethereum/go-ethereum/ethutil"
|
||||
|
||||
var cnfCtr = ethutil.Hex2Bytes("661005d2720d855f1d9976f88bb10c1a3398c77f")
|
||||
|
||||
type Config struct {
|
||||
pipe *Pipe
|
||||
pipe *XEth
|
||||
}
|
||||
|
||||
func (self *Config) Get(name string) *Object {
|
|
@ -1,4 +1,4 @@
|
|||
package ethpipe
|
||||
package xeth
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -11,22 +11,22 @@ import (
|
|||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
)
|
||||
|
||||
type JSPipe struct {
|
||||
*Pipe
|
||||
type JSXEth struct {
|
||||
*XEth
|
||||
}
|
||||
|
||||
func NewJSPipe(eth chain.EthManager) *JSPipe {
|
||||
return &JSPipe{New(eth)}
|
||||
func NewJSXEth(eth chain.EthManager) *JSXEth {
|
||||
return &JSXEth{New(eth)}
|
||||
}
|
||||
|
||||
func (self *JSPipe) BlockByHash(strHash string) *JSBlock {
|
||||
func (self *JSXEth) BlockByHash(strHash string) *JSBlock {
|
||||
hash := ethutil.Hex2Bytes(strHash)
|
||||
block := self.obj.ChainManager().GetBlock(hash)
|
||||
|
||||
return NewJSBlock(block)
|
||||
}
|
||||
|
||||
func (self *JSPipe) BlockByNumber(num int32) *JSBlock {
|
||||
func (self *JSXEth) BlockByNumber(num int32) *JSBlock {
|
||||
if num == -1 {
|
||||
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)))
|
||||
}
|
||||
|
||||
func (self *JSPipe) Block(v interface{}) *JSBlock {
|
||||
func (self *JSXEth) Block(v interface{}) *JSBlock {
|
||||
if n, ok := v.(int32); ok {
|
||||
return self.BlockByNumber(n)
|
||||
} else if str, ok := v.(string); ok {
|
||||
|
@ -46,21 +46,21 @@ func (self *JSPipe) Block(v interface{}) *JSBlock {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (self *JSPipe) Key() *JSKey {
|
||||
func (self *JSXEth) Key() *JSKey {
|
||||
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))}
|
||||
|
||||
return NewJSObject(object)
|
||||
}
|
||||
|
||||
func (self *JSPipe) PeerCount() int {
|
||||
func (self *JSXEth) PeerCount() int {
|
||||
return self.obj.PeerCount()
|
||||
}
|
||||
|
||||
func (self *JSPipe) Peers() []JSPeer {
|
||||
func (self *JSXEth) Peers() []JSPeer {
|
||||
var peers []JSPeer
|
||||
for peer := self.obj.Peers().Front(); peer != nil; peer = peer.Next() {
|
||||
p := peer.Value.(chain.Peer)
|
||||
|
@ -73,47 +73,47 @@ func (self *JSPipe) Peers() []JSPeer {
|
|||
return peers
|
||||
}
|
||||
|
||||
func (self *JSPipe) IsMining() bool {
|
||||
func (self *JSXEth) IsMining() bool {
|
||||
return self.obj.IsMining()
|
||||
}
|
||||
|
||||
func (self *JSPipe) IsListening() bool {
|
||||
func (self *JSXEth) IsListening() bool {
|
||||
return self.obj.IsListening()
|
||||
}
|
||||
|
||||
func (self *JSPipe) CoinBase() string {
|
||||
func (self *JSXEth) CoinBase() string {
|
||||
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)
|
||||
|
||||
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))
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
func (self *JSPipe) TxCountAt(address string) int {
|
||||
func (self *JSXEth) TxCountAt(address string) int {
|
||||
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)
|
||||
}
|
||||
|
||||
func (self *JSPipe) IsContract(address string) bool {
|
||||
func (self *JSXEth) IsContract(address string) bool {
|
||||
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))
|
||||
if err != nil {
|
||||
return ""
|
||||
|
@ -122,7 +122,7 @@ func (self *JSPipe) SecretToAddress(key string) string {
|
|||
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{
|
||||
self.World().safeGet(ethutil.Hex2Bytes(addr))},
|
||||
ethutil.Hex2Bytes(data),
|
||||
|
@ -139,7 +139,7 @@ type KeyVal struct {
|
|||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
func (self *JSPipe) EachStorage(addr string) string {
|
||||
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) {
|
||||
|
@ -155,13 +155,13 @@ func (self *JSPipe) EachStorage(addr string) string {
|
|||
return string(valuesJson)
|
||||
}
|
||||
|
||||
func (self *JSPipe) ToAscii(str string) string {
|
||||
func (self *JSXEth) ToAscii(str string) string {
|
||||
padded := ethutil.RightPadBytes([]byte(str), 32)
|
||||
|
||||
return "0x" + ethutil.Bytes2Hex(padded)
|
||||
}
|
||||
|
||||
func (self *JSPipe) FromAscii(str string) string {
|
||||
func (self *JSXEth) FromAscii(str string) string {
|
||||
if ethutil.IsHex(str) {
|
||||
str = str[2:]
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ func (self *JSPipe) FromAscii(str string) string {
|
|||
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) {
|
||||
str = str[2:]
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ func (self *JSPipe) FromNumber(str string) 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 contractCreation bool
|
||||
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
|
||||
}
|
||||
|
||||
func (self *JSPipe) PushTx(txStr string) (*JSReceipt, error) {
|
||||
func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) {
|
||||
tx := chain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr))
|
||||
self.obj.TxPool().QueueTransaction(tx)
|
||||
return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(self.World().State()), tx.Hash(), tx.Sender()), nil
|
||||
}
|
||||
|
||||
func (self *JSPipe) CompileMutan(code string) string {
|
||||
data, err := self.Pipe.CompileMutan(code)
|
||||
func (self *JSXEth) CompileMutan(code string) string {
|
||||
data, err := self.XEth.CompileMutan(code)
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package ethpipe
|
||||
package xeth
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package ethpipe
|
||||
package xeth
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/ethstate"
|
|
@ -1,4 +1,8 @@
|
|||
package ethpipe
|
||||
package xeth
|
||||
|
||||
/*
|
||||
* eXtended ETHereum
|
||||
*/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -12,13 +16,13 @@ import (
|
|||
"github.com/ethereum/go-ethereum/vm"
|
||||
)
|
||||
|
||||
var pipelogger = logger.NewLogger("PIPE")
|
||||
var pipelogger = logger.NewLogger("XETH")
|
||||
|
||||
type VmVars struct {
|
||||
State *ethstate.State
|
||||
}
|
||||
|
||||
type Pipe struct {
|
||||
type XEth struct {
|
||||
obj chain.EthManager
|
||||
stateManager *chain.StateManager
|
||||
blockChain *chain.ChainManager
|
||||
|
@ -27,8 +31,8 @@ type Pipe struct {
|
|||
Vm VmVars
|
||||
}
|
||||
|
||||
func New(obj chain.EthManager) *Pipe {
|
||||
pipe := &Pipe{
|
||||
func New(obj chain.EthManager) *XEth {
|
||||
pipe := &XEth{
|
||||
obj: obj,
|
||||
stateManager: obj.StateManager(),
|
||||
blockChain: obj.ChainManager(),
|
||||
|
@ -38,19 +42,19 @@ func New(obj chain.EthManager) *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)
|
||||
}
|
||||
|
||||
func (self *Pipe) Nonce(addr []byte) uint64 {
|
||||
func (self *XEth) Nonce(addr []byte) uint64 {
|
||||
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)
|
||||
}
|
||||
|
||||
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 (
|
||||
initiator = ethstate.NewStateObject(self.obj.KeyManager().KeyPair().Address())
|
||||
block = self.blockChain.CurrentBlock
|
||||
|
@ -68,15 +72,15 @@ func (self *Pipe) ExecuteObject(object *Object, data []byte, value, gas, price *
|
|||
return ret, err
|
||||
}
|
||||
|
||||
func (self *Pipe) Block(hash []byte) *chain.Block {
|
||||
func (self *XEth) Block(hash []byte) *chain.Block {
|
||||
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))
|
||||
}
|
||||
|
||||
func (self *Pipe) ToAddress(priv []byte) []byte {
|
||||
func (self *XEth) ToAddress(priv []byte) []byte {
|
||||
pair, err := crypto.NewKeyPairFromSec(priv)
|
||||
if err != nil {
|
||||
return nil
|
||||
|
@ -85,11 +89,11 @@ func (self *Pipe) ToAddress(priv []byte) []byte {
|
|||
return pair.Address()
|
||||
}
|
||||
|
||||
func (self *Pipe) Exists(addr []byte) bool {
|
||||
func (self *XEth) Exists(addr []byte) bool {
|
||||
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
|
||||
var hash []byte
|
||||
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)
|
||||
}
|
||||
|
||||
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 contractCreation bool
|
||||
if rec == nil {
|
||||
|
@ -151,7 +155,7 @@ func (self *Pipe) Transact(key *crypto.KeyPair, rec []byte, value, gas, price *e
|
|||
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)
|
||||
if tx.Recipient == nil {
|
||||
addr := tx.CreationAddress(self.World().State())
|
||||
|
@ -161,7 +165,7 @@ func (self *Pipe) PushTx(tx *chain.Transaction) ([]byte, error) {
|
|||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
|
@ -1,4 +1,4 @@
|
|||
package ethpipe
|
||||
package xeth
|
||||
|
||||
import (
|
||||
"math/big"
|
|
@ -1,4 +1,4 @@
|
|||
package ethpipe
|
||||
package xeth
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
|
@ -7,18 +7,18 @@ import (
|
|||
)
|
||||
|
||||
type World struct {
|
||||
pipe *Pipe
|
||||
pipe *XEth
|
||||
cfg *Config
|
||||
}
|
||||
|
||||
func NewWorld(pipe *Pipe) *World {
|
||||
func NewWorld(pipe *XEth) *World {
|
||||
world := &World{pipe, nil}
|
||||
world.cfg = &Config{pipe}
|
||||
|
||||
return world
|
||||
}
|
||||
|
||||
func (self *Pipe) World() *World {
|
||||
func (self *XEth) World() *World {
|
||||
return self.world
|
||||
}
|
||||
|
Loading…
Reference in New Issue