Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
60f9966c
Commit
60f9966c
authored
May 02, 2014
by
Maran
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into feature/rpc
parents
3424bf17
f1da6f05
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
352 additions
and
253 deletions
+352
-253
README.md
README.md
+9
-1
ethereum.js
ethereal/assets/ethereum.js
+63
-3
webapp.qml
ethereal/assets/qml/webapp.qml
+9
-0
samplecoin.html
ethereal/assets/samplecoin.html
+0
-69
bootstrap-theme.min.css
ethereal/assets/samplecoin/bootstrap-theme.min.css
+7
-0
bootstrap.min.css
ethereal/assets/samplecoin/bootstrap.min.css
+7
-0
icon.png
ethereal/assets/samplecoin/icon.png
+0
-0
samplecoin.css
ethereal/assets/samplecoin/samplecoin.css
+34
-0
samplecoin.html
ethereal/assets/samplecoin/samplecoin.html
+70
-0
test.html
ethereal/assets/test.html
+0
-55
ext_app.go
ethereal/ui/ext_app.go
+2
-94
gui.go
ethereal/ui/gui.go
+7
-6
html_container.go
ethereal/ui/html_container.go
+3
-2
library.go
ethereal/ui/library.go
+5
-5
ethereum.go
utils/ethereum.go
+110
-0
types.go
utils/types.go
+26
-18
No files found.
README.md
View file @
60f9966c
...
...
@@ -12,7 +12,15 @@ For the development package please see the [eth-go package](https://github.com/e
Build
=======
For build instruction please see the
[
Wiki
](
https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum(Go
)
)
To build Ethereal (GUI):
`go get github.com/ethereum/go-ethereum/ethereal`
To build the node (CLI):
`go get github.com/ethereum/go-ethereum/ethereum`
For further, detailed, build instruction please see the
[
Wiki
](
https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum(Go
)
)
General command line options
====================
...
...
ethereal/assets/ethereum.js
View file @
60f9966c
...
...
@@ -19,8 +19,7 @@ window.eth = {
// Create transaction
//
// Creates a transaction with the current account
// If no recipient is set, the Ethereum API will see it as a contract creation
// Transact between two state objects
transact
:
function
(
sec
,
recipient
,
value
,
gas
,
gasPrice
,
data
,
cb
)
{
postData
({
call
:
"transact"
,
args
:
[
sec
,
recipient
,
value
,
gas
,
gasPrice
,
data
]},
cb
);
},
...
...
@@ -71,6 +70,10 @@ window.eth = {
postData
({
call
:
"disconnect"
,
args
:
[
address
,
storageAddrOrCb
]});
},
set
:
function
(
props
)
{
postData
({
call
:
"set"
,
args
:
props
});
},
on
:
function
(
event
,
cb
)
{
if
(
eth
.
_onCallbacks
[
event
]
===
undefined
)
{
eth
.
_onCallbacks
[
event
]
=
[];
...
...
@@ -110,7 +113,7 @@ function debug(/**/) {
var
args
=
arguments
;
var
msg
=
""
for
(
var
i
=
0
;
i
<
args
.
length
;
i
++
){
if
(
typeof
args
[
i
]
==
"object"
)
{
if
(
typeof
args
[
i
]
==
=
"object"
)
{
msg
+=
" "
+
JSON
.
stringify
(
args
[
i
])
}
else
{
msg
+=
args
[
i
]
...
...
@@ -151,3 +154,60 @@ navigator.qt.onmessage = function(ev) {
}
}
}
window
.
eth
.
_0
=
"
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0
\
0"
String
.
prototype
.
pad
=
function
(
len
)
{
var
bin
=
this
.
bin
();
var
l
=
bin
.
length
;
if
(
l
<
32
)
{
return
eth
.
_0
.
substr
(
0
,
32
-
bin
.
length
)
+
bin
;
}
return
bin
;
}
String
.
prototype
.
unpad
=
function
()
{
var
i
,
l
;
for
(
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
{
if
(
this
[
i
]
!=
"
\
0"
)
{
return
this
.
substr
(
i
,
this
.
length
);
}
}
return
this
.
substr
(
i
,
this
.
length
);
}
String
.
prototype
.
bin
=
function
()
{
if
(
this
.
substr
(
0
,
2
)
==
"0x"
)
{
return
this
.
hex2bin
();
}
else
if
(
/^
\d
+$/
.
test
(
this
))
{
return
this
.
num2bin
()
}
// Otherwise we'll return the "String" object instead of an actual string
return
this
.
substr
(
0
,
this
.
length
)
}
String
.
prototype
.
unbin
=
function
()
{
var
i
,
l
,
o
=
''
;
for
(
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
{
var
n
=
this
.
charCodeAt
(
i
).
toString
(
16
);
o
+=
n
.
length
<
2
?
'0'
+
n
:
n
;
}
return
"0x"
+
o
;
}
String
.
prototype
.
hex2bin
=
function
()
{
bytes
=
[]
for
(
var
i
=
2
;
i
<
this
.
length
-
1
;
i
+=
2
)
{
bytes
.
push
(
parseInt
(
this
.
substr
(
i
,
2
),
16
));
}
return
String
.
fromCharCode
.
apply
(
String
,
bytes
);
}
String
.
prototype
.
num2bin
=
function
()
{
return
(
"0x"
+
parseInt
(
this
).
toString
(
16
)).
bin
()
}
ethereal/assets/qml/webapp.qml
View file @
60f9966c
...
...
@@ -60,6 +60,7 @@ ApplicationWindow {
var
tx
=
eth
.
transact
(
data
.
args
[
0
],
data
.
args
[
1
],
data
.
args
[
2
],
data
.
args
[
3
],
data
.
args
[
4
],
data
.
args
[
5
])
postData
(
data
.
_seed
,
tx
)
break
case
"create"
:
postData
(
data
.
_seed
,
null
)
...
...
@@ -91,6 +92,12 @@ ApplicationWindow {
require
(
1
)
postData
(
data
.
_seed
,
null
)
break
;
case
"set"
:
for
(
var
key
in
data
.
args
)
{
if
(
webview
.
hasOwnProperty
(
key
))
{
window
[
key
]
=
data
.
args
[
key
];
}
}
}
}
catch
(
e
)
{
console
.
log
(
data
.
call
+
": "
+
e
)
...
...
@@ -117,6 +124,8 @@ ApplicationWindow {
function
onObjectChangeCb
(
stateObject
)
{
postEvent
(
"object:"
+
stateObject
.
address
(),
stateObject
)
}
function
onStorageChangeCb
()
{
}
}
Rectangle
{
...
...
ethereal/assets/samplecoin.html
deleted
100644 → 0
View file @
3424bf17
<html>
<head>
<title>
jeffcoin
</title>
<script
type=
"text/javascript"
>
var
jefcoinAddr
=
"3dff537f51350239abc95c76a5864aa605259e7d"
function
createTransaction
()
{
var
addr
=
document
.
querySelector
(
"#addr"
).
value
;
var
amount
=
document
.
querySelector
(
"#amount"
).
value
;
var
data
=
"0x"
+
addr
+
"
\n
"
+
amount
eth
.
transact
(
""
,
jefcoinAddr
,
0
,
"10000000"
,
"250"
,
data
,
function
(
tx
)
{
debug
(
"received tx hash:"
,
tx
)
})
}
// Any test related actions here please
function
tests
()
{
eth
.
getKey
(
function
(
keys
)
{
debug
(
keys
)
})
}
function
init
()
{
eth
.
getKey
(
function
(
key
)
{
eth
.
getStorageAt
(
jefcoinAddr
,
key
,
function
(
storage
)
{
document
.
querySelector
(
"#currentAmount"
).
innerHTML
=
"Amount: "
+
storage
;
});
eth
.
watch
(
jefcoinAddr
,
function
(
stateObject
)
{
eth
.
getStorageAt
(
jefcoinAddr
,
key
,
function
(
storage
)
{
document
.
querySelector
(
"#currentAmount"
).
innerHTML
=
"Amount: "
+
storage
;
});
});
eth
.
getBalanceAt
(
key
,
function
(
balance
)
{
debug
(
"balance"
,
balance
);
})
});
}
</script>
<style
type=
"text/css"
>
input
[
type
=
"text"
]
{
width
:
300px
;
}
</style>
</head>
<body
onload=
"init();"
>
<h1>
Jeff Coin
</h1>
<img
src=
"icon.png"
>
<div
id=
"currentAmount"
></div>
<div
id=
"transactions"
>
<input
id=
"addr"
type=
"text"
placeholder=
"Receiver address"
></input><br>
<input
id=
"amount"
type=
"text"
placeholder=
"Amount"
></input><br>
<button
onclick=
"createTransaction();"
>
Send Tx
</button>
</div>
<div><button
onclick=
"tests();"
>
Tests
</button></div>
<div
id=
"debug"
style=
"border: 1px solid block"
></div>
</body>
</html>
ethereal/assets/samplecoin/bootstrap-theme.min.css
0 → 100755
View file @
60f9966c
This diff is collapsed.
Click to expand it.
ethereal/assets/samplecoin/bootstrap.min.css
0 → 100755
View file @
60f9966c
This diff is collapsed.
Click to expand it.
ethereal/assets/icon.png
→
ethereal/assets/
samplecoin/
icon.png
View file @
60f9966c
File moved
ethereal/assets/samplecoin/samplecoin.css
0 → 100644
View file @
60f9966c
/* Space out content a bit */
body
{
padding-top
:
20px
;
padding-bottom
:
20px
;
}
/* Everything but the jumbotron gets side spacing for mobile first
* views */
.header
,
.marketing
,
.footer
{
padding-right
:
15px
;
padding-left
:
15px
;
}
/* Custom page header */
.header
{
border-bottom
:
1px
solid
#e5e5e5
;
}
/* Make the masthead heading the same height as the navigation */
.header
h3
{
padding-bottom
:
19px
;
margin-top
:
0
;
margin-bottom
:
0
;
line-height
:
40px
;
}
.jumbotron
{
text-align
:
center
;
border-bottom
:
1px
solid
#e5e5e5
;
margin
:
0
auto
;
width
:
300px
;
}
ethereal/assets/samplecoin/samplecoin.html
0 → 100644
View file @
60f9966c
<html>
<head>
<title>
jeffcoin
</title>
<link
rel=
"stylesheet"
href=
"bootstrap.min.css"
>
<link
rel=
"stylesheet"
href=
"bootstrap-theme.min.css"
>
<link
rel=
"stylesheet"
href=
"samplecoin.css"
>
<meta
name=
"viewport"
content=
"minimum-scale=1; maximum-scale=1; initial-scale=1;"
>
<script
type=
"text/javascript"
>
var
jefcoinAddr
=
"3dff537f51350239abc95c76a5864aa605259e7d"
var
mAddr
=
""
function
createTransaction
()
{
var
addr
=
document
.
querySelector
(
"#addr"
).
value
;
var
amount
=
document
.
querySelector
(
"#amount"
).
value
;
var
data
=
((
"0x"
+
addr
).
pad
(
32
)
+
amount
.
pad
(
32
)).
unbin
()
eth
.
transact
(
mAddr
,
jefcoinAddr
,
0
,
"10000000"
,
"250"
,
data
,
function
(
tx
)
{
debug
(
"received tx hash:"
,
tx
)
})
}
function
init
()
{
eth
.
set
({
width
:
500
})
eth
.
getKey
(
function
(
keyPair
)
{
mAddr
=
keyPair
.
privateKey
;
eth
.
getStorageAt
(
jefcoinAddr
,
keyPair
.
address
,
function
(
storage
)
{
document
.
querySelector
(
"#current-amount"
).
innerHTML
=
storage
;
});
eth
.
watch
(
jefcoinAddr
,
function
(
stateObject
)
{
eth
.
getStorageAt
(
jefcoinAddr
,
keyPair
.
address
,
function
(
storage
)
{
document
.
querySelector
(
"#current-amount"
).
innerHTML
=
storage
;
});
});
});
}
</script>
</head>
<body
onload=
"init();"
>
<div
class=
"container"
>
<div
class=
"header"
>
<h3
class=
"text-muted"
>
JeffCoin
</h3>
</div>
<div
class=
"jumbotron "
>
<img
src=
"icon.png"
>
<div>
Amount:
<strong
id=
"current-amount"
></strong></div>
<div
id=
"transactions"
>
<div
class=
"form-group"
>
<input
id=
"addr"
class=
"form-control"
type=
"text"
placeholder=
"Receiver address"
></input><br>
<input
id=
"amount"
class=
"form-control"
type=
"text"
placeholder=
"Amount"
></input><br>
</div>
<button
class=
"btn btn-default"
onclick=
"createTransaction();"
>
Send Tx
</button>
</div>
</div>
</div>
<div
id=
"debug"
style=
"border: 1px solid black; min-height: 30px;"
></div>
</body>
</html>
ethereal/assets/test.html
deleted
100644 → 0
View file @
3424bf17
<html>
<head>
<title>
jeffcoin
</title>
<script
type=
"text/javascript"
>
var
jefcoinAddr
=
"3dff537f51350239abc95c76a5864aa605259e7d"
function
createTransaction
()
{
var
addr
=
document
.
querySelector
(
"#addr"
).
value
;
var
amount
=
document
.
querySelector
(
"#amount"
).
value
;
var
data
=
"0x"
+
addr
+
"
\n
"
+
amount
eth
.
createTx
(
jefcoinAddr
,
0
,
"10000000"
,
"250"
,
data
,
function
(
tx
)
{
debug
(
"received tx hash:"
,
tx
)
})
}
function
init
()
{
eth
.
getKey
(
function
(
key
)
{
eth
.
getStorage
(
jefcoinAddr
,
key
,
function
(
storage
)
{
document
.
querySelector
(
"#currentAmount"
).
innerHTML
=
"Amount: "
+
storage
;
});
eth
.
on
(
"block:new"
,
function
()
{
eth
.
getStorage
(
jefcoinAddr
,
key
,
function
(
storage
)
{
document
.
querySelector
(
"#currentAmount"
).
innerHTML
=
"Amount: "
+
storage
;
});
});
});
}
</script>
<style
type=
"text/css"
>
input
[
type
=
"text"
]
{
width
:
300px
;
}
</style>
</head>
<body
onload=
"init();"
>
<h1>
Jeff Coin
</h1>
<img
src=
"icon.png"
>
<div
id=
"currentAmount"
></div>
<div
id=
"transactions"
>
<input
id=
"addr"
type=
"text"
placeholder=
"Receiver address"
></input><br>
<input
id=
"amount"
type=
"text"
placeholder=
"Amount"
></input><br>
<button
onclick=
"createTransaction();"
>
Send Tx
</button>
</div>
<div
id=
"debug"
style=
"border: 1px solid block"
></div>
</body>
</html>
ethereal/ui/ext_app.go
View file @
60f9966c
...
...
@@ -2,13 +2,11 @@ package ethui
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"
"github.com/go-qml/qml"
"math/big"
"strings"
)
type
AppContainer
interface
{
...
...
@@ -24,7 +22,7 @@ type AppContainer interface {
}
type
ExtApplication
struct
{
*
Q
Ethereum
*
utils
.
P
Ethereum
blockChan
chan
ethutil
.
React
changeChan
chan
ethutil
.
React
...
...
@@ -37,7 +35,7 @@ type ExtApplication struct {
func
NewExtApplication
(
container
AppContainer
,
lib
*
UiLib
)
*
ExtApplication
{
app
:=
&
ExtApplication
{
NewQ
Ethereum
(
lib
.
eth
),
utils
.
NewP
Ethereum
(
lib
.
eth
),
make
(
chan
ethutil
.
React
,
1
),
make
(
chan
ethutil
.
React
,
1
),
make
(
chan
bool
),
...
...
@@ -127,93 +125,3 @@ func (app *ExtApplication) Watch(addr, storageAddr string) {
app
.
registeredEvents
=
append
(
app
.
registeredEvents
,
event
)
}
type
QEthereum
struct
{
stateManager
*
ethchain
.
StateManager
blockChain
*
ethchain
.
BlockChain
txPool
*
ethchain
.
TxPool
}
func
NewQEthereum
(
eth
*
eth
.
Ethereum
)
*
QEthereum
{
return
&
QEthereum
{
eth
.
StateManager
(),
eth
.
BlockChain
(),
eth
.
TxPool
(),
}
}
func
(
lib
*
QEthereum
)
GetBlock
(
hexHash
string
)
*
QBlock
{
hash
:=
ethutil
.
FromHex
(
hexHash
)
block
:=
lib
.
blockChain
.
GetBlock
(
hash
)
return
&
QBlock
{
Number
:
int
(
block
.
BlockInfo
()
.
Number
),
Hash
:
ethutil
.
Hex
(
block
.
Hash
())}
}
func
(
lib
*
QEthereum
)
GetKey
()
string
{
return
ethutil
.
Hex
(
ethutil
.
Config
.
Db
.
GetKeys
()[
0
]
.
Address
())
}
func
(
lib
*
QEthereum
)
GetStateObject
(
address
string
)
*
QStateObject
{
stateObject
:=
lib
.
stateManager
.
ProcState
()
.
GetContract
(
ethutil
.
FromHex
(
address
))
if
stateObject
!=
nil
{
return
NewQStateObject
(
stateObject
)
}
// See GetStorage for explanation on "nil"
return
NewQStateObject
(
nil
)
}
func
(
lib
*
QEthereum
)
Watch
(
addr
,
storageAddr
string
)
{
// lib.stateManager.Watch(ethutil.FromHex(addr), ethutil.FromHex(storageAddr))
}
func
(
lib
*
QEthereum
)
CreateTx
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
(
string
,
error
)
{
return
lib
.
Transact
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
)
}
func
(
lib
*
QEthereum
)
Transact
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
(
string
,
error
)
{
var
hash
[]
byte
var
contractCreation
bool
if
len
(
recipient
)
==
0
{
contractCreation
=
true
}
else
{
hash
=
ethutil
.
FromHex
(
recipient
)
}
keyPair
:=
ethutil
.
Config
.
Db
.
GetKeys
()[
0
]
value
:=
ethutil
.
Big
(
valueStr
)
gas
:=
ethutil
.
Big
(
gasStr
)
gasPrice
:=
ethutil
.
Big
(
gasPriceStr
)
var
tx
*
ethchain
.
Transaction
// Compile and assemble the given data
if
contractCreation
{
// Compile script
mainScript
,
initScript
,
err
:=
utils
.
CompileScript
(
dataStr
)
if
err
!=
nil
{
return
""
,
err
}
tx
=
ethchain
.
NewContractCreationTx
(
value
,
gas
,
gasPrice
,
mainScript
,
initScript
)
}
else
{
lines
:=
strings
.
Split
(
dataStr
,
"
\n
"
)
var
data
[]
byte
for
_
,
line
:=
range
lines
{
data
=
append
(
data
,
ethutil
.
BigToBytes
(
ethutil
.
Big
(
line
),
256
)
...
)
}
tx
=
ethchain
.
NewTransactionMessage
(
hash
,
value
,
gas
,
gasPrice
,
data
)
}
acc
:=
lib
.
stateManager
.
GetAddrState
(
keyPair
.
Address
())
tx
.
Nonce
=
acc
.
Nonce
tx
.
Sign
(
keyPair
.
PrivateKey
)
lib
.
txPool
.
QueueTransaction
(
tx
)
if
contractCreation
{
ethutil
.
Config
.
Log
.
Infof
(
"Contract addr %x"
,
tx
.
Hash
()[
12
:
])
}
else
{
ethutil
.
Config
.
Log
.
Infof
(
"Tx hash %x"
,
tx
.
Hash
())
}
return
ethutil
.
Hex
(
tx
.
Hash
()),
nil
}
ethereal/ui/gui.go
View file @
60f9966c
...
...
@@ -7,6 +7,7 @@ import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/go-ethereum/utils"
"github.com/go-qml/qml"
"math/big"
"strings"
...
...
@@ -56,9 +57,9 @@ func (ui *Gui) Start(assetPath string) {
// Register ethereum functions
qml
.
RegisterTypes
(
"Ethereum"
,
1
,
0
,
[]
qml
.
TypeSpec
{{
Init
:
func
(
p
*
Q
Block
,
obj
qml
.
Object
)
{
p
.
Number
=
0
;
p
.
Hash
=
""
},
Init
:
func
(
p
*
utils
.
P
Block
,
obj
qml
.
Object
)
{
p
.
Number
=
0
;
p
.
Hash
=
""
},
},
{
Init
:
func
(
p
*
Q
Tx
,
obj
qml
.
Object
)
{
p
.
Value
=
""
;
p
.
Hash
=
""
;
p
.
Address
=
""
},
Init
:
func
(
p
*
utils
.
P
Tx
,
obj
qml
.
Object
)
{
p
.
Value
=
""
;
p
.
Hash
=
""
;
p
.
Address
=
""
},
}})
ethutil
.
Config
.
SetClientString
(
fmt
.
Sprintf
(
"/Ethereal v%s"
,
"0.2"
))
...
...
@@ -129,13 +130,13 @@ func (ui *Gui) readPreviousTransactions() {
for
it
.
Next
()
{
tx
:=
ethchain
.
NewTransactionFromBytes
(
it
.
Value
())
ui
.
win
.
Root
()
.
Call
(
"addTx"
,
NewQ
Tx
(
tx
))
ui
.
win
.
Root
()
.
Call
(
"addTx"
,
utils
.
NewP
Tx
(
tx
))
}
it
.
Release
()
}
func
(
ui
*
Gui
)
ProcessBlock
(
block
*
ethchain
.
Block
)
{
ui
.
win
.
Root
()
.
Call
(
"addBlock"
,
NewQ
Block
(
block
))
ui
.
win
.
Root
()
.
Call
(
"addBlock"
,
utils
.
NewP
Block
(
block
))
}
// Simple go routine function that updates the list of peers in the GUI
...
...
@@ -156,13 +157,13 @@ func (ui *Gui) update() {
if
txMsg
.
Type
==
ethchain
.
TxPre
{
if
bytes
.
Compare
(
tx
.
Sender
(),
ui
.
addr
)
==
0
&&
addrState
.
Nonce
<=
tx
.
Nonce
{
ui
.
win
.
Root
()
.
Call
(
"addTx"
,
NewQ
Tx
(
tx
))
ui
.
win
.
Root
()
.
Call
(
"addTx"
,
utils
.
NewP
Tx
(
tx
))
ui
.
txDb
.
Put
(
tx
.
Hash
(),
tx
.
RlpEncode
())
addrState
.
Nonce
+=
1
unconfirmedFunds
.
Sub
(
unconfirmedFunds
,
tx
.
Value
)
}
else
if
bytes
.
Compare
(
tx
.
Recipient
,
ui
.
addr
)
==
0
{
ui
.
win
.
Root
()
.
Call
(
"addTx"
,
NewQ
Tx
(
tx
))
ui
.
win
.
Root
()
.
Call
(
"addTx"
,
utils
.
NewP
Tx
(
tx
))
ui
.
txDb
.
Put
(
tx
.
Hash
(),
tx
.
RlpEncode
())
unconfirmedFunds
.
Add
(
unconfirmedFunds
,
tx
.
Value
)
...
...
ethereal/ui/html_container.go
View file @
60f9966c
...
...
@@ -4,6 +4,7 @@ import (
"errors"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/go-ethereum/utils"
"github.com/go-qml/qml"
"math/big"
"path/filepath"
...
...
@@ -56,12 +57,12 @@ func (app *HtmlApplication) Window() *qml.Window {
}
func
(
app
*
HtmlApplication
)
NewBlock
(
block
*
ethchain
.
Block
)
{
b
:=
&
Q
Block
{
Number
:
int
(
block
.
BlockInfo
()
.
Number
),
Hash
:
ethutil
.
Hex
(
block
.
Hash
())}
b
:=
&
utils
.
P
Block
{
Number
:
int
(
block
.
BlockInfo
()
.
Number
),
Hash
:
ethutil
.
Hex
(
block
.
Hash
())}
app
.
webView
.
Call
(
"onNewBlockCb"
,
b
)
}
func
(
app
*
HtmlApplication
)
ObjectChanged
(
stateObject
*
ethchain
.
StateObject
)
{
app
.
webView
.
Call
(
"onObjectChangeCb"
,
NewQ
StateObject
(
stateObject
))
app
.
webView
.
Call
(
"onObjectChangeCb"
,
utils
.
NewP
StateObject
(
stateObject
))
}
func
(
app
*
HtmlApplication
)
StorageChanged
(
stateObject
*
ethchain
.
StateObject
,
addr
[]
byte
,
value
*
big
.
Int
)
{
...
...
ethereal/ui/library.go
View file @
60f9966c
...
...
@@ -47,14 +47,14 @@ func (lib *EthLib) GetKey() string {
return
ethutil
.
Hex
(
ethutil
.
Config
.
Db
.
GetKeys
()[
0
]
.
Address
())
}
func
(
lib
*
EthLib
)
GetStateObject
(
address
string
)
*
Q
StateObject
{
func
(
lib
*
EthLib
)
GetStateObject
(
address
string
)
*
utils
.
P
StateObject
{
stateObject
:=
lib
.
stateManager
.
ProcState
()
.
GetContract
(
ethutil
.
FromHex
(
address
))
if
stateObject
!=
nil
{
return
NewQ
StateObject
(
stateObject
)
return
utils
.
NewP
StateObject
(
stateObject
)
}
// See GetStorage for explanation on "nil"
return
NewQ
StateObject
(
nil
)
return
utils
.
NewP
StateObject
(
nil
)
}
func
(
lib
*
EthLib
)
Watch
(
addr
,
storageAddr
string
)
{
...
...
@@ -115,7 +115,7 @@ func (lib *EthLib) Transact(recipient, valueStr, gasStr, gasPriceStr, dataStr st
return
ethutil
.
Hex
(
tx
.
Hash
()),
nil
}
func
(
lib
*
EthLib
)
GetBlock
(
hexHash
string
)
*
Q
Block
{
func
(
lib
*
EthLib
)
GetBlock
(
hexHash
string
)
*
utils
.
P
Block
{
hash
,
err
:=
hex
.
DecodeString
(
hexHash
)
if
err
!=
nil
{
return
nil
...
...
@@ -123,5 +123,5 @@ func (lib *EthLib) GetBlock(hexHash string) *QBlock {
block
:=
lib
.
blockChain
.
GetBlock
(
hash
)
return
&
Q
Block
{
Number
:
int
(
block
.
BlockInfo
()
.
Number
),
Hash
:
ethutil
.
Hex
(
block
.
Hash
())}
return
&
utils
.
P
Block
{
Number
:
int
(
block
.
BlockInfo
()
.
Number
),
Hash
:
ethutil
.
Hex
(
block
.
Hash
())}
}
utils/ethereum.go
0 → 100644
View file @
60f9966c
package
utils
import
(
"fmt"
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
)
type
PEthereum
struct
{
stateManager
*
ethchain
.
StateManager
blockChain
*
ethchain
.
BlockChain
txPool
*
ethchain
.
TxPool
}
func
NewPEthereum
(
eth
*
eth
.
Ethereum
)
*
PEthereum
{
return
&
PEthereum
{
eth
.
StateManager
(),
eth
.
BlockChain
(),
eth
.
TxPool
(),
}
}
func
(
lib
*
PEthereum
)
GetBlock
(
hexHash
string
)
*
PBlock
{
hash
:=
ethutil
.
FromHex
(
hexHash
)
block
:=
lib
.
blockChain
.
GetBlock
(
hash
)
return
&
PBlock
{
Number
:
int
(
block
.
BlockInfo
()
.
Number
),
Hash
:
ethutil
.
Hex
(
block
.
Hash
())}
}
func
(
lib
*
PEthereum
)
GetKey
()
*
PKey
{
keyPair
,
err
:=
ethchain
.
NewKeyPairFromSec
(
ethutil
.
Config
.
Db
.
GetKeys
()[
0
]
.
PrivateKey
)
if
err
!=
nil
{
return
nil
}
return
NewPKey
(
keyPair
)
}
func
(
lib
*
PEthereum
)
GetStateObject
(
address
string
)
*
PStateObject
{
stateObject
:=
lib
.
stateManager
.
ProcState
()
.
GetContract
(
ethutil
.
FromHex
(
address
))
if
stateObject
!=
nil
{
return
NewPStateObject
(
stateObject
)
}
// See GetStorage for explanation on "nil"
return
NewPStateObject
(
nil
)
}
func
(
lib
*
PEthereum
)
Transact
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
(
string
,
error
)
{
return
lib
.
createTx
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
,
""
)
}
func
(
lib
*
PEthereum
)
Create
(
key
,
valueStr
,
gasStr
,
gasPriceStr
,
initStr
,
bodyStr
string
)
(
string
,
error
)
{
return
lib
.
createTx
(
key
,
""
,
valueStr
,
gasStr
,
gasPriceStr
,
initStr
,
bodyStr
)
}
func
(
lib
*
PEthereum
)
createTx
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
initStr
,
scriptStr
string
)
(
string
,
error
)
{
var
hash
[]
byte
var
contractCreation
bool
if
len
(
recipient
)
==
0
{
contractCreation
=
true
}
else
{
hash
=
ethutil
.
FromHex
(
recipient
)
}
keyPair
,
err
:=
ethchain
.
NewKeyPairFromSec
([]
byte
(
ethutil
.
FromHex
(
key
)))
if
err
!=
nil
{
return
""
,
err
}
value
:=
ethutil
.
Big
(
valueStr
)
gas
:=
ethutil
.
Big
(
gasStr
)
gasPrice
:=
ethutil
.
Big
(
gasPriceStr
)
var
tx
*
ethchain
.
Transaction
// Compile and assemble the given data
if
contractCreation
{
initScript
,
err
:=
Compile
(
initStr
)
if
err
!=
nil
{
return
""
,
err
}
mainScript
,
err
:=
Compile
(
scriptStr
)
if
err
!=
nil
{
return
""
,
err
}
tx
=
ethchain
.
NewContractCreationTx
(
value
,
gas
,
gasPrice
,
mainScript
,
initScript
)
}
else
{
// Just in case it was submitted as a 0x prefixed string
if
initStr
[
0
:
2
]
==
"0x"
{
initStr
=
initStr
[
2
:
len
(
initStr
)]
}
fmt
.
Println
(
"DATA:"
,
initStr
)
tx
=
ethchain
.
NewTransactionMessage
(
hash
,
value
,
gas
,
gasPrice
,
ethutil
.
FromHex
(
initStr
))
}
acc
:=
lib
.
stateManager
.
GetAddrState
(
keyPair
.
Address
())
tx
.
Nonce
=
acc
.
Nonce
tx
.
Sign
(
keyPair
.
PrivateKey
)
lib
.
txPool
.
QueueTransaction
(
tx
)
if
contractCreation
{
ethutil
.
Config
.
Log
.
Infof
(
"Contract addr %x"
,
tx
.
Hash
()[
12
:
])
}
else
{
ethutil
.
Config
.
Log
.
Infof
(
"Tx hash %x"
,
tx
.
Hash
())
}
return
ethutil
.
Hex
(
tx
.
Hash
()),
nil
}
ethereal/ui
/types.go
→
utils
/types.go
View file @
60f9966c
package
ethui
package
utils
import
(
"encoding/hex"
...
...
@@ -7,53 +7,61 @@ import (
)
// Block interface exposed to QML
type
Q
Block
struct
{
type
P
Block
struct
{
Number
int
Hash
string
}
// Creates a new QML Block from a chain block
func
New
QBlock
(
block
*
ethchain
.
Block
)
*
Q
Block
{
func
New
PBlock
(
block
*
ethchain
.
Block
)
*
P
Block
{
info
:=
block
.
BlockInfo
()
hash
:=
hex
.
EncodeToString
(
block
.
Hash
())
return
&
Q
Block
{
Number
:
int
(
info
.
Number
),
Hash
:
hash
}
return
&
P
Block
{
Number
:
int
(
info
.
Number
),
Hash
:
hash
}
}
type
Q
Tx
struct
{
type
P
Tx
struct
{
Value
,
Hash
,
Address
string
Contract
bool
}
func
New
QTx
(
tx
*
ethchain
.
Transaction
)
*
Q
Tx
{
func
New
PTx
(
tx
*
ethchain
.
Transaction
)
*
P
Tx
{
hash
:=
hex
.
EncodeToString
(
tx
.
Hash
())
sender
:=
hex
.
EncodeToString
(
tx
.
Recipient
)
isContract
:=
len
(
tx
.
Data
)
>
0
return
&
Q
Tx
{
Hash
:
hash
,
Value
:
ethutil
.
CurrencyToString
(
tx
.
Value
),
Address
:
sender
,
Contract
:
isContract
}
return
&
P
Tx
{
Hash
:
hash
,
Value
:
ethutil
.
CurrencyToString
(
tx
.
Value
),
Address
:
sender
,
Contract
:
isContract
}
}
type
QKey
struct
{
Address
string
type
PKey
struct
{
Address
string
PrivateKey
string
PublicKey
string
}
type
QKeyRing
struct
{
func
NewPKey
(
key
*
ethchain
.
KeyPair
)
*
PKey
{
return
&
PKey
{
ethutil
.
Hex
(
key
.
Address
()),
ethutil
.
Hex
(
key
.
PrivateKey
),
ethutil
.
Hex
(
key
.
PublicKey
)}
}
/*
type PKeyRing struct {
Keys []interface{}
}
func
New
QKeyRing
(
keys
[]
interface
{})
*
Q
KeyRing
{
return
&
Q
KeyRing
{
Keys
:
keys
}
func New
PKeyRing(keys []interface{}) *P
KeyRing {
return &
P
KeyRing{Keys: keys}
}
*/
type
Q
StateObject
struct
{
type
P
StateObject
struct
{
object
*
ethchain
.
StateObject
}
func
New
QStateObject
(
object
*
ethchain
.
StateObject
)
*
Q
StateObject
{
return
&
Q
StateObject
{
object
:
object
}
func
New
PStateObject
(
object
*
ethchain
.
StateObject
)
*
P
StateObject
{
return
&
P
StateObject
{
object
:
object
}
}
func
(
c
*
Q
StateObject
)
GetStorage
(
address
string
)
string
{
func
(
c
*
P
StateObject
)
GetStorage
(
address
string
)
string
{
// Because somehow, even if you return nil to QML it
// still has some magical object so we can't rely on
// undefined or null at the QML side
...
...
@@ -66,7 +74,7 @@ func (c *QStateObject) GetStorage(address string) string {
return
""
}
func
(
c
*
Q
StateObject
)
Value
()
string
{
func
(
c
*
P
StateObject
)
Value
()
string
{
if
c
.
object
!=
nil
{
return
c
.
object
.
Amount
.
String
()
}
...
...
@@ -74,7 +82,7 @@ func (c *QStateObject) Value() string {
return
""
}
func
(
c
*
Q
StateObject
)
Address
()
string
{
func
(
c
*
P
StateObject
)
Address
()
string
{
if
c
.
object
!=
nil
{
return
ethutil
.
Hex
(
c
.
object
.
Address
())
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment