Compare commits
86 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f702e27485 | ||
|
|
0c5a747ef1 | ||
|
|
75df148ba2 | ||
|
|
4572d4940c | ||
|
|
2b9f16802d | ||
|
|
34e2ab9f9f | ||
|
|
44296c0b33 | ||
|
|
01d9107bce | ||
|
|
ba3fabda77 | ||
|
|
edf10ef8c5 | ||
|
|
6c565eae74 | ||
|
|
c951702423 | ||
|
|
7d64b589b4 | ||
|
|
c302afd411 | ||
|
|
28948d061c | ||
|
|
223432fa1e | ||
|
|
c0ae5c58a6 | ||
|
|
e53acdc2ac | ||
|
|
dce0ccf490 | ||
|
|
e6a428f85f | ||
|
|
288f1c5387 | ||
|
|
d3e31a4a6d | ||
|
|
fc8bd7229e | ||
|
|
c2bca5939d | ||
|
|
05c1899895 | ||
|
|
7e88dd4e6b | ||
|
|
61d5d107b6 | ||
|
|
7f9e614b5d | ||
|
|
79259c916d | ||
|
|
685aebc72e | ||
|
|
0360e60dd5 | ||
|
|
0c132e4c9e | ||
|
|
f9e2e5276f | ||
|
|
8e5117444e | ||
|
|
1e4ae24126 | ||
|
|
0ae3bbc3f5 | ||
|
|
b9fa4dada8 | ||
|
|
9754c01f56 | ||
|
|
043920d157 | ||
|
|
3ebcd36667 | ||
|
|
9e38ca555d | ||
|
|
de183e80db | ||
|
|
ca395306e3 | ||
|
|
24ff81d14e | ||
|
|
9de30d96f0 | ||
|
|
a3c4823511 | ||
|
|
0076fa583c | ||
|
|
a0dd1ebb6d | ||
|
|
50c0938226 | ||
|
|
98f21669c7 | ||
|
|
7d0004f058 | ||
|
|
e5b45d1c86 | ||
|
|
677de48f6c | ||
|
|
c4f9151c67 | ||
|
|
4918531dd5 | ||
|
|
2835321377 | ||
|
|
74ef489fe2 | ||
|
|
cb595fb63c | ||
|
|
5d3259587f | ||
|
|
5e02d2b586 | ||
|
|
ce88a73aa6 | ||
|
|
41a03b29ab | ||
|
|
0ed9528d76 | ||
|
|
098f7f23ce | ||
|
|
8aea468744 | ||
|
|
29cc1af2bc | ||
|
|
e43e4ff2c1 | ||
|
|
12fbb7ae5c | ||
|
|
ce4080faa7 | ||
|
|
cf7fcadeca | ||
|
|
9bd67de671 | ||
|
|
27e1352c85 | ||
|
|
0ea9595d41 | ||
|
|
e38b016547 | ||
|
|
2d48fc1113 | ||
|
|
328ee9a3ec | ||
|
|
4fc60f340f | ||
|
|
1b74b98f90 | ||
|
|
d57b7e8d5f | ||
|
|
2d274003b8 | ||
|
|
52ddf044ae | ||
|
|
214721ca01 | ||
|
|
cad98dc4d5 | ||
|
|
e46e7e7a9c | ||
|
|
bf2ac5acc5 | ||
|
|
42414cadaa |
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "ethereal/assets/samplecoin"]
|
||||||
|
path = ethereal/assets/samplecoin
|
||||||
|
url = git@github.com:obscuren/SampleCoin.git
|
||||||
@@ -5,7 +5,7 @@ Ethereum
|
|||||||
|
|
||||||
Ethereum Go Client © 2014 Jeffrey Wilcke.
|
Ethereum Go Client © 2014 Jeffrey Wilcke.
|
||||||
|
|
||||||
Current state: Proof of Concept 0.5.15.
|
Current state: Proof of Concept 0.5.17.
|
||||||
|
|
||||||
For the development package please see the [eth-go package](https://github.com/ethereum/eth-go).
|
For the development package please see the [eth-go package](https://github.com/ethereum/eth-go).
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
UNAME = $(shell uname)
|
|
||||||
FILES=qml *.png
|
|
||||||
GOPATH=$(PWD)
|
|
||||||
|
|
||||||
|
|
||||||
# Default is building
|
|
||||||
all:
|
|
||||||
go get -d
|
|
||||||
cp *.go $(GOPATH)/src/github.com/ethereum/go-ethereum
|
|
||||||
cp -r ui $(GOPATH)/src/github.com/ethereum/go-ethereum
|
|
||||||
go build
|
|
||||||
|
|
||||||
install:
|
|
||||||
# Linux build
|
|
||||||
ifeq ($(UNAME),Linux)
|
|
||||||
cp -r assets/* /usr/share/ethereal
|
|
||||||
cp go-ethereum /usr/local/bin/ethereal
|
|
||||||
endif
|
|
||||||
# OS X build
|
|
||||||
ifeq ($(UNAME),Darwin)
|
|
||||||
# Execute py script
|
|
||||||
endif
|
|
||||||
@@ -7,16 +7,21 @@ import QtQuick.Controls.Styles 1.1
|
|||||||
import Ethereum 1.0
|
import Ethereum 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
|
id: win
|
||||||
visible: false
|
visible: false
|
||||||
title: "IceCREAM"
|
title: "IceCREAM"
|
||||||
minimumWidth: 1280
|
minimumWidth: 1280
|
||||||
minimumHeight: 700
|
minimumHeight: 700
|
||||||
width: 1290
|
width: 1290
|
||||||
height: 700
|
height: 750
|
||||||
|
|
||||||
property alias codeText: codeEditor.text
|
property alias codeText: codeEditor.text
|
||||||
property alias dataText: rawDataField.text
|
property alias dataText: rawDataField.text
|
||||||
|
|
||||||
|
onClosing: {
|
||||||
|
//compileTimer.stop()
|
||||||
|
}
|
||||||
|
|
||||||
MenuBar {
|
MenuBar {
|
||||||
Menu {
|
Menu {
|
||||||
title: "Debugger"
|
title: "Debugger"
|
||||||
@@ -31,18 +36,57 @@ ApplicationWindow {
|
|||||||
shortcut: "Ctrl+n"
|
shortcut: "Ctrl+n"
|
||||||
onTriggered: dbg.next()
|
onTriggered: dbg.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MenuItem {
|
||||||
|
text: "Continue"
|
||||||
|
shortcut: "Ctrl+g"
|
||||||
|
onTriggered: dbg.continue()
|
||||||
|
}
|
||||||
|
MenuItem {
|
||||||
|
text: "Command"
|
||||||
|
shortcut: "Ctrl+l"
|
||||||
|
onTriggered: {
|
||||||
|
dbgCommand.focus = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MenuItem {
|
||||||
|
text: "Focus code"
|
||||||
|
shortcut: "Ctrl+1"
|
||||||
|
onTriggered: {
|
||||||
|
codeEditor.focus = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MenuItem {
|
||||||
|
text: "Focus data"
|
||||||
|
shortcut: "Ctrl+2"
|
||||||
|
onTriggered: {
|
||||||
|
rawDataField.focus = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
MenuItem {
|
||||||
|
text: "Close window"
|
||||||
|
shortcut: "Ctrl+w"
|
||||||
|
onTriggered: {
|
||||||
|
win.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SplitView {
|
SplitView {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
property var asmModel: ListModel {
|
property var asmModel: ListModel {
|
||||||
id: asmModel
|
id: asmModel
|
||||||
}
|
}
|
||||||
|
|
||||||
TableView {
|
TableView {
|
||||||
id: asmTableView
|
id: asmTableView
|
||||||
width: 200
|
width: 200
|
||||||
TableViewColumn{ role: "value" ; title: "" ; width: 200 }
|
TableViewColumn{ role: "value" ; title: "" ; width: asmTableView.width - 2 }
|
||||||
model: asmModel
|
model: asmModel
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,6 +110,17 @@ ApplicationWindow {
|
|||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: settings.left
|
anchors.right: settings.left
|
||||||
|
focus: true
|
||||||
|
|
||||||
|
/*
|
||||||
|
Timer {
|
||||||
|
id: compileTimer
|
||||||
|
interval: 500 ; running: true ; repeat: true
|
||||||
|
onTriggered: {
|
||||||
|
dbg.autoComp(codeEditor.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
@@ -178,7 +233,7 @@ ApplicationWindow {
|
|||||||
}
|
}
|
||||||
height: parent.height
|
height: parent.height
|
||||||
width: parent.width
|
width: parent.width
|
||||||
TableViewColumn{ id: message ; role: "message" ; title: "log" ; width: logTableView.width }
|
TableViewColumn{ id: message ; role: "message" ; title: "log" ; width: logTableView.width - 2 }
|
||||||
model: logModel
|
model: logModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,7 +242,28 @@ ApplicationWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function exec() {
|
||||||
|
dbg.execCommand(dbgCommand.text);
|
||||||
|
dbgCommand.text = "";
|
||||||
|
}
|
||||||
|
statusBar: StatusBar {
|
||||||
|
height: 30
|
||||||
|
|
||||||
|
|
||||||
|
TextField {
|
||||||
|
id: dbgCommand
|
||||||
|
y: 1
|
||||||
|
x: asmTableView.width
|
||||||
|
width: 500
|
||||||
|
placeholderText: "Debugger (type 'help')"
|
||||||
|
Keys.onReturnPressed: {
|
||||||
|
exec()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
toolBar: ToolBar {
|
toolBar: ToolBar {
|
||||||
|
height: 30
|
||||||
RowLayout {
|
RowLayout {
|
||||||
spacing: 5
|
spacing: 5
|
||||||
|
|
||||||
@@ -208,13 +284,32 @@ ApplicationWindow {
|
|||||||
}
|
}
|
||||||
text: "Next"
|
text: "Next"
|
||||||
}
|
}
|
||||||
CheckBox {
|
|
||||||
id: breakEachLine
|
Button {
|
||||||
objectName: "breakEachLine"
|
id: debugContinueButton
|
||||||
text: "Break each instruction"
|
onClicked: {
|
||||||
checked: true
|
dbg.continue()
|
||||||
|
}
|
||||||
|
text: "Continue"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ComboBox {
|
||||||
|
id: snippets
|
||||||
|
anchors.right: parent.right
|
||||||
|
model: ListModel {
|
||||||
|
ListElement { text: "Snippets" ; value: "" }
|
||||||
|
ListElement { text: "Call Contract" ; value: "var[2] in;\nvar ret;\n\nin[0] = \"arg1\"\nin[1] = 0xdeadbeef\n\nvar success = call(0x0c542ddea93dae0c2fcb2cf175f03ad80d6be9a0, 0, 7000, in, ret)\n\nreturn ret" }
|
||||||
|
}
|
||||||
|
onCurrentIndexChanged: {
|
||||||
|
if(currentIndex != 0) {
|
||||||
|
var code = snippets.model.get(currentIndex).value;
|
||||||
|
codeEditor.insert(codeEditor.cursorPosition, code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function debugCurrent() {
|
function debugCurrent() {
|
||||||
@@ -261,7 +356,19 @@ ApplicationWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setLog(msg) {
|
function setLog(msg) {
|
||||||
logModel.insert(0, {message: msg})
|
// Remove first item once we've reached max log items
|
||||||
|
if(logModel.count > 250) {
|
||||||
|
logModel.remove(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(msg.len != 0) {
|
||||||
|
if(logTableView.flickableItem.atYEnd) {
|
||||||
|
logModel.append({message: msg})
|
||||||
|
logTableView.positionViewAtRow(logTableView.rowCount - 1, ListView.Contain)
|
||||||
|
} else {
|
||||||
|
logModel.append({message: msg})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearLog() {
|
function clearLog() {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ ApplicationWindow {
|
|||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
height: 200
|
height: 200
|
||||||
Image {
|
Image {
|
||||||
source: ui.assetPath("tx.png")
|
source: "../tx.png"
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
@@ -110,7 +110,7 @@ ApplicationWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Image {
|
Image {
|
||||||
source: ui.assetPath("new.png")
|
source: "../new.png"
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
@@ -120,7 +120,7 @@ ApplicationWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Image {
|
Image {
|
||||||
source: ui.assetPath("net.png")
|
source: "../net.png"
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
@@ -131,7 +131,7 @@ ApplicationWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
source: ui.assetPath("heart.png")
|
source: "../heart.png"
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
@@ -248,9 +248,9 @@ ApplicationWindow {
|
|||||||
text: "Client ID"
|
text: "Client ID"
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
text: eth.clientId()
|
text: eth.getCustomIdentifier()
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
eth.changeClientId(text)
|
eth.setCustomIdentifier(text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -420,29 +420,53 @@ ApplicationWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
y: 7
|
y: 6
|
||||||
anchors.right: peerImage.left
|
id: lastBlockLabel
|
||||||
|
objectName: "lastBlockLabel"
|
||||||
|
visible: true
|
||||||
|
text: ""
|
||||||
|
font.pixelSize: 10
|
||||||
|
anchors.right: peerGroup.left
|
||||||
anchors.rightMargin: 5
|
anchors.rightMargin: 5
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressBar {
|
||||||
|
id: syncProgressIndicator
|
||||||
|
visible: false
|
||||||
|
objectName: "syncProgressIndicator"
|
||||||
|
y: 3
|
||||||
|
width: 140
|
||||||
|
indeterminate: true
|
||||||
|
anchors.right: peerGroup.left
|
||||||
|
anchors.rightMargin: 5
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
id: peerGroup
|
||||||
|
y: 7
|
||||||
|
anchors.right: parent.right
|
||||||
|
MouseArea {
|
||||||
|
onDoubleClicked: peerWindow.visible = true
|
||||||
|
anchors.fill: parent
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
id: peerLabel
|
id: peerLabel
|
||||||
font.pixelSize: 8
|
font.pixelSize: 8
|
||||||
text: "0 / 0"
|
text: "0 / 0"
|
||||||
}
|
}
|
||||||
Image {
|
Image {
|
||||||
y: 7
|
|
||||||
id: peerImage
|
id: peerImage
|
||||||
anchors.right: parent.right
|
|
||||||
width: 10; height: 10
|
width: 10; height: 10
|
||||||
MouseArea {
|
source: "../network.png"
|
||||||
onDoubleClicked: peerWindow.visible = true
|
|
||||||
anchors.fill: parent
|
|
||||||
}
|
}
|
||||||
source: ui.assetPath("network.png")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
id: popup
|
id: popup
|
||||||
visible: false
|
visible: false
|
||||||
|
//flags: Qt.CustomizeWindowHint | Qt.Tool | Qt.WindowCloseButtonHint
|
||||||
property var block
|
property var block
|
||||||
width: root.width
|
width: root.width
|
||||||
height: 300
|
height: 300
|
||||||
@@ -460,7 +484,7 @@ ApplicationWindow {
|
|||||||
Text { text: '<h3>Block details</h3>'; color: "#F2F2F2"}
|
Text { text: '<h3>Block details</h3>'; color: "#F2F2F2"}
|
||||||
Text { text: '<b>Block number:</b> ' + number; color: "#F2F2F2"}
|
Text { text: '<b>Block number:</b> ' + number; color: "#F2F2F2"}
|
||||||
Text { text: '<b>Hash:</b> ' + hash; color: "#F2F2F2"}
|
Text { text: '<b>Hash:</b> ' + hash; color: "#F2F2F2"}
|
||||||
Text { text: '<b>Coinbase:</b> ' + coinbase; color: "#F2F2F2"}
|
Text { text: '<b>Coinbase:</b> <' + name + '> ' + coinbase; color: "#F2F2F2"}
|
||||||
Text { text: '<b>Block found at:</b> ' + prettyTime; color: "#F2F2F2"}
|
Text { text: '<b>Block found at:</b> ' + prettyTime; color: "#F2F2F2"}
|
||||||
Text { text: '<b>Gas used:</b> ' + gasUsed + " / " + gasLimit; color: "#F2F2F2"}
|
Text { text: '<b>Gas used:</b> ' + gasUsed + " / " + gasLimit; color: "#F2F2F2"}
|
||||||
}
|
}
|
||||||
@@ -577,6 +601,7 @@ ApplicationWindow {
|
|||||||
|
|
||||||
Window {
|
Window {
|
||||||
id: addPeerWin
|
id: addPeerWin
|
||||||
|
//flags: Qt.CustomizeWindowHint | Qt.Tool | Qt.WindowCloseButtonHint
|
||||||
visible: false
|
visible: false
|
||||||
minimumWidth: 230
|
minimumWidth: 230
|
||||||
maximumWidth: 230
|
maximumWidth: 230
|
||||||
@@ -624,7 +649,7 @@ ApplicationWindow {
|
|||||||
width: 150
|
width: 150
|
||||||
fillMode: Image.PreserveAspectFit
|
fillMode: Image.PreserveAspectFit
|
||||||
smooth: true
|
smooth: true
|
||||||
source: ui.assetPath("facet.png")
|
source: "../facet.png"
|
||||||
x: 10
|
x: 10
|
||||||
y: 10
|
y: 10
|
||||||
}
|
}
|
||||||
@@ -633,7 +658,7 @@ ApplicationWindow {
|
|||||||
anchors.left: aboutIcon.right
|
anchors.left: aboutIcon.right
|
||||||
anchors.leftMargin: 10
|
anchors.leftMargin: 10
|
||||||
font.pointSize: 12
|
font.pointSize: 12
|
||||||
text: "<h2>Ethereal</h2><br><h3>Development</h3>Jeffrey Wilcke<br>Maran Hidskes<br>"
|
text: "<h2>Ethereal</h2><br><h3>Development</h3>Jeffrey Wilcke<br>Maran Hidskes<br>Viktor Trón<br>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,9 +711,9 @@ ApplicationWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(initial){
|
if(initial){
|
||||||
blockModel.append({number: block.number, gasLimit: block.gasLimit, gasUsed: block.gasUsed, coinbase: block.coinbase, hash: block.hash, txs: txs, txAmount: amount, time: block.time, prettyTime: convertToPretty(block.time)})
|
blockModel.append({number: block.number, name: block.name, gasLimit: block.gasLimit, gasUsed: block.gasUsed, coinbase: block.coinbase, hash: block.hash, txs: txs, txAmount: amount, time: block.time, prettyTime: convertToPretty(block.time)})
|
||||||
}else{
|
}else{
|
||||||
blockModel.insert(0, {number: block.number, gasLimit: block.gasLimit, gasUsed: block.gasUsed, coinbase: block.coinbase, hash: block.hash, txs: txs, txAmount: amount, time: block.time, prettyTime: convertToPretty(block.time)})
|
blockModel.insert(0, {number: block.number, name: block.name, gasLimit: block.gasLimit, gasUsed: block.gasUsed, coinbase: block.coinbase, hash: block.hash, txs: txs, txAmount: amount, time: block.time, prettyTime: convertToPretty(block.time)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -743,6 +768,7 @@ ApplicationWindow {
|
|||||||
// ******************************************
|
// ******************************************
|
||||||
Window {
|
Window {
|
||||||
id: peerWindow
|
id: peerWindow
|
||||||
|
//flags: Qt.CustomizeWindowHint | Qt.Tool | Qt.WindowCloseButtonHint
|
||||||
height: 200
|
height: 200
|
||||||
width: 700
|
width: 700
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ ApplicationWindow {
|
|||||||
experimental.preferences.javascriptEnabled: true
|
experimental.preferences.javascriptEnabled: true
|
||||||
experimental.preferences.navigatorQtObjectEnabled: true
|
experimental.preferences.navigatorQtObjectEnabled: true
|
||||||
experimental.preferences.developerExtrasEnabled: true
|
experimental.preferences.developerExtrasEnabled: true
|
||||||
experimental.userScripts: [ui.assetPath("ext/pre.js"), ui.assetPath("ext/big.js"), ui.assetPath("ext/string.js"), ui.assetPath("ext/ethereum.js")]
|
experimental.userScripts: ["../ext/pre.js", "../ext/big.js", "../ext/string.js", "../ext/ethereum.js"]
|
||||||
experimental.onMessageReceived: {
|
experimental.onMessageReceived: {
|
||||||
console.log("[onMessageReceived]: ", message.data)
|
console.log("[onMessageReceived]: ", message.data)
|
||||||
// TODO move to messaging.js
|
// TODO move to messaging.js
|
||||||
@@ -191,6 +191,7 @@ ApplicationWindow {
|
|||||||
inspector.visible = false
|
inspector.visible = false
|
||||||
}else{
|
}else{
|
||||||
inspector.visible = true
|
inspector.visible = true
|
||||||
|
inspector.url = webview.experimental.remoteInspectorUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onDoubleClicked: {
|
onDoubleClicked: {
|
||||||
@@ -224,7 +225,6 @@ ApplicationWindow {
|
|||||||
WebView {
|
WebView {
|
||||||
id: inspector
|
id: inspector
|
||||||
visible: false
|
visible: false
|
||||||
url: webview.experimental.remoteInspectorUrl
|
|
||||||
anchors {
|
anchors {
|
||||||
left: root.left
|
left: root.left
|
||||||
right: root.right
|
right: root.right
|
||||||
@@ -238,7 +238,6 @@ ApplicationWindow {
|
|||||||
name: "inspectorShown"
|
name: "inspectorShown"
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: inspector
|
target: inspector
|
||||||
url: webview.experimental.remoteInspectorUrl
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
7
ethereal/assets/samplecoin/bootstrap.min.css
vendored
7
ethereal/assets/samplecoin/bootstrap.min.css
vendored
File diff suppressed because one or more lines are too long
Binary file not shown.
|
Before Width: | Height: | Size: 85 KiB |
@@ -1,34 +0,0 @@
|
|||||||
/* Space out content a bit */
|
|
||||||
body {
|
|
||||||
padding-top: 20px;
|
|
||||||
padding-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Everything but the jumbotron gets side spacing for mobile first
|
|
||||||
* views */
|
|
||||||
.header,
|
|
||||||
.marketing,
|
|
||||||
.footer {
|
|
||||||
padding-right: 15px;
|
|
||||||
padding-left: 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Custom page header */
|
|
||||||
.header {
|
|
||||||
border-bottom: 1px solid #e5e5e5;
|
|
||||||
}
|
|
||||||
/* Make the masthead heading the same height as the navigation */
|
|
||||||
.header h3 {
|
|
||||||
padding-bottom: 19px;
|
|
||||||
margin-top: 0;
|
|
||||||
margin-bottom: 0;
|
|
||||||
line-height: 40px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.jumbotron {
|
|
||||||
text-align: center;
|
|
||||||
border-bottom: 1px solid #e5e5e5;
|
|
||||||
|
|
||||||
margin: 0 auto;
|
|
||||||
width: 300px;
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>jeffcoin</title>
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="bootstrap.min.css">
|
|
||||||
<link rel="stylesheet" href="bootstrap-theme.min.css">
|
|
||||||
<link rel="stylesheet" href="samplecoin.css">
|
|
||||||
<meta name="viewport" content="minimum-scale=1; maximum-scale=1; initial-scale=1;">
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
|
|
||||||
var jefcoinAddr = "22fa3ebce6ef9ca661a960104d3087eec040011e"
|
|
||||||
var mAddr = ""
|
|
||||||
|
|
||||||
function createTransaction() {
|
|
||||||
var addr = ("0x" + document.querySelector("#addr").value).pad(32);
|
|
||||||
var amount = document.querySelector("#amount").value.pad(32);
|
|
||||||
|
|
||||||
var data = (addr + amount).unbin();
|
|
||||||
eth.transact(mAddr, jefcoinAddr, 0, "50000", "1000000", data, function(receipt) {
|
|
||||||
debug("received tx hash:", reciept.address)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function init() {
|
|
||||||
eth.getKey(function(sec) {
|
|
||||||
mAddr = sec;
|
|
||||||
eth.getSecretToAddress(sec, function(addr) {
|
|
||||||
eth.getStorageAt(jefcoinAddr, addr, function(storage) {
|
|
||||||
document.querySelector("#current-amount").innerHTML = storage;
|
|
||||||
});
|
|
||||||
|
|
||||||
eth.watch(jefcoinAddr, addr, function(addr, value) {
|
|
||||||
document.querySelector("#current-amount").innerHTML = value
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body onload="init();">
|
|
||||||
<div class="container">
|
|
||||||
<div class="header">
|
|
||||||
<h3 class="text-muted">JeffCoin</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="jumbotron ">
|
|
||||||
<img src="icon.png">
|
|
||||||
<div>Amount: <strong id="current-amount"></strong></div>
|
|
||||||
|
|
||||||
<div id="transactions">
|
|
||||||
<div class="form-group">
|
|
||||||
<input id="addr" class="form-control" type="text" placeholder="Receiver address"></input><br>
|
|
||||||
<input id="amount" class="form-control" type="text" placeholder="Amount"></input><br>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button class="btn btn-default" onclick="createTransaction();">Send Tx</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="debug" style="border: 1px solid black; min-height: 30px;"></div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ethui
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/go-qml/qml"
|
"github.com/go-qml/qml"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,7 +14,11 @@ type DebuggerWindow struct {
|
|||||||
win *qml.Window
|
win *qml.Window
|
||||||
engine *qml.Engine
|
engine *qml.Engine
|
||||||
lib *UiLib
|
lib *UiLib
|
||||||
|
|
||||||
|
vm *ethchain.Vm
|
||||||
Db *Debugger
|
Db *Debugger
|
||||||
|
|
||||||
|
state *ethchain.State
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDebuggerWindow(lib *UiLib) *DebuggerWindow {
|
func NewDebuggerWindow(lib *UiLib) *DebuggerWindow {
|
||||||
@@ -26,9 +31,11 @@ func NewDebuggerWindow(lib *UiLib) *DebuggerWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
win := component.CreateWindow(nil)
|
win := component.CreateWindow(nil)
|
||||||
db := &Debugger{win, make(chan bool), make(chan bool), true, false, true}
|
|
||||||
|
|
||||||
return &DebuggerWindow{engine: engine, win: win, lib: lib, Db: db}
|
w := &DebuggerWindow{engine: engine, win: win, lib: lib, vm: ðchain.Vm{}}
|
||||||
|
w.Db = NewDebugger(w)
|
||||||
|
|
||||||
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *DebuggerWindow) Show() {
|
func (self *DebuggerWindow) Show() {
|
||||||
@@ -48,18 +55,43 @@ func (self *DebuggerWindow) SetCode(code string) {
|
|||||||
func (self *DebuggerWindow) SetData(data string) {
|
func (self *DebuggerWindow) SetData(data string) {
|
||||||
self.win.Set("dataText", data)
|
self.win.Set("dataText", data)
|
||||||
}
|
}
|
||||||
func (self *DebuggerWindow) SetAsm(data string) {
|
|
||||||
dis := ethchain.Disassemble(ethutil.FromHex(data))
|
func (self *DebuggerWindow) SetAsm(data []byte) {
|
||||||
|
self.win.Root().Call("clearAsm")
|
||||||
|
|
||||||
|
dis := ethchain.Disassemble(data)
|
||||||
for _, str := range dis {
|
for _, str := range dis {
|
||||||
self.win.Root().Call("setAsm", str)
|
self.win.Root().Call("setAsm", str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *DebuggerWindow) Compile(code string) {
|
||||||
|
var err error
|
||||||
|
script := ethutil.StringToByteFunc(code, func(s string) (ret []byte) {
|
||||||
|
ret, err = ethutil.Compile(s, true)
|
||||||
|
return
|
||||||
|
})
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
self.SetAsm(script)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used by QML
|
||||||
|
func (self *DebuggerWindow) AutoComp(code string) {
|
||||||
|
if self.Db.done {
|
||||||
|
self.Compile(code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *DebuggerWindow) ClearLog() {
|
||||||
|
self.win.Root().Call("clearLog")
|
||||||
|
}
|
||||||
|
|
||||||
func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, dataStr string) {
|
func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, dataStr string) {
|
||||||
if !self.Db.done {
|
if !self.Db.done {
|
||||||
self.Db.Q <- true
|
self.Db.Q <- true
|
||||||
}
|
}
|
||||||
self.Db.breakOnInstr = self.win.Root().ObjectByName("breakEachLine").Bool("checked")
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
@@ -78,7 +110,7 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
script := ethutil.StringToByteFunc(scriptStr, func(s string) (ret []byte) {
|
script := ethutil.StringToByteFunc(scriptStr, func(s string) (ret []byte) {
|
||||||
ret, err = ethutil.Compile(s)
|
ret, err = ethutil.Compile(s, false)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -88,28 +120,19 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dis := ethchain.Disassemble(script)
|
|
||||||
self.win.Root().Call("clearAsm")
|
|
||||||
self.win.Root().Call("clearLog")
|
|
||||||
|
|
||||||
for _, str := range dis {
|
|
||||||
self.win.Root().Call("setAsm", str)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gas = ethutil.Big(gasStr)
|
gas = ethutil.Big(gasStr)
|
||||||
gasPrice = ethutil.Big(gasPriceStr)
|
gasPrice = ethutil.Big(gasPriceStr)
|
||||||
value = ethutil.Big(valueStr)
|
value = ethutil.Big(valueStr)
|
||||||
// Contract addr as test address
|
// Contract addr as test address
|
||||||
keyPair = ethutil.GetKeyRing().Get(0)
|
keyPair = self.lib.eth.KeyManager().KeyPair()
|
||||||
callerTx = ethchain.NewContractCreationTx(ethutil.Big(valueStr), gas, gasPrice, script)
|
|
||||||
)
|
)
|
||||||
callerTx.Sign(keyPair.PrivateKey)
|
|
||||||
|
|
||||||
state := self.lib.eth.BlockChain().CurrentBlock.State()
|
state := self.lib.eth.StateManager().TransState()
|
||||||
account := self.lib.eth.StateManager().TransState().GetAccount(keyPair.Address())
|
account := self.lib.eth.StateManager().TransState().GetAccount(keyPair.Address())
|
||||||
contract := ethchain.MakeContract(callerTx, state)
|
contract := ethchain.NewStateObject([]byte{0})
|
||||||
contract.Amount = value
|
contract.Amount = value
|
||||||
|
|
||||||
callerClosure := ethchain.NewClosure(account, contract, script, state, gas, gasPrice)
|
callerClosure := ethchain.NewClosure(account, contract, script, state, gas, gasPrice)
|
||||||
|
|
||||||
block := self.lib.eth.BlockChain().CurrentBlock
|
block := self.lib.eth.BlockChain().CurrentBlock
|
||||||
@@ -124,11 +147,13 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data
|
|||||||
Value: ethutil.Big(valueStr),
|
Value: ethutil.Big(valueStr),
|
||||||
})
|
})
|
||||||
vm.Verbose = true
|
vm.Verbose = true
|
||||||
|
vm.Dbg = self.Db
|
||||||
|
|
||||||
|
self.vm = vm
|
||||||
self.Db.done = false
|
self.Db.done = false
|
||||||
self.Logf("callsize %d", len(script))
|
self.Logf("callsize %d", len(script))
|
||||||
go func() {
|
go func() {
|
||||||
ret, g, err := callerClosure.Call(vm, data, self.Db.halting)
|
ret, g, err := callerClosure.Call(vm, data)
|
||||||
tot := new(big.Int).Mul(g, gasPrice)
|
tot := new(big.Int).Mul(g, gasPrice)
|
||||||
self.Logf("gas usage %v total price = %v (%v)", g, tot, ethutil.CurrencyToString(tot))
|
self.Logf("gas usage %v total price = %v (%v)", g, tot, ethutil.CurrencyToString(tot))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -164,18 +189,90 @@ func (self *DebuggerWindow) Next() {
|
|||||||
self.Db.Next()
|
self.Db.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *DebuggerWindow) Continue() {
|
||||||
|
self.vm.Stepping = false
|
||||||
|
self.Next()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *DebuggerWindow) ExecCommand(command string) {
|
||||||
|
if len(command) > 0 {
|
||||||
|
cmd := strings.Split(command, " ")
|
||||||
|
switch cmd[0] {
|
||||||
|
case "help":
|
||||||
|
self.Logln("Debugger commands:")
|
||||||
|
self.Logln("break, bp Set breakpoint on instruction")
|
||||||
|
self.Logln("clear [log, break, bp] Clears previous set sub-command(s)")
|
||||||
|
case "break", "bp":
|
||||||
|
if len(cmd) > 1 {
|
||||||
|
lineNo, err := strconv.Atoi(cmd[1])
|
||||||
|
if err != nil {
|
||||||
|
self.Logln(err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
self.Db.breakPoints = append(self.Db.breakPoints, int64(lineNo))
|
||||||
|
self.Logf("break point set on instruction %d", lineNo)
|
||||||
|
} else {
|
||||||
|
self.Logf("'%s' requires line number", cmd[0])
|
||||||
|
}
|
||||||
|
case "clear":
|
||||||
|
if len(cmd) > 1 {
|
||||||
|
switch cmd[1] {
|
||||||
|
case "break", "bp":
|
||||||
|
self.Db.breakPoints = nil
|
||||||
|
|
||||||
|
self.Logln("Breakpoints cleared")
|
||||||
|
case "log":
|
||||||
|
self.ClearLog()
|
||||||
|
default:
|
||||||
|
self.Logf("clear '%s' is not valid", cmd[1])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.Logln("'clear' requires sub command")
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
self.Logf("Unknown command %s", cmd[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Debugger struct {
|
type Debugger struct {
|
||||||
win *qml.Window
|
|
||||||
N chan bool
|
N chan bool
|
||||||
Q chan bool
|
Q chan bool
|
||||||
done, interrupt bool
|
done, interrupt bool
|
||||||
breakOnInstr bool
|
breakPoints []int64
|
||||||
|
main *DebuggerWindow
|
||||||
|
win *qml.Window
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDebugger(main *DebuggerWindow) *Debugger {
|
||||||
|
db := &Debugger{make(chan bool), make(chan bool), true, false, nil, main, main.win}
|
||||||
|
|
||||||
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
type storeVal struct {
|
type storeVal struct {
|
||||||
Key, Value string
|
Key, Value string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Debugger) BreakHook(pc int, op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack, stateObject *ethchain.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 {
|
||||||
|
return self.halting(pc, op, mem, stack, stateObject)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Debugger) SetCode(byteCode []byte) {
|
||||||
|
self.main.SetAsm(byteCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack, stateObject *ethchain.StateObject) bool {
|
||||||
d.win.Root().Call("setInstruction", pc)
|
d.win.Root().Call("setInstruction", pc)
|
||||||
d.win.Root().Call("clearMem")
|
d.win.Root().Call("clearMem")
|
||||||
@@ -196,7 +293,6 @@ func (d *Debugger) halting(pc int, op ethchain.OpCode, mem *ethchain.Memory, sta
|
|||||||
d.win.Root().Call("setStorage", storeVal{fmt.Sprintf("% x", key), fmt.Sprintf("% x", node.Str())})
|
d.win.Root().Call("setStorage", storeVal{fmt.Sprintf("% x", key), fmt.Sprintf("% x", node.Str())})
|
||||||
})
|
})
|
||||||
|
|
||||||
if d.breakOnInstr {
|
|
||||||
out:
|
out:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@@ -209,7 +305,6 @@ func (d *Debugger) halting(pc int, op ethchain.OpCode, mem *ethchain.Memory, sta
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ethui
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -121,10 +121,10 @@ out:
|
|||||||
func (app *ExtApplication) Watch(addr, storageAddr string) {
|
func (app *ExtApplication) Watch(addr, storageAddr string) {
|
||||||
var event string
|
var event string
|
||||||
if len(storageAddr) == 0 {
|
if len(storageAddr) == 0 {
|
||||||
event = "object:" + string(ethutil.FromHex(addr))
|
event = "object:" + string(ethutil.Hex2Bytes(addr))
|
||||||
app.lib.eth.Reactor().Subscribe(event, app.changeChan)
|
app.lib.eth.Reactor().Subscribe(event, app.changeChan)
|
||||||
} else {
|
} else {
|
||||||
event = "storage:" + string(ethutil.FromHex(addr)) + ":" + string(ethutil.FromHex(storageAddr))
|
event = "storage:" + string(ethutil.Hex2Bytes(addr)) + ":" + string(ethutil.Hex2Bytes(storageAddr))
|
||||||
app.lib.eth.Reactor().Subscribe(event, app.changeChan)
|
app.lib.eth.Reactor().Subscribe(event, app.changeChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,6 +13,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var Identifier string
|
var Identifier string
|
||||||
|
var KeyRing string
|
||||||
|
var KeyStore string
|
||||||
var StartRpc bool
|
var StartRpc bool
|
||||||
var RpcPort int
|
var RpcPort int
|
||||||
var UseUPnP bool
|
var UseUPnP bool
|
||||||
@@ -22,8 +24,8 @@ var AddPeer string
|
|||||||
var MaxPeer int
|
var MaxPeer int
|
||||||
var GenAddr bool
|
var GenAddr bool
|
||||||
var UseSeed bool
|
var UseSeed bool
|
||||||
var ImportKey string
|
var SecretFile string
|
||||||
var ExportKey bool
|
var ExportDir string
|
||||||
var NonInteractive bool
|
var NonInteractive bool
|
||||||
var Datadir string
|
var Datadir string
|
||||||
var LogFile string
|
var LogFile string
|
||||||
@@ -34,6 +36,7 @@ var LogLevel int
|
|||||||
// flags specific to gui client
|
// flags specific to gui client
|
||||||
var AssetPath string
|
var AssetPath string
|
||||||
|
|
||||||
|
//TODO: If we re-use the one defined in cmd.go the binary osx image crashes. If somebody finds out why we can dry this up.
|
||||||
func defaultAssetPath() string {
|
func defaultAssetPath() string {
|
||||||
var assetPath string
|
var assetPath string
|
||||||
// If the current working directory is the go-ethereum dir
|
// If the current working directory is the go-ethereum dir
|
||||||
@@ -50,15 +53,14 @@ func defaultAssetPath() string {
|
|||||||
assetPath = filepath.Join(exedir, "../Resources")
|
assetPath = filepath.Join(exedir, "../Resources")
|
||||||
case "linux":
|
case "linux":
|
||||||
assetPath = "/usr/share/ethereal"
|
assetPath = "/usr/share/ethereal"
|
||||||
case "window":
|
case "windows":
|
||||||
fallthrough
|
assetPath = "./assets"
|
||||||
default:
|
default:
|
||||||
assetPath = "."
|
assetPath = "."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return assetPath
|
return assetPath
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultDataDir() string {
|
func defaultDataDir() string {
|
||||||
usr, _ := user.Current()
|
usr, _ := user.Current()
|
||||||
return path.Join(usr.HomeDir, ".ethereal")
|
return path.Join(usr.HomeDir, ".ethereal")
|
||||||
@@ -73,6 +75,8 @@ func Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
flag.StringVar(&Identifier, "id", "", "Custom client identifier")
|
flag.StringVar(&Identifier, "id", "", "Custom client identifier")
|
||||||
|
flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
|
||||||
|
flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
|
||||||
flag.StringVar(&OutboundPort, "port", "30303", "listening port")
|
flag.StringVar(&OutboundPort, "port", "30303", "listening port")
|
||||||
flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support")
|
flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support")
|
||||||
flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers")
|
flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers")
|
||||||
@@ -81,9 +85,9 @@ func Init() {
|
|||||||
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
||||||
flag.BoolVar(&UseSeed, "seed", true, "seed peers")
|
flag.BoolVar(&UseSeed, "seed", true, "seed peers")
|
||||||
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
||||||
flag.BoolVar(&ExportKey, "export", false, "export private key")
|
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
|
||||||
|
flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
|
||||||
flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
|
flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
|
||||||
flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)")
|
|
||||||
flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
|
flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
|
||||||
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
||||||
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
|
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package ethui
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -7,11 +7,14 @@ import (
|
|||||||
"github.com/ethereum/eth-go/ethchain"
|
"github.com/ethereum/eth-go/ethchain"
|
||||||
"github.com/ethereum/eth-go/ethdb"
|
"github.com/ethereum/eth-go/ethdb"
|
||||||
"github.com/ethereum/eth-go/ethlog"
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
|
"github.com/ethereum/eth-go/ethminer"
|
||||||
"github.com/ethereum/eth-go/ethpub"
|
"github.com/ethereum/eth-go/ethpub"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
|
"github.com/ethereum/eth-go/ethwire"
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
"github.com/go-qml/qml"
|
"github.com/go-qml/qml"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -28,40 +31,34 @@ type Gui struct {
|
|||||||
eth *eth.Ethereum
|
eth *eth.Ethereum
|
||||||
|
|
||||||
// The public Ethereum library
|
// The public Ethereum library
|
||||||
lib *EthLib
|
|
||||||
uiLib *UiLib
|
uiLib *UiLib
|
||||||
|
|
||||||
txDb *ethdb.LDBDatabase
|
txDb *ethdb.LDBDatabase
|
||||||
|
|
||||||
addr []byte
|
|
||||||
|
|
||||||
pub *ethpub.PEthereum
|
pub *ethpub.PEthereum
|
||||||
logLevel ethlog.LogLevel
|
logLevel ethlog.LogLevel
|
||||||
open bool
|
open bool
|
||||||
|
|
||||||
|
Session string
|
||||||
|
clientIdentity *ethwire.SimpleClientIdentity
|
||||||
|
config *ethutil.ConfigManager
|
||||||
|
|
||||||
|
miner *ethminer.Miner
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create GUI, but doesn't start it
|
// Create GUI, but doesn't start it
|
||||||
func New(ethereum *eth.Ethereum, logLevel int) *Gui {
|
func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIdentity *ethwire.SimpleClientIdentity, session string, logLevel int) *Gui {
|
||||||
lib := &EthLib{stateManager: ethereum.StateManager(), blockChain: ethereum.BlockChain(), txPool: ethereum.TxPool()}
|
|
||||||
db, err := ethdb.NewLDBDatabase("tx_database")
|
db, err := ethdb.NewLDBDatabase("tx_database")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// On first run we won't have any keys yet, so this would crash.
|
|
||||||
// Therefor we check if we are ready to actually start this process
|
|
||||||
var addr []byte
|
|
||||||
if ethutil.GetKeyRing().Len() != 0 {
|
|
||||||
addr = ethutil.GetKeyRing().Get(0).Address()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub := ethpub.NewPEthereum(ethereum)
|
pub := ethpub.NewPEthereum(ethereum)
|
||||||
|
|
||||||
return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub, logLevel: ethlog.LogLevel(logLevel), open: false}
|
return &Gui{eth: ethereum, txDb: db, pub: pub, logLevel: ethlog.LogLevel(logLevel), Session: session, open: false, clientIdentity: clientIdentity, config: config}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) Start(assetPath string) {
|
func (gui *Gui) Start(assetPath string) {
|
||||||
const version = "0.5.0 RC15"
|
|
||||||
|
|
||||||
defer gui.txDb.Close()
|
defer gui.txDb.Close()
|
||||||
|
|
||||||
@@ -74,8 +71,6 @@ func (gui *Gui) Start(assetPath string) {
|
|||||||
Init: func(p *ethpub.KeyVal, obj qml.Object) { p.Key = ""; p.Value = "" },
|
Init: func(p *ethpub.KeyVal, obj qml.Object) { p.Key = ""; p.Value = "" },
|
||||||
}})
|
}})
|
||||||
|
|
||||||
ethutil.Config.SetClientString("Ethereal")
|
|
||||||
|
|
||||||
// Create a new QML engine
|
// Create a new QML engine
|
||||||
gui.engine = qml.NewEngine()
|
gui.engine = qml.NewEngine()
|
||||||
context := gui.engine.Context()
|
context := gui.engine.Context()
|
||||||
@@ -112,14 +107,14 @@ func (gui *Gui) Start(assetPath string) {
|
|||||||
ethlog.AddLogSystem(gui)
|
ethlog.AddLogSystem(gui)
|
||||||
}
|
}
|
||||||
win.Wait()
|
win.Wait()
|
||||||
// need to silence gui logger after window closed otherwise logsystem hangs
|
// need to silence gui logger after window closed otherwise logsystem hangs (but do not save loglevel)
|
||||||
gui.SetLogLevel(ethlog.Silence)
|
gui.logLevel = ethlog.Silence
|
||||||
gui.open = false
|
gui.open = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) Stop() {
|
func (gui *Gui) Stop() {
|
||||||
if gui.open {
|
if gui.open {
|
||||||
gui.SetLogLevel(ethlog.Silence)
|
gui.logLevel = ethlog.Silence
|
||||||
gui.open = false
|
gui.open = false
|
||||||
gui.win.Hide()
|
gui.win.Hide()
|
||||||
}
|
}
|
||||||
@@ -133,6 +128,7 @@ func (gui *Gui) ToggleMining() {
|
|||||||
txt = "Start mining"
|
txt = "Start mining"
|
||||||
} else {
|
} else {
|
||||||
utils.StartMining(gui.eth)
|
utils.StartMining(gui.eth)
|
||||||
|
gui.miner = utils.GetMiner()
|
||||||
txt = "Stop mining"
|
txt = "Stop mining"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,12 +154,11 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) showKeyImport(context *qml.Context) (*qml.Window, error) {
|
func (gui *Gui) showKeyImport(context *qml.Context) (*qml.Window, error) {
|
||||||
context.SetVar("lib", gui.lib)
|
context.SetVar("lib", gui)
|
||||||
component, err := gui.engine.LoadFile(gui.uiLib.AssetPath("qml/first_run.qml"))
|
component, err := gui.engine.LoadFile(gui.uiLib.AssetPath("qml/first_run.qml"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.createWindow(component), nil
|
return gui.createWindow(component), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,15 +170,36 @@ func (gui *Gui) createWindow(comp qml.Object) *qml.Window {
|
|||||||
|
|
||||||
return gui.win
|
return gui.win
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) ImportAndSetPrivKey(secret string) bool {
|
||||||
|
err := gui.eth.KeyManager().InitFromString(gui.Session, 0, secret)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorln("unable to import: ", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
logger.Errorln("successfully imported: ", err)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) CreateAndSetPrivKey() (string, string, string, string) {
|
||||||
|
err := gui.eth.KeyManager().Init(gui.Session, 0, true)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorln("unable to create key: ", err)
|
||||||
|
return "", "", "", ""
|
||||||
|
}
|
||||||
|
return gui.eth.KeyManager().KeyPair().AsStrings()
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) setInitialBlockChain() {
|
func (gui *Gui) setInitialBlockChain() {
|
||||||
sBlk := gui.eth.BlockChain().LastBlockHash
|
sBlk := gui.eth.BlockChain().LastBlockHash
|
||||||
blk := gui.eth.BlockChain().GetBlock(sBlk)
|
blk := gui.eth.BlockChain().GetBlock(sBlk)
|
||||||
for ; blk != nil; blk = gui.eth.BlockChain().GetBlock(sBlk) {
|
for ; blk != nil; blk = gui.eth.BlockChain().GetBlock(sBlk) {
|
||||||
sBlk = blk.PrevHash
|
sBlk = blk.PrevHash
|
||||||
|
addr := gui.address()
|
||||||
|
|
||||||
// Loop through all transactions to see if we missed any while being offline
|
// Loop through all transactions to see if we missed any while being offline
|
||||||
for _, tx := range blk.Transactions() {
|
for _, tx := range blk.Transactions() {
|
||||||
if bytes.Compare(tx.Sender(), gui.addr) == 0 || bytes.Compare(tx.Recipient, gui.addr) == 0 {
|
if bytes.Compare(tx.Sender(), addr) == 0 || bytes.Compare(tx.Recipient, addr) == 0 {
|
||||||
if ok, _ := gui.txDb.Get(tx.Hash()); ok == nil {
|
if ok, _ := gui.txDb.Get(tx.Hash()); ok == nil {
|
||||||
gui.txDb.Put(tx.Hash(), tx.RlpEncode())
|
gui.txDb.Put(tx.Hash(), tx.RlpEncode())
|
||||||
}
|
}
|
||||||
@@ -199,25 +215,27 @@ type address struct {
|
|||||||
Name, Address string
|
Name, Address string
|
||||||
}
|
}
|
||||||
|
|
||||||
var namereg = ethutil.FromHex("bb5f186604d057c1c5240ca2ae0f6430138ac010")
|
|
||||||
|
|
||||||
func (gui *Gui) loadAddressBook() {
|
func (gui *Gui) loadAddressBook() {
|
||||||
gui.win.Root().Call("clearAddress")
|
gui.win.Root().Call("clearAddress")
|
||||||
stateObject := gui.eth.StateManager().CurrentState().GetStateObject(namereg)
|
|
||||||
if stateObject != nil {
|
nameReg := ethpub.EthereumConfig(gui.eth.StateManager()).NameReg()
|
||||||
stateObject.State().EachStorage(func(name string, value *ethutil.Value) {
|
if nameReg != nil {
|
||||||
gui.win.Root().Call("addAddress", struct{ Name, Address string }{name, ethutil.Hex(value.Bytes())})
|
nameReg.State().EachStorage(func(name string, value *ethutil.Value) {
|
||||||
|
if name[0] != 0 {
|
||||||
|
gui.win.Root().Call("addAddress", struct{ Name, Address string }{name, ethutil.Bytes2Hex(value.Bytes())})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) readPreviousTransactions() {
|
func (gui *Gui) readPreviousTransactions() {
|
||||||
it := gui.txDb.Db().NewIterator(nil, nil)
|
it := gui.txDb.Db().NewIterator(nil, nil)
|
||||||
|
addr := gui.address()
|
||||||
for it.Next() {
|
for it.Next() {
|
||||||
tx := ethchain.NewTransactionFromBytes(it.Value())
|
tx := ethchain.NewTransactionFromBytes(it.Value())
|
||||||
|
|
||||||
var inout string
|
var inout string
|
||||||
if bytes.Compare(tx.Sender(), gui.addr) == 0 {
|
if bytes.Compare(tx.Sender(), addr) == 0 {
|
||||||
inout = "send"
|
inout = "send"
|
||||||
} else {
|
} else {
|
||||||
inout = "recv"
|
inout = "recv"
|
||||||
@@ -230,7 +248,11 @@ func (gui *Gui) readPreviousTransactions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) processBlock(block *ethchain.Block, initial bool) {
|
func (gui *Gui) processBlock(block *ethchain.Block, initial bool) {
|
||||||
gui.win.Root().Call("addBlock", ethpub.NewPBlock(block), initial)
|
name := ethpub.FindNameInNameReg(gui.eth.StateManager(), block.Coinbase)
|
||||||
|
b := ethpub.NewPBlock(block)
|
||||||
|
b.Name = name
|
||||||
|
|
||||||
|
gui.win.Root().Call("addBlock", b, initial)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) {
|
func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) {
|
||||||
@@ -249,49 +271,68 @@ func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) {
|
|||||||
gui.win.Root().Call("setWalletValue", str)
|
gui.win.Root().Call("setWalletValue", str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Gui) getObjectByName(objectName string) qml.Object {
|
||||||
|
return self.win.Root().ObjectByName(objectName)
|
||||||
|
}
|
||||||
|
|
||||||
// Simple go routine function that updates the list of peers in the GUI
|
// Simple go routine function that updates the list of peers in the GUI
|
||||||
func (gui *Gui) update() {
|
func (gui *Gui) update() {
|
||||||
reactor := gui.eth.Reactor()
|
reactor := gui.eth.Reactor()
|
||||||
|
|
||||||
blockChan := make(chan ethutil.React, 1)
|
var (
|
||||||
txChan := make(chan ethutil.React, 1)
|
blockChan = make(chan ethutil.React, 1)
|
||||||
objectChan := make(chan ethutil.React, 1)
|
txChan = make(chan ethutil.React, 1)
|
||||||
peerChan := make(chan ethutil.React, 1)
|
objectChan = make(chan ethutil.React, 1)
|
||||||
|
peerChan = make(chan ethutil.React, 1)
|
||||||
|
chainSyncChan = make(chan ethutil.React, 1)
|
||||||
|
miningChan = make(chan ethutil.React, 1)
|
||||||
|
)
|
||||||
|
|
||||||
reactor.Subscribe("newBlock", blockChan)
|
reactor.Subscribe("newBlock", blockChan)
|
||||||
reactor.Subscribe("newTx:pre", txChan)
|
reactor.Subscribe("newTx:pre", txChan)
|
||||||
reactor.Subscribe("newTx:post", txChan)
|
reactor.Subscribe("newTx:post", txChan)
|
||||||
reactor.Subscribe("object:"+string(namereg), objectChan)
|
reactor.Subscribe("chainSync", chainSyncChan)
|
||||||
|
reactor.Subscribe("miner:start", miningChan)
|
||||||
|
reactor.Subscribe("miner:stop", miningChan)
|
||||||
|
|
||||||
|
nameReg := ethpub.EthereumConfig(gui.eth.StateManager()).NameReg()
|
||||||
|
if nameReg != nil {
|
||||||
|
reactor.Subscribe("object:"+string(nameReg.Address()), objectChan)
|
||||||
|
}
|
||||||
reactor.Subscribe("peerList", peerChan)
|
reactor.Subscribe("peerList", peerChan)
|
||||||
|
|
||||||
ticker := time.NewTicker(5 * time.Second)
|
peerUpdateTicker := time.NewTicker(5 * time.Second)
|
||||||
|
generalUpdateTicker := time.NewTicker(1 * time.Second)
|
||||||
|
|
||||||
state := gui.eth.StateManager().TransState()
|
state := gui.eth.StateManager().TransState()
|
||||||
|
|
||||||
unconfirmedFunds := new(big.Int)
|
unconfirmedFunds := new(big.Int)
|
||||||
gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.addr).Amount)))
|
gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Amount)))
|
||||||
|
gui.getObjectByName("syncProgressIndicator").Set("visible", !gui.eth.IsUpToDate())
|
||||||
|
|
||||||
|
lastBlockLabel := gui.getObjectByName("lastBlockLabel")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case b := <-blockChan:
|
case b := <-blockChan:
|
||||||
block := b.Resource.(*ethchain.Block)
|
block := b.Resource.(*ethchain.Block)
|
||||||
gui.processBlock(block, false)
|
gui.processBlock(block, false)
|
||||||
if bytes.Compare(block.Coinbase, gui.addr) == 0 {
|
if bytes.Compare(block.Coinbase, gui.address()) == 0 {
|
||||||
gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.addr).Amount, nil)
|
gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Amount, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
case txMsg := <-txChan:
|
case txMsg := <-txChan:
|
||||||
tx := txMsg.Resource.(*ethchain.Transaction)
|
tx := txMsg.Resource.(*ethchain.Transaction)
|
||||||
|
|
||||||
if txMsg.Event == "newTx:pre" {
|
if txMsg.Event == "newTx:pre" {
|
||||||
object := state.GetAccount(gui.addr)
|
object := state.GetAccount(gui.address())
|
||||||
|
|
||||||
if bytes.Compare(tx.Sender(), gui.addr) == 0 {
|
if bytes.Compare(tx.Sender(), gui.address()) == 0 {
|
||||||
gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "send")
|
gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "send")
|
||||||
gui.txDb.Put(tx.Hash(), tx.RlpEncode())
|
gui.txDb.Put(tx.Hash(), tx.RlpEncode())
|
||||||
|
|
||||||
unconfirmedFunds.Sub(unconfirmedFunds, tx.Value)
|
unconfirmedFunds.Sub(unconfirmedFunds, tx.Value)
|
||||||
} else if bytes.Compare(tx.Recipient, gui.addr) == 0 {
|
} else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
|
||||||
gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "recv")
|
gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "recv")
|
||||||
gui.txDb.Put(tx.Hash(), tx.RlpEncode())
|
gui.txDb.Put(tx.Hash(), tx.RlpEncode())
|
||||||
|
|
||||||
@@ -300,10 +341,10 @@ func (gui *Gui) update() {
|
|||||||
|
|
||||||
gui.setWalletValue(object.Amount, unconfirmedFunds)
|
gui.setWalletValue(object.Amount, unconfirmedFunds)
|
||||||
} else {
|
} else {
|
||||||
object := state.GetAccount(gui.addr)
|
object := state.GetAccount(gui.address())
|
||||||
if bytes.Compare(tx.Sender(), gui.addr) == 0 {
|
if bytes.Compare(tx.Sender(), gui.address()) == 0 {
|
||||||
object.SubAmount(tx.Value)
|
object.SubAmount(tx.Value)
|
||||||
} else if bytes.Compare(tx.Recipient, gui.addr) == 0 {
|
} else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
|
||||||
object.AddAmount(tx.Value)
|
object.AddAmount(tx.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,12 +352,32 @@ func (gui *Gui) update() {
|
|||||||
|
|
||||||
state.UpdateStateObject(object)
|
state.UpdateStateObject(object)
|
||||||
}
|
}
|
||||||
|
case msg := <-chainSyncChan:
|
||||||
|
sync := msg.Resource.(bool)
|
||||||
|
gui.win.Root().ObjectByName("syncProgressIndicator").Set("visible", sync)
|
||||||
|
|
||||||
case <-objectChan:
|
case <-objectChan:
|
||||||
gui.loadAddressBook()
|
gui.loadAddressBook()
|
||||||
case <-peerChan:
|
case <-peerChan:
|
||||||
gui.setPeerInfo()
|
gui.setPeerInfo()
|
||||||
case <-ticker.C:
|
case <-peerUpdateTicker.C:
|
||||||
gui.setPeerInfo()
|
gui.setPeerInfo()
|
||||||
|
case msg := <-miningChan:
|
||||||
|
if msg.Event == "miner:start" {
|
||||||
|
gui.miner = msg.Resource.(*ethminer.Miner)
|
||||||
|
} else {
|
||||||
|
gui.miner = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
case <-generalUpdateTicker.C:
|
||||||
|
statusText := "#" + gui.eth.BlockChain().CurrentBlock.Number.String()
|
||||||
|
if gui.miner != nil {
|
||||||
|
pow := gui.miner.GetPow()
|
||||||
|
if pow.GetHashrate() != 0 {
|
||||||
|
statusText = "Mining @ " + strconv.FormatInt(pow.GetHashrate(), 10) + "Khash - " + statusText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastBlockLabel.Set("text", statusText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -330,35 +391,41 @@ func (gui *Gui) setPeerInfo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) privateKey() string {
|
||||||
|
return ethutil.Bytes2Hex(gui.eth.KeyManager().PrivateKey())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) address() []byte {
|
||||||
|
return gui.eth.KeyManager().Address()
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) RegisterName(name string) {
|
func (gui *Gui) RegisterName(name string) {
|
||||||
keyPair := ethutil.GetKeyRing().Get(0)
|
name = fmt.Sprintf("\"register\"\n\"%s\"", name)
|
||||||
name = fmt.Sprintf("\"%s\"\n1", name)
|
|
||||||
gui.pub.Transact(ethutil.Hex(keyPair.PrivateKey), "namereg", "1000", "1000000", "150", name)
|
gui.pub.Transact(gui.privateKey(), "NameReg", "", "10000", "10000000000000", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) {
|
func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) {
|
||||||
keyPair := ethutil.GetKeyRing().Get(0)
|
return gui.pub.Transact(gui.privateKey(), recipient, value, gas, gasPrice, data)
|
||||||
|
|
||||||
return gui.pub.Transact(ethutil.Hex(keyPair.PrivateKey), recipient, value, gas, gasPrice, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) {
|
func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) {
|
||||||
keyPair := ethutil.GetKeyRing().Get(0)
|
return gui.pub.Transact(gui.privateKey(), recipient, value, gas, gasPrice, data)
|
||||||
|
|
||||||
return gui.pub.Transact(ethutil.Hex(keyPair.PrivateKey), recipient, value, gas, gasPrice, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) ChangeClientId(id string) {
|
func (gui *Gui) SetCustomIdentifier(customIdentifier string) {
|
||||||
ethutil.Config.SetIdentifier(id)
|
gui.clientIdentity.SetCustomIdentifier(customIdentifier)
|
||||||
|
gui.config.Save("id", customIdentifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) ClientId() string {
|
func (gui *Gui) GetCustomIdentifier() string {
|
||||||
return ethutil.Config.Identifier
|
return gui.clientIdentity.GetCustomIdentifier()
|
||||||
}
|
}
|
||||||
|
|
||||||
// functions that allow Gui to implement interface ethlog.LogSystem
|
// functions that allow Gui to implement interface ethlog.LogSystem
|
||||||
func (gui *Gui) SetLogLevel(level ethlog.LogLevel) {
|
func (gui *Gui) SetLogLevel(level ethlog.LogLevel) {
|
||||||
gui.logLevel = level
|
gui.logLevel = level
|
||||||
|
gui.config.Save("loglevel", level)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) GetLogLevel() ethlog.LogLevel {
|
func (gui *Gui) GetLogLevel() ethlog.LogLevel {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ethui
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/go-qml/qml"
|
"github.com/go-qml/qml"
|
||||||
"github.com/howeyc/fsnotify"
|
"github.com/howeyc/fsnotify"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@@ -59,7 +58,7 @@ func (app *HtmlApplication) RootFolder() string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return path.Dir(folder.RequestURI())
|
return path.Dir(ethutil.WindonizePath(folder.RequestURI()))
|
||||||
}
|
}
|
||||||
func (app *HtmlApplication) RecursiveFolders() []os.FileInfo {
|
func (app *HtmlApplication) RecursiveFolders() []os.FileInfo {
|
||||||
files, _ := ioutil.ReadDir(app.RootFolder())
|
files, _ := ioutil.ReadDir(app.RootFolder())
|
||||||
@@ -77,11 +76,13 @@ func (app *HtmlApplication) NewWatcher(quitChan chan bool) {
|
|||||||
|
|
||||||
app.watcher, err = fsnotify.NewWatcher()
|
app.watcher, err = fsnotify.NewWatcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Infoln("Could not create new auto-reload watcher:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = app.watcher.Watch(app.RootFolder())
|
err = app.watcher.Watch(app.RootFolder())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
logger.Infoln("Could not start auto-reload watcher:", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
for _, folder := range app.RecursiveFolders() {
|
for _, folder := range app.RecursiveFolders() {
|
||||||
fullPath := app.RootFolder() + "/" + folder.Name()
|
fullPath := app.RootFolder() + "/" + folder.Name()
|
||||||
@@ -116,7 +117,7 @@ func (app *HtmlApplication) Window() *qml.Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *HtmlApplication) NewBlock(block *ethchain.Block) {
|
func (app *HtmlApplication) NewBlock(block *ethchain.Block) {
|
||||||
b := ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())}
|
b := ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Bytes2Hex(block.Hash())}
|
||||||
app.webView.Call("onNewBlockCb", b)
|
app.webView.Call("onNewBlockCb", b)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2,18 +2,23 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/eth-go/ethlog"
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
"github.com/ethereum/go-ethereum/ethereal/ui"
|
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
"github.com/go-qml/qml"
|
"github.com/go-qml/qml"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
const (
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
ClientIdentifier = "Ethereal"
|
||||||
|
Version = "0.5.17"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Leave QT on top at ALL times. Qt Needs to be initialized from the main thread
|
||||||
qml.Init(nil)
|
qml.Init(nil)
|
||||||
|
|
||||||
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
||||||
var interrupted = false
|
var interrupted = false
|
||||||
utils.RegisterInterrupt(func(os.Signal) {
|
utils.RegisterInterrupt(func(os.Signal) {
|
||||||
interrupted = true
|
interrupted = true
|
||||||
@@ -23,16 +28,23 @@ func main() {
|
|||||||
|
|
||||||
// precedence: code-internal flag default < config file < environment variables < command line
|
// precedence: code-internal flag default < config file < environment variables < command line
|
||||||
Init() // parsing command line
|
Init() // parsing command line
|
||||||
utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH")
|
|
||||||
|
config := utils.InitConfig(ConfigFile, Datadir, "ETH")
|
||||||
|
|
||||||
utils.InitDataDir(Datadir)
|
utils.InitDataDir(Datadir)
|
||||||
|
|
||||||
utils.InitLogging(Datadir, LogFile, LogLevel, DebugFile)
|
utils.InitLogging(Datadir, LogFile, LogLevel, DebugFile)
|
||||||
|
|
||||||
ethereum := utils.NewEthereum(UseUPnP, OutboundPort, MaxPeer)
|
db := utils.NewDatabase()
|
||||||
|
|
||||||
|
keyManager := utils.NewKeyManager(KeyStore, Datadir, db)
|
||||||
|
|
||||||
// create, import, export keys
|
// create, import, export keys
|
||||||
utils.KeyTasks(GenAddr, ImportKey, ExportKey, NonInteractive)
|
utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
|
||||||
|
|
||||||
|
clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier)
|
||||||
|
|
||||||
|
ethereum := utils.NewEthereum(db, clientIdentity, keyManager, UseUPnP, OutboundPort, MaxPeer)
|
||||||
|
|
||||||
if ShowGenesis {
|
if ShowGenesis {
|
||||||
utils.ShowGenesis(ethereum)
|
utils.ShowGenesis(ethereum)
|
||||||
@@ -42,7 +54,7 @@ func main() {
|
|||||||
utils.StartRpc(ethereum, RpcPort)
|
utils.StartRpc(ethereum, RpcPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
gui := ethui.New(ethereum, LogLevel)
|
gui := NewWindow(ethereum, config, clientIdentity, KeyRing, LogLevel)
|
||||||
|
|
||||||
utils.RegisterInterrupt(func(os.Signal) {
|
utils.RegisterInterrupt(func(os.Signal) {
|
||||||
gui.Stop()
|
gui.Stop()
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package ethui
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/eth-go/ethchain"
|
"github.com/ethereum/eth-go/ethchain"
|
||||||
"github.com/ethereum/eth-go/ethpub"
|
"github.com/ethereum/eth-go/ethpub"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/go-qml/qml"
|
"github.com/go-qml/qml"
|
||||||
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
type QmlApplication struct {
|
type QmlApplication struct {
|
||||||
@@ -20,7 +21,14 @@ func NewQmlApplication(path string, lib *UiLib) *QmlApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *QmlApplication) Create() error {
|
func (app *QmlApplication) Create() error {
|
||||||
component, err := app.engine.LoadFile(app.path)
|
path := string(app.path)
|
||||||
|
|
||||||
|
// For some reason for windows we get /c:/path/to/something, windows doesn't like the first slash but is fine with the others so we are removing it
|
||||||
|
if string(app.path[0]) == "/" && runtime.GOOS == "windows" {
|
||||||
|
path = app.path[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
component, err := app.engine.LoadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnln(err)
|
logger.Warnln(err)
|
||||||
}
|
}
|
||||||
@@ -38,7 +46,7 @@ func (app *QmlApplication) NewWatcher(quitChan chan bool) {
|
|||||||
|
|
||||||
// Events
|
// Events
|
||||||
func (app *QmlApplication) NewBlock(block *ethchain.Block) {
|
func (app *QmlApplication) NewBlock(block *ethchain.Block) {
|
||||||
pblock := ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())}
|
pblock := ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Bytes2Hex(block.Hash())}
|
||||||
app.win.Call("onNewBlockCb", pblock)
|
app.win.Call("onNewBlockCb", pblock)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package ethui
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/ethereum/eth-go/ethchain"
|
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
|
||||||
"github.com/obscuren/secp256k1-go"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type EthLib struct {
|
|
||||||
stateManager *ethchain.StateManager
|
|
||||||
blockChain *ethchain.BlockChain
|
|
||||||
txPool *ethchain.TxPool
|
|
||||||
Db *Debugger
|
|
||||||
}
|
|
||||||
|
|
||||||
func (lib *EthLib) ImportAndSetPrivKey(privKey string) bool {
|
|
||||||
fmt.Println(privKey)
|
|
||||||
mnemonic := strings.Split(privKey, " ")
|
|
||||||
if len(mnemonic) == 24 {
|
|
||||||
fmt.Println("Got mnemonic key, importing.")
|
|
||||||
key := ethutil.MnemonicDecode(mnemonic)
|
|
||||||
utils.ImportPrivateKey(key)
|
|
||||||
} else if len(mnemonic) == 1 {
|
|
||||||
fmt.Println("Got hex key, importing.")
|
|
||||||
utils.ImportPrivateKey(privKey)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Did not recognise format, exiting.")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) {
|
|
||||||
_, prv := secp256k1.GenerateKeyPair()
|
|
||||||
keyPair, err := ethutil.GetKeyRing().NewKeyPair(prv)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mne := ethutil.MnemonicEncode(ethutil.Hex(keyPair.PrivateKey))
|
|
||||||
mnemonicString := strings.Join(mne, " ")
|
|
||||||
return mnemonicString, fmt.Sprintf("%x", keyPair.Address()), ethutil.Hex(keyPair.PrivateKey), ethutil.Hex(keyPair.PublicKey)
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ethui
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/eth-go"
|
"github.com/ethereum/eth-go"
|
||||||
@@ -77,9 +77,9 @@ func (ui *UiLib) AssetPath(p string) string {
|
|||||||
|
|
||||||
func (self *UiLib) StartDbWithContractAndData(contractHash, data string) {
|
func (self *UiLib) StartDbWithContractAndData(contractHash, data string) {
|
||||||
dbWindow := NewDebuggerWindow(self)
|
dbWindow := NewDebuggerWindow(self)
|
||||||
object := self.eth.StateManager().CurrentState().GetStateObject(ethutil.FromHex(contractHash))
|
object := self.eth.StateManager().CurrentState().GetStateObject(ethutil.Hex2Bytes(contractHash))
|
||||||
if len(object.Script()) > 0 {
|
if len(object.Script()) > 0 {
|
||||||
dbWindow.SetCode("0x" + ethutil.Hex(object.Script()))
|
dbWindow.SetCode("0x" + ethutil.Bytes2Hex(object.Script()))
|
||||||
}
|
}
|
||||||
dbWindow.SetData("0x" + data)
|
dbWindow.SetData("0x" + data)
|
||||||
|
|
||||||
@@ -2,13 +2,14 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/eth-go"
|
"github.com/ethereum/eth-go"
|
||||||
|
"github.com/ethereum/go-ethereum/ethereum/repl"
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitJsConsole(ethereum *eth.Ethereum) {
|
func InitJsConsole(ethereum *eth.Ethereum) {
|
||||||
repl := NewJSRepl(ethereum)
|
repl := ethrepl.NewJSRepl(ethereum)
|
||||||
go repl.Start()
|
go repl.Start()
|
||||||
utils.RegisterInterrupt(func(os.Signal) {
|
utils.RegisterInterrupt(func(os.Signal) {
|
||||||
repl.Stop()
|
repl.Stop()
|
||||||
@@ -24,7 +25,7 @@ func ExecJsFile(ethereum *eth.Ethereum, InputFile string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalln(err)
|
logger.Fatalln(err)
|
||||||
}
|
}
|
||||||
re := NewJSRE(ethereum)
|
re := ethrepl.NewJSRE(ethereum)
|
||||||
utils.RegisterInterrupt(func(os.Signal) {
|
utils.RegisterInterrupt(func(os.Signal) {
|
||||||
re.Stop()
|
re.Stop()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var Identifier string
|
var Identifier string
|
||||||
|
var KeyRing string
|
||||||
|
var DiffTool bool
|
||||||
|
var DiffType string
|
||||||
|
var KeyStore string
|
||||||
var StartRpc bool
|
var StartRpc bool
|
||||||
var RpcPort int
|
var RpcPort int
|
||||||
var UseUPnP bool
|
var UseUPnP bool
|
||||||
@@ -19,8 +23,8 @@ var AddPeer string
|
|||||||
var MaxPeer int
|
var MaxPeer int
|
||||||
var GenAddr bool
|
var GenAddr bool
|
||||||
var UseSeed bool
|
var UseSeed bool
|
||||||
var ImportKey string
|
var SecretFile string
|
||||||
var ExportKey bool
|
var ExportDir string
|
||||||
var NonInteractive bool
|
var NonInteractive bool
|
||||||
var Datadir string
|
var Datadir string
|
||||||
var LogFile string
|
var LogFile string
|
||||||
@@ -47,6 +51,8 @@ func Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
flag.StringVar(&Identifier, "id", "", "Custom client identifier")
|
flag.StringVar(&Identifier, "id", "", "Custom client identifier")
|
||||||
|
flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
|
||||||
|
flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
|
||||||
flag.StringVar(&OutboundPort, "port", "30303", "listening port")
|
flag.StringVar(&OutboundPort, "port", "30303", "listening port")
|
||||||
flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support")
|
flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support")
|
||||||
flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers")
|
flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers")
|
||||||
@@ -55,13 +61,15 @@ func Init() {
|
|||||||
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
||||||
flag.BoolVar(&UseSeed, "seed", true, "seed peers")
|
flag.BoolVar(&UseSeed, "seed", true, "seed peers")
|
||||||
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
||||||
flag.BoolVar(&ExportKey, "export", false, "export private key")
|
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
|
||||||
|
flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
|
||||||
flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
|
flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
|
||||||
flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)")
|
|
||||||
flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
|
flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
|
||||||
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
||||||
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
|
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
|
||||||
flag.IntVar(&LogLevel, "loglevel", int(ethlog.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
|
flag.IntVar(&LogLevel, "loglevel", int(ethlog.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
|
||||||
|
flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
|
||||||
|
flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false")
|
||||||
|
|
||||||
flag.BoolVar(&StartMining, "mine", false, "start dagger mining")
|
flag.BoolVar(&StartMining, "mine", false, "start dagger mining")
|
||||||
flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console")
|
flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console")
|
||||||
|
|||||||
@@ -2,10 +2,16 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/eth-go/ethlog"
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ClientIdentifier = "Ethereum(G)"
|
||||||
|
Version = "0.5.17"
|
||||||
|
)
|
||||||
|
|
||||||
var logger = ethlog.NewLogger("CLI")
|
var logger = ethlog.NewLogger("CLI")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -15,16 +21,30 @@ func main() {
|
|||||||
|
|
||||||
// precedence: code-internal flag default < config file < environment variables < command line
|
// precedence: code-internal flag default < config file < environment variables < command line
|
||||||
Init() // parsing command line
|
Init() // parsing command line
|
||||||
utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH")
|
|
||||||
|
// If the difftool option is selected ignore all other log output
|
||||||
|
if DiffTool {
|
||||||
|
LogLevel = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.InitConfig(ConfigFile, Datadir, "ETH")
|
||||||
|
ethutil.Config.Diff = DiffTool
|
||||||
|
ethutil.Config.DiffType = DiffType
|
||||||
|
|
||||||
utils.InitDataDir(Datadir)
|
utils.InitDataDir(Datadir)
|
||||||
|
|
||||||
utils.InitLogging(Datadir, LogFile, LogLevel, DebugFile)
|
utils.InitLogging(Datadir, LogFile, LogLevel, DebugFile)
|
||||||
|
|
||||||
ethereum := utils.NewEthereum(UseUPnP, OutboundPort, MaxPeer)
|
db := utils.NewDatabase()
|
||||||
|
|
||||||
|
keyManager := utils.NewKeyManager(KeyStore, Datadir, db)
|
||||||
|
|
||||||
// create, import, export keys
|
// create, import, export keys
|
||||||
utils.KeyTasks(GenAddr, ImportKey, ExportKey, NonInteractive)
|
utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
|
||||||
|
|
||||||
|
clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier)
|
||||||
|
|
||||||
|
ethereum := utils.NewEthereum(db, clientIdentity, keyManager, UseUPnP, OutboundPort, MaxPeer)
|
||||||
|
|
||||||
if ShowGenesis {
|
if ShowGenesis {
|
||||||
utils.ShowGenesis(ethereum)
|
utils.ShowGenesis(ethereum)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package ethrepl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -122,12 +122,12 @@ out:
|
|||||||
}
|
}
|
||||||
case object := <-self.changeChan:
|
case object := <-self.changeChan:
|
||||||
if stateObject, ok := object.Resource.(*ethchain.StateObject); ok {
|
if stateObject, ok := object.Resource.(*ethchain.StateObject); ok {
|
||||||
for _, cb := range self.objectCb[ethutil.Hex(stateObject.Address())] {
|
for _, cb := range self.objectCb[ethutil.Bytes2Hex(stateObject.Address())] {
|
||||||
val, _ := self.vm.ToValue(ethpub.NewPStateObject(stateObject))
|
val, _ := self.vm.ToValue(ethpub.NewPStateObject(stateObject))
|
||||||
cb.Call(cb, val)
|
cb.Call(cb, val)
|
||||||
}
|
}
|
||||||
} else if storageObject, ok := object.Resource.(*ethchain.StorageState); ok {
|
} else if storageObject, ok := object.Resource.(*ethchain.StorageState); ok {
|
||||||
for _, cb := range self.objectCb[ethutil.Hex(storageObject.StateAddress)+ethutil.Hex(storageObject.Address)] {
|
for _, cb := range self.objectCb[ethutil.Bytes2Hex(storageObject.StateAddress)+ethutil.Bytes2Hex(storageObject.Address)] {
|
||||||
val, _ := self.vm.ToValue(ethpub.NewPStorageState(storageObject))
|
val, _ := self.vm.ToValue(ethpub.NewPStorageState(storageObject))
|
||||||
cb.Call(cb, val)
|
cb.Call(cb, val)
|
||||||
}
|
}
|
||||||
@@ -178,12 +178,12 @@ func (self *JSRE) watch(call otto.FunctionCall) otto.Value {
|
|||||||
if storageCallback {
|
if storageCallback {
|
||||||
self.objectCb[addr+storageAddr] = append(self.objectCb[addr+storageAddr], cb)
|
self.objectCb[addr+storageAddr] = append(self.objectCb[addr+storageAddr], cb)
|
||||||
|
|
||||||
event := "storage:" + string(ethutil.FromHex(addr)) + ":" + string(ethutil.FromHex(storageAddr))
|
event := "storage:" + string(ethutil.Hex2Bytes(addr)) + ":" + string(ethutil.Hex2Bytes(storageAddr))
|
||||||
self.ethereum.Reactor().Subscribe(event, self.changeChan)
|
self.ethereum.Reactor().Subscribe(event, self.changeChan)
|
||||||
} else {
|
} else {
|
||||||
self.objectCb[addr] = append(self.objectCb[addr], cb)
|
self.objectCb[addr] = append(self.objectCb[addr], cb)
|
||||||
|
|
||||||
event := "object:" + string(ethutil.FromHex(addr))
|
event := "object:" + string(ethutil.Hex2Bytes(addr))
|
||||||
self.ethereum.Reactor().Subscribe(event, self.changeChan)
|
self.ethereum.Reactor().Subscribe(event, self.changeChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ func (self *JSRE) execBlock(call otto.FunctionCall) otto.Value {
|
|||||||
return otto.UndefinedValue()
|
return otto.UndefinedValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = utils.BlockDo(self.ethereum, ethutil.FromHex(hash))
|
err = utils.BlockDo(self.ethereum, ethutil.Hex2Bytes(hash))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return otto.FalseValue()
|
return otto.FalseValue()
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package ethrepl
|
||||||
|
|
||||||
const jsLib = `
|
const jsLib = `
|
||||||
function pp(object) {
|
function pp(object) {
|
||||||
83
ethereum/repl/repl.go
Normal file
83
ethereum/repl/repl.go
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
package ethrepl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"github.com/ethereum/eth-go"
|
||||||
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
|
var logger = ethlog.NewLogger("REPL")
|
||||||
|
|
||||||
|
type Repl interface {
|
||||||
|
Start()
|
||||||
|
Stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
type JSRepl struct {
|
||||||
|
re *JSRE
|
||||||
|
|
||||||
|
prompt string
|
||||||
|
|
||||||
|
history *os.File
|
||||||
|
|
||||||
|
running bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewJSRepl(ethereum *eth.Ethereum) *JSRepl {
|
||||||
|
hist, err := os.OpenFile(path.Join(ethutil.Config.ExecPath, "history"), os.O_RDWR|os.O_CREATE, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &JSRepl{re: NewJSRE(ethereum), prompt: "> ", history: hist}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *JSRepl) Start() {
|
||||||
|
if !self.running {
|
||||||
|
self.running = true
|
||||||
|
logger.Infoln("init JS Console")
|
||||||
|
reader := bufio.NewReader(self.history)
|
||||||
|
for {
|
||||||
|
line, err := reader.ReadString('\n')
|
||||||
|
if err != nil && err == io.EOF {
|
||||||
|
break
|
||||||
|
} else if err != nil {
|
||||||
|
fmt.Println("error reading history", err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
addHistory(line[:len(line)-1])
|
||||||
|
}
|
||||||
|
self.read()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *JSRepl) Stop() {
|
||||||
|
if self.running {
|
||||||
|
self.running = false
|
||||||
|
self.re.Stop()
|
||||||
|
logger.Infoln("exit JS Console")
|
||||||
|
self.history.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *JSRepl) parseInput(code string) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
fmt.Println("[native] error", r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
value, err := self.re.Run(code)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.PrintValue(value)
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package ethrepl
|
||||||
|
|
||||||
// #cgo darwin CFLAGS: -I/usr/local/opt/readline/include
|
// #cgo darwin CFLAGS: -I/usr/local/opt/readline/include
|
||||||
// #cgo darwin LDFLAGS: -L/usr/local/opt/readline/lib
|
// #cgo darwin LDFLAGS: -L/usr/local/opt/readline/lib
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package ethrepl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@@ -1,84 +1,26 @@
|
|||||||
package main
|
package ethrepl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/eth-go"
|
|
||||||
"github.com/ethereum/eth-go/ethpub"
|
"github.com/ethereum/eth-go/ethpub"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/obscuren/otto"
|
"github.com/obscuren/otto"
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Repl interface {
|
type JSStateObject struct {
|
||||||
Start()
|
*ethpub.PStateObject
|
||||||
Stop()
|
eth *JSEthereum
|
||||||
}
|
}
|
||||||
|
|
||||||
type JSRepl struct {
|
func (self *JSStateObject) EachStorage(call otto.FunctionCall) otto.Value {
|
||||||
re *JSRE
|
cb := call.Argument(0)
|
||||||
|
self.PStateObject.EachStorage(func(key string, value *ethutil.Value) {
|
||||||
|
value.Decode()
|
||||||
|
|
||||||
prompt string
|
cb.Call(self.eth.toVal(self), self.eth.toVal(key), self.eth.toVal(ethutil.Bytes2Hex(value.Bytes())))
|
||||||
|
})
|
||||||
|
|
||||||
history *os.File
|
return otto.UndefinedValue()
|
||||||
|
|
||||||
running bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewJSRepl(ethereum *eth.Ethereum) *JSRepl {
|
|
||||||
hist, err := os.OpenFile(path.Join(ethutil.Config.ExecPath, "history"), os.O_RDWR|os.O_CREATE, os.ModePerm)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &JSRepl{re: NewJSRE(ethereum), prompt: "> ", history: hist}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *JSRepl) Start() {
|
|
||||||
if !self.running {
|
|
||||||
self.running = true
|
|
||||||
logger.Infoln("init JS Console")
|
|
||||||
reader := bufio.NewReader(self.history)
|
|
||||||
for {
|
|
||||||
line, err := reader.ReadString('\n')
|
|
||||||
if err != nil && err == io.EOF {
|
|
||||||
break
|
|
||||||
} else if err != nil {
|
|
||||||
fmt.Println("error reading history", err)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
addHistory(line[:len(line)-1])
|
|
||||||
}
|
|
||||||
self.read()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *JSRepl) Stop() {
|
|
||||||
if self.running {
|
|
||||||
self.running = false
|
|
||||||
self.re.Stop()
|
|
||||||
logger.Infoln("exit JS Console")
|
|
||||||
self.history.Close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *JSRepl) parseInput(code string) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
fmt.Println("[native] error", r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
value, err := self.re.Run(code)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
self.PrintValue(value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The JSEthereum object attempts to wrap the PEthereum object and returns
|
// The JSEthereum object attempts to wrap the PEthereum object and returns
|
||||||
@@ -110,7 +52,7 @@ func (self *JSEthereum) GetKey() otto.Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *JSEthereum) GetStateObject(addr string) otto.Value {
|
func (self *JSEthereum) GetStateObject(addr string) otto.Value {
|
||||||
return self.toVal(self.PEthereum.GetStateObject(addr))
|
return self.toVal(&JSStateObject{self.PEthereum.GetStateObject(addr), self})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *JSEthereum) GetStateKeyVals(addr string) otto.Value {
|
func (self *JSEthereum) GetStateKeyVals(addr string) otto.Value {
|
||||||
57
install.sh
Executable file
57
install.sh
Executable file
@@ -0,0 +1,57 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ "$1" == "" ]; then
|
||||||
|
echo "Usage $0 executable branch ethereum develop"
|
||||||
|
echo "executable ethereum or ethereal"
|
||||||
|
echo "branch develop or master"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
exe=$1
|
||||||
|
branch=$2
|
||||||
|
|
||||||
|
# Test if go is installed
|
||||||
|
command -v go >/dev/null 2>&1 || { echo >&2 "Unable to find 'go'. This script requires go."; exit 1; }
|
||||||
|
|
||||||
|
# Test if $GOPATH is set
|
||||||
|
if [ "$GOPATH" == "" ]; then
|
||||||
|
echo "\$GOPATH not set"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "go get -u -d github.com/ethereum/go-ethereum/$exe"
|
||||||
|
go get -v -u -d github.com/ethereum/go-ethereum/$exe
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
echo "go get failed"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "serpent-go"
|
||||||
|
cd $GOPATH/src/github.com/obscuren/serpent-go
|
||||||
|
|
||||||
|
echo "init submodule"
|
||||||
|
git submodule init
|
||||||
|
git submodule update
|
||||||
|
|
||||||
|
echo "eth-go"
|
||||||
|
cd $GOPATH/src/github.com/ethereum/eth-go
|
||||||
|
git checkout $branch
|
||||||
|
|
||||||
|
echo "go-ethereum"
|
||||||
|
cd $GOPATH/src/github.com/ethereum/go-ethereum/$exe
|
||||||
|
git checkout $branch
|
||||||
|
|
||||||
|
if [ "$exe" == "ethereal" ]; then
|
||||||
|
echo "Building ethereal GUI. Assuming Qt is installed. If this step"
|
||||||
|
echo "fails; please refer to: https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum(Go)"
|
||||||
|
else
|
||||||
|
echo "Building ethereum CLI."
|
||||||
|
fi
|
||||||
|
|
||||||
|
go install
|
||||||
|
if [ $? == 0 ]; then
|
||||||
|
echo "go install failed"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "done. Please run $exe :-)"
|
||||||
160
utils/cmd.go
160
utils/cmd.go
@@ -1,19 +1,24 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bitbucket.org/kardianos/osext"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/eth-go"
|
"github.com/ethereum/eth-go"
|
||||||
|
"github.com/ethereum/eth-go/ethcrypto"
|
||||||
|
"github.com/ethereum/eth-go/ethdb"
|
||||||
"github.com/ethereum/eth-go/ethlog"
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
"github.com/ethereum/eth-go/ethminer"
|
"github.com/ethereum/eth-go/ethminer"
|
||||||
"github.com/ethereum/eth-go/ethpub"
|
"github.com/ethereum/eth-go/ethpub"
|
||||||
"github.com/ethereum/eth-go/ethrpc"
|
"github.com/ethereum/eth-go/ethrpc"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
|
"github.com/ethereum/eth-go/ethwire"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -77,7 +82,7 @@ func InitDataDir(Datadir string) {
|
|||||||
_, err := os.Stat(Datadir)
|
_, err := os.Stat(Datadir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
fmt.Printf("Debug logging directory '%s' doesn't exist, creating it\n", Datadir)
|
fmt.Printf("Data directory '%s' doesn't exist, creating it\n", Datadir)
|
||||||
os.Mkdir(Datadir, 0777)
|
os.Mkdir(Datadir, 0777)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,19 +102,36 @@ func InitLogging(Datadir string, LogFile string, LogLevel int, DebugFile string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitConfig(ConfigFile string, Datadir string, Identifier string, EnvPrefix string) {
|
func InitConfig(ConfigFile string, Datadir string, EnvPrefix string) *ethutil.ConfigManager {
|
||||||
InitDataDir(Datadir)
|
InitDataDir(Datadir)
|
||||||
ethutil.ReadConfig(ConfigFile, Datadir, Identifier, EnvPrefix)
|
return ethutil.ReadConfig(ConfigFile, Datadir, EnvPrefix)
|
||||||
ethutil.Config.Set("rpcport", "700")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func exit(status int) {
|
func exit(err error) {
|
||||||
|
status := 0
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
logger.Errorln("Fatal: ", err)
|
||||||
|
status = 1
|
||||||
|
}
|
||||||
ethlog.Flush()
|
ethlog.Flush()
|
||||||
os.Exit(status)
|
os.Exit(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEthereum(UseUPnP bool, OutboundPort string, MaxPeer int) *eth.Ethereum {
|
func NewDatabase() ethutil.Database {
|
||||||
ethereum, err := eth.New(eth.CapDefault, UseUPnP)
|
db, err := ethdb.NewLDBDatabase("database")
|
||||||
|
if err != nil {
|
||||||
|
exit(err)
|
||||||
|
}
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewClientIdentity(clientIdentifier, version, customIdentifier string) *ethwire.SimpleClientIdentity {
|
||||||
|
return ethwire.NewSimpleClientIdentity(clientIdentifier, version, customIdentifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEthereum(db ethutil.Database, clientIdentity ethwire.ClientIdentity, keyManager *ethcrypto.KeyManager, usePnp bool, OutboundPort string, MaxPeer int) *eth.Ethereum {
|
||||||
|
ethereum, err := eth.New(db, clientIdentity, keyManager, eth.CapDefault, usePnp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalln("eth start err:", err)
|
logger.Fatalln("eth start err:", err)
|
||||||
}
|
}
|
||||||
@@ -119,7 +141,7 @@ func NewEthereum(UseUPnP bool, OutboundPort string, MaxPeer int) *eth.Ethereum {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func StartEthereum(ethereum *eth.Ethereum, UseSeed bool) {
|
func StartEthereum(ethereum *eth.Ethereum, UseSeed bool) {
|
||||||
logger.Infof("Starting Ethereum v%s", ethutil.Config.Ver)
|
logger.Infof("Starting %s", ethereum.ClientIdentity())
|
||||||
ethereum.Start(UseSeed)
|
ethereum.Start(UseSeed)
|
||||||
RegisterInterrupt(func(sig os.Signal) {
|
RegisterInterrupt(func(sig os.Signal) {
|
||||||
ethereum.Stop()
|
ethereum.Stop()
|
||||||
@@ -129,50 +151,76 @@ func StartEthereum(ethereum *eth.Ethereum, UseSeed bool) {
|
|||||||
|
|
||||||
func ShowGenesis(ethereum *eth.Ethereum) {
|
func ShowGenesis(ethereum *eth.Ethereum) {
|
||||||
logger.Infoln(ethereum.BlockChain().Genesis())
|
logger.Infoln(ethereum.BlockChain().Genesis())
|
||||||
exit(0)
|
exit(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func KeyTasks(GenAddr bool, ImportKey string, ExportKey bool, NonInteractive bool) {
|
func NewKeyManager(KeyStore string, Datadir string, db ethutil.Database) *ethcrypto.KeyManager {
|
||||||
|
var keyManager *ethcrypto.KeyManager
|
||||||
|
switch {
|
||||||
|
case KeyStore == "db":
|
||||||
|
keyManager = ethcrypto.NewDBKeyManager(db)
|
||||||
|
case KeyStore == "file":
|
||||||
|
keyManager = ethcrypto.NewFileKeyManager(Datadir)
|
||||||
|
default:
|
||||||
|
exit(fmt.Errorf("unknown keystore type: %s", KeyStore))
|
||||||
|
}
|
||||||
|
return keyManager
|
||||||
|
}
|
||||||
|
|
||||||
|
func DefaultAssetPath() string {
|
||||||
|
var assetPath string
|
||||||
|
// If the current working directory is the go-ethereum dir
|
||||||
|
// assume a debug build and use the source directory as
|
||||||
|
// asset directory.
|
||||||
|
pwd, _ := os.Getwd()
|
||||||
|
if pwd == path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "ethereal") {
|
||||||
|
assetPath = path.Join(pwd, "assets")
|
||||||
|
} else {
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "darwin":
|
||||||
|
// Get Binary Directory
|
||||||
|
exedir, _ := osext.ExecutableFolder()
|
||||||
|
assetPath = filepath.Join(exedir, "../Resources")
|
||||||
|
case "linux":
|
||||||
|
assetPath = "/usr/share/ethereal"
|
||||||
|
case "windows":
|
||||||
|
assetPath = "./assets"
|
||||||
|
default:
|
||||||
|
assetPath = "."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return assetPath
|
||||||
|
}
|
||||||
|
|
||||||
|
func KeyTasks(keyManager *ethcrypto.KeyManager, KeyRing string, GenAddr bool, SecretFile string, ExportDir string, NonInteractive bool) {
|
||||||
|
ethcrypto.InitWords(DefaultAssetPath()) // Init mnemonic word list
|
||||||
|
|
||||||
|
var err error
|
||||||
switch {
|
switch {
|
||||||
case GenAddr:
|
case GenAddr:
|
||||||
if NonInteractive || confirm("This action overwrites your old private key.") {
|
if NonInteractive || confirm("This action overwrites your old private key.") {
|
||||||
CreateKeyPair(true)
|
err = keyManager.Init(KeyRing, 0, true)
|
||||||
}
|
}
|
||||||
exit(0)
|
exit(err)
|
||||||
case len(ImportKey) > 0:
|
case len(SecretFile) > 0:
|
||||||
|
SecretFile = ethutil.ExpandHomePath(SecretFile)
|
||||||
|
|
||||||
if NonInteractive || confirm("This action overwrites your old private key.") {
|
if NonInteractive || confirm("This action overwrites your old private key.") {
|
||||||
// import should be from file
|
err = keyManager.InitFromSecretsFile(KeyRing, 0, SecretFile)
|
||||||
mnemonic := strings.Split(ImportKey, " ")
|
|
||||||
if len(mnemonic) == 24 {
|
|
||||||
logger.Infoln("Got mnemonic key, importing.")
|
|
||||||
key := ethutil.MnemonicDecode(mnemonic)
|
|
||||||
ImportPrivateKey(key)
|
|
||||||
} else if len(mnemonic) == 1 {
|
|
||||||
logger.Infoln("Got hex key, importing.")
|
|
||||||
ImportPrivateKey(ImportKey)
|
|
||||||
} else {
|
|
||||||
logger.Errorln("Did not recognise format, exiting.")
|
|
||||||
}
|
}
|
||||||
|
exit(err)
|
||||||
|
case len(ExportDir) > 0:
|
||||||
|
err = keyManager.Init(KeyRing, 0, false)
|
||||||
|
if err == nil {
|
||||||
|
err = keyManager.Export(ExportDir)
|
||||||
}
|
}
|
||||||
exit(0)
|
exit(err)
|
||||||
case ExportKey: // this should be exporting to a filename
|
|
||||||
keyPair := ethutil.GetKeyRing().Get(0)
|
|
||||||
fmt.Printf(`
|
|
||||||
Generating new address and keypair.
|
|
||||||
Please keep your keys somewhere save.
|
|
||||||
|
|
||||||
++++++++++++++++ KeyRing +++++++++++++++++++
|
|
||||||
addr: %x
|
|
||||||
prvk: %x
|
|
||||||
pubk: %x
|
|
||||||
++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
save these words so you can restore your account later: %s
|
|
||||||
`, keyPair.Address(), keyPair.PrivateKey, keyPair.PublicKey)
|
|
||||||
|
|
||||||
exit(0)
|
|
||||||
default:
|
default:
|
||||||
// Creates a keypair if none exists
|
// Creates a keypair if none exists
|
||||||
CreateKeyPair(false)
|
err = keyManager.Init(KeyRing, 0, false)
|
||||||
|
if err != nil {
|
||||||
|
exit(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,26 +234,30 @@ func StartRpc(ethereum *eth.Ethereum, RpcPort int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var miner ethminer.Miner
|
var miner *ethminer.Miner
|
||||||
|
|
||||||
|
func GetMiner() *ethminer.Miner {
|
||||||
|
return miner
|
||||||
|
}
|
||||||
|
|
||||||
func StartMining(ethereum *eth.Ethereum) bool {
|
func StartMining(ethereum *eth.Ethereum) bool {
|
||||||
if !ethereum.Mining {
|
if !ethereum.Mining {
|
||||||
ethereum.Mining = true
|
ethereum.Mining = true
|
||||||
|
|
||||||
if ethutil.GetKeyRing().Len() == 0 {
|
addr := ethereum.KeyManager().Address()
|
||||||
logger.Errorln("No address found, can't start mining")
|
|
||||||
ethereum.Mining = false
|
|
||||||
return true //????
|
|
||||||
}
|
|
||||||
keyPair := ethutil.GetKeyRing().Get(0)
|
|
||||||
addr := keyPair.Address()
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
if miner == nil {
|
||||||
miner = ethminer.NewDefaultMiner(addr, ethereum)
|
miner = ethminer.NewDefaultMiner(addr, ethereum)
|
||||||
|
}
|
||||||
|
|
||||||
// Give it some time to connect with peers
|
// Give it some time to connect with peers
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
|
for !ethereum.IsUpToDate() {
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
logger.Infoln("Miner started")
|
logger.Infoln("Miner started")
|
||||||
miner := ethminer.NewDefaultMiner(addr, ethereum)
|
|
||||||
miner.Start()
|
miner.Start()
|
||||||
}()
|
}()
|
||||||
RegisterInterrupt(func(os.Signal) {
|
RegisterInterrupt(func(os.Signal) {
|
||||||
@@ -217,12 +269,16 @@ func StartMining(ethereum *eth.Ethereum) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func StopMining(ethereum *eth.Ethereum) bool {
|
func StopMining(ethereum *eth.Ethereum) bool {
|
||||||
if ethereum.Mining {
|
if ethereum.Mining && miner != nil {
|
||||||
miner.Stop()
|
miner.Stop()
|
||||||
|
|
||||||
logger.Infoln("Miner stopped")
|
logger.Infoln("Miner stopped")
|
||||||
|
|
||||||
ethereum.Mining = false
|
ethereum.Mining = false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
108
utils/keys.go
108
utils/keys.go
@@ -1,108 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
|
||||||
"github.com/obscuren/secp256k1-go"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CreateKeyPair(force bool) {
|
|
||||||
if force {
|
|
||||||
ethutil.GetKeyRing().Reset()
|
|
||||||
fmt.Println("resetting")
|
|
||||||
}
|
|
||||||
|
|
||||||
if ethutil.GetKeyRing().Get(0) == nil {
|
|
||||||
_, prv := secp256k1.GenerateKeyPair()
|
|
||||||
|
|
||||||
keyPair, err := ethutil.GetKeyRing().NewKeyPair(prv)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mne := ethutil.MnemonicEncode(ethutil.Hex(keyPair.PrivateKey))
|
|
||||||
|
|
||||||
fmt.Printf(`
|
|
||||||
Generating new address and keypair.
|
|
||||||
Please keep your keys somewhere save.
|
|
||||||
|
|
||||||
++++++++++++++++ KeyRing +++++++++++++++++++
|
|
||||||
addr: %x
|
|
||||||
prvk: %x
|
|
||||||
pubk: %x
|
|
||||||
++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
save these words so you can restore your account later: %s
|
|
||||||
`, keyPair.Address(), keyPair.PrivateKey, keyPair.PublicKey, mne)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ImportPrivateKey(sec string) {
|
|
||||||
ethutil.GetKeyRing().Reset()
|
|
||||||
|
|
||||||
keyPair, err := ethutil.GetKeyRing().NewKeyPair(ethutil.FromHex(sec))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mne := ethutil.MnemonicEncode(ethutil.Hex(keyPair.PrivateKey))
|
|
||||||
|
|
||||||
fmt.Printf(`
|
|
||||||
Generating new address and keypair.
|
|
||||||
Please keep your keys somewhere save.
|
|
||||||
|
|
||||||
++++++++++++++++ KeyRing +++++++++++++++++++
|
|
||||||
addr: %x
|
|
||||||
prvk: %x
|
|
||||||
pubk: %x
|
|
||||||
++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
save these words so you can restore your account later: %s
|
|
||||||
`, keyPair.Address(), keyPair.PrivateKey, keyPair.PublicKey, mne)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
func CreateKeyPair(force bool) {
|
|
||||||
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
|
|
||||||
if len(data) == 0 || force {
|
|
||||||
pub, prv := secp256k1.GenerateKeyPair()
|
|
||||||
pair := ðutil.Key{PrivateKey: prv, PublicKey: pub}
|
|
||||||
ethutil.Config.Db.Put([]byte("KeyRing"), pair.RlpEncode())
|
|
||||||
mne := ethutil.MnemonicEncode(ethutil.Hex(prv))
|
|
||||||
|
|
||||||
fmt.Printf(`
|
|
||||||
Generating new address and keypair.
|
|
||||||
Please keep your keys somewhere save.
|
|
||||||
|
|
||||||
++++++++++++++++ KeyRing +++++++++++++++++++
|
|
||||||
addr: %x
|
|
||||||
prvk: %x
|
|
||||||
pubk: %x
|
|
||||||
++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
save these words so you can restore your account later: %s
|
|
||||||
`, pair.Address(), prv, pub, mne)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
func ImportPrivateKey(prvKey string) {
|
|
||||||
key := ethutil.FromHex(prvKey)
|
|
||||||
msg := []byte("tmp")
|
|
||||||
// Couldn't think of a better way to get the pub key
|
|
||||||
sig, _ := secp256k1.Sign(msg, key)
|
|
||||||
pub, _ := secp256k1.RecoverPubkey(msg, sig)
|
|
||||||
pair := ðutil.Key{PrivateKey: key, PublicKey: pub}
|
|
||||||
ethutil.Config.Db.Put([]byte("KeyRing"), pair.RlpEncode())
|
|
||||||
|
|
||||||
fmt.Printf(`
|
|
||||||
Importing private key
|
|
||||||
|
|
||||||
++++++++++++++++ KeyRing +++++++++++++++++++
|
|
||||||
addr: %x
|
|
||||||
prvk: %x
|
|
||||||
pubk: %x
|
|
||||||
++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
|
|
||||||
`, pair.Address(), key, pub)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
Reference in New Issue
Block a user