Compare commits

...

20 Commits

Author SHA1 Message Date
obscuren
0d89c1d212 Merge branch 'release/poc5-rc9' 2014-05-26 00:41:55 +02:00
obscuren
818bc84591 Bump 2014-05-26 00:39:05 +02:00
obscuren
b42c70be9c Recv send for txs 2014-05-26 00:10:38 +02:00
obscuren
d35380c19e New main script through init return value 2014-05-23 14:37:03 +02:00
obscuren
5f8911f7cb Custom identifier 2014-05-22 10:38:37 +02:00
obscuren
01b833146f Added mining stop and start 2014-05-22 00:25:48 +02:00
obscuren
b902de20c7 Fixes #49 2014-05-21 23:46:16 +02:00
obscuren
3f5b348451 Fixes #50 2014-05-21 23:36:55 +02:00
obscuren
941e0ba60a Merge branch 'release/poc5-rc8' into develop 2014-05-21 14:05:01 +02:00
obscuren
7f1a4c377c Merge branch 'release/poc5-rc8' 2014-05-21 14:04:54 +02:00
obscuren
3ddaf56afd Bumped 2014-05-21 14:04:11 +02:00
obscuren
10e2c40b59 Improved on some ui elements 2014-05-21 14:00:54 +02:00
obscuren
68f4a12a8b Fixed unconfirmed balance string 2014-05-21 13:37:46 +02:00
obscuren
16bd88c10a Removed method name 2014-05-21 12:14:39 +02:00
obscuren
d16d56d39f Updated readme to reflect options 2014-05-20 22:13:39 +02:00
obscuren
93e12250c7 Switch variables as intended 2014-05-20 22:12:42 +02:00
obscuren
f4551a7e9f Changed flag parsing 2014-05-20 22:12:22 +02:00
obscuren
563c035eb5 Refactored some of the functions 2014-05-20 19:28:48 +02:00
obscuren
de1dfae717 Forked version of otto so we can support lowerCased methods 2014-05-20 17:49:12 +02:00
obscuren
4198969302 Merge branch 'release/poc5-rc7' into develop 2014-05-20 17:09:36 +02:00
13 changed files with 266 additions and 76 deletions

View File

@@ -5,7 +5,7 @@ Ethereum
Ethereum Go Client © 2014 Jeffrey Wilcke.
Current state: Proof of Concept 5.0 RC7.
Current state: Proof of Concept 5.0 RC9.
For the development package please see the [eth-go package](https://github.com/ethereum/eth-go).
@@ -26,28 +26,25 @@ General command line options
====================
```
-c Launch the developer console (node only)
Shared between ethereum and ethereal
-m Start mining blocks
-genaddr Generates a new address and private key (destructive action)
-p Port on which the server will accept incomming connections (= 30303)
-upnp Enable UPnP (= false)
-x Desired amount of peers (= 5)
-h This help
-p Port on which the server will accept incomming connections
-upnp Enable UPnP
-x Desired amount of peers
-r Start JSON RPC
-dir Data directory used to store configs and databases (=".ethereum")
-import Import a private key (hex)
```
-dir Data directory used to store configs and databases
-import Import a private key
-h This
Developer console commands
==========================
Ethereum only
ethereum [options] [filename]
-js Start the JavaScript REPL
filename Load the given file and interpret as JavaScript
Etheral only
-asset_path absolute path to GUI assets directory
```
addp <host>:<port> Connect to the given host
tx <addr> <amount> Send <amount> Wei to the specified <addr>
contract <value> <gasprice> Creates a new contract and launches the editor
```
See the "help" command for *developer* options.
Contribution
============

View File

@@ -67,6 +67,7 @@ ApplicationWindow {
networkView.visible = false
historyView.visible = false
newTxView.visible = false
infoView.visible = false
view.visible = true
//root.title = "Ethereal - " = view.title
}
@@ -84,7 +85,6 @@ ApplicationWindow {
//color: "#D9DDE7"
color: "#252525"
ColumnLayout {
y: 50
anchors.left: parent.left
@@ -120,6 +120,17 @@ ApplicationWindow {
}
}
}
Image {
source: ui.assetPath("net.png")
anchors.horizontalCenter: parent.horizontalCenter
MouseArea {
anchors.fill: parent
onClicked: {
setView(infoView)
}
}
}
}
}
@@ -143,6 +154,7 @@ ApplicationWindow {
TableView {
id: txTableView
anchors.fill: parent
TableViewColumn{ role: "inout" ; title: "" ; width: 40 }
TableViewColumn{ role: "value" ; title: "Value" ; width: 100 }
TableViewColumn{ role: "address" ; title: "Address" ; width: 430 }
TableViewColumn{ role: "contract" ; title: "Contract" ; width: 100 }
@@ -217,6 +229,33 @@ ApplicationWindow {
}
}
Rectangle {
id: infoView
property var title: "Information"
visible: false
color: "#00000000"
anchors.fill: parent
Label {
id: addressLabel
text: "Address"
anchors {
margins: 5
top: parent.top
left: parent.left
}
}
TextField {
anchors {
margins: 5
left: addressLabel.right
top: parent.top
}
text: pub.getKey().address
width: 500
}
}
/*
signal addPlugin(string name)
Component {
@@ -365,7 +404,7 @@ ApplicationWindow {
anchors.left: aboutIcon.right
anchors.leftMargin: 10
font.pointSize: 12
text: "<h2>Ethereal</h2><br><h3>Development</h3>Jeffrey Wilcke<br>Maran Hidskes<br><h3>Binary Distribution</h3>Jarrad Hope<br>"
text: "<h2>Ethereal</h2><br><h3>Development</h3>Jeffrey Wilcke<br>Maran Hidskes<br>"
}
}
@@ -390,7 +429,6 @@ ApplicationWindow {
}
}
SplitView {
anchors.fill: parent
property var asmModel: ListModel {
id: asmModel
@@ -485,14 +523,14 @@ ApplicationWindow {
walletValueLabel.text = value
}
function addTx(tx) {
function addTx(tx, inout) {
var isContract
if (tx.contract == true){
isContract = "Yes"
}else{
isContract = "No"
}
txModel.insert(0, {hash: tx.hash, address: tx.address, value: tx.value, contract: isContract})
txModel.insert(0, {inout: inout, hash: tx.hash, address: tx.address, value: tx.value, contract: isContract})
}
function addBlock(block) {

View File

@@ -9,7 +9,7 @@
<script type="text/javascript">
var jefcoinAddr = "739105c31705038744d190332e3a07c8fea8a9eb"
var jefcoinAddr = "fc0a9436890478bb9b1c6ed7455c2535366f4a99"
var mAddr = ""
function createTransaction() {

View File

@@ -4,6 +4,7 @@ import (
"flag"
)
var Identifier string
var StartConsole bool
var StartMining bool
var StartRpc bool
@@ -21,6 +22,7 @@ var DataDir string
var AssetPath string
func Init() {
flag.StringVar(&Identifier, "i", "", "Custom client identifier")
flag.BoolVar(&StartConsole, "c", false, "debug and testing console")
flag.BoolVar(&StartMining, "m", false, "start dagger mining")
flag.BoolVar(&StartRpc, "r", false, "start rpc server")

View File

@@ -39,7 +39,7 @@ func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
ethchain.InitFees()
ethutil.ReadConfig(DataDir, ethutil.LogFile|ethutil.LogStd)
ethutil.ReadConfig(DataDir, ethutil.LogFile|ethutil.LogStd, Identifier)
// Instantiated a eth stack
ethereum, err := eth.New(eth.CapDefault, UseUPnP)

View File

@@ -9,7 +9,6 @@ import (
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethutil"
"github.com/go-qml/qml"
"github.com/obscuren/mutan"
"math/big"
"strings"
)
@@ -55,7 +54,7 @@ func New(ethereum *eth.Ethereum) *Gui {
}
func (gui *Gui) Start(assetPath string) {
const version = "0.5.0 RC7"
const version = "0.5.0 RC9"
defer gui.txDb.Close()
@@ -74,6 +73,7 @@ func (gui *Gui) Start(assetPath string) {
// Expose the eth library and the ui library to QML
context.SetVar("eth", gui)
context.SetVar("pub", gui.pub)
gui.uiLib = NewUiLib(gui.engine, gui.eth, assetPath)
context.SetVar("ui", gui.uiLib)
@@ -151,7 +151,15 @@ func (gui *Gui) readPreviousTransactions() {
for it.Next() {
tx := ethchain.NewTransactionFromBytes(it.Value())
gui.win.Root().Call("addTx", ethpub.NewPTx(tx))
var inout string
if bytes.Compare(tx.Sender(), gui.addr) == 0 {
inout = "send"
} else {
inout = "recv"
}
gui.win.Root().Call("addTx", ethpub.NewPTx(tx), inout)
}
it.Release()
}
@@ -164,7 +172,7 @@ func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) {
var str string
if unconfirmedFunds != nil {
pos := "+"
if unconfirmedFunds.Cmp(big.NewInt(0)) >= 0 {
if unconfirmedFunds.Cmp(big.NewInt(0)) < 0 {
pos = "-"
}
val := ethutil.CurrencyToString(new(big.Int).Abs(ethutil.BigCopy(unconfirmedFunds)))
@@ -206,18 +214,13 @@ func (gui *Gui) update() {
if txMsg.Event == "newTx:pre" {
object := state.GetAccount(gui.addr)
if bytes.Compare(tx.Sender(), gui.addr) == 0 && object.Nonce <= tx.Nonce {
gui.win.Root().Call("addTx", ethpub.NewPTx(tx))
if bytes.Compare(tx.Sender(), gui.addr) == 0 {
gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "send")
gui.txDb.Put(tx.Hash(), tx.RlpEncode())
/*
object.Nonce += 1
state.SetStateObject(object)
*/
unconfirmedFunds.Sub(unconfirmedFunds, tx.Value)
} else if bytes.Compare(tx.Recipient, gui.addr) == 0 {
gui.win.Root().Call("addTx", ethpub.NewPTx(tx))
gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "recv")
gui.txDb.Put(tx.Hash(), tx.RlpEncode())
unconfirmedFunds.Add(unconfirmedFunds, tx.Value)
@@ -234,7 +237,7 @@ func (gui *Gui) update() {
gui.setWalletValue(object.Amount, nil)
state.SetStateObject(object)
state.UpdateStateObject(object)
}
}
}
@@ -266,7 +269,5 @@ func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub.
func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) {
keyPair := ethutil.GetKeyRing().Get(0)
mainInput, initInput := mutan.PreParse(data)
return gui.pub.Create(ethutil.Hex(keyPair.PrivateKey), value, gas, gasPrice, initInput, mainInput)
return gui.pub.Create(ethutil.Hex(keyPair.PrivateKey), value, gas, gasPrice, data)
}

View File

@@ -135,7 +135,7 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string)
for _, str := range dis {
ui.win.Root().Call("setAsm", str)
}
callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), callerScript, nil)
callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), nil)
// Contract addr as test address
keyPair := ethutil.GetKeyRing().Get(0)

View File

@@ -2,8 +2,11 @@ package main
import (
"flag"
"fmt"
"os"
)
var Identifier string
var StartMining bool
var StartRpc bool
var RpcPort int
@@ -23,6 +26,12 @@ var StartJsConsole bool
var InputFile string
func Init() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "%s [options] [filename]:\n", os.Args[0])
flag.PrintDefaults()
}
flag.StringVar(&Identifier, "i", "", "custom client identifier")
flag.BoolVar(&StartMining, "m", false, "start dagger mining")
flag.BoolVar(&ShowGenesis, "g", false, "prints genesis header and exits")
flag.BoolVar(&StartRpc, "r", false, "start rpc server")
@@ -38,7 +47,8 @@ func Init() {
flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)")
flag.IntVar(&MaxPeer, "x", 10, "maximum desired peers")
flag.BoolVar(&StartJsConsole, "js", false, "exp")
flag.StringVar(&InputFile, "e", "", "Run javascript file")
flag.Parse()
InputFile = flag.Arg(0)
}

View File

@@ -52,12 +52,15 @@ func main() {
var logSys *log.Logger
flags := log.LstdFlags
var lt ethutil.LoggerType
if StartJsConsole || len(InputFile) > 0 {
ethutil.ReadConfig(DataDir, ethutil.LogFile)
lt = ethutil.LogFile
} else {
ethutil.ReadConfig(DataDir, ethutil.LogFile|ethutil.LogStd)
lt = ethutil.LogFile | ethutil.LogStd
}
ethutil.ReadConfig(DataDir, lt, Identifier)
logger := ethutil.Config.Log
if LogFile != "" {

View File

@@ -6,7 +6,11 @@ import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethutil"
"github.com/robertkrimen/otto"
"github.com/ethereum/go-ethereum/utils"
"github.com/obscuren/otto"
"io/ioutil"
"os"
"path/filepath"
)
type JSRE struct {
@@ -53,6 +57,22 @@ func (self *JSRE) Run(code string) (otto.Value, error) {
return self.vm.Run(code)
}
func (self *JSRE) Require(file string) error {
if len(filepath.Ext(file)) == 0 {
file += ".js"
}
fh, err := os.Open(file)
if err != nil {
return err
}
content, _ := ioutil.ReadAll(fh)
self.Run("exports = {};(function() {" + string(content) + "})();")
return nil
}
func (self *JSRE) Stop() {
// Kill the main loop
self.quitChan <- true
@@ -82,7 +102,10 @@ out:
cb.Call(cb, val)
}
} else if storageObject, ok := object.Resource.(*ethchain.StorageState); ok {
fmt.Println(storageObject)
for _, cb := range self.objectCb[ethutil.Hex(storageObject.StateAddress)+ethutil.Hex(storageObject.Address)] {
val, _ := self.vm.ToValue(ethpub.NewPStorageState(storageObject))
cb.Call(cb, val)
}
}
}
}
@@ -91,24 +114,77 @@ out:
func (self *JSRE) initStdFuncs() {
t, _ := self.vm.Get("eth")
eth := t.Object()
eth.Set("watch", func(call otto.FunctionCall) otto.Value {
addr, _ := call.Argument(0).ToString()
cb := call.Argument(1)
eth.Set("watch", self.watch)
eth.Set("addPeer", self.addPeer)
eth.Set("require", self.require)
eth.Set("stopMining", self.stopMining)
eth.Set("startMining", self.startMining)
}
/*
* The following methods are natively implemented javascript functions
*/
func (self *JSRE) stopMining(call otto.FunctionCall) otto.Value {
v, _ := self.vm.ToValue(utils.StopMining(self.ethereum))
return v
}
func (self *JSRE) startMining(call otto.FunctionCall) otto.Value {
v, _ := self.vm.ToValue(utils.StartMining(self.ethereum))
return v
}
// eth.watch
func (self *JSRE) watch(call otto.FunctionCall) otto.Value {
addr, _ := call.Argument(0).ToString()
var storageAddr string
var cb otto.Value
var storageCallback bool
if len(call.ArgumentList) > 2 {
storageCallback = true
storageAddr, _ = call.Argument(1).ToString()
cb = call.Argument(2)
} else {
cb = call.Argument(1)
}
if storageCallback {
self.objectCb[addr+storageAddr] = append(self.objectCb[addr+storageAddr], cb)
event := "storage:" + string(ethutil.FromHex(addr)) + ":" + string(ethutil.FromHex(storageAddr))
self.ethereum.Reactor().Subscribe(event, self.changeChan)
} else {
self.objectCb[addr] = append(self.objectCb[addr], cb)
event := "object:" + string(ethutil.FromHex(addr))
self.ethereum.Reactor().Subscribe(event, self.changeChan)
}
return otto.UndefinedValue()
})
eth.Set("addPeer", func(call otto.FunctionCall) otto.Value {
host, err := call.Argument(0).ToString()
if err != nil {
return otto.FalseValue()
}
self.ethereum.ConnectToPeer(host)
return otto.TrueValue()
})
return otto.UndefinedValue()
}
func (self *JSRE) addPeer(call otto.FunctionCall) otto.Value {
host, err := call.Argument(0).ToString()
if err != nil {
return otto.FalseValue()
}
self.ethereum.ConnectToPeer(host)
return otto.TrueValue()
}
func (self *JSRE) require(call otto.FunctionCall) otto.Value {
file, err := call.Argument(0).ToString()
if err != nil {
return otto.UndefinedValue()
}
if err := self.Require(file); err != nil {
fmt.Println("err:", err)
return otto.UndefinedValue()
}
t, _ := self.vm.Get("exports")
return t
}

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethpub"
"github.com/robertkrimen/otto"
"github.com/obscuren/otto"
)
type Repl interface {
@@ -48,11 +48,24 @@ func (self *JSRepl) parseInput(code string) {
// The JSEthereum object attempts to wrap the PEthereum object and returns
// meaningful javascript objects
type JSBlock struct {
*ethpub.PBlock
eth *JSEthereum
}
func (self *JSBlock) GetTransaction(hash string) otto.Value {
return self.eth.toVal(self.PBlock.GetTransaction(hash))
}
type JSEthereum struct {
*ethpub.PEthereum
vm *otto.Otto
}
func (self *JSEthereum) GetBlock(hash string) otto.Value {
return self.toVal(&JSBlock{self.PEthereum.GetBlock(hash), self})
}
func (self *JSEthereum) GetKey() otto.Value {
return self.toVal(self.PEthereum.GetKey())
}
@@ -72,8 +85,8 @@ func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr,
return self.toVal(r)
}
func (self *JSEthereum) Create(key, valueStr, gasStr, gasPriceStr, initStr, bodyStr string) otto.Value {
r, err := self.PEthereum.Create(key, valueStr, gasStr, gasPriceStr, initStr, bodyStr)
func (self *JSEthereum) Create(key, valueStr, gasStr, gasPriceStr, scriptStr string) otto.Value {
r, err := self.PEthereum.Create(key, valueStr, gasStr, gasPriceStr, scriptStr)
if err != nil {
fmt.Println(err)

View File

@@ -1,18 +1,42 @@
package main
// #cgo darwin CFLAGS: -I/usr/local/opt/readline/include
// #cgo darwin LDFLAGS: -L/usr/local/opt/readline/lib
// #cgo LDFLAGS: -lreadline
// #include <stdio.h>
// #include <stdlib.h>
// #include <readline/readline.h>
// #include <readline/history.h>
import "C"
import (
"github.com/robertkrimen/otto"
"os"
"os/signal"
"strings"
"syscall"
"unsafe"
)
func initReadLine() {
C.rl_catch_sigwinch = 0
C.rl_catch_signals = 0
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGWINCH)
signal.Notify(c, os.Interrupt)
go func() {
for sig := range c {
switch sig {
case syscall.SIGWINCH:
C.rl_resize_terminal()
case os.Interrupt:
C.rl_cleanup_after_signal()
default:
}
}
}()
}
func readLine(prompt *string) *string {
var p *C.char
@@ -60,6 +84,7 @@ func (self *JSRepl) setIndent() {
}
func (self *JSRepl) read() {
initReadLine()
L:
for {
switch result := readLine(&self.prompt); true {
@@ -77,7 +102,7 @@ L:
break L
}
addHistory(str) //allow user to recall this line
addHistory(str[:len(str)-1]) //allow user to recall this line
self.parseInput(str)
@@ -87,7 +112,10 @@ L:
}
}
func (self *JSRepl) PrintValue(value otto.Value) {
func (self *JSRepl) PrintValue(v interface{}) {
method, _ := self.re.vm.Get("prettyPrint")
method.Call(method, value)
v, err := self.re.vm.ToValue(v)
if err == nil {
method.Call(method, v)
}
}

View File

@@ -19,6 +19,8 @@ func DoRpc(ethereum *eth.Ethereum, RpcPort int) {
}
}
var miner ethminer.Miner
func DoMining(ethereum *eth.Ethereum) {
// Set Mining status
ethereum.Mining = true
@@ -31,17 +33,37 @@ func DoMining(ethereum *eth.Ethereum) {
addr := keyPair.Address()
go func() {
ethutil.Config.Log.Infoln("Miner started")
miner = ethminer.NewDefaultMiner(addr, ethereum)
// Give it some time to connect with peers
time.Sleep(3 * time.Second)
/*
for ethereum.IsUpToDate() == false {
time.Sleep(5 * time.Second)
}
*/
ethutil.Config.Log.Infoln("Miner started")
miner := ethminer.NewDefaultMiner(addr, ethereum)
miner.Start()
}()
}
func StopMining(ethereum *eth.Ethereum) bool {
if ethereum.Mining {
miner.Stop()
ethutil.Config.Log.Infoln("Miner stopped")
ethereum.Mining = false
return true
}
return false
}
func StartMining(ethereum *eth.Ethereum) bool {
if !ethereum.Mining {
DoMining(ethereum)
return true
}
return false
}