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
747647e0
Commit
747647e0
authored
Feb 23, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into develop
parents
0b57bad2
b2a225a5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
22 deletions
+59
-22
coin.html
cmd/mist/assets/examples/coin.html
+18
-6
chain_manager.go
core/chain_manager.go
+26
-4
packages.go
rpc/packages.go
+4
-7
util.go
rpc/util.go
+2
-0
whisper.go
whisper/whisper.go
+4
-0
xeth.go
xeth/xeth.go
+5
-5
No files found.
cmd/mist/assets/examples/coin.html
View file @
747647e0
...
...
@@ -19,6 +19,7 @@
<span>
Amount:
</span>
<input
type=
"text"
id=
"amount"
style=
"width:200px"
>
<button
onclick=
"transact()"
>
Send
</button>
<span
id=
"message"
></span>
</div>
<hr>
...
...
@@ -95,17 +96,28 @@
}
function
transact
()
{
var
to
=
document
.
querySelector
(
"#address"
)
.
value
;
if
(
to
.
length
==
0
)
{
var
to
=
document
.
querySelector
(
"#address"
);
if
(
to
.
value
.
length
==
0
)
{
to
=
"0x4205b06c2cfa0e30359edcab94543266cb6fa1d3"
;
}
else
{
to
=
"0x"
+
to
;
if
(
to
.
value
.
substr
(
0
,
2
)
!=
"0x"
)
to
.
value
=
"0x"
+
to
.
value
;
}
var
value
=
parseInt
(
document
.
querySelector
(
"#amount"
).
value
);
console
.
log
(
"transact: "
,
to
,
" => "
,
value
)
var
value
=
document
.
querySelector
(
"#amount"
);
var
amount
=
parseInt
(
value
.
value
);
console
.
log
(
"transact: "
,
to
.
value
,
" => "
,
amount
)
contract
.
send
(
to
,
value
);
contract
.
send
(
to
.
value
,
amount
);
to
.
value
=
""
;
value
.
value
=
""
;
var
message
=
document
.
querySelector
(
"#message"
)
message
.
innerHTML
=
"Submitted"
;
setTimeout
(
function
()
{
message
.
innerHTML
=
""
;
},
1000
);
}
refresh
();
...
...
core/chain_manager.go
View file @
747647e0
...
...
@@ -85,12 +85,14 @@ type ChainManager struct {
lastBlockHash
[]
byte
transState
*
state
.
StateDB
txState
*
state
.
StateDB
}
func
NewChainManager
(
db
ethutil
.
Database
,
mux
*
event
.
TypeMux
)
*
ChainManager
{
bc
:=
&
ChainManager
{
db
:
db
,
genesisBlock
:
GenesisBlock
(
db
),
eventMux
:
mux
}
bc
.
setLastBlock
()
bc
.
transState
=
bc
.
State
()
.
Copy
()
bc
.
txState
=
bc
.
State
()
.
Copy
()
return
bc
}
...
...
@@ -138,6 +140,19 @@ func (self *ChainManager) TransState() *state.StateDB {
return
self
.
transState
}
func
(
self
*
ChainManager
)
TxState
()
*
state
.
StateDB
{
self
.
tsmu
.
RLock
()
defer
self
.
tsmu
.
RUnlock
()
return
self
.
txState
}
func
(
self
*
ChainManager
)
setTxState
(
state
*
state
.
StateDB
)
{
self
.
tsmu
.
Lock
()
defer
self
.
tsmu
.
Unlock
()
self
.
txState
=
state
}
func
(
self
*
ChainManager
)
setTransState
(
statedb
*
state
.
StateDB
)
{
self
.
transState
=
statedb
}
...
...
@@ -362,6 +377,8 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
defer
self
.
tsmu
.
Unlock
()
for
_
,
block
:=
range
chain
{
// Call in to the block processor and check for errors. It's likely that if one block fails
// all others will fail too (unless a known block is returned).
td
,
err
:=
self
.
processor
.
Process
(
block
)
if
err
!=
nil
{
if
IsKnownBlockErr
(
err
)
{
...
...
@@ -376,11 +393,15 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
}
block
.
Td
=
td
var
c
hain
,
split
bool
var
c
anonical
,
split
bool
self
.
mu
.
Lock
()
{
// Write block to database. Eventually we'll have to improve on this and throw away blocks that are
// not in the canonical chain.
self
.
write
(
block
)
cblock
:=
self
.
currentBlock
// Compare the TD of the last known block in the canonical chain to make sure it's greater.
// At this point it's possible that a different chain (fork) becomes the new canonical chain.
if
td
.
Cmp
(
self
.
td
)
>
0
{
if
block
.
Header
()
.
Number
.
Cmp
(
new
(
big
.
Int
)
.
Add
(
cblock
.
Header
()
.
Number
,
ethutil
.
Big1
))
<
0
{
chainlogger
.
Infof
(
"Split detected. New head #%v (%x) TD=%v, was #%v (%x) TD=%v
\n
"
,
block
.
Header
()
.
Number
,
block
.
Hash
()[
:
4
],
td
,
cblock
.
Header
()
.
Number
,
cblock
.
Hash
()[
:
4
],
self
.
td
)
...
...
@@ -390,17 +411,18 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
self
.
setTotalDifficulty
(
td
)
self
.
insert
(
block
)
c
hain
=
true
c
anonical
=
true
}
}
self
.
mu
.
Unlock
()
if
chain
{
if
canonical
{
self
.
setTransState
(
state
.
New
(
block
.
Root
(),
self
.
db
))
self
.
eventMux
.
Post
(
ChainEvent
{
block
,
td
})
}
if
split
{
self
.
setT
rans
State
(
state
.
New
(
block
.
Root
(),
self
.
db
))
self
.
setT
x
State
(
state
.
New
(
block
.
Root
(),
self
.
db
))
self
.
eventMux
.
Post
(
ChainSplitEvent
{
block
})
}
}
...
...
rpc/packages.go
View file @
747647e0
...
...
@@ -126,10 +126,6 @@ func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error
self
.
logMut
.
Lock
()
defer
self
.
logMut
.
Unlock
()
if
self
.
logs
[
id
]
==
nil
{
self
.
logs
[
id
]
=
&
logFilter
{
timeout
:
time
.
Now
()}
}
self
.
logs
[
id
]
.
add
(
&
state
.
StateLog
{})
}
if
args
==
"pending"
{
...
...
@@ -139,6 +135,7 @@ func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error
}
id
=
self
.
filterManager
.
InstallFilter
(
filter
)
self
.
logs
[
id
]
=
&
logFilter
{
timeout
:
time
.
Now
()}
*
reply
=
id
return
nil
...
...
@@ -377,12 +374,10 @@ func (p *EthereumApi) NewWhisperFilter(args *xeth.Options, reply *interface{}) e
args
.
Fn
=
func
(
msg
xeth
.
WhisperMessage
)
{
p
.
messagesMut
.
Lock
()
defer
p
.
messagesMut
.
Unlock
()
if
p
.
messages
[
id
]
==
nil
{
p
.
messages
[
id
]
=
&
whisperFilter
{
timeout
:
time
.
Now
()}
}
p
.
messages
[
id
]
.
add
(
msg
)
// = append(p.messages[id], msg)
}
id
=
p
.
xeth
.
Whisper
()
.
Watch
(
args
)
p
.
messages
[
id
]
=
&
whisperFilter
{
timeout
:
time
.
Now
()}
*
reply
=
id
return
nil
}
...
...
@@ -623,12 +618,14 @@ done:
self
.
messagesMut
.
Lock
()
for
id
,
filter
:=
range
self
.
logs
{
if
time
.
Since
(
filter
.
timeout
)
>
20
*
time
.
Second
{
self
.
filterManager
.
UninstallFilter
(
id
)
delete
(
self
.
logs
,
id
)
}
}
for
id
,
filter
:=
range
self
.
messages
{
if
time
.
Since
(
filter
.
timeout
)
>
20
*
time
.
Second
{
self
.
xeth
.
Whisper
()
.
Unwatch
(
id
)
delete
(
self
.
messages
,
id
)
}
}
...
...
rpc/util.go
View file @
747647e0
...
...
@@ -108,6 +108,7 @@ func toLogs(logs state.Logs) (ls []Log) {
type
whisperFilter
struct
{
messages
[]
xeth
.
WhisperMessage
timeout
time
.
Time
id
int
}
func
(
w
*
whisperFilter
)
add
(
msgs
...
xeth
.
WhisperMessage
)
{
...
...
@@ -123,6 +124,7 @@ func (w *whisperFilter) get() []xeth.WhisperMessage {
type
logFilter
struct
{
logs
state
.
Logs
timeout
time
.
Time
id
int
}
func
(
l
*
logFilter
)
add
(
logs
...
state
.
Log
)
{
...
...
whisper/whisper.go
View file @
747647e0
...
...
@@ -127,6 +127,10 @@ func (self *Whisper) Watch(opts Filter) int {
})
}
func
(
self
*
Whisper
)
Unwatch
(
id
int
)
{
self
.
filters
.
Uninstall
(
id
)
}
func
(
self
*
Whisper
)
Messages
(
id
int
)
(
messages
[]
*
Message
)
{
filter
:=
self
.
filters
.
Get
(
id
)
if
filter
!=
nil
{
...
...
xeth/xeth.go
View file @
747647e0
...
...
@@ -277,7 +277,7 @@ func (self *XEth) Transact(toStr, valueStr, gasStr, gasPriceStr, codeStr string)
}
var
err
error
state
:=
self
.
eth
.
ChainManager
()
.
T
rans
State
()
state
:=
self
.
eth
.
ChainManager
()
.
T
x
State
()
if
balance
:=
state
.
GetBalance
(
key
.
Address
());
balance
.
Cmp
(
tx
.
Value
())
<
0
{
return
""
,
fmt
.
Errorf
(
"insufficient balance. balance=%v tx=%v"
,
balance
,
tx
.
Value
())
}
...
...
@@ -289,10 +289,10 @@ func (self *XEth) Transact(toStr, valueStr, gasStr, gasPriceStr, codeStr string)
//fmt.Printf("create tx: %x %v\n", tx.Hash()[:4], tx.Nonce())
// Do some pre processing for our "pre" events and hooks
block
:=
self
.
chainManager
.
NewBlock
(
key
.
Address
())
coinbase
:=
state
.
GetOrNewStateObject
(
key
.
Address
())
coinbase
.
SetGasPool
(
block
.
GasLimit
())
self
.
blockProcessor
.
ApplyTransactions
(
coinbase
,
state
,
block
,
types
.
Transactions
{
tx
},
true
)
//
block := self.chainManager.NewBlock(key.Address())
//
coinbase := state.GetOrNewStateObject(key.Address())
//
coinbase.SetGasPool(block.GasLimit())
//
self.blockProcessor.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true)
err
=
self
.
eth
.
TxPool
()
.
Add
(
tx
)
if
err
!=
nil
{
...
...
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