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
3c319f93
Commit
3c319f93
authored
Aug 01, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ethersphere-feature/ethutil-refactor' into develop
parents
834803f1
34e937c9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
100 deletions
+98
-100
ext_app.go
ethereal/ext_app.go
+6
-7
gui.go
ethereal/gui.go
+80
-78
javascript_runtime.go
ethereum/repl/javascript_runtime.go
+9
-8
cmd.go
utils/cmd.go
+3
-7
No files found.
ethereal/ext_app.go
View file @
3c319f93
package
main
import
(
"fmt"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethreact"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
"github.com/go-qml/qml"
...
...
@@ -25,8 +25,8 @@ type AppContainer interface {
type
ExtApplication
struct
{
*
ethpub
.
PEthereum
blockChan
chan
eth
util
.
Reac
t
changeChan
chan
eth
util
.
Reac
t
blockChan
chan
eth
react
.
Even
t
changeChan
chan
eth
react
.
Even
t
quitChan
chan
bool
watcherQuitChan
chan
bool
...
...
@@ -38,8 +38,8 @@ type ExtApplication struct {
func
NewExtApplication
(
container
AppContainer
,
lib
*
UiLib
)
*
ExtApplication
{
app
:=
&
ExtApplication
{
ethpub
.
NewPEthereum
(
lib
.
eth
),
make
(
chan
eth
util
.
React
,
1
),
make
(
chan
eth
util
.
React
,
1
),
make
(
chan
eth
react
.
Event
,
100
),
make
(
chan
eth
react
.
Event
,
100
),
make
(
chan
bool
),
make
(
chan
bool
),
container
,
...
...
@@ -58,8 +58,7 @@ func (app *ExtApplication) run() {
err
:=
app
.
container
.
Create
()
if
err
!=
nil
{
fmt
.
Println
(
err
)
logger
.
Errorln
(
err
)
return
}
...
...
ethereal/gui.go
View file @
3c319f93
...
...
@@ -14,6 +14,7 @@ import (
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethminer"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethreact"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
"github.com/ethereum/go-ethereum/utils"
...
...
@@ -151,7 +152,7 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
gui
.
readPreviousTransactions
()
}()
g
o
g
ui
.
update
()
gui
.
update
()
return
win
,
nil
}
...
...
@@ -284,30 +285,16 @@ func (self *Gui) getObjectByName(objectName string) qml.Object {
// Simple go routine function that updates the list of peers in the GUI
func
(
gui
*
Gui
)
update
()
{
reactor
:=
gui
.
eth
.
Reactor
()
var
(
blockChan
=
make
(
chan
eth
util
.
React
,
1
)
txChan
=
make
(
chan
eth
util
.
React
,
1
)
objectChan
=
make
(
chan
eth
util
.
React
,
1
)
peerChan
=
make
(
chan
eth
util
.
React
,
1
)
chainSyncChan
=
make
(
chan
eth
util
.
React
,
1
)
miningChan
=
make
(
chan
eth
util
.
React
,
1
)
blockChan
=
make
(
chan
eth
react
.
Event
,
100
)
txChan
=
make
(
chan
eth
react
.
Event
,
100
)
objectChan
=
make
(
chan
eth
react
.
Event
,
100
)
peerChan
=
make
(
chan
eth
react
.
Event
,
100
)
chainSyncChan
=
make
(
chan
eth
react
.
Event
,
100
)
miningChan
=
make
(
chan
eth
react
.
Event
,
100
)
)
reactor
.
Subscribe
(
"newBlock"
,
blockChan
)
reactor
.
Subscribe
(
"newTx:pre"
,
txChan
)
reactor
.
Subscribe
(
"newTx:post"
,
txChan
)
reactor
.
Subscribe
(
"chainSync"
,
chainSyncChan
)
reactor
.
Subscribe
(
"miner:start"
,
miningChan
)
reactor
.
Subscribe
(
"miner:stop"
,
miningChan
)
nameReg
:=
ethpub
.
EthereumConfig
(
gui
.
eth
.
StateManager
())
.
NameReg
()
if
nameReg
!=
nil
{
reactor
.
Subscribe
(
"object:"
+
string
(
nameReg
.
Address
()),
objectChan
)
}
reactor
.
Subscribe
(
"peerList"
,
peerChan
)
peerUpdateTicker
:=
time
.
NewTicker
(
5
*
time
.
Second
)
generalUpdateTicker
:=
time
.
NewTicker
(
1
*
time
.
Second
)
...
...
@@ -319,74 +306,89 @@ func (gui *Gui) update() {
lastBlockLabel
:=
gui
.
getObjectByName
(
"lastBlockLabel"
)
for
{
select
{
case
b
:=
<-
blockChan
:
block
:=
b
.
Resource
.
(
*
ethchain
.
Block
)
gui
.
processBlock
(
block
,
false
)
if
bytes
.
Compare
(
block
.
Coinbase
,
gui
.
address
())
==
0
{
gui
.
setWalletValue
(
gui
.
eth
.
StateManager
()
.
CurrentState
()
.
GetAccount
(
gui
.
address
())
.
Balance
,
nil
)
}
case
txMsg
:=
<-
txChan
:
tx
:=
txMsg
.
Resource
.
(
*
ethchain
.
Transaction
)
go
func
()
{
for
{
select
{
case
b
:=
<-
blockChan
:
block
:=
b
.
Resource
.
(
*
ethchain
.
Block
)
gui
.
processBlock
(
block
,
false
)
if
bytes
.
Compare
(
block
.
Coinbase
,
gui
.
address
())
==
0
{
gui
.
setWalletValue
(
gui
.
eth
.
StateManager
()
.
CurrentState
()
.
GetAccount
(
gui
.
address
())
.
Balance
,
nil
)
}
case
txMsg
:=
<-
txChan
:
tx
:=
txMsg
.
Resource
.
(
*
ethchain
.
Transaction
)
if
txMsg
.
Event
==
"newTx:pre"
{
object
:=
state
.
GetAccount
(
gui
.
address
())
if
txMsg
.
Name
==
"newTx:pre"
{
object
:=
state
.
GetAccount
(
gui
.
address
())
if
bytes
.
Compare
(
tx
.
Sender
(),
gui
.
address
())
==
0
{
gui
.
win
.
Root
()
.
Call
(
"addTx"
,
ethpub
.
NewPTx
(
tx
),
"send"
)
gui
.
txDb
.
Put
(
tx
.
Hash
(),
tx
.
RlpEncode
())
unconfirmedFunds
.
Sub
(
unconfirmedFunds
,
tx
.
Value
)
}
else
if
bytes
.
Compare
(
tx
.
Recipient
,
gui
.
address
())
==
0
{
gui
.
win
.
Root
()
.
Call
(
"addTx"
,
ethpub
.
NewPTx
(
tx
),
"recv"
)
gui
.
txDb
.
Put
(
tx
.
Hash
(),
tx
.
RlpEncode
())
if
bytes
.
Compare
(
tx
.
Sender
(),
gui
.
address
())
==
0
{
gui
.
win
.
Root
()
.
Call
(
"addTx"
,
ethpub
.
NewPTx
(
tx
),
"send"
)
gui
.
txDb
.
Put
(
tx
.
Hash
(),
tx
.
RlpEncode
())
unconfirmedFunds
.
Add
(
unconfirmedFunds
,
tx
.
Value
)
}
unconfirmedFunds
.
Sub
(
unconfirmedFunds
,
tx
.
Value
)
}
else
if
bytes
.
Compare
(
tx
.
Recipient
,
gui
.
address
())
==
0
{
gui
.
win
.
Root
()
.
Call
(
"addTx"
,
ethpub
.
NewPTx
(
tx
),
"recv"
)
gui
.
txDb
.
Put
(
tx
.
Hash
(),
tx
.
RlpEncode
())
gui
.
setWalletValue
(
object
.
Balance
,
unconfirmedFunds
)
}
else
{
object
:=
state
.
GetAccount
(
gui
.
address
())
if
bytes
.
Compare
(
tx
.
Sender
(),
gui
.
address
())
==
0
{
object
.
SubAmount
(
tx
.
Value
)
}
else
if
bytes
.
Compare
(
tx
.
Recipient
,
gui
.
address
())
==
0
{
object
.
AddAmount
(
tx
.
Value
)
}
unconfirmedFunds
.
Add
(
unconfirmedFunds
,
tx
.
Value
)
}
gui
.
setWalletValue
(
object
.
Balance
,
nil
)
gui
.
setWalletValue
(
object
.
Balance
,
unconfirmedFunds
)
}
else
{
object
:=
state
.
GetAccount
(
gui
.
address
())
if
bytes
.
Compare
(
tx
.
Sender
(),
gui
.
address
())
==
0
{
object
.
SubAmount
(
tx
.
Value
)
}
else
if
bytes
.
Compare
(
tx
.
Recipient
,
gui
.
address
())
==
0
{
object
.
AddAmount
(
tx
.
Value
)
}
state
.
UpdateStateObject
(
object
)
}
case
msg
:=
<-
chainSyncChan
:
sync
:=
msg
.
Resource
.
(
bool
)
gui
.
win
.
Root
()
.
ObjectByName
(
"syncProgressIndicator"
)
.
Set
(
"visible"
,
sync
)
case
<-
objectChan
:
gui
.
loadAddressBook
()
case
<-
peerChan
:
gui
.
setPeerInfo
()
case
<-
peerUpdateTicker
.
C
:
gui
.
setPeerInfo
()
case
msg
:=
<-
miningChan
:
if
msg
.
Event
==
"miner:start"
{
gui
.
miner
=
msg
.
Resource
.
(
*
ethminer
.
Miner
)
}
else
{
gui
.
miner
=
nil
}
gui
.
setWalletValue
(
object
.
Balance
,
nil
)
case
<-
generalUpdateTicker
.
C
:
statusText
:=
"#"
+
gui
.
eth
.
BlockChain
()
.
CurrentBlock
.
Number
.
String
()
if
gui
.
miner
!=
nil
{
pow
:=
gui
.
miner
.
GetPow
()
if
pow
.
GetHashrate
()
!=
0
{
statusText
=
"Mining @ "
+
strconv
.
FormatInt
(
pow
.
GetHashrate
(),
10
)
+
"Khash - "
+
statusText
state
.
UpdateStateObject
(
object
)
}
case
msg
:=
<-
chainSyncChan
:
sync
:=
msg
.
Resource
.
(
bool
)
gui
.
win
.
Root
()
.
ObjectByName
(
"syncProgressIndicator"
)
.
Set
(
"visible"
,
sync
)
case
<-
objectChan
:
gui
.
loadAddressBook
()
case
<-
peerChan
:
gui
.
setPeerInfo
()
case
<-
peerUpdateTicker
.
C
:
gui
.
setPeerInfo
()
case
msg
:=
<-
miningChan
:
if
msg
.
Name
==
"miner:start"
{
gui
.
miner
=
msg
.
Resource
.
(
*
ethminer
.
Miner
)
}
else
{
gui
.
miner
=
nil
}
case
<-
generalUpdateTicker
.
C
:
statusText
:=
"#"
+
gui
.
eth
.
BlockChain
()
.
CurrentBlock
.
Number
.
String
()
if
gui
.
miner
!=
nil
{
pow
:=
gui
.
miner
.
GetPow
()
if
pow
.
GetHashrate
()
!=
0
{
statusText
=
"Mining @ "
+
strconv
.
FormatInt
(
pow
.
GetHashrate
(),
10
)
+
"Khash - "
+
statusText
}
}
lastBlockLabel
.
Set
(
"text"
,
statusText
)
}
lastBlockLabel
.
Set
(
"text"
,
statusText
)
}
}()
reactor
:=
gui
.
eth
.
Reactor
()
reactor
.
Subscribe
(
"newBlock"
,
blockChan
)
reactor
.
Subscribe
(
"newTx:pre"
,
txChan
)
reactor
.
Subscribe
(
"newTx:post"
,
txChan
)
reactor
.
Subscribe
(
"chainSync"
,
chainSyncChan
)
reactor
.
Subscribe
(
"miner:start"
,
miningChan
)
reactor
.
Subscribe
(
"miner:stop"
,
miningChan
)
nameReg
:=
ethpub
.
EthereumConfig
(
gui
.
eth
.
StateManager
())
.
NameReg
()
if
nameReg
!=
nil
{
reactor
.
Subscribe
(
"object:"
+
string
(
nameReg
.
Address
()),
objectChan
)
}
reactor
.
Subscribe
(
"peerList"
,
peerChan
)
}
func
(
gui
*
Gui
)
setPeerInfo
()
{
...
...
ethereum/repl/javascript_runtime.go
View file @
3c319f93
...
...
@@ -6,6 +6,7 @@ import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethreact"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/go-ethereum/utils"
...
...
@@ -23,8 +24,8 @@ type JSRE struct {
vm
*
otto
.
Otto
lib
*
ethpub
.
PEthereum
blockChan
chan
eth
util
.
Reac
t
changeChan
chan
eth
util
.
Reac
t
blockChan
chan
eth
react
.
Even
t
changeChan
chan
eth
react
.
Even
t
quitChan
chan
bool
objectCb
map
[
string
][]
otto
.
Value
...
...
@@ -49,8 +50,8 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
ethereum
,
otto
.
New
(),
ethpub
.
NewPEthereum
(
ethereum
),
make
(
chan
eth
util
.
React
,
1
),
make
(
chan
eth
util
.
React
,
1
),
make
(
chan
eth
react
.
Event
,
10
),
make
(
chan
eth
react
.
Event
,
10
),
make
(
chan
bool
),
make
(
map
[
string
][]
otto
.
Value
),
}
...
...
@@ -65,6 +66,10 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
// We have to make sure that, whoever calls this, calls "Stop"
go
re
.
mainLoop
()
// Subscribe to events
reactor
:=
ethereum
.
Reactor
()
reactor
.
Subscribe
(
"newBlock"
,
re
.
blockChan
)
re
.
Bind
(
"eth"
,
&
JSEthereum
{
re
.
lib
,
re
.
vm
})
re
.
initStdFuncs
()
...
...
@@ -109,10 +114,6 @@ func (self *JSRE) Stop() {
}
func
(
self
*
JSRE
)
mainLoop
()
{
// Subscribe to events
reactor
:=
self
.
ethereum
.
Reactor
()
reactor
.
Subscribe
(
"newBlock"
,
self
.
blockChan
)
out
:
for
{
select
{
...
...
utils/cmd.go
View file @
3c319f93
...
...
@@ -127,6 +127,7 @@ func NewDatabase() ethutil.Database {
}
func
NewClientIdentity
(
clientIdentifier
,
version
,
customIdentifier
string
)
*
ethwire
.
SimpleClientIdentity
{
logger
.
Infoln
(
"identity created"
)
return
ethwire
.
NewSimpleClientIdentity
(
clientIdentifier
,
version
,
customIdentifier
)
}
...
...
@@ -243,21 +244,18 @@ func GetMiner() *ethminer.Miner {
func
StartMining
(
ethereum
*
eth
.
Ethereum
)
bool
{
if
!
ethereum
.
Mining
{
ethereum
.
Mining
=
true
addr
:=
ethereum
.
KeyManager
()
.
Address
()
go
func
()
{
logger
.
Infoln
(
"Start mining"
)
if
miner
==
nil
{
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
.
Start
()
}()
RegisterInterrupt
(
func
(
os
.
Signal
)
{
...
...
@@ -271,9 +269,7 @@ func StartMining(ethereum *eth.Ethereum) bool {
func
StopMining
(
ethereum
*
eth
.
Ethereum
)
bool
{
if
ethereum
.
Mining
&&
miner
!=
nil
{
miner
.
Stop
()
logger
.
Infoln
(
"Miner stopped"
)
logger
.
Infoln
(
"Stopped mining"
)
ethereum
.
Mining
=
false
return
true
...
...
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