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
e8d1b622
Commit
e8d1b622
authored
Mar 11, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Default block number changes
parent
08b11540
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
45 deletions
+27
-45
api.go
rpc/api.go
+26
-44
xeth.go
xeth/xeth.go
+1
-1
No files found.
rpc/api.go
View file @
e8d1b622
...
@@ -22,7 +22,7 @@ import (
...
@@ -22,7 +22,7 @@ import (
var
(
var
(
defaultGasPrice
=
big
.
NewInt
(
10000000000000
)
defaultGasPrice
=
big
.
NewInt
(
10000000000000
)
defaultGas
=
big
.
NewInt
(
1
0000
)
defaultGas
=
big
.
NewInt
(
5
0000
)
filterTickerTime
=
15
*
time
.
Second
filterTickerTime
=
15
*
time
.
Second
)
)
...
@@ -44,8 +44,6 @@ type EthereumApi struct {
...
@@ -44,8 +44,6 @@ type EthereumApi struct {
register
map
[
string
][]
*
NewTxArgs
register
map
[
string
][]
*
NewTxArgs
db
ethutil
.
Database
db
ethutil
.
Database
// defaultBlockAge int64
}
}
func
NewEthereumApi
(
eth
*
xeth
.
XEth
,
dataDir
string
)
*
EthereumApi
{
func
NewEthereumApi
(
eth
*
xeth
.
XEth
,
dataDir
string
)
*
EthereumApi
{
...
@@ -58,7 +56,6 @@ func NewEthereumApi(eth *xeth.XEth, dataDir string) *EthereumApi {
...
@@ -58,7 +56,6 @@ func NewEthereumApi(eth *xeth.XEth, dataDir string) *EthereumApi {
logs
:
make
(
map
[
int
]
*
logFilter
),
logs
:
make
(
map
[
int
]
*
logFilter
),
messages
:
make
(
map
[
int
]
*
whisperFilter
),
messages
:
make
(
map
[
int
]
*
whisperFilter
),
db
:
db
,
db
:
db
,
// defaultBlockAge: -1,
}
}
go
api
.
filterManager
.
Start
()
go
api
.
filterManager
.
Start
()
go
api
.
start
()
go
api
.
start
()
...
@@ -66,36 +63,33 @@ func NewEthereumApi(eth *xeth.XEth, dataDir string) *EthereumApi {
...
@@ -66,36 +63,33 @@ func NewEthereumApi(eth *xeth.XEth, dataDir string) *EthereumApi {
return
api
return
api
}
}
// func (self *EthereumApi) setStateByBlockNumber(num int64)
{
func
(
self
*
EthereumApi
)
xethWithStateNum
(
num
int64
)
*
xeth
.
XEth
{
//
chain := self.xeth().Backend().ChainManager()
chain
:=
self
.
xeth
()
.
Backend
()
.
ChainManager
()
//
var block *types.Block
var
block
*
types
.
Block
// if self.defaultBlockAge
< 0 {
if
num
<
0
{
//
num = chain.CurrentBlock().Number().Int64() + num + 1
num
=
chain
.
CurrentBlock
()
.
Number
()
.
Int64
()
+
num
+
1
//
}
}
//
block = chain.GetBlockByNumber(uint64(num))
block
=
chain
.
GetBlockByNumber
(
uint64
(
num
))
// if block != nil {
var
st
*
state
.
StateDB
// self.useState(state.New(block.Root(), self.xeth().Backend().StateDb()))
if
block
!=
nil
{
// } else {
st
=
state
.
New
(
block
.
Root
(),
self
.
xeth
()
.
Backend
()
.
StateDb
())
// self.useState(chain.State())
}
else
{
// }
st
=
chain
.
State
()
// }
}
return
self
.
xeth
()
.
WithState
(
st
)
}
func
(
self
*
EthereumApi
)
getStateWithNum
(
num
int64
)
*
xeth
.
State
{
return
self
.
xethWithStateNum
(
num
)
.
State
()
}
func
(
self
*
EthereumApi
)
start
()
{
func
(
self
*
EthereumApi
)
start
()
{
timer
:=
time
.
NewTicker
(
filterTickerTime
)
timer
:=
time
.
NewTicker
(
filterTickerTime
)
// events := self.mux.Subscribe(core.ChainEvent{})
done
:
done
:
for
{
for
{
select
{
select
{
// case ev := <-events.Chan():
// switch ev.(type) {
// case core.ChainEvent:
// if self.defaultBlockAge < 0 {
// self.setStateByBlockNumber(self.defaultBlockAge)
// }
// }
case
<-
timer
.
C
:
case
<-
timer
.
C
:
self
.
logMut
.
Lock
()
self
.
logMut
.
Lock
()
self
.
messagesMut
.
Lock
()
self
.
messagesMut
.
Lock
()
...
@@ -277,7 +271,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error)
...
@@ -277,7 +271,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error)
}
}
func
(
p
*
EthereumApi
)
Call
(
args
*
NewTxArgs
,
reply
*
interface
{})
error
{
func
(
p
*
EthereumApi
)
Call
(
args
*
NewTxArgs
,
reply
*
interface
{})
error
{
result
,
err
:=
p
.
xeth
(
)
.
Call
(
args
.
From
,
args
.
To
,
args
.
Value
.
String
(),
args
.
Gas
.
String
(),
args
.
GasPrice
.
String
(),
args
.
Data
)
result
,
err
:=
p
.
xeth
WithStateNum
(
args
.
BlockNumber
)
.
Call
(
args
.
From
,
args
.
To
,
args
.
Value
.
String
(),
args
.
Gas
.
String
(),
args
.
GasPrice
.
String
(),
args
.
Data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -290,7 +284,7 @@ func (p *EthereumApi) GetBalance(args *GetBalanceArgs, reply *interface{}) error
...
@@ -290,7 +284,7 @@ func (p *EthereumApi) GetBalance(args *GetBalanceArgs, reply *interface{}) error
if
err
:=
args
.
requirements
();
err
!=
nil
{
if
err
:=
args
.
requirements
();
err
!=
nil
{
return
err
return
err
}
}
state
:=
p
.
xeth
()
.
State
(
)
.
SafeGet
(
args
.
Address
)
state
:=
p
.
getStateWithNum
(
args
.
BlockNumber
)
.
SafeGet
(
args
.
Address
)
*
reply
=
toHex
(
state
.
Balance
()
.
Bytes
())
*
reply
=
toHex
(
state
.
Balance
()
.
Bytes
())
return
nil
return
nil
}
}
...
@@ -299,7 +293,7 @@ func (p *EthereumApi) GetStorage(args *GetStorageArgs, reply *interface{}) error
...
@@ -299,7 +293,7 @@ func (p *EthereumApi) GetStorage(args *GetStorageArgs, reply *interface{}) error
if
err
:=
args
.
requirements
();
err
!=
nil
{
if
err
:=
args
.
requirements
();
err
!=
nil
{
return
err
return
err
}
}
*
reply
=
p
.
xeth
()
.
State
(
)
.
SafeGet
(
args
.
Address
)
.
Storage
()
*
reply
=
p
.
getStateWithNum
(
args
.
BlockNumber
)
.
SafeGet
(
args
.
Address
)
.
Storage
()
return
nil
return
nil
}
}
...
@@ -307,7 +301,7 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e
...
@@ -307,7 +301,7 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e
if
err
:=
args
.
requirements
();
err
!=
nil
{
if
err
:=
args
.
requirements
();
err
!=
nil
{
return
err
return
err
}
}
state
:=
p
.
xeth
()
.
State
(
)
.
SafeGet
(
args
.
Address
)
state
:=
p
.
getStateWithNum
(
args
.
BlockNumber
)
.
SafeGet
(
args
.
Address
)
value
:=
state
.
StorageString
(
args
.
Key
)
value
:=
state
.
StorageString
(
args
.
Key
)
var
hx
string
var
hx
string
...
@@ -328,7 +322,7 @@ func (p *EthereumApi) GetTxCountAt(args *GetTxCountArgs, reply *interface{}) err
...
@@ -328,7 +322,7 @@ func (p *EthereumApi) GetTxCountAt(args *GetTxCountArgs, reply *interface{}) err
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
*
reply
=
p
.
xeth
(
)
.
TxCountAt
(
args
.
Address
)
*
reply
=
p
.
xeth
WithStateNum
(
args
.
BlockNumber
)
.
TxCountAt
(
args
.
Address
)
return
nil
return
nil
}
}
...
@@ -336,7 +330,7 @@ func (p *EthereumApi) GetData(args *GetDataArgs, reply *interface{}) error {
...
@@ -336,7 +330,7 @@ func (p *EthereumApi) GetData(args *GetDataArgs, reply *interface{}) error {
if
err
:=
args
.
requirements
();
err
!=
nil
{
if
err
:=
args
.
requirements
();
err
!=
nil
{
return
err
return
err
}
}
*
reply
=
p
.
xeth
(
)
.
CodeAt
(
args
.
Address
)
*
reply
=
p
.
xeth
WithStateNum
(
args
.
BlockNumber
)
.
CodeAt
(
args
.
Address
)
return
nil
return
nil
}
}
...
@@ -482,28 +476,24 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
...
@@ -482,28 +476,24 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
case
"eth_blockNumber"
:
case
"eth_blockNumber"
:
*
reply
=
toHex
(
p
.
xeth
()
.
Backend
()
.
ChainManager
()
.
CurrentBlock
()
.
Number
()
.
Bytes
())
*
reply
=
toHex
(
p
.
xeth
()
.
Backend
()
.
ChainManager
()
.
CurrentBlock
()
.
Number
()
.
Bytes
())
case
"eth_getBalance"
:
case
"eth_getBalance"
:
// TODO handle BlockNumber
args
:=
new
(
GetBalanceArgs
)
args
:=
new
(
GetBalanceArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
GetBalance
(
args
,
reply
)
return
p
.
GetBalance
(
args
,
reply
)
case
"eth_getStorage"
,
"eth_storageAt"
:
case
"eth_getStorage"
,
"eth_storageAt"
:
// TODO handle BlockNumber
args
:=
new
(
GetStorageArgs
)
args
:=
new
(
GetStorageArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
GetStorage
(
args
,
reply
)
return
p
.
GetStorage
(
args
,
reply
)
case
"eth_getStorageAt"
:
case
"eth_getStorageAt"
:
// TODO handle BlockNumber
args
:=
new
(
GetStorageAtArgs
)
args
:=
new
(
GetStorageAtArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
GetStorageAt
(
args
,
reply
)
return
p
.
GetStorageAt
(
args
,
reply
)
case
"eth_getTransactionCount"
:
case
"eth_getTransactionCount"
:
// TODO handle BlockNumber
args
:=
new
(
GetTxCountArgs
)
args
:=
new
(
GetTxCountArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
...
@@ -554,7 +544,6 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
...
@@ -554,7 +544,6 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
}
}
*
reply
=
toHex
(
big
.
NewInt
(
v
)
.
Bytes
())
*
reply
=
toHex
(
big
.
NewInt
(
v
)
.
Bytes
())
case
"eth_getData"
:
case
"eth_getData"
:
// TODO handle BlockNumber
args
:=
new
(
GetDataArgs
)
args
:=
new
(
GetDataArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
...
@@ -756,13 +745,6 @@ func (self *EthereumApi) xeth() *xeth.XEth {
...
@@ -756,13 +745,6 @@ func (self *EthereumApi) xeth() *xeth.XEth {
return
self
.
eth
return
self
.
eth
}
}
func
(
self
*
EthereumApi
)
useState
(
statedb
*
state
.
StateDB
)
{
self
.
xethMu
.
Lock
()
defer
self
.
xethMu
.
Unlock
()
self
.
eth
=
self
.
eth
.
UseState
(
statedb
)
}
func
toFilterOptions
(
options
*
FilterOptions
)
core
.
FilterOptions
{
func
toFilterOptions
(
options
*
FilterOptions
)
core
.
FilterOptions
{
var
opts
core
.
FilterOptions
var
opts
core
.
FilterOptions
...
...
xeth/xeth.go
View file @
e8d1b622
...
@@ -98,7 +98,7 @@ func New(eth Backend, frontend Frontend) *XEth {
...
@@ -98,7 +98,7 @@ func New(eth Backend, frontend Frontend) *XEth {
}
}
func
(
self
*
XEth
)
Backend
()
Backend
{
return
self
.
eth
}
func
(
self
*
XEth
)
Backend
()
Backend
{
return
self
.
eth
}
func
(
self
*
XEth
)
Use
State
(
statedb
*
state
.
StateDB
)
*
XEth
{
func
(
self
*
XEth
)
With
State
(
statedb
*
state
.
StateDB
)
*
XEth
{
xeth
:=
&
XEth
{
xeth
:=
&
XEth
{
eth
:
self
.
eth
,
eth
:
self
.
eth
,
blockProcessor
:
self
.
blockProcessor
,
blockProcessor
:
self
.
blockProcessor
,
...
...
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