Compare commits
130 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
3777ead25e | |||
a68bfd215f | |||
fd89df4d38 | |||
91bdf9e801 | |||
ae5ace1619 | |||
b57ee87485 | |||
8100903d92 | |||
648c418fcd | |||
21d86ca486 | |||
c0a05fcf89 | |||
b89076faa2 | |||
2f96652bb4 | |||
b3367ec0e3 | |||
9a06efd080 | |||
6763d28a17 | |||
bf57e9603b | |||
096427c3b1 | |||
8ee1abecb9 | |||
39c0f7f386 | |||
1268413ba7 | |||
08de13a57b | |||
9654b80912 | |||
1e965cb8f5 | |||
fd1ddbce68 | |||
a13aa873c2 | |||
17e8d7519b | |||
bcb88e7352 | |||
f6aabb7a90 | |||
6f09a3e820 | |||
34284b7532 | |||
1024766514 | |||
456167aca0 | |||
c67cdab221 | |||
d060ae6a36 | |||
7bcf875c57 | |||
f90001e938 | |||
176b780251 | |||
2408e38218 | |||
cba4796311 | |||
65cbea2b6a | |||
c89566a42f | |||
3ec0c719b9 | |||
a32a15ad93 | |||
e517fb5f9d | |||
98335d2040 | |||
c1220e8729 | |||
3744151359 | |||
7ab735eb02 | |||
ef1b923b31 | |||
50fdfb127a | |||
e7a22af0e6 | |||
1d300bbc10 | |||
e36badd744 | |||
57e3b1b093 | |||
0ee258bb75 | |||
66199497a0 | |||
aa8a86f0a6 | |||
d929c63474 | |||
ba3623d0cc | |||
cc20b0e3a0 | |||
a107a5db05 | |||
964587b14a | |||
7843390ecd | |||
307fe4a3cd | |||
3755616a29 | |||
cc1d043423 | |||
9e411d785b | |||
a6f4eef1da | |||
98811f11e5 | |||
d6acb74ac9 | |||
397e99fcc6 | |||
be27309dbb | |||
4dfce5d347 | |||
0bdb0a9d58 | |||
5f28013f79 | |||
65c5a20e1c | |||
1020d7ff67 | |||
e7c9b86a5a | |||
0938b56829 | |||
fcbf99a30a | |||
40d72ff40b | |||
efadfbfb17 | |||
8ee6574d12 | |||
efb3ee044b | |||
0b4c42d756 | |||
f0f205004c | |||
f802e17626 | |||
8fab7ce37d | |||
44db1a1eb2 | |||
0aee830bde | |||
06d41794f9 | |||
2114218ed8 | |||
58032d60e7 | |||
d4f9daa631 | |||
1eda1d25b0 | |||
aaeb268522 | |||
540d39220d | |||
09728bf43c | |||
090447c664 | |||
d4af5a5763 | |||
72df038d25 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -9,5 +9,6 @@
|
|||||||
*un~
|
*un~
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*/**/.DS_Store
|
*/**/.DS_Store
|
||||||
./ethereum/ethereum
|
ethereum/ethereum
|
||||||
|
ethereal/ethereal
|
||||||
|
|
||||||
|
14
README.md
14
README.md
@ -5,7 +5,7 @@ Ethereum
|
|||||||
|
|
||||||
Ethereum Go Client © 2014 Jeffrey Wilcke.
|
Ethereum Go Client © 2014 Jeffrey Wilcke.
|
||||||
|
|
||||||
Current state: Proof of Concept 5.0 RC10.
|
Current state: Proof of Concept 0.5.16.
|
||||||
|
|
||||||
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).
|
||||||
|
|
||||||
@ -27,20 +27,22 @@ General command line options
|
|||||||
|
|
||||||
```
|
```
|
||||||
Shared between ethereum and ethereal
|
Shared between ethereum and ethereal
|
||||||
-m Start mining blocks
|
-id Set the custom identifier of the client (shows up on other clients)
|
||||||
-genaddr Generates a new address and private key (destructive action)
|
-port Port on which the server will accept incomming connections
|
||||||
-p Port on which the server will accept incomming connections
|
|
||||||
-upnp Enable UPnP
|
-upnp Enable UPnP
|
||||||
-x Desired amount of peers
|
-maxpeer Desired amount of peers
|
||||||
-r Start JSON RPC
|
-rpc Start JSON RPC
|
||||||
|
|
||||||
-dir Data directory used to store configs and databases
|
-dir Data directory used to store configs and databases
|
||||||
-import Import a private key
|
-import Import a private key
|
||||||
|
-genaddr Generates a new address and private key (destructive action)
|
||||||
-h This
|
-h This
|
||||||
|
|
||||||
Ethereum only
|
Ethereum only
|
||||||
ethereum [options] [filename]
|
ethereum [options] [filename]
|
||||||
-js Start the JavaScript REPL
|
-js Start the JavaScript REPL
|
||||||
filename Load the given file and interpret as JavaScript
|
filename Load the given file and interpret as JavaScript
|
||||||
|
-m Start mining blocks
|
||||||
|
|
||||||
Etheral only
|
Etheral only
|
||||||
-asset_path absolute path to GUI assets directory
|
-asset_path absolute path to GUI assets directory
|
||||||
|
@ -7,12 +7,15 @@ import QtQuick.Controls.Styles 1.1
|
|||||||
import Ethereum 1.0
|
import Ethereum 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
visible: false
|
visible: false
|
||||||
title: "IceCream"
|
title: "IceCREAM"
|
||||||
minimumWidth: 1280
|
minimumWidth: 1280
|
||||||
minimumHeight: 900
|
minimumHeight: 700
|
||||||
width: 1290
|
width: 1290
|
||||||
height: 900
|
height: 700
|
||||||
|
|
||||||
|
property alias codeText: codeEditor.text
|
||||||
|
property alias dataText: rawDataField.text
|
||||||
|
|
||||||
MenuBar {
|
MenuBar {
|
||||||
Menu {
|
Menu {
|
||||||
@ -29,208 +32,239 @@ ApplicationWindow {
|
|||||||
onTriggered: dbg.next()
|
onTriggered: dbg.next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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: 100 }
|
TableViewColumn{ role: "value" ; title: "" ; width: 200 }
|
||||||
model: asmModel
|
model: asmModel
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
color: "#00000000"
|
color: "#00000000"
|
||||||
anchors.left: asmTableView.right
|
anchors.left: asmTableView.right
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
SplitView {
|
SplitView {
|
||||||
orientation: Qt.Vertical
|
orientation: Qt.Vertical
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
color: "#00000000"
|
color: "#00000000"
|
||||||
height: 500
|
height: 330
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
|
||||||
TextArea {
|
TextArea {
|
||||||
id: codeEditor
|
id: codeEditor
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: settings.left
|
anchors.right: settings.left
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
id: settings
|
id: settings
|
||||||
spacing: 5
|
spacing: 5
|
||||||
width: 300
|
width: 300
|
||||||
height: parent.height
|
height: parent.height
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: "Arbitrary data"
|
text: "Arbitrary data"
|
||||||
}
|
}
|
||||||
TextArea {
|
TextArea {
|
||||||
id: rawDataField
|
id: rawDataField
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
height: 150
|
height: 150
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: "Amount"
|
text: "Amount"
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
id: txValue
|
id: txValue
|
||||||
width: 200
|
width: 200
|
||||||
placeholderText: "Amount"
|
placeholderText: "Amount"
|
||||||
validator: RegExpValidator { regExp: /\d*/ }
|
validator: RegExpValidator { regExp: /\d*/ }
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
text: "Amount of gas"
|
text: "Amount of gas"
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
id: txGas
|
id: txGas
|
||||||
width: 200
|
width: 200
|
||||||
validator: RegExpValidator { regExp: /\d*/ }
|
validator: RegExpValidator { regExp: /\d*/ }
|
||||||
text: "10000"
|
text: "10000"
|
||||||
placeholderText: "Gas"
|
placeholderText: "Gas"
|
||||||
}
|
}
|
||||||
Label {
|
Label {
|
||||||
text: "Gas price"
|
text: "Gas price"
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
id: txGasPrice
|
id: txGasPrice
|
||||||
width: 200
|
width: 200
|
||||||
placeholderText: "Gas price"
|
placeholderText: "Gas price"
|
||||||
text: "1000000000000"
|
text: "1000000000000"
|
||||||
validator: RegExpValidator { regExp: /\d*/ }
|
validator: RegExpValidator { regExp: /\d*/ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SplitView {
|
SplitView {
|
||||||
orientation: Qt.Vertical
|
orientation: Qt.Vertical
|
||||||
id: inspectorPane
|
id: inspectorPane
|
||||||
height: 500
|
height: 500
|
||||||
|
|
||||||
SplitView {
|
SplitView {
|
||||||
orientation: Qt.Horizontal
|
orientation: Qt.Horizontal
|
||||||
height: 250
|
height: 150
|
||||||
|
|
||||||
TableView {
|
TableView {
|
||||||
id: stackTableView
|
id: stackTableView
|
||||||
property var stackModel: ListModel {
|
property var stackModel: ListModel {
|
||||||
id: stackModel
|
id: stackModel
|
||||||
}
|
}
|
||||||
height: parent.height
|
height: parent.height
|
||||||
width: 300
|
width: 300
|
||||||
TableViewColumn{ role: "value" ; title: "Stack" ; width: 200 }
|
TableViewColumn{ role: "value" ; title: "Temp" ; width: 200 }
|
||||||
model: stackModel
|
model: stackModel
|
||||||
}
|
}
|
||||||
|
|
||||||
TableView {
|
TableView {
|
||||||
id: memoryTableView
|
id: memoryTableView
|
||||||
property var memModel: ListModel {
|
property var memModel: ListModel {
|
||||||
id: memModel
|
id: memModel
|
||||||
}
|
}
|
||||||
height: parent.height
|
height: parent.height
|
||||||
width: parent.width - stackTableView.width
|
width: parent.width - stackTableView.width
|
||||||
TableViewColumn{ id:mnumColmn ; role: "num" ; title: "#" ; width: 50}
|
TableViewColumn{ id:mnumColmn ; role: "num" ; title: "#" ; width: 50}
|
||||||
TableViewColumn{ role: "value" ; title: "Memory" ; width: 750}
|
TableViewColumn{ role: "value" ; title: "Memory" ; width: 750}
|
||||||
model: memModel
|
model: memModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SplitView {
|
Rectangle {
|
||||||
height: 300
|
height: 100
|
||||||
TableView {
|
width: parent.width
|
||||||
id: storageTableView
|
TableView {
|
||||||
property var memModel: ListModel {
|
id: storageTableView
|
||||||
id: storageModel
|
property var memModel: ListModel {
|
||||||
}
|
id: storageModel
|
||||||
height: parent.height
|
}
|
||||||
width: parent.width - stackTableView.width
|
height: parent.height
|
||||||
TableViewColumn{ id: key ; role: "key" ; title: "#" ; width: storageTableView.width / 2}
|
width: parent.width
|
||||||
TableViewColumn{ role: "value" ; title: "value" ; width: storageTableView.width / 2}
|
TableViewColumn{ id: key ; role: "key" ; title: "#" ; width: storageTableView.width / 2}
|
||||||
model: storageModel
|
TableViewColumn{ role: "value" ; title: "Storage" ; width: storageTableView.width / 2}
|
||||||
}
|
model: storageModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
toolBar: ToolBar {
|
|
||||||
RowLayout {
|
|
||||||
spacing: 5
|
|
||||||
|
|
||||||
Button {
|
Rectangle {
|
||||||
property var enabled: true
|
height: 200
|
||||||
id: debugStart
|
width: parent.width
|
||||||
onClicked: {
|
TableView {
|
||||||
debugCurrent()
|
id: logTableView
|
||||||
}
|
property var logModel: ListModel {
|
||||||
text: "Debug"
|
id: logModel
|
||||||
}
|
}
|
||||||
|
height: parent.height
|
||||||
|
width: parent.width
|
||||||
|
TableViewColumn{ id: message ; role: "message" ; title: "log" ; width: logTableView.width }
|
||||||
|
model: logModel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Button {
|
toolBar: ToolBar {
|
||||||
property var enabled: true
|
RowLayout {
|
||||||
id: debugNextButton
|
spacing: 5
|
||||||
onClicked: {
|
|
||||||
dbg.next()
|
|
||||||
}
|
|
||||||
text: "Next"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function debugCurrent() {
|
Button {
|
||||||
dbg.debug(txValue.text, txGas.text, txGasPrice.text, codeEditor.text, rawDataField.text)
|
property var enabled: true
|
||||||
}
|
id: debugStart
|
||||||
|
onClicked: {
|
||||||
|
debugCurrent()
|
||||||
|
}
|
||||||
|
text: "Debug"
|
||||||
|
}
|
||||||
|
|
||||||
function setAsm(asm) {
|
Button {
|
||||||
asmModel.append({asm: asm})
|
property var enabled: true
|
||||||
}
|
id: debugNextButton
|
||||||
|
onClicked: {
|
||||||
|
dbg.next()
|
||||||
|
}
|
||||||
|
text: "Next"
|
||||||
|
}
|
||||||
|
CheckBox {
|
||||||
|
id: breakEachLine
|
||||||
|
objectName: "breakEachLine"
|
||||||
|
text: "Break each instruction"
|
||||||
|
checked: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function clearAsm() {
|
function debugCurrent() {
|
||||||
asmModel.clear()
|
dbg.debug(txValue.text, txGas.text, txGasPrice.text, codeEditor.text, rawDataField.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setInstruction(num) {
|
function setAsm(asm) {
|
||||||
asmTableView.selection.clear()
|
asmModel.append({asm: asm})
|
||||||
asmTableView.selection.select(num-1)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function setMem(mem) {
|
function clearAsm() {
|
||||||
memModel.append({num: mem.num, value: mem.value})
|
asmModel.clear()
|
||||||
}
|
}
|
||||||
function clearMem(){
|
|
||||||
memModel.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
function setStack(stack) {
|
function setInstruction(num) {
|
||||||
stackModel.append({value: stack})
|
asmTableView.selection.clear()
|
||||||
}
|
asmTableView.selection.select(num)
|
||||||
function addDebugMessage(message){
|
}
|
||||||
debuggerLog.append({value: message})
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearStack() {
|
function setMem(mem) {
|
||||||
stackModel.clear()
|
memModel.append({num: mem.num, value: mem.value})
|
||||||
}
|
}
|
||||||
|
function clearMem(){
|
||||||
|
memModel.clear()
|
||||||
|
}
|
||||||
|
|
||||||
function clearStorage() {
|
function setStack(stack) {
|
||||||
storageModel.clear()
|
stackModel.append({value: stack})
|
||||||
}
|
}
|
||||||
|
function addDebugMessage(message){
|
||||||
|
debuggerLog.append({value: message})
|
||||||
|
}
|
||||||
|
|
||||||
function setStorage(storage) {
|
function clearStack() {
|
||||||
storageModel.append({key: storage.key, value: storage.value})
|
stackModel.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearStorage() {
|
||||||
|
storageModel.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
function setStorage(storage) {
|
||||||
|
storageModel.append({key: storage.key, value: storage.value})
|
||||||
|
}
|
||||||
|
|
||||||
|
function setLog(msg) {
|
||||||
|
logModel.insert(0, {message: msg})
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearLog() {
|
||||||
|
logModel.clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,10 @@ window.eth = {
|
|||||||
postData({call: "getStorage", args: [address, storageAddress]}, cb);
|
postData({call: "getStorage", args: [address, storageAddress]}, cb);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getStateKeyVals: function(address, cb){
|
||||||
|
postData({call: "getStateKeyVals", args: [address]}, cb);
|
||||||
|
},
|
||||||
|
|
||||||
getKey: function(cb) {
|
getKey: function(cb) {
|
||||||
postData({call: "getKey"}, cb);
|
postData({call: "getKey"}, cb);
|
||||||
},
|
},
|
||||||
@ -54,6 +58,9 @@ window.eth = {
|
|||||||
getBalanceAt: function(address, cb) {
|
getBalanceAt: function(address, cb) {
|
||||||
postData({call: "getBalance", args: [address]}, cb);
|
postData({call: "getBalance", args: [address]}, cb);
|
||||||
},
|
},
|
||||||
|
getTransactionsFor: function(address, cb) {
|
||||||
|
postData({call: "getTransactionsFor", args: [address]}, cb);
|
||||||
|
},
|
||||||
|
|
||||||
getSecretToAddress: function(sec, cb) {
|
getSecretToAddress: function(sec, cb) {
|
||||||
postData({call: "getSecretToAddress", args: [sec]}, cb);
|
postData({call: "getSecretToAddress", args: [sec]}, cb);
|
||||||
|
22
ethereal/assets/qml/QmlApp.qml
Normal file
22
ethereal/assets/qml/QmlApp.qml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import QtQuick 2.0
|
||||||
|
import QtQuick.Controls 1.0;
|
||||||
|
import QtQuick.Layouts 1.0;
|
||||||
|
import Ethereum 1.0
|
||||||
|
|
||||||
|
ApplicationWindow {
|
||||||
|
minimumWidth: 500
|
||||||
|
maximumWidth: 500
|
||||||
|
maximumHeight: 400
|
||||||
|
minimumHeight: 400
|
||||||
|
|
||||||
|
function onNewBlockCb(block) {
|
||||||
|
console.log("Please overwrite onNewBlock(block):", block)
|
||||||
|
}
|
||||||
|
function onObjectChangeCb(stateObject) {
|
||||||
|
console.log("Please overwrite onObjectChangeCb(object)", stateObject)
|
||||||
|
}
|
||||||
|
function onStorageChangeCb(storageObject) {
|
||||||
|
var ev = ["storage", storageObject.stateAddress, storageObject.address].join(":");
|
||||||
|
console.log("Please overwrite onStorageChangeCb(object)", ev)
|
||||||
|
}
|
||||||
|
}
|
@ -3,33 +3,68 @@ import QtQuick.Controls 1.0;
|
|||||||
import QtQuick.Layouts 1.0;
|
import QtQuick.Layouts 1.0;
|
||||||
import Ethereum 1.0
|
import Ethereum 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
QmlApp {
|
||||||
minimumWidth: 500
|
minimumWidth: 350
|
||||||
maximumWidth: 500
|
maximumWidth: 350
|
||||||
maximumHeight: 100
|
maximumHeight: 80
|
||||||
minimumHeight: 100
|
minimumHeight: 80
|
||||||
|
|
||||||
title: "Ethereum Dice"
|
title: "Generic Coin"
|
||||||
|
|
||||||
TextField {
|
property string contractAddr: "f299f6c74515620e4c4cd8fe3d205b5c4f2e25c8"
|
||||||
id: textField
|
property string addr: "2ef47100e0787b915105fd5e3f4ff6752079d5cb"
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
Component.onCompleted: {
|
||||||
placeholderText: "Amount"
|
eth.watch(contractAddr, addr)
|
||||||
|
eth.watch(addr, contractAddr)
|
||||||
|
setAmount()
|
||||||
}
|
}
|
||||||
Label {
|
|
||||||
id: txHash
|
function onStorageChangeCb(storageObject) {
|
||||||
anchors.bottom: textField.top
|
setAmount()
|
||||||
anchors.bottomMargin: 5
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
}
|
}
|
||||||
Button {
|
|
||||||
anchors.top: textField.bottom
|
function setAmount(){
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
var state = eth.getStateObject(contractAddr)
|
||||||
anchors.topMargin: 5
|
var storage = state.getStorage(addr)
|
||||||
text: "Place bet"
|
amountLabel.text = storage
|
||||||
onClicked: {
|
}
|
||||||
txHash.text = eth.createTx("e6716f9544a56c530d868e4bfbacb172315bdead", textField.text)
|
Column {
|
||||||
|
spacing: 5
|
||||||
|
Row {
|
||||||
|
spacing: 20
|
||||||
|
Label {
|
||||||
|
id: genLabel
|
||||||
|
text: "Generic coin balance:"
|
||||||
|
}
|
||||||
|
Label {
|
||||||
|
id: amountLabel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Row {
|
||||||
|
spacing: 20
|
||||||
|
TextField {
|
||||||
|
id: address
|
||||||
|
placeholderText: "Address"
|
||||||
|
}
|
||||||
|
TextField {
|
||||||
|
id: amount
|
||||||
|
placeholderText: "Amount"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Button {
|
||||||
|
text: "Send coins"
|
||||||
|
onClicked: {
|
||||||
|
var privKey = eth.getKey().privateKey
|
||||||
|
if(privKey){
|
||||||
|
var result = eth.transact(privKey, contractAddr, 0,"100000","250", "0x" + address.text + "\n" + amount.text)
|
||||||
|
resultTx.text = result.hash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Label {
|
||||||
|
id: resultTx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -34,7 +34,6 @@ ApplicationWindow {
|
|||||||
top: parent.top
|
top: parent.top
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
onTitleChanged: { window.title = title }
|
onTitleChanged: { window.title = title }
|
||||||
experimental.preferences.javascriptEnabled: true
|
experimental.preferences.javascriptEnabled: true
|
||||||
experimental.preferences.navigatorQtObjectEnabled: true
|
experimental.preferences.navigatorQtObjectEnabled: true
|
||||||
@ -98,6 +97,18 @@ ApplicationWindow {
|
|||||||
postData(data._seed, storage)
|
postData(data._seed, storage)
|
||||||
|
|
||||||
break
|
break
|
||||||
|
case "getStateKeyVals":
|
||||||
|
require(1);
|
||||||
|
var stateObject = eth.getStateObject(data.args[0]).stateKeyVal(true)
|
||||||
|
postData(data._seed,stateObject)
|
||||||
|
|
||||||
|
break
|
||||||
|
case "getTransactionsFor":
|
||||||
|
require(1);
|
||||||
|
var txs = eth.getTransactionsFor(data.args[0], true)
|
||||||
|
postData(data._seed, txs)
|
||||||
|
|
||||||
|
break
|
||||||
case "getBalance":
|
case "getBalance":
|
||||||
require(1);
|
require(1);
|
||||||
|
|
||||||
@ -165,6 +176,30 @@ ApplicationWindow {
|
|||||||
postEvent(ev, [storageObject.address, storageObject.value])
|
postEvent(ev, [storageObject.address, storageObject.value])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Rectangle {
|
||||||
|
id: toggleInspector
|
||||||
|
color: "#bcbcbc"
|
||||||
|
visible: true
|
||||||
|
height: 12
|
||||||
|
width: 12
|
||||||
|
anchors {
|
||||||
|
right: root.right
|
||||||
|
}
|
||||||
|
MouseArea {
|
||||||
|
onClicked: {
|
||||||
|
if(inspector.visible == true){
|
||||||
|
inspector.visible = false
|
||||||
|
}else{
|
||||||
|
inspector.visible = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onDoubleClicked: {
|
||||||
|
console.log('refreshing')
|
||||||
|
webView.reload()
|
||||||
|
}
|
||||||
|
anchors.fill: parent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: sizeGrip
|
id: sizeGrip
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
var jefcoinAddr = "518546ffa883dcc838a64bc2dabada0fd64af459"
|
var jefcoinAddr = "22fa3ebce6ef9ca661a960104d3087eec040011e"
|
||||||
var mAddr = ""
|
var mAddr = ""
|
||||||
|
|
||||||
function createTransaction() {
|
function createTransaction() {
|
||||||
@ -17,7 +17,7 @@ function createTransaction() {
|
|||||||
var amount = document.querySelector("#amount").value.pad(32);
|
var amount = document.querySelector("#amount").value.pad(32);
|
||||||
|
|
||||||
var data = (addr + amount).unbin();
|
var data = (addr + amount).unbin();
|
||||||
eth.transact(mAddr, jefcoinAddr, 0, "10000000", "250", data, function(receipt) {
|
eth.transact(mAddr, jefcoinAddr, 0, "50000", "1000000", data, function(receipt) {
|
||||||
debug("received tx hash:", reciept.address)
|
debug("received tx hash:", reciept.address)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Identifier string
|
|
||||||
var StartConsole bool
|
|
||||||
var StartMining bool
|
|
||||||
var StartRpc bool
|
|
||||||
var RpcPort int
|
|
||||||
var UseUPnP bool
|
|
||||||
var OutboundPort string
|
|
||||||
var ShowGenesis bool
|
|
||||||
var AddPeer string
|
|
||||||
var MaxPeer int
|
|
||||||
var GenAddr bool
|
|
||||||
var UseSeed bool
|
|
||||||
var ImportKey string
|
|
||||||
var ExportKey bool
|
|
||||||
var DataDir string
|
|
||||||
var AssetPath string
|
|
||||||
|
|
||||||
func Init() {
|
|
||||||
flag.StringVar(&Identifier, "i", "", "Custom client identifier")
|
|
||||||
flag.BoolVar(&StartConsole, "c", false, "debug and testing console")
|
|
||||||
flag.BoolVar(&StartMining, "m", false, "start dagger mining")
|
|
||||||
flag.BoolVar(&StartRpc, "r", false, "start rpc server")
|
|
||||||
flag.BoolVar(&ShowGenesis, "g", false, "prints genesis header and exits")
|
|
||||||
flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support")
|
|
||||||
flag.BoolVar(&UseSeed, "seed", true, "seed peers")
|
|
||||||
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
|
||||||
flag.BoolVar(&ExportKey, "export", false, "export private key")
|
|
||||||
flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on")
|
|
||||||
flag.StringVar(&OutboundPort, "p", "30303", "listening port")
|
|
||||||
flag.StringVar(&DataDir, "dir", ".ethereal", "ethereum data directory")
|
|
||||||
flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)")
|
|
||||||
flag.IntVar(&MaxPeer, "x", 10, "maximum desired peers")
|
|
||||||
flag.StringVar(&AssetPath, "asset_path", "", "absolute path to GUI assets directory")
|
|
||||||
|
|
||||||
flag.Parse()
|
|
||||||
}
|
|
@ -1,132 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/ethereum/eth-go"
|
|
||||||
"github.com/ethereum/eth-go/ethchain"
|
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
|
||||||
"github.com/ethereum/go-ethereum/ethereal/ui"
|
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
|
||||||
"github.com/go-qml/qml"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
const Debug = true
|
|
||||||
|
|
||||||
// Register interrupt handlers so we can stop the ethereum
|
|
||||||
func RegisterInterupts(s *eth.Ethereum) {
|
|
||||||
// Buffered chan of one is enough
|
|
||||||
c := make(chan os.Signal, 1)
|
|
||||||
// Notify about interrupts for now
|
|
||||||
signal.Notify(c, os.Interrupt)
|
|
||||||
go func() {
|
|
||||||
for sig := range c {
|
|
||||||
fmt.Printf("Shutting down (%v) ... \n", sig)
|
|
||||||
|
|
||||||
s.Stop()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
Init()
|
|
||||||
|
|
||||||
qml.Init(nil)
|
|
||||||
|
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
||||||
|
|
||||||
ethchain.InitFees()
|
|
||||||
ethutil.ReadConfig(DataDir, ethutil.LogFile|ethutil.LogStd, Identifier)
|
|
||||||
|
|
||||||
// Instantiated a eth stack
|
|
||||||
ethereum, err := eth.New(eth.CapDefault, UseUPnP)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("eth start err:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ethereum.Port = OutboundPort
|
|
||||||
|
|
||||||
if GenAddr {
|
|
||||||
fmt.Println("This action overwrites your old private key. Are you sure? (y/n)")
|
|
||||||
|
|
||||||
var r string
|
|
||||||
fmt.Scanln(&r)
|
|
||||||
for ; ; fmt.Scanln(&r) {
|
|
||||||
if r == "n" || r == "y" {
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Yes or no?", r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if r == "y" {
|
|
||||||
utils.CreateKeyPair(true)
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
|
||||||
} else {
|
|
||||||
if len(ImportKey) > 0 {
|
|
||||||
fmt.Println("This action overwrites your old private key. Are you sure? (y/n)")
|
|
||||||
var r string
|
|
||||||
fmt.Scanln(&r)
|
|
||||||
for ; ; fmt.Scanln(&r) {
|
|
||||||
if r == "n" || r == "y" {
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Yes or no?", r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if r == "y" {
|
|
||||||
utils.ImportPrivateKey(ImportKey)
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ExportKey {
|
|
||||||
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)
|
|
||||||
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if ShowGenesis {
|
|
||||||
fmt.Println(ethereum.BlockChain().Genesis())
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if StartMining {
|
|
||||||
utils.DoMining(ethereum)
|
|
||||||
}
|
|
||||||
|
|
||||||
if StartRpc {
|
|
||||||
utils.DoRpc(ethereum, RpcPort)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("Starting Ethereum GUI v%s\n", ethutil.Config.Ver)
|
|
||||||
|
|
||||||
// Set the max peers
|
|
||||||
ethereum.MaxPeers = MaxPeer
|
|
||||||
|
|
||||||
gui := ethui.New(ethereum)
|
|
||||||
|
|
||||||
ethereum.Start(UseSeed)
|
|
||||||
|
|
||||||
gui.Start(AssetPath)
|
|
||||||
|
|
||||||
// Wait for shutdown
|
|
||||||
ethereum.WaitForShutdown()
|
|
||||||
}
|
|
99
ethereal/flags.go
Normal file
99
ethereal/flags.go
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bitbucket.org/kardianos/osext"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Identifier string
|
||||||
|
var KeyRing string
|
||||||
|
var KeyStore string
|
||||||
|
var StartRpc bool
|
||||||
|
var RpcPort int
|
||||||
|
var UseUPnP bool
|
||||||
|
var OutboundPort string
|
||||||
|
var ShowGenesis bool
|
||||||
|
var AddPeer string
|
||||||
|
var MaxPeer int
|
||||||
|
var GenAddr bool
|
||||||
|
var UseSeed bool
|
||||||
|
var SecretFile string
|
||||||
|
var ExportDir string
|
||||||
|
var NonInteractive bool
|
||||||
|
var Datadir string
|
||||||
|
var LogFile string
|
||||||
|
var ConfigFile string
|
||||||
|
var DebugFile string
|
||||||
|
var LogLevel int
|
||||||
|
|
||||||
|
// flags specific to gui client
|
||||||
|
var AssetPath string
|
||||||
|
|
||||||
|
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 "window":
|
||||||
|
fallthrough
|
||||||
|
default:
|
||||||
|
assetPath = "."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return assetPath
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultDataDir() string {
|
||||||
|
usr, _ := user.Current()
|
||||||
|
return path.Join(usr.HomeDir, ".ethereal")
|
||||||
|
}
|
||||||
|
|
||||||
|
var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini")
|
||||||
|
|
||||||
|
func Init() {
|
||||||
|
flag.Usage = func() {
|
||||||
|
fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line\n", os.Args[0])
|
||||||
|
flag.PrintDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
|
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.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support")
|
||||||
|
flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers")
|
||||||
|
flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on")
|
||||||
|
flag.BoolVar(&StartRpc, "rpc", false, "start rpc server")
|
||||||
|
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
||||||
|
flag.BoolVar(&UseSeed, "seed", true, "seed peers")
|
||||||
|
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub 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(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
|
||||||
|
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
||||||
|
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.StringVar(&AssetPath, "asset_path", defaultAssetPath(), "absolute path to GUI assets directory")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
}
|
66
ethereal/main.go
Normal file
66
ethereal/main.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
|
"github.com/ethereum/go-ethereum/ethereal/ui"
|
||||||
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
|
"github.com/go-qml/qml"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Leave QT on top at ALL times. Qt Needs to be initialized from the main thread
|
||||||
|
qml.Init(nil)
|
||||||
|
|
||||||
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
||||||
|
var interrupted = false
|
||||||
|
utils.RegisterInterrupt(func(os.Signal) {
|
||||||
|
interrupted = true
|
||||||
|
})
|
||||||
|
|
||||||
|
utils.HandleInterrupt()
|
||||||
|
|
||||||
|
// precedence: code-internal flag default < config file < environment variables < command line
|
||||||
|
Init() // parsing command line
|
||||||
|
utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH")
|
||||||
|
|
||||||
|
utils.InitDataDir(Datadir)
|
||||||
|
|
||||||
|
utils.InitLogging(Datadir, LogFile, LogLevel, DebugFile)
|
||||||
|
|
||||||
|
db := utils.NewDatabase()
|
||||||
|
|
||||||
|
keyManager := utils.NewKeyManager(KeyStore, Datadir, db)
|
||||||
|
|
||||||
|
// create, import, export keys
|
||||||
|
utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
|
||||||
|
|
||||||
|
ethereum := utils.NewEthereum(db, keyManager, UseUPnP, OutboundPort, MaxPeer)
|
||||||
|
|
||||||
|
if ShowGenesis {
|
||||||
|
utils.ShowGenesis(ethereum)
|
||||||
|
}
|
||||||
|
|
||||||
|
if StartRpc {
|
||||||
|
utils.StartRpc(ethereum, RpcPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
gui := ethui.New(ethereum, KeyRing, LogLevel)
|
||||||
|
|
||||||
|
utils.RegisterInterrupt(func(os.Signal) {
|
||||||
|
gui.Stop()
|
||||||
|
})
|
||||||
|
utils.StartEthereum(ethereum, UseSeed)
|
||||||
|
// gui blocks the main thread
|
||||||
|
gui.Start(AssetPath)
|
||||||
|
// we need to run the interrupt callbacks in case gui is closed
|
||||||
|
// this skips if we got here by actual interrupt stopping the GUI
|
||||||
|
if !interrupted {
|
||||||
|
utils.RunInterruptCallbacks(os.Interrupt)
|
||||||
|
}
|
||||||
|
// this blocks the thread
|
||||||
|
ethereum.WaitForShutdown()
|
||||||
|
ethlog.Flush()
|
||||||
|
}
|
@ -26,7 +26,7 @@ func NewDebuggerWindow(lib *UiLib) *DebuggerWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
win := component.CreateWindow(nil)
|
win := component.CreateWindow(nil)
|
||||||
db := &Debugger{win, make(chan bool), make(chan bool), true}
|
db := &Debugger{win, make(chan bool), make(chan bool), true, false, true}
|
||||||
|
|
||||||
return &DebuggerWindow{engine: engine, win: win, lib: lib, Db: db}
|
return &DebuggerWindow{engine: engine, win: win, lib: lib, Db: db}
|
||||||
}
|
}
|
||||||
@ -41,94 +41,135 @@ func (self *DebuggerWindow) Show() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatData(data string) []byte {
|
func (self *DebuggerWindow) SetCode(code string) {
|
||||||
if len(data) == 0 {
|
self.win.Set("codeText", code)
|
||||||
return nil
|
}
|
||||||
}
|
|
||||||
// Simple stupid
|
|
||||||
d := new(big.Int)
|
|
||||||
if data[0:1] == "\"" && data[len(data)-1:] == "\"" {
|
|
||||||
d.SetBytes([]byte(data[1 : len(data)-1]))
|
|
||||||
} else if data[:2] == "0x" {
|
|
||||||
d.SetBytes(ethutil.FromHex(data[2:]))
|
|
||||||
} else {
|
|
||||||
d.SetString(data, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ethutil.BigToBytes(d, 256)
|
func (self *DebuggerWindow) SetData(data string) {
|
||||||
|
self.win.Set("dataText", data)
|
||||||
|
}
|
||||||
|
func (self *DebuggerWindow) SetAsm(data string) {
|
||||||
|
dis := ethchain.Disassemble(ethutil.Hex2Bytes(data))
|
||||||
|
for _, str := range dis {
|
||||||
|
self.win.Root().Call("setAsm", str)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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")
|
||||||
dataSlice := strings.Split(dataStr, "\n")
|
|
||||||
var data []byte
|
|
||||||
for _, dataItem := range dataSlice {
|
|
||||||
d := formatData(dataItem)
|
|
||||||
data = append(data, d...)
|
|
||||||
}
|
|
||||||
|
|
||||||
state := self.lib.eth.BlockChain().CurrentBlock.State()
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
fmt.Println(r)
|
self.Logf("compile FAULT: %v", r)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
script, err := ethutil.Compile(scriptStr)
|
data := ethutil.StringToByteFunc(dataStr, func(s string) (ret []byte) {
|
||||||
|
slice := strings.Split(dataStr, "\n")
|
||||||
|
for _, dataItem := range slice {
|
||||||
|
d := ethutil.FormatData(dataItem)
|
||||||
|
ret = append(ret, d...)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
})
|
||||||
|
|
||||||
|
var err error
|
||||||
|
script := ethutil.StringToByteFunc(scriptStr, func(s string) (ret []byte) {
|
||||||
|
ret, err = ethutil.Compile(s)
|
||||||
|
return
|
||||||
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ethutil.Config.Log.Debugln(err)
|
self.Logln(err)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dis := ethchain.Disassemble(script)
|
dis := ethchain.Disassemble(script)
|
||||||
self.win.Root().Call("clearAsm")
|
self.win.Root().Call("clearAsm")
|
||||||
|
self.win.Root().Call("clearLog")
|
||||||
|
|
||||||
for _, str := range dis {
|
for _, str := range dis {
|
||||||
self.win.Root().Call("setAsm", str)
|
self.win.Root().Call("setAsm", str)
|
||||||
}
|
}
|
||||||
// Contract addr as test address
|
|
||||||
keyPair := ethutil.GetKeyRing().Get(0)
|
var (
|
||||||
callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), script)
|
gas = ethutil.Big(gasStr)
|
||||||
|
gasPrice = ethutil.Big(gasPriceStr)
|
||||||
|
value = ethutil.Big(valueStr)
|
||||||
|
// Contract addr as test address
|
||||||
|
keyPair = self.lib.eth.KeyManager().KeyPair()
|
||||||
|
callerTx = ethchain.NewContractCreationTx(ethutil.Big(valueStr), gas, gasPrice, script)
|
||||||
|
)
|
||||||
callerTx.Sign(keyPair.PrivateKey)
|
callerTx.Sign(keyPair.PrivateKey)
|
||||||
|
|
||||||
|
state := self.lib.eth.BlockChain().CurrentBlock.State()
|
||||||
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.MakeContract(callerTx, state)
|
||||||
callerClosure := ethchain.NewClosure(account, contract, script, state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr))
|
contract.Amount = value
|
||||||
|
callerClosure := ethchain.NewClosure(account, contract, script, state, gas, gasPrice)
|
||||||
|
|
||||||
block := self.lib.eth.BlockChain().CurrentBlock
|
block := self.lib.eth.BlockChain().CurrentBlock
|
||||||
vm := ethchain.NewVm(state, self.lib.eth.StateManager(), ethchain.RuntimeVars{
|
vm := ethchain.NewVm(state, self.lib.eth.StateManager(), ethchain.RuntimeVars{
|
||||||
|
Block: block,
|
||||||
Origin: account.Address(),
|
Origin: account.Address(),
|
||||||
BlockNumber: block.BlockInfo().Number,
|
BlockNumber: block.Number,
|
||||||
PrevHash: block.PrevHash,
|
PrevHash: block.PrevHash,
|
||||||
Coinbase: block.Coinbase,
|
Coinbase: block.Coinbase,
|
||||||
Time: block.Time,
|
Time: block.Time,
|
||||||
Diff: block.Difficulty,
|
Diff: block.Difficulty,
|
||||||
|
Value: ethutil.Big(valueStr),
|
||||||
})
|
})
|
||||||
|
vm.Verbose = true
|
||||||
|
|
||||||
self.Db.done = false
|
self.Db.done = false
|
||||||
|
self.Logf("callsize %d", len(script))
|
||||||
go func() {
|
go func() {
|
||||||
callerClosure.Call(vm, data, self.Db.halting)
|
ret, g, err := callerClosure.Call(vm, data, self.Db.halting)
|
||||||
|
tot := new(big.Int).Mul(g, gasPrice)
|
||||||
|
self.Logf("gas usage %v total price = %v (%v)", g, tot, ethutil.CurrencyToString(tot))
|
||||||
|
if err != nil {
|
||||||
|
self.Logln("exited with errors:", err)
|
||||||
|
} else {
|
||||||
|
if len(ret) > 0 {
|
||||||
|
self.Logf("exited: % x", ret)
|
||||||
|
} else {
|
||||||
|
self.Logf("exited: nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
state.Reset()
|
state.Reset()
|
||||||
|
|
||||||
self.Db.done = true
|
if !self.Db.interrupt {
|
||||||
|
self.Db.done = true
|
||||||
|
} else {
|
||||||
|
self.Db.interrupt = false
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *DebuggerWindow) Logf(format string, v ...interface{}) {
|
||||||
|
self.win.Root().Call("setLog", fmt.Sprintf(format, v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *DebuggerWindow) Logln(v ...interface{}) {
|
||||||
|
str := fmt.Sprintln(v...)
|
||||||
|
self.Logf("%s", str[:len(str)-1])
|
||||||
|
}
|
||||||
|
|
||||||
func (self *DebuggerWindow) Next() {
|
func (self *DebuggerWindow) Next() {
|
||||||
self.Db.Next()
|
self.Db.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
type Debugger struct {
|
type Debugger struct {
|
||||||
win *qml.Window
|
win *qml.Window
|
||||||
N chan bool
|
N chan bool
|
||||||
Q chan bool
|
Q chan bool
|
||||||
done bool
|
done, interrupt bool
|
||||||
|
breakOnInstr bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type storeVal struct {
|
type storeVal struct {
|
||||||
@ -155,21 +196,37 @@ 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())})
|
||||||
})
|
})
|
||||||
|
|
||||||
out:
|
if d.breakOnInstr {
|
||||||
for {
|
out:
|
||||||
select {
|
for {
|
||||||
case <-d.N:
|
select {
|
||||||
break out
|
case <-d.N:
|
||||||
case <-d.Q:
|
break out
|
||||||
d.done = true
|
case <-d.Q:
|
||||||
|
d.interrupt = true
|
||||||
|
d.clearBuffers()
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Debugger) clearBuffers() {
|
||||||
|
out:
|
||||||
|
// drain
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-d.N:
|
||||||
|
case <-d.Q:
|
||||||
|
default:
|
||||||
|
break out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Debugger) Next() {
|
func (d *Debugger) Next() {
|
||||||
if !d.done {
|
if !d.done {
|
||||||
d.N <- true
|
d.N <- true
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,13 +6,18 @@ import (
|
|||||||
"github.com/ethereum/eth-go"
|
"github.com/ethereum/eth-go"
|
||||||
"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/ethpub"
|
"github.com/ethereum/eth-go/ethpub"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
"github.com/go-qml/qml"
|
"github.com/go-qml/qml"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var logger = ethlog.NewLogger("GUI")
|
||||||
|
|
||||||
type Gui struct {
|
type Gui struct {
|
||||||
// The main application window
|
// The main application window
|
||||||
win *qml.Window
|
win *qml.Window
|
||||||
@ -23,38 +28,32 @@ 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
|
||||||
|
logLevel ethlog.LogLevel
|
||||||
|
open bool
|
||||||
|
|
||||||
pub *ethpub.PEthereum
|
Session string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create GUI, but doesn't start it
|
// Create GUI, but doesn't start it
|
||||||
func New(ethereum *eth.Ethereum) *Gui {
|
func New(ethereum *eth.Ethereum, 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}
|
return &Gui{eth: ethereum, txDb: db, pub: pub, logLevel: ethlog.LogLevel(logLevel), Session: session, open: false}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) Start(assetPath string) {
|
func (gui *Gui) Start(assetPath string) {
|
||||||
const version = "0.5.0 RC10"
|
const version = "0.5.16"
|
||||||
|
|
||||||
defer gui.txDb.Close()
|
defer gui.txDb.Close()
|
||||||
|
|
||||||
@ -63,10 +62,12 @@ func (gui *Gui) Start(assetPath string) {
|
|||||||
Init: func(p *ethpub.PBlock, obj qml.Object) { p.Number = 0; p.Hash = "" },
|
Init: func(p *ethpub.PBlock, obj qml.Object) { p.Number = 0; p.Hash = "" },
|
||||||
}, {
|
}, {
|
||||||
Init: func(p *ethpub.PTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" },
|
Init: func(p *ethpub.PTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" },
|
||||||
|
}, {
|
||||||
|
Init: func(p *ethpub.KeyVal, obj qml.Object) { p.Key = ""; p.Value = "" },
|
||||||
}})
|
}})
|
||||||
|
|
||||||
ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", version))
|
ethutil.Config.SetClientString("Ethereal")
|
||||||
ethutil.Config.Log.Infoln("[GUI] Starting GUI")
|
|
||||||
// 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()
|
||||||
@ -82,21 +83,52 @@ func (gui *Gui) Start(assetPath string) {
|
|||||||
|
|
||||||
var win *qml.Window
|
var win *qml.Window
|
||||||
var err error
|
var err error
|
||||||
|
var addlog = false
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
win, err = gui.showKeyImport(context)
|
win, err = gui.showKeyImport(context)
|
||||||
} else {
|
} else {
|
||||||
win, err = gui.showWallet(context)
|
win, err = gui.showWallet(context)
|
||||||
|
addlog = true
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'")
|
logger.Errorln("asset not found: you can set an alternative asset path on the command line using option 'asset_path'", err)
|
||||||
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Infoln("Starting GUI")
|
||||||
|
gui.open = true
|
||||||
win.Show()
|
win.Show()
|
||||||
|
// only add the gui logger after window is shown otherwise slider wont be shown
|
||||||
|
if addlog {
|
||||||
|
ethlog.AddLogSystem(gui)
|
||||||
|
}
|
||||||
win.Wait()
|
win.Wait()
|
||||||
|
// need to silence gui logger after window closed otherwise logsystem hangs
|
||||||
|
gui.SetLogLevel(ethlog.Silence)
|
||||||
|
gui.open = false
|
||||||
|
}
|
||||||
|
|
||||||
gui.eth.Stop()
|
func (gui *Gui) Stop() {
|
||||||
|
if gui.open {
|
||||||
|
gui.SetLogLevel(ethlog.Silence)
|
||||||
|
gui.open = false
|
||||||
|
gui.win.Hide()
|
||||||
|
}
|
||||||
|
logger.Infoln("Stopped")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) ToggleMining() {
|
||||||
|
var txt string
|
||||||
|
if gui.eth.Mining {
|
||||||
|
utils.StopMining(gui.eth)
|
||||||
|
txt = "Start mining"
|
||||||
|
} else {
|
||||||
|
utils.StartMining(gui.eth)
|
||||||
|
txt = "Stop mining"
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.win.Root().Set("miningButtonText", txt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
|
func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
|
||||||
@ -107,20 +139,22 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
|
|||||||
|
|
||||||
win := gui.createWindow(component)
|
win := gui.createWindow(component)
|
||||||
|
|
||||||
go gui.setInitialBlockChain()
|
gui.setInitialBlockChain()
|
||||||
go gui.readPreviousTransactions()
|
gui.loadAddressBook()
|
||||||
|
gui.readPreviousTransactions()
|
||||||
|
gui.setPeerInfo()
|
||||||
|
|
||||||
go gui.update()
|
go gui.update()
|
||||||
|
|
||||||
return win, nil
|
return win, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,28 +164,73 @@ func (gui *Gui) createWindow(comp qml.Object) *qml.Window {
|
|||||||
gui.win = win
|
gui.win = win
|
||||||
gui.uiLib.win = win
|
gui.uiLib.win = win
|
||||||
|
|
||||||
db := &Debugger{gui.win, make(chan bool), make(chan bool), true}
|
|
||||||
gui.lib.Db = db
|
|
||||||
gui.uiLib.Db = db
|
|
||||||
|
|
||||||
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
|
||||||
|
for _, tx := range blk.Transactions() {
|
||||||
|
if bytes.Compare(tx.Sender(), addr) == 0 || bytes.Compare(tx.Recipient, addr) == 0 {
|
||||||
|
if ok, _ := gui.txDb.Get(tx.Hash()); ok == nil {
|
||||||
|
gui.txDb.Put(tx.Hash(), tx.RlpEncode())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gui.processBlock(blk, true)
|
gui.processBlock(blk, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type address struct {
|
||||||
|
Name, Address string
|
||||||
|
}
|
||||||
|
|
||||||
|
var namereg = ethutil.Hex2Bytes("bb5f186604d057c1c5240ca2ae0f6430138ac010")
|
||||||
|
|
||||||
|
func (gui *Gui) loadAddressBook() {
|
||||||
|
gui.win.Root().Call("clearAddress")
|
||||||
|
stateObject := gui.eth.StateManager().CurrentState().GetStateObject(namereg)
|
||||||
|
if stateObject != nil {
|
||||||
|
stateObject.State().EachStorage(func(name string, value *ethutil.Value) {
|
||||||
|
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"
|
||||||
@ -189,37 +268,43 @@ func (gui *Gui) update() {
|
|||||||
|
|
||||||
blockChan := make(chan ethutil.React, 1)
|
blockChan := make(chan ethutil.React, 1)
|
||||||
txChan := make(chan ethutil.React, 1)
|
txChan := make(chan ethutil.React, 1)
|
||||||
|
objectChan := make(chan ethutil.React, 1)
|
||||||
|
peerChan := 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("peerList", peerChan)
|
||||||
|
|
||||||
|
ticker := time.NewTicker(5 * 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)))
|
||||||
|
|
||||||
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())
|
||||||
|
|
||||||
@ -228,10 +313,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,35 +324,82 @@ func (gui *Gui) update() {
|
|||||||
|
|
||||||
state.UpdateStateObject(object)
|
state.UpdateStateObject(object)
|
||||||
}
|
}
|
||||||
|
case <-objectChan:
|
||||||
|
gui.loadAddressBook()
|
||||||
|
case <-peerChan:
|
||||||
|
gui.setPeerInfo()
|
||||||
|
case <-ticker.C:
|
||||||
|
gui.setPeerInfo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logging functions that log directly to the GUI interface
|
func (gui *Gui) setPeerInfo() {
|
||||||
func (gui *Gui) Println(v ...interface{}) {
|
gui.win.Root().Call("setPeers", fmt.Sprintf("%d / %d", gui.eth.PeerCount(), gui.eth.MaxPeers))
|
||||||
str := strings.TrimRight(fmt.Sprintln(v...), "\n")
|
|
||||||
lines := strings.Split(str, "\n")
|
gui.win.Root().Call("resetPeers")
|
||||||
for _, line := range lines {
|
for _, peer := range gui.pub.GetPeers() {
|
||||||
gui.win.Root().Call("addLog", line)
|
gui.win.Root().Call("addPeer", peer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) Printf(format string, v ...interface{}) {
|
func (gui *Gui) privateKey() string {
|
||||||
str := strings.TrimRight(fmt.Sprintf(format, v...), "\n")
|
return ethutil.Bytes2Hex(gui.eth.KeyManager().PrivateKey())
|
||||||
lines := strings.Split(str, "\n")
|
}
|
||||||
for _, line := range lines {
|
|
||||||
gui.win.Root().Call("addLog", line)
|
func (gui *Gui) address() []byte {
|
||||||
}
|
return gui.eth.KeyManager().Address()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) RegisterName(name string) {
|
||||||
|
name = fmt.Sprintf("\"%s\"\n1", name)
|
||||||
|
gui.pub.Transact(gui.privateKey(), "namereg", "1000", "1000000", "150", 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.Create(ethutil.Hex(keyPair.PrivateKey), value, gas, gasPrice, data)
|
|
||||||
|
func (gui *Gui) ChangeClientId(id string) {
|
||||||
|
ethutil.Config.SetIdentifier(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) ClientId() string {
|
||||||
|
return ethutil.Config.Identifier
|
||||||
|
}
|
||||||
|
|
||||||
|
// functions that allow Gui to implement interface ethlog.LogSystem
|
||||||
|
func (gui *Gui) SetLogLevel(level ethlog.LogLevel) {
|
||||||
|
gui.logLevel = level
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) GetLogLevel() ethlog.LogLevel {
|
||||||
|
return gui.logLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
// this extra function needed to give int typecast value to gui widget
|
||||||
|
// that sets initial loglevel to default
|
||||||
|
func (gui *Gui) GetLogLevelInt() int {
|
||||||
|
return int(gui.logLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) Println(v ...interface{}) {
|
||||||
|
gui.printLog(fmt.Sprintln(v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) Printf(format string, v ...interface{}) {
|
||||||
|
gui.printLog(fmt.Sprintf(format, v...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print function that logs directly to the GUI
|
||||||
|
func (gui *Gui) printLog(s string) {
|
||||||
|
str := strings.TrimRight(s, "\n")
|
||||||
|
lines := strings.Split(str, "\n")
|
||||||
|
for _, line := range lines {
|
||||||
|
gui.win.Root().Call("addLog", line)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,11 +96,11 @@ func (app *HtmlApplication) NewWatcher(quitChan chan bool) {
|
|||||||
app.watcher.Close()
|
app.watcher.Close()
|
||||||
break out
|
break out
|
||||||
case <-app.watcher.Event:
|
case <-app.watcher.Event:
|
||||||
//ethutil.Config.Log.Debugln("Got event:", ev)
|
//logger.Debugln("Got event:", ev)
|
||||||
app.webView.Call("reload")
|
app.webView.Call("reload")
|
||||||
case err := <-app.watcher.Error:
|
case err := <-app.watcher.Error:
|
||||||
// TODO: Do something here
|
// TODO: Do something here
|
||||||
ethutil.Config.Log.Infoln("Watcher error:", err)
|
logger.Infoln("Watcher error:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -116,7 +116,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
|
||||||
}
|
|
59
ethereal/ui/qml_app.go
Normal file
59
ethereal/ui/qml_app.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package ethui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ethereum/eth-go/ethchain"
|
||||||
|
"github.com/ethereum/eth-go/ethpub"
|
||||||
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
|
"github.com/go-qml/qml"
|
||||||
|
)
|
||||||
|
|
||||||
|
type QmlApplication struct {
|
||||||
|
win *qml.Window
|
||||||
|
engine *qml.Engine
|
||||||
|
lib *UiLib
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewQmlApplication(path string, lib *UiLib) *QmlApplication {
|
||||||
|
engine := qml.NewEngine()
|
||||||
|
return &QmlApplication{engine: engine, path: path, lib: lib}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *QmlApplication) Create() error {
|
||||||
|
component, err := app.engine.LoadFile(app.path)
|
||||||
|
if err != nil {
|
||||||
|
logger.Warnln(err)
|
||||||
|
}
|
||||||
|
app.win = component.CreateWindow(nil)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *QmlApplication) Destroy() {
|
||||||
|
app.engine.Destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *QmlApplication) NewWatcher(quitChan chan bool) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Events
|
||||||
|
func (app *QmlApplication) NewBlock(block *ethchain.Block) {
|
||||||
|
pblock := ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Bytes2Hex(block.Hash())}
|
||||||
|
app.win.Call("onNewBlockCb", pblock)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *QmlApplication) ObjectChanged(stateObject *ethchain.StateObject) {
|
||||||
|
app.win.Call("onObjectChangeCb", ethpub.NewPStateObject(stateObject))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *QmlApplication) StorageChanged(storageObject *ethchain.StorageState) {
|
||||||
|
app.win.Call("onStorageChangeCb", ethpub.NewPStorageState(storageObject))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
func (app *QmlApplication) Engine() *qml.Engine {
|
||||||
|
return app.engine
|
||||||
|
}
|
||||||
|
func (app *QmlApplication) Window() *qml.Window {
|
||||||
|
return app.win
|
||||||
|
}
|
@ -1,15 +1,10 @@
|
|||||||
package ethui
|
package ethui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bitbucket.org/kardianos/osext"
|
|
||||||
"github.com/ethereum/eth-go"
|
"github.com/ethereum/eth-go"
|
||||||
"github.com/ethereum/eth-go/ethchain"
|
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/go-qml/qml"
|
"github.com/go-qml/qml"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type memAddr struct {
|
type memAddr struct {
|
||||||
@ -24,29 +19,20 @@ type UiLib struct {
|
|||||||
connected bool
|
connected bool
|
||||||
assetPath string
|
assetPath string
|
||||||
// The main application window
|
// The main application window
|
||||||
win *qml.Window
|
win *qml.Window
|
||||||
Db *Debugger
|
Db *Debugger
|
||||||
|
DbWindow *DebuggerWindow
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib {
|
func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib {
|
||||||
if assetPath == "" {
|
|
||||||
assetPath = DefaultAssetPath()
|
|
||||||
}
|
|
||||||
return &UiLib{engine: engine, eth: eth, assetPath: assetPath}
|
return &UiLib{engine: engine, eth: eth, assetPath: assetPath}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opens a QML file (external application)
|
func (ui *UiLib) OpenQml(path string) {
|
||||||
func (ui *UiLib) Open(path string) {
|
container := NewQmlApplication(path[7:], ui)
|
||||||
component, err := ui.engine.LoadFile(path[7:])
|
app := NewExtApplication(container, ui)
|
||||||
if err != nil {
|
|
||||||
ethutil.Config.Log.Debugln(err)
|
|
||||||
}
|
|
||||||
win := component.CreateWindow(nil)
|
|
||||||
|
|
||||||
go func() {
|
go app.run()
|
||||||
win.Show()
|
|
||||||
win.Wait()
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *UiLib) OpenHtml(path string) {
|
func (ui *UiLib) OpenHtml(path string) {
|
||||||
@ -59,7 +45,7 @@ func (ui *UiLib) OpenHtml(path string) {
|
|||||||
func (ui *UiLib) Muted(content string) {
|
func (ui *UiLib) Muted(content string) {
|
||||||
component, err := ui.engine.LoadFile(ui.AssetPath("qml/muted.qml"))
|
component, err := ui.engine.LoadFile(ui.AssetPath("qml/muted.qml"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ethutil.Config.Log.Debugln(err)
|
logger.Debugln(err)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -89,84 +75,26 @@ func (ui *UiLib) AssetPath(p string) string {
|
|||||||
return path.Join(ui.assetPath, p)
|
return path.Join(ui.assetPath, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *UiLib) StartDebugger() {
|
func (self *UiLib) StartDbWithContractAndData(contractHash, data string) {
|
||||||
dbWindow := NewDebuggerWindow(self)
|
dbWindow := NewDebuggerWindow(self)
|
||||||
|
object := self.eth.StateManager().CurrentState().GetStateObject(ethutil.Hex2Bytes(contractHash))
|
||||||
|
if len(object.Script()) > 0 {
|
||||||
|
dbWindow.SetCode("0x" + ethutil.Bytes2Hex(object.Script()))
|
||||||
|
}
|
||||||
|
dbWindow.SetData("0x" + data)
|
||||||
|
|
||||||
dbWindow.Show()
|
dbWindow.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultAssetPath() string {
|
func (self *UiLib) StartDbWithCode(code string) {
|
||||||
var base string
|
dbWindow := NewDebuggerWindow(self)
|
||||||
// If the current working directory is the go-ethereum dir
|
dbWindow.SetCode("0x" + code)
|
||||||
// assume a debug build and use the source directory as
|
dbWindow.Show()
|
||||||
// asset directory.
|
|
||||||
pwd, _ := os.Getwd()
|
|
||||||
if pwd == path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "ethereal") {
|
|
||||||
base = path.Join(pwd, "assets")
|
|
||||||
} else {
|
|
||||||
switch runtime.GOOS {
|
|
||||||
case "darwin":
|
|
||||||
// Get Binary Directory
|
|
||||||
exedir, _ := osext.ExecutableFolder()
|
|
||||||
base = filepath.Join(exedir, "../Resources")
|
|
||||||
case "linux":
|
|
||||||
base = "/usr/share/ethereal"
|
|
||||||
case "window":
|
|
||||||
fallthrough
|
|
||||||
default:
|
|
||||||
base = "."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return base
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) {
|
func (self *UiLib) StartDebugger() {
|
||||||
state := ui.eth.BlockChain().CurrentBlock.State()
|
dbWindow := NewDebuggerWindow(self)
|
||||||
|
//self.DbWindow = dbWindow
|
||||||
|
|
||||||
script, err := ethutil.Compile(data)
|
dbWindow.Show()
|
||||||
if err != nil {
|
|
||||||
ethutil.Config.Log.Debugln(err)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
dis := ethchain.Disassemble(script)
|
|
||||||
ui.win.Root().Call("clearAsm")
|
|
||||||
|
|
||||||
for _, str := range dis {
|
|
||||||
ui.win.Root().Call("setAsm", str)
|
|
||||||
}
|
|
||||||
// Contract addr as test address
|
|
||||||
keyPair := ethutil.GetKeyRing().Get(0)
|
|
||||||
callerTx :=
|
|
||||||
ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), script)
|
|
||||||
callerTx.Sign(keyPair.PrivateKey)
|
|
||||||
|
|
||||||
account := ui.eth.StateManager().TransState().GetStateObject(keyPair.Address())
|
|
||||||
contract := ethchain.MakeContract(callerTx, state)
|
|
||||||
callerClosure := ethchain.NewClosure(account, contract, contract.Init(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr))
|
|
||||||
|
|
||||||
block := ui.eth.BlockChain().CurrentBlock
|
|
||||||
vm := ethchain.NewVm(state, ui.eth.StateManager(), ethchain.RuntimeVars{
|
|
||||||
Origin: account.Address(),
|
|
||||||
BlockNumber: block.BlockInfo().Number,
|
|
||||||
PrevHash: block.PrevHash,
|
|
||||||
Coinbase: block.Coinbase,
|
|
||||||
Time: block.Time,
|
|
||||||
Diff: block.Difficulty,
|
|
||||||
})
|
|
||||||
|
|
||||||
ui.Db.done = false
|
|
||||||
go func() {
|
|
||||||
callerClosure.Call(vm, contract.Init(), ui.Db.halting)
|
|
||||||
|
|
||||||
state.Reset()
|
|
||||||
|
|
||||||
ui.Db.done = true
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ui *UiLib) Next() {
|
|
||||||
ui.Db.Next()
|
|
||||||
}
|
}
|
||||||
|
32
ethereum/cmd.go
Normal file
32
ethereum/cmd.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ethereum/eth-go"
|
||||||
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitJsConsole(ethereum *eth.Ethereum) {
|
||||||
|
repl := NewJSRepl(ethereum)
|
||||||
|
go repl.Start()
|
||||||
|
utils.RegisterInterrupt(func(os.Signal) {
|
||||||
|
repl.Stop()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExecJsFile(ethereum *eth.Ethereum, InputFile string) {
|
||||||
|
file, err := os.Open(InputFile)
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatalln(err)
|
||||||
|
}
|
||||||
|
content, err := ioutil.ReadAll(file)
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatalln(err)
|
||||||
|
}
|
||||||
|
re := NewJSRE(ethereum)
|
||||||
|
utils.RegisterInterrupt(func(os.Signal) {
|
||||||
|
re.Stop()
|
||||||
|
})
|
||||||
|
re.Run(string(content))
|
||||||
|
}
|
@ -1,54 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Identifier string
|
|
||||||
var StartMining bool
|
|
||||||
var StartRpc bool
|
|
||||||
var RpcPort int
|
|
||||||
var UseUPnP bool
|
|
||||||
var OutboundPort string
|
|
||||||
var ShowGenesis bool
|
|
||||||
var AddPeer string
|
|
||||||
var MaxPeer int
|
|
||||||
var GenAddr bool
|
|
||||||
var UseSeed bool
|
|
||||||
var ImportKey string
|
|
||||||
var ExportKey bool
|
|
||||||
var LogFile string
|
|
||||||
var DataDir string
|
|
||||||
var NonInteractive bool
|
|
||||||
var StartJsConsole bool
|
|
||||||
var InputFile string
|
|
||||||
|
|
||||||
func Init() {
|
|
||||||
flag.Usage = func() {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s [options] [filename]:\n", os.Args[0])
|
|
||||||
flag.PrintDefaults()
|
|
||||||
}
|
|
||||||
|
|
||||||
flag.StringVar(&Identifier, "i", "", "custom client identifier")
|
|
||||||
flag.BoolVar(&StartMining, "m", false, "start dagger mining")
|
|
||||||
flag.BoolVar(&ShowGenesis, "g", false, "prints genesis header and exits")
|
|
||||||
flag.BoolVar(&StartRpc, "r", false, "start rpc server")
|
|
||||||
flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on")
|
|
||||||
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
|
||||||
flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support")
|
|
||||||
flag.BoolVar(&UseSeed, "seed", true, "seed peers")
|
|
||||||
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
|
||||||
flag.BoolVar(&ExportKey, "export", false, "export private key")
|
|
||||||
flag.StringVar(&OutboundPort, "p", "30303", "listening port")
|
|
||||||
flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
|
|
||||||
flag.StringVar(&DataDir, "dir", ".ethereum", "ethereum data directory")
|
|
||||||
flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)")
|
|
||||||
flag.IntVar(&MaxPeer, "x", 10, "maximum desired peers")
|
|
||||||
flag.BoolVar(&StartJsConsole, "js", false, "exp")
|
|
||||||
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
InputFile = flag.Arg(0)
|
|
||||||
}
|
|
@ -1,186 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/ethereum/eth-go"
|
|
||||||
"github.com/ethereum/eth-go/ethchain"
|
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"runtime"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
const Debug = true
|
|
||||||
|
|
||||||
func RegisterInterrupt(cb func(os.Signal)) {
|
|
||||||
go func() {
|
|
||||||
// Buffered chan of one is enough
|
|
||||||
c := make(chan os.Signal, 1)
|
|
||||||
// Notify about interrupts for now
|
|
||||||
signal.Notify(c, os.Interrupt)
|
|
||||||
|
|
||||||
for sig := range c {
|
|
||||||
cb(sig)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func confirm(message string) bool {
|
|
||||||
fmt.Println(message, "Are you sure? (y/n)")
|
|
||||||
var r string
|
|
||||||
fmt.Scanln(&r)
|
|
||||||
for ; ; fmt.Scanln(&r) {
|
|
||||||
if r == "n" || r == "y" {
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Yes or no?", r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return r == "y"
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
Init()
|
|
||||||
|
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
||||||
|
|
||||||
// set logger
|
|
||||||
var logSys *log.Logger
|
|
||||||
flags := log.LstdFlags
|
|
||||||
|
|
||||||
var lt ethutil.LoggerType
|
|
||||||
if StartJsConsole || len(InputFile) > 0 {
|
|
||||||
lt = ethutil.LogFile
|
|
||||||
} else {
|
|
||||||
lt = ethutil.LogFile | ethutil.LogStd
|
|
||||||
}
|
|
||||||
|
|
||||||
ethutil.ReadConfig(DataDir, lt, Identifier)
|
|
||||||
|
|
||||||
logger := ethutil.Config.Log
|
|
||||||
|
|
||||||
if LogFile != "" {
|
|
||||||
logfile, err := os.OpenFile(LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("error opening log file '%s': %v", LogFile, err))
|
|
||||||
}
|
|
||||||
defer logfile.Close()
|
|
||||||
log.SetOutput(logfile)
|
|
||||||
logSys = log.New(logfile, "", flags)
|
|
||||||
logger.AddLogSystem(logSys)
|
|
||||||
} else {
|
|
||||||
logSys = log.New(os.Stdout, "", flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
ethchain.InitFees()
|
|
||||||
|
|
||||||
// Instantiated a eth stack
|
|
||||||
ethereum, err := eth.New(eth.CapDefault, UseUPnP)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("eth start err:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ethereum.Port = OutboundPort
|
|
||||||
|
|
||||||
// bookkeeping tasks
|
|
||||||
switch {
|
|
||||||
case GenAddr:
|
|
||||||
if NonInteractive || confirm("This action overwrites your old private key.") {
|
|
||||||
utils.CreateKeyPair(true)
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
|
||||||
case len(ImportKey) > 0:
|
|
||||||
if NonInteractive || confirm("This action overwrites your old private key.") {
|
|
||||||
mnemonic := strings.Split(ImportKey, " ")
|
|
||||||
if len(mnemonic) == 24 {
|
|
||||||
logSys.Println("Got mnemonic key, importing.")
|
|
||||||
key := ethutil.MnemonicDecode(mnemonic)
|
|
||||||
utils.ImportPrivateKey(key)
|
|
||||||
} else if len(mnemonic) == 1 {
|
|
||||||
logSys.Println("Got hex key, importing.")
|
|
||||||
utils.ImportPrivateKey(ImportKey)
|
|
||||||
} else {
|
|
||||||
logSys.Println("Did not recognise format, exiting.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
|
||||||
case ExportKey:
|
|
||||||
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)
|
|
||||||
|
|
||||||
os.Exit(0)
|
|
||||||
case ShowGenesis:
|
|
||||||
logSys.Println(ethereum.BlockChain().Genesis())
|
|
||||||
os.Exit(0)
|
|
||||||
default:
|
|
||||||
// Creates a keypair if non exists
|
|
||||||
utils.CreateKeyPair(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// client
|
|
||||||
logger.Infoln(fmt.Sprintf("Starting Ethereum v%s", ethutil.Config.Ver))
|
|
||||||
|
|
||||||
// Set the max peers
|
|
||||||
ethereum.MaxPeers = MaxPeer
|
|
||||||
|
|
||||||
// Set Mining status
|
|
||||||
ethereum.Mining = StartMining
|
|
||||||
|
|
||||||
if StartMining {
|
|
||||||
utils.DoMining(ethereum)
|
|
||||||
}
|
|
||||||
|
|
||||||
if StartJsConsole {
|
|
||||||
repl := NewJSRepl(ethereum)
|
|
||||||
|
|
||||||
go repl.Start()
|
|
||||||
|
|
||||||
RegisterInterrupt(func(os.Signal) {
|
|
||||||
repl.Stop()
|
|
||||||
})
|
|
||||||
} else if len(InputFile) > 0 {
|
|
||||||
file, err := os.Open(InputFile)
|
|
||||||
if err != nil {
|
|
||||||
ethutil.Config.Log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
content, err := ioutil.ReadAll(file)
|
|
||||||
if err != nil {
|
|
||||||
ethutil.Config.Log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
re := NewJSRE(ethereum)
|
|
||||||
RegisterInterrupt(func(os.Signal) {
|
|
||||||
re.Stop()
|
|
||||||
})
|
|
||||||
re.Run(string(content))
|
|
||||||
}
|
|
||||||
|
|
||||||
if StartRpc {
|
|
||||||
utils.DoRpc(ethereum, RpcPort)
|
|
||||||
}
|
|
||||||
|
|
||||||
RegisterInterrupt(func(sig os.Signal) {
|
|
||||||
fmt.Printf("Shutting down (%v) ... \n", sig)
|
|
||||||
ethereum.Stop()
|
|
||||||
})
|
|
||||||
|
|
||||||
ethereum.Start(UseSeed)
|
|
||||||
|
|
||||||
// Wait for shutdown
|
|
||||||
ethereum.WaitForShutdown()
|
|
||||||
}
|
|
76
ethereum/flags.go
Normal file
76
ethereum/flags.go
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Identifier string
|
||||||
|
var KeyRing string
|
||||||
|
var KeyStore string
|
||||||
|
var StartRpc bool
|
||||||
|
var RpcPort int
|
||||||
|
var UseUPnP bool
|
||||||
|
var OutboundPort string
|
||||||
|
var ShowGenesis bool
|
||||||
|
var AddPeer string
|
||||||
|
var MaxPeer int
|
||||||
|
var GenAddr bool
|
||||||
|
var UseSeed bool
|
||||||
|
var SecretFile string
|
||||||
|
var ExportDir string
|
||||||
|
var NonInteractive bool
|
||||||
|
var Datadir string
|
||||||
|
var LogFile string
|
||||||
|
var ConfigFile string
|
||||||
|
var DebugFile string
|
||||||
|
var LogLevel int
|
||||||
|
|
||||||
|
// flags specific to cli client
|
||||||
|
var StartMining bool
|
||||||
|
var StartJsConsole bool
|
||||||
|
var InputFile string
|
||||||
|
|
||||||
|
func defaultDataDir() string {
|
||||||
|
usr, _ := user.Current()
|
||||||
|
return path.Join(usr.HomeDir, ".ethereum")
|
||||||
|
}
|
||||||
|
|
||||||
|
var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini")
|
||||||
|
|
||||||
|
func Init() {
|
||||||
|
flag.Usage = func() {
|
||||||
|
fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line\n", os.Args[0])
|
||||||
|
flag.PrintDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
|
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.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support")
|
||||||
|
flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers")
|
||||||
|
flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on")
|
||||||
|
flag.BoolVar(&StartRpc, "rpc", false, "start rpc server")
|
||||||
|
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
||||||
|
flag.BoolVar(&UseSeed, "seed", true, "seed peers")
|
||||||
|
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub 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(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
|
||||||
|
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
||||||
|
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.BoolVar(&StartMining, "mine", false, "start dagger mining")
|
||||||
|
flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
InputFile = flag.Arg(0)
|
||||||
|
}
|
@ -4,15 +4,19 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/eth-go"
|
"github.com/ethereum/eth-go"
|
||||||
"github.com/ethereum/eth-go/ethchain"
|
"github.com/ethereum/eth-go/ethchain"
|
||||||
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
"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/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
"github.com/obscuren/otto"
|
"github.com/obscuren/otto"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var jsrelogger = ethlog.NewLogger("JSRE")
|
||||||
|
|
||||||
type JSRE struct {
|
type JSRE struct {
|
||||||
ethereum *eth.Ethereum
|
ethereum *eth.Ethereum
|
||||||
vm *otto.Otto
|
vm *otto.Otto
|
||||||
@ -25,6 +29,20 @@ type JSRE struct {
|
|||||||
objectCb map[string][]otto.Value
|
objectCb map[string][]otto.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (jsre *JSRE) LoadExtFile(path string) {
|
||||||
|
result, err := ioutil.ReadFile(path)
|
||||||
|
if err == nil {
|
||||||
|
jsre.vm.Run(result)
|
||||||
|
} else {
|
||||||
|
jsrelogger.Debugln("Could not load file:", path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (jsre *JSRE) LoadIntFile(file string) {
|
||||||
|
assetPath := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "ethereal", "assets", "ext")
|
||||||
|
jsre.LoadExtFile(path.Join(assetPath, file))
|
||||||
|
}
|
||||||
|
|
||||||
func NewJSRE(ethereum *eth.Ethereum) *JSRE {
|
func NewJSRE(ethereum *eth.Ethereum) *JSRE {
|
||||||
re := &JSRE{
|
re := &JSRE{
|
||||||
ethereum,
|
ethereum,
|
||||||
@ -39,6 +57,10 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
|
|||||||
// Init the JS lib
|
// Init the JS lib
|
||||||
re.vm.Run(jsLib)
|
re.vm.Run(jsLib)
|
||||||
|
|
||||||
|
// Load extra javascript files
|
||||||
|
re.LoadIntFile("string.js")
|
||||||
|
re.LoadIntFile("big.js")
|
||||||
|
|
||||||
// We have to make sure that, whoever calls this, calls "Stop"
|
// We have to make sure that, whoever calls this, calls "Stop"
|
||||||
go re.mainLoop()
|
go re.mainLoop()
|
||||||
|
|
||||||
@ -46,6 +68,8 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
|
|||||||
|
|
||||||
re.initStdFuncs()
|
re.initStdFuncs()
|
||||||
|
|
||||||
|
jsrelogger.Infoln("started")
|
||||||
|
|
||||||
return re
|
return re
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +104,7 @@ func (self *JSRE) Stop() {
|
|||||||
close(self.blockChan)
|
close(self.blockChan)
|
||||||
close(self.quitChan)
|
close(self.quitChan)
|
||||||
close(self.changeChan)
|
close(self.changeChan)
|
||||||
|
jsrelogger.Infoln("stopped")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *JSRE) mainLoop() {
|
func (self *JSRE) mainLoop() {
|
||||||
@ -97,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)
|
||||||
}
|
}
|
||||||
@ -119,6 +144,7 @@ func (self *JSRE) initStdFuncs() {
|
|||||||
eth.Set("require", self.require)
|
eth.Set("require", self.require)
|
||||||
eth.Set("stopMining", self.stopMining)
|
eth.Set("stopMining", self.stopMining)
|
||||||
eth.Set("startMining", self.startMining)
|
eth.Set("startMining", self.startMining)
|
||||||
|
eth.Set("execBlock", self.execBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -152,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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,3 +214,18 @@ func (self *JSRE) require(call otto.FunctionCall) otto.Value {
|
|||||||
|
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *JSRE) execBlock(call otto.FunctionCall) otto.Value {
|
||||||
|
hash, err := call.Argument(0).ToString()
|
||||||
|
if err != nil {
|
||||||
|
return otto.UndefinedValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
err = utils.BlockDo(self.ethereum, ethutil.Hex2Bytes(hash))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return otto.FalseValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
return otto.TrueValue()
|
||||||
|
}
|
||||||
|
57
ethereum/main.go
Normal file
57
ethereum/main.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
var logger = ethlog.NewLogger("CLI")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
||||||
|
utils.HandleInterrupt()
|
||||||
|
|
||||||
|
// precedence: code-internal flag default < config file < environment variables < command line
|
||||||
|
Init() // parsing command line
|
||||||
|
utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH")
|
||||||
|
|
||||||
|
utils.InitDataDir(Datadir)
|
||||||
|
|
||||||
|
utils.InitLogging(Datadir, LogFile, LogLevel, DebugFile)
|
||||||
|
|
||||||
|
db := utils.NewDatabase()
|
||||||
|
|
||||||
|
keyManager := utils.NewKeyManager(KeyStore, Datadir, db)
|
||||||
|
|
||||||
|
// create, import, export keys
|
||||||
|
utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
|
||||||
|
|
||||||
|
ethereum := utils.NewEthereum(db, keyManager, UseUPnP, OutboundPort, MaxPeer)
|
||||||
|
|
||||||
|
if ShowGenesis {
|
||||||
|
utils.ShowGenesis(ethereum)
|
||||||
|
}
|
||||||
|
|
||||||
|
if StartMining {
|
||||||
|
utils.StartMining(ethereum)
|
||||||
|
}
|
||||||
|
|
||||||
|
// better reworked as cases
|
||||||
|
if StartJsConsole {
|
||||||
|
InitJsConsole(ethereum)
|
||||||
|
} else if len(InputFile) > 0 {
|
||||||
|
ExecJsFile(ethereum, InputFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
if StartRpc {
|
||||||
|
utils.StartRpc(ethereum, RpcPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.StartEthereum(ethereum, UseSeed)
|
||||||
|
|
||||||
|
// this blocks the thread
|
||||||
|
ethereum.WaitForShutdown()
|
||||||
|
ethlog.Flush()
|
||||||
|
}
|
@ -1,10 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/eth-go"
|
"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/obscuren/otto"
|
"github.com/obscuren/otto"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Repl interface {
|
type Repl interface {
|
||||||
@ -16,18 +21,48 @@ type JSRepl struct {
|
|||||||
re *JSRE
|
re *JSRE
|
||||||
|
|
||||||
prompt string
|
prompt string
|
||||||
|
|
||||||
|
history *os.File
|
||||||
|
|
||||||
|
running bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewJSRepl(ethereum *eth.Ethereum) *JSRepl {
|
func NewJSRepl(ethereum *eth.Ethereum) *JSRepl {
|
||||||
return &JSRepl{re: NewJSRE(ethereum), prompt: "> "}
|
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() {
|
func (self *JSRepl) Start() {
|
||||||
self.read()
|
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() {
|
func (self *JSRepl) Stop() {
|
||||||
self.re.Stop()
|
if self.running {
|
||||||
|
self.running = false
|
||||||
|
self.re.Stop()
|
||||||
|
logger.Infoln("exit JS Console")
|
||||||
|
self.history.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *JSRepl) parseInput(code string) {
|
func (self *JSRepl) parseInput(code string) {
|
||||||
@ -66,6 +101,10 @@ func (self *JSEthereum) GetBlock(hash string) otto.Value {
|
|||||||
return self.toVal(&JSBlock{self.PEthereum.GetBlock(hash), self})
|
return self.toVal(&JSBlock{self.PEthereum.GetBlock(hash), self})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *JSEthereum) GetPeers() otto.Value {
|
||||||
|
return self.toVal(self.PEthereum.GetPeers())
|
||||||
|
}
|
||||||
|
|
||||||
func (self *JSEthereum) GetKey() otto.Value {
|
func (self *JSEthereum) GetKey() otto.Value {
|
||||||
return self.toVal(self.PEthereum.GetKey())
|
return self.toVal(self.PEthereum.GetKey())
|
||||||
}
|
}
|
||||||
@ -74,6 +113,10 @@ func (self *JSEthereum) GetStateObject(addr string) otto.Value {
|
|||||||
return self.toVal(self.PEthereum.GetStateObject(addr))
|
return self.toVal(self.PEthereum.GetStateObject(addr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *JSEthereum) GetStateKeyVals(addr string) otto.Value {
|
||||||
|
return self.toVal(self.PEthereum.GetStateObject(addr).StateKeyVal(false))
|
||||||
|
}
|
||||||
|
|
||||||
func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) otto.Value {
|
func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) otto.Value {
|
||||||
r, err := self.PEthereum.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr)
|
r, err := self.PEthereum.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -101,7 +144,7 @@ func (self *JSEthereum) toVal(v interface{}) otto.Value {
|
|||||||
result, err := self.vm.ToValue(v)
|
result, err := self.vm.ToValue(v)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println("Value unknown:", err)
|
||||||
|
|
||||||
return otto.UndefinedValue()
|
return otto.UndefinedValue()
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,9 @@ L:
|
|||||||
break L
|
break L
|
||||||
}
|
}
|
||||||
|
|
||||||
addHistory(str[:len(str)-1]) //allow user to recall this line
|
hist := str[:len(str)-1]
|
||||||
|
addHistory(hist) //allow user to recall this line
|
||||||
|
self.history.WriteString(str)
|
||||||
|
|
||||||
self.parseInput(str)
|
self.parseInput(str)
|
||||||
|
|
||||||
|
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 :-)"
|
255
utils/cmd.go
255
utils/cmd.go
@ -1,19 +1,196 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"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/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"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"path"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DoRpc(ethereum *eth.Ethereum, RpcPort int) {
|
var logger = ethlog.NewLogger("CLI")
|
||||||
|
var interruptCallbacks = []func(os.Signal){}
|
||||||
|
|
||||||
|
// Register interrupt handlers callbacks
|
||||||
|
func RegisterInterrupt(cb func(os.Signal)) {
|
||||||
|
interruptCallbacks = append(interruptCallbacks, cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
// go routine that call interrupt handlers in order of registering
|
||||||
|
func HandleInterrupt() {
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
go func() {
|
||||||
|
signal.Notify(c, os.Interrupt)
|
||||||
|
for sig := range c {
|
||||||
|
logger.Errorf("Shutting down (%v) ... \n", sig)
|
||||||
|
RunInterruptCallbacks(sig)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RunInterruptCallbacks(sig os.Signal) {
|
||||||
|
for _, cb := range interruptCallbacks {
|
||||||
|
cb(sig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func AbsolutePath(Datadir string, filename string) string {
|
||||||
|
if path.IsAbs(filename) {
|
||||||
|
return filename
|
||||||
|
}
|
||||||
|
return path.Join(Datadir, filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
func openLogFile(Datadir string, filename string) *os.File {
|
||||||
|
path := AbsolutePath(Datadir, filename)
|
||||||
|
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("error opening log file '%s': %v", filename, err))
|
||||||
|
}
|
||||||
|
return file
|
||||||
|
}
|
||||||
|
|
||||||
|
func confirm(message string) bool {
|
||||||
|
fmt.Println(message, "Are you sure? (y/n)")
|
||||||
|
var r string
|
||||||
|
fmt.Scanln(&r)
|
||||||
|
for ; ; fmt.Scanln(&r) {
|
||||||
|
if r == "n" || r == "y" {
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Yes or no?", r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r == "y"
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitDataDir(Datadir string) {
|
||||||
|
_, err := os.Stat(Datadir)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
fmt.Printf("Data directory '%s' doesn't exist, creating it\n", Datadir)
|
||||||
|
os.Mkdir(Datadir, 0777)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitLogging(Datadir string, LogFile string, LogLevel int, DebugFile string) {
|
||||||
|
var writer io.Writer
|
||||||
|
if LogFile == "" {
|
||||||
|
writer = os.Stdout
|
||||||
|
} else {
|
||||||
|
writer = openLogFile(Datadir, LogFile)
|
||||||
|
}
|
||||||
|
ethlog.AddLogSystem(ethlog.NewStdLogSystem(writer, log.LstdFlags, ethlog.LogLevel(LogLevel)))
|
||||||
|
if DebugFile != "" {
|
||||||
|
writer = openLogFile(Datadir, DebugFile)
|
||||||
|
ethlog.AddLogSystem(ethlog.NewStdLogSystem(writer, log.LstdFlags, ethlog.DebugLevel))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitConfig(ConfigFile string, Datadir string, Identifier string, EnvPrefix string) {
|
||||||
|
InitDataDir(Datadir)
|
||||||
|
ethutil.ReadConfig(ConfigFile, Datadir, Identifier, EnvPrefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
func exit(err error) {
|
||||||
|
status := 0
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorln("Fatal: ", err)
|
||||||
|
status = 1
|
||||||
|
}
|
||||||
|
ethlog.Flush()
|
||||||
|
os.Exit(status)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDatabase() ethutil.Database {
|
||||||
|
db, err := ethdb.NewLDBDatabase("database")
|
||||||
|
if err != nil {
|
||||||
|
exit(err)
|
||||||
|
}
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEthereum(db ethutil.Database, keyManager *ethcrypto.KeyManager, usePnp bool, OutboundPort string, MaxPeer int) *eth.Ethereum {
|
||||||
|
ethereum, err := eth.New(db, keyManager, eth.CapDefault, usePnp)
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatalln("eth start err:", err)
|
||||||
|
}
|
||||||
|
ethereum.Port = OutboundPort
|
||||||
|
ethereum.MaxPeers = MaxPeer
|
||||||
|
return ethereum
|
||||||
|
}
|
||||||
|
|
||||||
|
func StartEthereum(ethereum *eth.Ethereum, UseSeed bool) {
|
||||||
|
logger.Infof("Starting Ethereum v%s", ethutil.Config.Ver)
|
||||||
|
ethereum.Start(UseSeed)
|
||||||
|
RegisterInterrupt(func(sig os.Signal) {
|
||||||
|
ethereum.Stop()
|
||||||
|
ethlog.Flush()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func ShowGenesis(ethereum *eth.Ethereum) {
|
||||||
|
logger.Infoln(ethereum.BlockChain().Genesis())
|
||||||
|
exit(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
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 KeyTasks(keyManager *ethcrypto.KeyManager, KeyRing string, GenAddr bool, SecretFile string, ExportDir string, NonInteractive bool) {
|
||||||
|
var err error
|
||||||
|
switch {
|
||||||
|
case GenAddr:
|
||||||
|
if NonInteractive || confirm("This action overwrites your old private key.") {
|
||||||
|
err = keyManager.Init(KeyRing, 0, true)
|
||||||
|
}
|
||||||
|
exit(err)
|
||||||
|
case len(SecretFile) > 0:
|
||||||
|
if NonInteractive || confirm("This action overwrites your old private key.") {
|
||||||
|
err = keyManager.InitFromSecretsFile(KeyRing, 0, SecretFile)
|
||||||
|
}
|
||||||
|
exit(err)
|
||||||
|
case len(ExportDir) > 0:
|
||||||
|
err = keyManager.Init(KeyRing, 0, false)
|
||||||
|
if err == nil {
|
||||||
|
err = keyManager.Export(ExportDir)
|
||||||
|
}
|
||||||
|
exit(err)
|
||||||
|
default:
|
||||||
|
// Creates a keypair if none exists
|
||||||
|
err = keyManager.Init(KeyRing, 0, false)
|
||||||
|
if err != nil {
|
||||||
|
exit(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func StartRpc(ethereum *eth.Ethereum, RpcPort int) {
|
||||||
var err error
|
var err error
|
||||||
ethereum.RpcServer, err = ethrpc.NewJsonRpcServer(ethpub.NewPEthereum(ethereum), RpcPort)
|
ethereum.RpcServer, err = ethrpc.NewJsonRpcServer(ethpub.NewPEthereum(ethereum), RpcPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ethutil.Config.Log.Infoln("Could not start RPC interface:", err)
|
logger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
|
||||||
} else {
|
} else {
|
||||||
go ethereum.RpcServer.Start()
|
go ethereum.RpcServer.Start()
|
||||||
}
|
}
|
||||||
@ -21,56 +198,56 @@ func DoRpc(ethereum *eth.Ethereum, RpcPort int) {
|
|||||||
|
|
||||||
var miner ethminer.Miner
|
var miner ethminer.Miner
|
||||||
|
|
||||||
func DoMining(ethereum *eth.Ethereum) {
|
func StartMining(ethereum *eth.Ethereum) bool {
|
||||||
// Set Mining status
|
if !ethereum.Mining {
|
||||||
ethereum.Mining = true
|
ethereum.Mining = true
|
||||||
|
|
||||||
if ethutil.GetKeyRing().Len() == 0 {
|
addr := ethereum.KeyManager().Address()
|
||||||
ethutil.Config.Log.Infoln("No address found, can't start mining")
|
|
||||||
return
|
go func() {
|
||||||
|
miner = ethminer.NewDefaultMiner(addr, ethereum)
|
||||||
|
// Give it some time to connect with peers
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
for !ethereum.IsUpToDate() {
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Infoln("Miner started")
|
||||||
|
miner := ethminer.NewDefaultMiner(addr, ethereum)
|
||||||
|
miner.Start()
|
||||||
|
}()
|
||||||
|
RegisterInterrupt(func(os.Signal) {
|
||||||
|
StopMining(ethereum)
|
||||||
|
})
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
keyPair := ethutil.GetKeyRing().Get(0)
|
return false
|
||||||
addr := keyPair.Address()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
ethutil.Config.Log.Infoln("Miner started")
|
|
||||||
|
|
||||||
miner = ethminer.NewDefaultMiner(addr, ethereum)
|
|
||||||
|
|
||||||
// Give it some time to connect with peers
|
|
||||||
time.Sleep(3 * time.Second)
|
|
||||||
|
|
||||||
for ethereum.IsUpToDate() == false {
|
|
||||||
time.Sleep(5 * time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
ethutil.Config.Log.Infoln("Miner started")
|
|
||||||
|
|
||||||
miner := ethminer.NewDefaultMiner(addr, ethereum)
|
|
||||||
miner.Start()
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func StopMining(ethereum *eth.Ethereum) bool {
|
func StopMining(ethereum *eth.Ethereum) bool {
|
||||||
if ethereum.Mining {
|
if ethereum.Mining {
|
||||||
miner.Stop()
|
miner.Stop()
|
||||||
|
logger.Infoln("Miner stopped")
|
||||||
ethutil.Config.Log.Infoln("Miner stopped")
|
|
||||||
|
|
||||||
ethereum.Mining = false
|
ethereum.Mining = false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartMining(ethereum *eth.Ethereum) bool {
|
// Replay block
|
||||||
if !ethereum.Mining {
|
func BlockDo(ethereum *eth.Ethereum, hash []byte) error {
|
||||||
DoMining(ethereum)
|
block := ethereum.BlockChain().GetBlock(hash)
|
||||||
|
if block == nil {
|
||||||
return true
|
return fmt.Errorf("unknown block %x", hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
parent := ethereum.BlockChain().GetBlock(block.PrevHash)
|
||||||
|
|
||||||
|
_, err := ethereum.StateManager().ApplyDiff(parent.State(), parent, block)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/obscuren/mutan"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// General compile function
|
|
||||||
func Compile(script string) ([]byte, error) {
|
|
||||||
byteCode, errors := mutan.Compile(strings.NewReader(script), false)
|
|
||||||
if len(errors) > 0 {
|
|
||||||
var errs string
|
|
||||||
for _, er := range errors {
|
|
||||||
if er != nil {
|
|
||||||
errs += er.Error()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("%v", errs)
|
|
||||||
}
|
|
||||||
|
|
||||||
return byteCode, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func CompileScript(script string) ([]byte, []byte, error) {
|
|
||||||
// Preprocess
|
|
||||||
mainInput, initInput := mutan.PreParse(script)
|
|
||||||
// Compile main script
|
|
||||||
mainScript, err := Compile(mainInput)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compile init script
|
|
||||||
initScript, err := Compile(initInput)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return mainScript, initScript, nil
|
|
||||||
}
|
|
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