aboutsummaryrefslogtreecommitdiffstats
path: root/ethereal/ui/ui_lib.go
diff options
context:
space:
mode:
Diffstat (limited to 'ethereal/ui/ui_lib.go')
-rw-r--r--ethereal/ui/ui_lib.go86
1 files changed, 38 insertions, 48 deletions
diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go
index 1c88b0181..9f2cca1e0 100644
--- a/ethereal/ui/ui_lib.go
+++ b/ethereal/ui/ui_lib.go
@@ -2,13 +2,10 @@ package ethui
import (
"bitbucket.org/kardianos/osext"
- "fmt"
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
- "github.com/ethereum/go-ethereum/utils"
"github.com/go-qml/qml"
- "github.com/obscuren/mutan"
"os"
"path"
"path/filepath"
@@ -27,8 +24,9 @@ type UiLib struct {
connected bool
assetPath string
// The main application window
- win *qml.Window
- Db *Debugger
+ win *qml.Window
+ Db *Debugger
+ DbWindow *DebuggerWindow
}
func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib {
@@ -91,6 +89,29 @@ func (ui *UiLib) ConnectToPeer(addr string) {
func (ui *UiLib) AssetPath(p string) string {
return path.Join(ui.assetPath, p)
}
+func (self *UiLib) StartDbWithContractAndData(contractHash, data string) {
+ dbWindow := NewDebuggerWindow(self)
+ object := self.eth.StateManager().CurrentState().GetStateObject(ethutil.FromHex(contractHash))
+ if len(object.Script()) > 0 {
+ dbWindow.SetCode("0x" + ethutil.Hex(object.Script()))
+ }
+ dbWindow.SetData("0x" + data)
+
+ dbWindow.Show()
+}
+
+func (self *UiLib) StartDbWithCode(code string) {
+ dbWindow := NewDebuggerWindow(self)
+ dbWindow.SetCode("0x" + code)
+ dbWindow.Show()
+}
+
+func (self *UiLib) StartDebugger() {
+ dbWindow := NewDebuggerWindow(self)
+ //self.DbWindow = dbWindow
+
+ dbWindow.Show()
+}
func DefaultAssetPath() string {
var base string
@@ -121,27 +142,28 @@ func DefaultAssetPath() string {
func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) {
state := ui.eth.BlockChain().CurrentBlock.State()
- mainInput, _ := mutan.PreParse(data)
- callerScript, err := utils.Compile(mainInput)
+ script, err := ethutil.Compile(data)
if err != nil {
ethutil.Config.Log.Debugln(err)
return
}
- dis := ethchain.Disassemble(callerScript)
+ dis := ethchain.Disassemble(script)
ui.win.Root().Call("clearAsm")
for _, str := range dis {
ui.win.Root().Call("setAsm", str)
}
- callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), nil)
-
// Contract addr as test address
keyPair := ethutil.GetKeyRing().Get(0)
+ callerTx :=
+ ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), script)
+ callerTx.Sign(keyPair.PrivateKey)
+
account := ui.eth.StateManager().TransState().GetStateObject(keyPair.Address())
- c := ethchain.MakeContract(callerTx, state)
- callerClosure := ethchain.NewClosure(account, c, c.Script(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr))
+ contract := ethchain.MakeContract(callerTx, state)
+ callerClosure := ethchain.NewClosure(account, contract, contract.Init(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr))
block := ui.eth.BlockChain().CurrentBlock
vm := ethchain.NewVm(state, ui.eth.StateManager(), ethchain.RuntimeVars{
@@ -151,50 +173,18 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string)
Coinbase: block.Coinbase,
Time: block.Time,
Diff: block.Difficulty,
- TxData: nil,
})
+ ui.Db.done = false
go func() {
- callerClosure.Call(vm, nil, ui.Db.halting)
+ callerClosure.Call(vm, contract.Init(), ui.Db.halting)
state.Reset()
+
+ ui.Db.done = true
}()
}
func (ui *UiLib) Next() {
ui.Db.Next()
}
-
-type Debugger struct {
- win *qml.Window
- N chan bool
-}
-
-func (d *Debugger) halting(pc int, op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack) {
- d.win.Root().Call("setInstruction", pc)
- d.win.Root().Call("clearMem")
- d.win.Root().Call("clearStack")
-
- addr := 0
- for i := 0; i+32 <= mem.Len(); i += 32 {
- d.win.Root().Call("setMem", memAddr{fmt.Sprintf("%03d", addr), fmt.Sprintf("% x", mem.Data()[i:i+32])})
- addr++
- }
-
- for _, val := range stack.Data() {
- d.win.Root().Call("setStack", val.String())
- }
-
-out:
- for {
- select {
- case <-d.N:
- break out
- default:
- }
- }
-}
-
-func (d *Debugger) Next() {
- d.N <- true
-}