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
e16fd323
Commit
e16fd323
authored
Apr 25, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Leverage the new watch & address:changed functionality
parent
d0438ac1
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
114 additions
and
68 deletions
+114
-68
ethereum.js
ethereal/assets/ethereum.js
+4
-0
webapp.qml
ethereal/assets/qml/webapp.qml
+11
-1
samplecoin.html
ethereal/assets/samplecoin.html
+4
-1
gui.go
ethereal/ui/gui.go
+6
-46
library.go
ethereal/ui/library.go
+6
-2
types.go
ethereal/ui/types.go
+56
-0
ui_lib.go
ethereal/ui/ui_lib.go
+10
-3
ethereum.go
ethereum/ethereum.go
+17
-15
No files found.
ethereal/assets/ethereum.js
View file @
e16fd323
...
...
@@ -47,6 +47,10 @@ window.eth = {
postData
({
call
:
"getKey"
},
cb
);
},
watch
:
function
(
address
)
{
postData
({
call
:
"watch"
,
args
:
[
address
]});
},
on
:
function
(
event
,
cb
)
{
if
(
eth
.
_onCallbacks
[
event
]
===
undefined
)
{
...
...
ethereal/assets/qml/webapp.qml
View file @
e16fd323
...
...
@@ -74,14 +74,24 @@ ApplicationWindow {
var
keys
=
eth
.
getKey
()
postData
(
data
.
_seed
,
keys
)
break
case
"watch"
:
if
(
data
.
args
.
length
>
0
)
{
eth
.
watch
(
data
.
args
[
0
]);
}
}
}
function
postData
(
seed
,
data
)
{
webview
.
experimental
.
postMessage
(
JSON
.
stringify
({
data
:
data
,
_seed
:
seed
}))
}
function
postEvent
(
event
,
data
)
{
webview
.
experimental
.
postMessage
(
JSON
.
stringify
({
data
:
data
,
_event
:
event
}))
}
function
onNewBlockCb
(
block
)
{
webview
.
experimental
.
postMessage
(
JSON
.
stringify
({
data
:
block
,
_event
:
"block:new"
}))
postEvent
(
"block:new"
,
block
)
}
function
onObjectChangeCb
(
stateObject
)
{
postEvent
(
"object:change"
,
stateObject
)
}
}
...
...
ethereal/assets/samplecoin.html
View file @
e16fd323
...
...
@@ -22,12 +22,15 @@ function tests() {
}
function
init
()
{
eth
.
watch
(
jefcoinAddr
);
eth
.
getKey
(
function
(
key
)
{
eth
.
getStorage
(
jefcoinAddr
,
key
,
function
(
storage
)
{
document
.
querySelector
(
"#currentAmount"
).
innerHTML
=
"Amount: "
+
storage
;
});
eth
.
on
(
"block:new"
,
function
()
{
eth
.
on
(
"object:change"
,
function
(
stateObject
)
{
debug
(
stateObject
);
eth
.
getStorage
(
jefcoinAddr
,
key
,
function
(
storage
)
{
document
.
querySelector
(
"#currentAmount"
).
innerHTML
=
"Amount: "
+
storage
;
});
...
...
ethereal/ui/gui.go
View file @
e16fd323
...
...
@@ -2,7 +2,6 @@ package ethui
import
(
"bytes"
"encoding/hex"
"fmt"
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethchain"
...
...
@@ -13,45 +12,6 @@ import (
"strings"
)
// Block interface exposed to QML
type
Block
struct
{
Number
int
Hash
string
}
type
Tx
struct
{
Value
,
Hash
,
Address
string
Contract
bool
}
type
Key
struct
{
Address
string
}
type
KeyRing
struct
{
Keys
[]
interface
{}
}
func
NewKeyRing
(
keys
[]
interface
{})
*
KeyRing
{
return
&
KeyRing
{
Keys
:
keys
}
}
func
NewTxFromTransaction
(
tx
*
ethchain
.
Transaction
)
*
Tx
{
hash
:=
hex
.
EncodeToString
(
tx
.
Hash
())
sender
:=
hex
.
EncodeToString
(
tx
.
Recipient
)
isContract
:=
len
(
tx
.
Data
)
>
0
return
&
Tx
{
Hash
:
hash
,
Value
:
ethutil
.
CurrencyToString
(
tx
.
Value
),
Address
:
sender
,
Contract
:
isContract
}
}
// Creates a new QML Block from a chain block
func
NewBlockFromBlock
(
block
*
ethchain
.
Block
)
*
Block
{
info
:=
block
.
BlockInfo
()
hash
:=
hex
.
EncodeToString
(
block
.
Hash
())
return
&
Block
{
Number
:
int
(
info
.
Number
),
Hash
:
hash
}
}
type
Gui
struct
{
// The main application window
win
*
qml
.
Window
...
...
@@ -96,9 +56,9 @@ func (ui *Gui) Start(assetPath string) {
// Register ethereum functions
qml
.
RegisterTypes
(
"Ethereum"
,
1
,
0
,
[]
qml
.
TypeSpec
{{
Init
:
func
(
p
*
Block
,
obj
qml
.
Object
)
{
p
.
Number
=
0
;
p
.
Hash
=
""
},
Init
:
func
(
p
*
Q
Block
,
obj
qml
.
Object
)
{
p
.
Number
=
0
;
p
.
Hash
=
""
},
},
{
Init
:
func
(
p
*
Tx
,
obj
qml
.
Object
)
{
p
.
Value
=
""
;
p
.
Hash
=
""
;
p
.
Address
=
""
},
Init
:
func
(
p
*
Q
Tx
,
obj
qml
.
Object
)
{
p
.
Value
=
""
;
p
.
Hash
=
""
;
p
.
Address
=
""
},
}})
ethutil
.
Config
.
SetClientString
(
fmt
.
Sprintf
(
"/Ethereal v%s"
,
"0.1"
))
...
...
@@ -169,13 +129,13 @@ func (ui *Gui) readPreviousTransactions() {
for
it
.
Next
()
{
tx
:=
ethchain
.
NewTransactionFromBytes
(
it
.
Value
())
ui
.
win
.
Root
()
.
Call
(
"addTx"
,
New
TxFromTransaction
(
tx
))
ui
.
win
.
Root
()
.
Call
(
"addTx"
,
New
QTx
(
tx
))
}
it
.
Release
()
}
func
(
ui
*
Gui
)
ProcessBlock
(
block
*
ethchain
.
Block
)
{
ui
.
win
.
Root
()
.
Call
(
"addBlock"
,
New
BlockFrom
Block
(
block
))
ui
.
win
.
Root
()
.
Call
(
"addBlock"
,
New
Q
Block
(
block
))
}
// Simple go routine function that updates the list of peers in the GUI
...
...
@@ -193,13 +153,13 @@ func (ui *Gui) update() {
if
txMsg
.
Type
==
ethchain
.
TxPre
{
if
bytes
.
Compare
(
tx
.
Sender
(),
ui
.
addr
)
==
0
{
ui
.
win
.
Root
()
.
Call
(
"addTx"
,
New
TxFromTransaction
(
tx
))
ui
.
win
.
Root
()
.
Call
(
"addTx"
,
New
QTx
(
tx
))
ui
.
txDb
.
Put
(
tx
.
Hash
(),
tx
.
RlpEncode
())
ui
.
eth
.
StateManager
()
.
GetAddrState
(
ui
.
addr
)
.
Nonce
+=
1
unconfirmedFunds
.
Sub
(
unconfirmedFunds
,
tx
.
Value
)
}
else
if
bytes
.
Compare
(
tx
.
Recipient
,
ui
.
addr
)
==
0
{
ui
.
win
.
Root
()
.
Call
(
"addTx"
,
New
TxFromTransaction
(
tx
))
ui
.
win
.
Root
()
.
Call
(
"addTx"
,
New
QTx
(
tx
))
ui
.
txDb
.
Put
(
tx
.
Hash
(),
tx
.
RlpEncode
())
unconfirmedFunds
.
Add
(
unconfirmedFunds
,
tx
.
Value
)
...
...
ethereal/ui/library.go
View file @
e16fd323
...
...
@@ -67,6 +67,10 @@ func (lib *EthLib) GetStateObject(address string) *Contract {
return
NewContract
(
stateObject
)
}
func
(
lib
*
EthLib
)
Watch
(
addr
string
)
{
lib
.
stateManager
.
Watch
(
ethutil
.
FromHex
(
addr
))
}
func
(
lib
*
EthLib
)
CreateTx
(
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
(
string
,
error
)
{
var
hash
[]
byte
var
contractCreation
bool
...
...
@@ -117,7 +121,7 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, dataStr st
return
ethutil
.
Hex
(
tx
.
Hash
()),
nil
}
func
(
lib
*
EthLib
)
GetBlock
(
hexHash
string
)
*
Block
{
func
(
lib
*
EthLib
)
GetBlock
(
hexHash
string
)
*
Q
Block
{
hash
,
err
:=
hex
.
DecodeString
(
hexHash
)
if
err
!=
nil
{
return
nil
...
...
@@ -125,5 +129,5 @@ func (lib *EthLib) GetBlock(hexHash string) *Block {
block
:=
lib
.
blockChain
.
GetBlock
(
hash
)
return
&
Block
{
Number
:
int
(
block
.
BlockInfo
()
.
Number
),
Hash
:
ethutil
.
Hex
(
block
.
Hash
())}
return
&
Q
Block
{
Number
:
int
(
block
.
BlockInfo
()
.
Number
),
Hash
:
ethutil
.
Hex
(
block
.
Hash
())}
}
ethereal/ui/types.go
0 → 100644
View file @
e16fd323
package
ethui
import
(
"encoding/hex"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
)
// Block interface exposed to QML
type
QBlock
struct
{
Number
int
Hash
string
}
// Creates a new QML Block from a chain block
func
NewQBlock
(
block
*
ethchain
.
Block
)
*
QBlock
{
info
:=
block
.
BlockInfo
()
hash
:=
hex
.
EncodeToString
(
block
.
Hash
())
return
&
QBlock
{
Number
:
int
(
info
.
Number
),
Hash
:
hash
}
}
type
QTx
struct
{
Value
,
Hash
,
Address
string
Contract
bool
}
func
NewQTx
(
tx
*
ethchain
.
Transaction
)
*
QTx
{
hash
:=
hex
.
EncodeToString
(
tx
.
Hash
())
sender
:=
hex
.
EncodeToString
(
tx
.
Recipient
)
isContract
:=
len
(
tx
.
Data
)
>
0
return
&
QTx
{
Hash
:
hash
,
Value
:
ethutil
.
CurrencyToString
(
tx
.
Value
),
Address
:
sender
,
Contract
:
isContract
}
}
type
QKey
struct
{
Address
string
}
type
QKeyRing
struct
{
Keys
[]
interface
{}
}
func
NewQKeyRing
(
keys
[]
interface
{})
*
QKeyRing
{
return
&
QKeyRing
{
Keys
:
keys
}
}
type
QStateObject
struct
{
Address
string
Amount
string
Nonce
int
}
func
NewQStateObject
(
stateObject
*
ethchain
.
StateObject
)
*
QStateObject
{
return
&
QStateObject
{
ethutil
.
Hex
(
stateObject
.
Address
()),
stateObject
.
Amount
.
String
(),
int
(
stateObject
.
Nonce
)}
}
ethereal/ui/ui_lib.go
View file @
e16fd323
...
...
@@ -69,8 +69,10 @@ func (ui *UiLib) OpenHtml(path string) {
}
win
.
Set
(
"url"
,
path
)
webView
:=
win
.
ObjectByName
(
"webView"
)
go
func
()
{
blockChan
:=
make
(
chan
ethutil
.
React
,
1
)
addrChan
:=
make
(
chan
ethutil
.
React
,
1
)
quitChan
:=
make
(
chan
bool
)
go
func
()
{
...
...
@@ -82,8 +84,12 @@ func (ui *UiLib) OpenHtml(path string) {
break
out
case
block
:=
<-
blockChan
:
if
block
,
ok
:=
block
.
Resource
.
(
*
ethchain
.
Block
);
ok
{
b
:=
&
Block
{
Number
:
int
(
block
.
BlockInfo
()
.
Number
),
Hash
:
ethutil
.
Hex
(
block
.
Hash
())}
win
.
ObjectByName
(
"webView"
)
.
Call
(
"onNewBlockCb"
,
b
)
b
:=
&
QBlock
{
Number
:
int
(
block
.
BlockInfo
()
.
Number
),
Hash
:
ethutil
.
Hex
(
block
.
Hash
())}
webView
.
Call
(
"onNewBlockCb"
,
b
)
}
case
stateObject
:=
<-
addrChan
:
if
stateObject
,
ok
:=
stateObject
.
Resource
.
(
*
ethchain
.
StateObject
);
ok
{
webView
.
Call
(
"onObjectChangeCb"
,
NewQStateObject
(
stateObject
))
}
}
}
...
...
@@ -93,6 +99,7 @@ func (ui *UiLib) OpenHtml(path string) {
close
(
quitChan
)
}()
ui
.
eth
.
Reactor
()
.
Subscribe
(
"newBlock"
,
blockChan
)
ui
.
eth
.
Reactor
()
.
Subscribe
(
"addressChanged"
,
addrChan
)
win
.
Show
()
win
.
Wait
()
...
...
@@ -169,7 +176,7 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string)
callerClosure
:=
ethchain
.
NewClosure
(
account
,
c
,
c
.
Script
(),
state
,
ethutil
.
Big
(
gasStr
),
ethutil
.
Big
(
gasPriceStr
),
ethutil
.
Big
(
valueStr
))
block
:=
ui
.
eth
.
BlockChain
()
.
CurrentBlock
vm
:=
ethchain
.
NewVm
(
state
,
ethchain
.
RuntimeVars
{
vm
:=
ethchain
.
NewVm
(
state
,
ui
.
eth
.
StateManager
(),
ethchain
.
RuntimeVars
{
Origin
:
account
.
Address
(),
BlockNumber
:
block
.
BlockInfo
()
.
Number
,
PrevHash
:
block
.
PrevHash
,
...
...
ethereum/ethereum.go
View file @
e16fd323
...
...
@@ -53,20 +53,22 @@ func main() {
var
logSys
*
log
.
Logger
flags
:=
log
.
LstdFlags
ethutil
.
ReadConfig
(
DataDir
)
logger
:=
ethutil
.
Config
.
Log
if
LogFile
!=
""
{
logfile
,
err
:=
os
.
OpenFile
(
LogFile
,
os
.
O_RDWR
|
os
.
O_CREATE
|
os
.
O_APPEND
,
0666
)
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
)
}
else
{
logSys
=
log
.
New
(
os
.
Stdout
,
""
,
flags
)
}
ethutil
.
ReadConfig
(
DataDir
)
logger
:=
ethutil
.
Config
.
Log
logger
.
AddLogSystem
(
logSys
)
}
/*else {
logSys = log.New(os.Stdout, "", flags)
}*/
ethchain
.
InitFees
()
ethutil
.
Config
.
Seed
=
UseSeed
...
...
@@ -101,9 +103,6 @@ func main() {
}
}
os
.
Exit
(
0
)
case
len
(
ImportKey
)
==
0
:
utils
.
CreateKeyPair
(
false
)
fallthrough
case
ExportKey
:
key
:=
ethutil
.
Config
.
Db
.
GetKeys
()[
0
]
logSys
.
Println
(
fmt
.
Sprintf
(
"prvk: %x
\n
"
,
key
.
PrivateKey
))
...
...
@@ -111,6 +110,9 @@ func main() {
case
ShowGenesis
:
logSys
.
Println
(
ethereum
.
BlockChain
()
.
Genesis
())
os
.
Exit
(
0
)
default
:
// Creates a keypair if non exists
utils
.
CreateKeyPair
(
false
)
}
// client
...
...
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