Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull #109

Closed
wants to merge 11 commits into from
22 changes: 22 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Ethereum

Ethereum Go Client © 2014 Jeffrey Wilcke.

Current state: Proof of Concept 0.5.17.
Current state: Proof of Concept 0.6.0.

For the development package please see the [eth-go package](https://github.com/ethereum/eth-go).

Expand Down
2 changes: 2 additions & 0 deletions ethereal/assets/qml/wallet.qml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ ApplicationWindow {
}
TextField {
text: eth.getCustomIdentifier()
width: 500
placeholderText: "Anonymous"
onTextChanged: {
eth.setCustomIdentifier(text)
}
Expand Down
48 changes: 29 additions & 19 deletions ethereal/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package main
import (
"fmt"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethvm"
"github.com/ethereum/go-ethereum/utils"
"github.com/go-qml/qml"
"math/big"
"strconv"
Expand All @@ -15,10 +18,10 @@ type DebuggerWindow struct {
engine *qml.Engine
lib *UiLib

vm *ethchain.Vm
vm *ethvm.Vm
Db *Debugger

state *ethchain.State
state *ethstate.State
}

func NewDebuggerWindow(lib *UiLib) *DebuggerWindow {
Expand All @@ -32,7 +35,7 @@ func NewDebuggerWindow(lib *UiLib) *DebuggerWindow {

win := component.CreateWindow(nil)

w := &DebuggerWindow{engine: engine, win: win, lib: lib, vm: &ethchain.Vm{}}
w := &DebuggerWindow{engine: engine, win: win, lib: lib, vm: &ethvm.Vm{}}
w.Db = NewDebugger(w)

return w
Expand Down Expand Up @@ -130,22 +133,29 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data

state := self.lib.eth.StateManager().TransState()
account := self.lib.eth.StateManager().TransState().GetAccount(keyPair.Address())
contract := ethchain.NewStateObject([]byte{0})
contract := ethstate.NewStateObject([]byte{0})
contract.Amount = value

callerClosure := ethchain.NewClosure(account, contract, script, state, gas, gasPrice)
self.SetAsm(script)

callerClosure := ethvm.NewClosure(account, contract, script, gas, gasPrice)

block := self.lib.eth.BlockChain().CurrentBlock
vm := ethchain.NewVm(state, self.lib.eth.StateManager(), ethchain.RuntimeVars{
Block: block,
Origin: account.Address(),
BlockNumber: block.Number,
PrevHash: block.PrevHash,
Coinbase: block.Coinbase,
Time: block.Time,
Diff: block.Difficulty,
Value: ethutil.Big(valueStr),
})

/*
vm := ethchain.NewVm(state, self.lib.eth.StateManager(), ethchain.RuntimeVars{
Block: block,
Origin: account.Address(),
BlockNumber: block.Number,
PrevHash: block.PrevHash,
Coinbase: block.Coinbase,
Time: block.Time,
Diff: block.Difficulty,
Value: ethutil.Big(valueStr),
})
*/
env := utils.NewEnv(state, block, account.Address(), value)
vm := ethvm.New(env)
vm.Verbose = true
vm.Dbg = self.Db

Expand Down Expand Up @@ -255,13 +265,13 @@ type storeVal struct {
Key, Value string
}

func (self *Debugger) BreakHook(pc int, op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack, stateObject *ethchain.StateObject) bool {
func (self *Debugger) BreakHook(pc int, op ethvm.OpCode, mem *ethvm.Memory, stack *ethvm.Stack, stateObject *ethstate.StateObject) bool {
self.main.Logln("break on instr:", pc)

return self.halting(pc, op, mem, stack, stateObject)
}

func (self *Debugger) StepHook(pc int, op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack, stateObject *ethchain.StateObject) bool {
func (self *Debugger) StepHook(pc int, op ethvm.OpCode, mem *ethvm.Memory, stack *ethvm.Stack, stateObject *ethstate.StateObject) bool {
return self.halting(pc, op, mem, stack, stateObject)
}

Expand All @@ -273,7 +283,7 @@ func (self *Debugger) BreakPoints() []int64 {
return self.breakPoints
}

func (d *Debugger) halting(pc int, op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack, stateObject *ethchain.StateObject) bool {
func (d *Debugger) halting(pc int, op ethvm.OpCode, mem *ethvm.Memory, stack *ethvm.Stack, stateObject *ethstate.StateObject) bool {
d.win.Root().Call("setInstruction", pc)
d.win.Root().Call("clearMem")
d.win.Root().Call("clearStack")
Expand All @@ -289,7 +299,7 @@ func (d *Debugger) halting(pc int, op ethchain.OpCode, mem *ethchain.Memory, sta
d.win.Root().Call("setStack", val.String())
}

stateObject.State().EachStorage(func(key string, node *ethutil.Value) {
stateObject.EachStorage(func(key string, node *ethutil.Value) {
d.win.Root().Call("setStorage", storeVal{fmt.Sprintf("% x", key), fmt.Sprintf("% x", node.Str())})
})

Expand Down
9 changes: 5 additions & 4 deletions ethereal/ext_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
"github.com/go-qml/qml"
)
Expand All @@ -16,8 +17,8 @@ type AppContainer interface {
Engine() *qml.Engine

NewBlock(*ethchain.Block)
ObjectChanged(*ethchain.StateObject)
StorageChanged(*ethchain.StorageState)
ObjectChanged(*ethstate.StateObject)
StorageChanged(*ethstate.StorageState)
NewWatcher(chan bool)
}

Expand Down Expand Up @@ -108,9 +109,9 @@ out:
app.container.NewBlock(block)
}
case object := <-app.changeChan:
if stateObject, ok := object.Resource.(*ethchain.StateObject); ok {
if stateObject, ok := object.Resource.(*ethstate.StateObject); ok {
app.container.ObjectChanged(stateObject)
} else if storageObject, ok := object.Resource.(*ethchain.StorageState); ok {
} else if storageObject, ok := object.Resource.(*ethstate.StorageState); ok {
app.container.StorageChanged(storageObject)
}
}
Expand Down
21 changes: 14 additions & 7 deletions ethereal/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/utils"
"github.com/go-qml/qml"
"math/big"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -142,10 +143,12 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {

win := gui.createWindow(component)

gui.setInitialBlockChain()
gui.loadAddressBook()
gui.readPreviousTransactions()
gui.setPeerInfo()
go func() {
gui.setInitialBlockChain()
gui.loadAddressBook()
gui.readPreviousTransactions()
gui.setPeerInfo()
}()

go gui.update()

Expand Down Expand Up @@ -219,8 +222,9 @@ func (gui *Gui) loadAddressBook() {

nameReg := ethpub.EthereumConfig(gui.eth.StateManager()).NameReg()
if nameReg != nil {
nameReg.State().EachStorage(func(name string, value *ethutil.Value) {
nameReg.EachStorage(func(name string, value *ethutil.Value) {
if name[0] != 0 {
value.Decode()
gui.win.Root().Call("addAddress", struct{ Name, Address string }{name, ethutil.Bytes2Hex(value.Bytes())})
}
})
Expand Down Expand Up @@ -369,11 +373,14 @@ func (gui *Gui) update() {
}

case <-generalUpdateTicker.C:
statusText := "#" + gui.eth.BlockChain().CurrentBlock.Number.String()
if gui.miner != nil {
pow := gui.miner.GetPow()
fmt.Println("HashRate from miner", pow.GetHashrate())
if pow.GetHashrate() != 0 {
statusText = "Mining @ " + strconv.FormatInt(pow.GetHashrate(), 10) + "Khash - " + statusText
}
}
lastBlockLabel.Set("text", "#"+gui.eth.BlockChain().CurrentBlock.Number.String())
lastBlockLabel.Set("text", statusText)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions ethereal/html_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
"github.com/go-qml/qml"
"github.com/howeyc/fsnotify"
Expand Down Expand Up @@ -121,11 +122,11 @@ func (app *HtmlApplication) NewBlock(block *ethchain.Block) {
app.webView.Call("onNewBlockCb", b)
}

func (app *HtmlApplication) ObjectChanged(stateObject *ethchain.StateObject) {
func (app *HtmlApplication) ObjectChanged(stateObject *ethstate.StateObject) {
app.webView.Call("onObjectChangeCb", ethpub.NewPStateObject(stateObject))
}

func (app *HtmlApplication) StorageChanged(storageObject *ethchain.StorageState) {
func (app *HtmlApplication) StorageChanged(storageObject *ethstate.StorageState) {
app.webView.Call("onStorageChangeCb", ethpub.NewPStorageState(storageObject))
}

Expand Down
7 changes: 3 additions & 4 deletions ethereal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import (

const (
ClientIdentifier = "Ethereal"
Version = "0.5.17"
Version = "0.6.0"
)

func main() {
// Leave QT on top at ALL times. Qt Needs to be initialized from the main thread
qml.Init(nil)

runtime.GOMAXPROCS(runtime.NumCPU())

qml.Init(nil)

var interrupted = false
utils.RegisterInterrupt(func(os.Signal) {
interrupted = true
Expand Down
5 changes: 3 additions & 2 deletions ethereal/qml_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
"github.com/go-qml/qml"
"runtime"
Expand Down Expand Up @@ -50,11 +51,11 @@ func (app *QmlApplication) NewBlock(block *ethchain.Block) {
app.win.Call("onNewBlockCb", pblock)
}

func (app *QmlApplication) ObjectChanged(stateObject *ethchain.StateObject) {
func (app *QmlApplication) ObjectChanged(stateObject *ethstate.StateObject) {
app.win.Call("onObjectChangeCb", ethpub.NewPStateObject(stateObject))
}

func (app *QmlApplication) StorageChanged(storageObject *ethchain.StorageState) {
func (app *QmlApplication) StorageChanged(storageObject *ethstate.StorageState) {
app.win.Call("onStorageChangeCb", ethpub.NewPStorageState(storageObject))
}

Expand Down
4 changes: 2 additions & 2 deletions ethereal/ui_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (ui *UiLib) AssetPath(p string) string {
func (self *UiLib) StartDbWithContractAndData(contractHash, data string) {
dbWindow := NewDebuggerWindow(self)
object := self.eth.StateManager().CurrentState().GetStateObject(ethutil.Hex2Bytes(contractHash))
if len(object.Script()) > 0 {
dbWindow.SetCode("0x" + ethutil.Bytes2Hex(object.Script()))
if len(object.Code) > 0 {
dbWindow.SetCode("0x" + ethutil.Bytes2Hex(object.Code))
}
dbWindow.SetData("0x" + data)

Expand Down
2 changes: 1 addition & 1 deletion ethereum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

const (
ClientIdentifier = "Ethereum(G)"
Version = "0.5.17"
Version = "0.6.0"
)

var logger = ethlog.NewLogger("CLI")
Expand Down
5 changes: 3 additions & 2 deletions ethereum/repl/javascript_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/go-ethereum/utils"
"github.com/obscuren/otto"
Expand Down Expand Up @@ -121,12 +122,12 @@ out:
if _, ok := block.Resource.(*ethchain.Block); ok {
}
case object := <-self.changeChan:
if stateObject, ok := object.Resource.(*ethchain.StateObject); ok {
if stateObject, ok := object.Resource.(*ethstate.StateObject); ok {
for _, cb := range self.objectCb[ethutil.Bytes2Hex(stateObject.Address())] {
val, _ := self.vm.ToValue(ethpub.NewPStateObject(stateObject))
cb.Call(cb, val)
}
} else if storageObject, ok := object.Resource.(*ethchain.StorageState); ok {
} else if storageObject, ok := object.Resource.(*ethstate.StorageState); ok {
for _, cb := range self.objectCb[ethutil.Bytes2Hex(storageObject.StateAddress)+ethutil.Bytes2Hex(storageObject.Address)] {
val, _ := self.vm.ToValue(ethpub.NewPStorageState(storageObject))
cb.Call(cb, val)
Expand Down
10 changes: 8 additions & 2 deletions utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,17 @@ func StartMining(ethereum *eth.Ethereum) bool {
addr := ethereum.KeyManager().Address()

go func() {
miner = ethminer.NewDefaultMiner(addr, ethereum)
if miner == nil {
miner = ethminer.NewDefaultMiner(addr, ethereum)
}

// Give it some time to connect with peers
time.Sleep(3 * time.Second)
for !ethereum.IsUpToDate() {
time.Sleep(5 * time.Second)
}

logger.Infoln("Miner started")
miner := ethminer.NewDefaultMiner(addr, ethereum)
miner.Start()
}()
RegisterInterrupt(func(os.Signal) {
Expand All @@ -269,10 +271,14 @@ func StartMining(ethereum *eth.Ethereum) bool {
func StopMining(ethereum *eth.Ethereum) bool {
if ethereum.Mining && miner != nil {
miner.Stop()

logger.Infoln("Miner stopped")

ethereum.Mining = false

return true
}

return false
}

Expand Down
Loading