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
bd38428f
Commit
bd38428f
authored
Jun 10, 2015
by
Bas van Kervel
Committed by
Bas van Kervel
Jun 11, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup of javascript API
parent
87b62f75
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
91 additions
and
89 deletions
+91
-89
js.go
cmd/console/js.go
+2
-1
admin.go
rpc/api/admin.go
+15
-10
admin_args.go
rpc/api/admin_args.go
+2
-12
admin_js.go
rpc/api/admin_js.go
+15
-14
miner_args.go
rpc/api/miner_args.go
+12
-5
miner_js.go
rpc/api/miner_js.go
+0
-7
net.go
rpc/api/net.go
+2
-2
net_js.go
rpc/api/net_js.go
+10
-14
personal_args.go
rpc/api/personal_args.go
+28
-17
personal_js.go
rpc/api/personal_js.go
+5
-7
No files found.
cmd/console/js.go
View file @
bd38428f
...
@@ -32,12 +32,12 @@ import (
...
@@ -32,12 +32,12 @@ import (
"github.com/ethereum/go-ethereum/common/docserver"
"github.com/ethereum/go-ethereum/common/docserver"
re
"github.com/ethereum/go-ethereum/jsre"
re
"github.com/ethereum/go-ethereum/jsre"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/rpc/api"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/comms"
"github.com/ethereum/go-ethereum/rpc/comms"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/peterh/liner"
"github.com/peterh/liner"
"github.com/robertkrimen/otto"
"github.com/robertkrimen/otto"
"github.com/ethereum/go-ethereum/rpc/api"
)
)
type
prompter
interface
{
type
prompter
interface
{
...
@@ -235,6 +235,7 @@ func (self *jsre) suportedApis(ipcpath string) ([]string, error) {
...
@@ -235,6 +235,7 @@ func (self *jsre) suportedApis(ipcpath string) ([]string, error) {
// show summary of current geth instance
// show summary of current geth instance
func
(
self
*
jsre
)
welcome
(
ipcpath
string
)
{
func
(
self
*
jsre
)
welcome
(
ipcpath
string
)
{
self
.
re
.
Eval
(
`console.log('instance: ' + web3.version.client);`
)
self
.
re
.
Eval
(
`console.log('instance: ' + web3.version.client);`
)
self
.
re
.
Eval
(
`console.log(' datadir: ' + admin.datadir);`
)
self
.
re
.
Eval
(
`console.log("coinbase: " + eth.coinbase);`
)
self
.
re
.
Eval
(
`console.log("coinbase: " + eth.coinbase);`
)
self
.
re
.
Eval
(
`var lastBlockTimestamp = 1000 * eth.getBlock(eth.blockNumber).timestamp`
)
self
.
re
.
Eval
(
`var lastBlockTimestamp = 1000 * eth.getBlock(eth.blockNumber).timestamp`
)
self
.
re
.
Eval
(
`console.log("at block: " + eth.blockNumber + " (" + new Date(lastBlockTimestamp).toLocaleDateString()
self
.
re
.
Eval
(
`console.log("at block: " + eth.blockNumber + " (" + new Date(lastBlockTimestamp).toLocaleDateString()
...
...
rpc/api/admin.go
View file @
bd38428f
...
@@ -31,8 +31,9 @@ var (
...
@@ -31,8 +31,9 @@ var (
"admin_exportChain"
:
(
*
adminApi
)
.
ExportChain
,
"admin_exportChain"
:
(
*
adminApi
)
.
ExportChain
,
"admin_importChain"
:
(
*
adminApi
)
.
ImportChain
,
"admin_importChain"
:
(
*
adminApi
)
.
ImportChain
,
"admin_verbosity"
:
(
*
adminApi
)
.
Verbosity
,
"admin_verbosity"
:
(
*
adminApi
)
.
Verbosity
,
"admin_
syncStatus"
:
(
*
adminApi
)
.
SyncStatus
,
"admin_
chainSyncStatus"
:
(
*
adminApi
)
.
Chain
SyncStatus
,
"admin_setSolc"
:
(
*
adminApi
)
.
SetSolc
,
"admin_setSolc"
:
(
*
adminApi
)
.
SetSolc
,
"admin_datadir"
:
(
*
adminApi
)
.
DataDir
,
}
}
)
)
...
@@ -129,6 +130,10 @@ func (self *adminApi) NodeInfo(req *shared.Request) (interface{}, error) {
...
@@ -129,6 +130,10 @@ func (self *adminApi) NodeInfo(req *shared.Request) (interface{}, error) {
return
self
.
ethereum
.
NodeInfo
(),
nil
return
self
.
ethereum
.
NodeInfo
(),
nil
}
}
func
(
self
*
adminApi
)
DataDir
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
return
self
.
ethereum
.
DataDir
,
nil
}
func
hasAllBlocks
(
chain
*
core
.
ChainManager
,
bs
[]
*
types
.
Block
)
bool
{
func
hasAllBlocks
(
chain
*
core
.
ChainManager
,
bs
[]
*
types
.
Block
)
bool
{
for
_
,
b
:=
range
bs
{
for
_
,
b
:=
range
bs
{
if
!
chain
.
HasBlock
(
b
.
Hash
())
{
if
!
chain
.
HasBlock
(
b
.
Hash
())
{
...
@@ -209,9 +214,9 @@ func (self *adminApi) Verbosity(req *shared.Request) (interface{}, error) {
...
@@ -209,9 +214,9 @@ func (self *adminApi) Verbosity(req *shared.Request) (interface{}, error) {
return
true
,
nil
return
true
,
nil
}
}
func
(
self
*
adminApi
)
SyncStatus
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
func
(
self
*
adminApi
)
Chain
SyncStatus
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
pending
,
cached
:=
self
.
ethereum
.
Downloader
()
.
Stats
()
pending
,
cached
:=
self
.
ethereum
.
Downloader
()
.
Stats
()
return
map
[
string
]
interface
{}{
"
available"
:
pending
,
"w
aitingForImport"
:
cached
},
nil
return
map
[
string
]
interface
{}{
"
blocksAvailable"
:
pending
,
"blocksW
aitingForImport"
:
cached
},
nil
}
}
func
(
self
*
adminApi
)
SetSolc
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
func
(
self
*
adminApi
)
SetSolc
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
...
...
rpc/api/admin_args.go
View file @
bd38428f
...
@@ -3,8 +3,6 @@ package api
...
@@ -3,8 +3,6 @@ package api
import
(
import
(
"encoding/json"
"encoding/json"
"math/big"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/rpc/shared"
)
)
...
@@ -68,16 +66,8 @@ func (args *VerbosityArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -68,16 +66,8 @@ func (args *VerbosityArgs) UnmarshalJSON(b []byte) (err error) {
return
shared
.
NewDecodeParamError
(
"Expected enode as argument"
)
return
shared
.
NewDecodeParamError
(
"Expected enode as argument"
)
}
}
if
levelint
,
ok
:=
obj
[
0
]
.
(
int
);
ok
{
level
,
err
:=
numString
(
obj
[
0
])
args
.
Level
=
levelint
if
err
==
nil
{
}
else
if
levelstr
,
ok
:=
obj
[
0
]
.
(
string
);
ok
{
if
!
ok
{
return
shared
.
NewInvalidTypeError
(
"level"
,
"not a string"
)
}
level
,
success
:=
new
(
big
.
Int
)
.
SetString
(
levelstr
,
0
)
if
!
success
{
return
shared
.
NewDecodeParamError
(
"Unable to parse verbosity level"
)
}
args
.
Level
=
int
(
level
.
Int64
())
args
.
Level
=
int
(
level
.
Int64
())
}
}
...
...
rpc/api/admin_js.go
View file @
bd38428f
...
@@ -12,13 +12,6 @@ web3._extend({
...
@@ -12,13 +12,6 @@ web3._extend({
inputFormatter: [web3._extend.utils.formatInputString],
inputFormatter: [web3._extend.utils.formatInputString],
outputFormatter: web3._extend.formatters.formatOutputBool
outputFormatter: web3._extend.formatters.formatOutputBool
}),
}),
new web3._extend.Method({
name: 'peers',
call: 'admin_peers',
params: 0,
inputFormatter: [],
outputFormatter: function(obj) { return obj; }
}),
new web3._extend.Method({
new web3._extend.Method({
name: 'exportChain',
name: 'exportChain',
call: 'admin_exportChain',
call: 'admin_exportChain',
...
@@ -40,13 +33,6 @@ web3._extend({
...
@@ -40,13 +33,6 @@ web3._extend({
inputFormatter: [web3._extend.utils.formatInputInt],
inputFormatter: [web3._extend.utils.formatInputInt],
outputFormatter: web3._extend.formatters.formatOutputBool
outputFormatter: web3._extend.formatters.formatOutputBool
}),
}),
new web3._extend.Method({
name: 'syncStatus',
call: 'admin_syncStatus',
params: 1,
inputFormatter: [web3._extend.utils.formatInputInt],
outputFormatter: function(obj) { return obj; }
}),
new web3._extend.Method({
new web3._extend.Method({
name: 'setSolc',
name: 'setSolc',
call: 'admin_setSolc',
call: 'admin_setSolc',
...
@@ -61,6 +47,21 @@ web3._extend({
...
@@ -61,6 +47,21 @@ web3._extend({
name: 'nodeInfo',
name: 'nodeInfo',
getter: 'admin_nodeInfo',
getter: 'admin_nodeInfo',
outputFormatter: web3._extend.formatters.formatOutputString
outputFormatter: web3._extend.formatters.formatOutputString
}),
new web3._extend.Property({
name: 'peers',
getter: 'admin_peers',
outputFormatter: function(obj) { return obj; }
}),
new web3._extend.Property({
name: 'datadir',
getter: 'admin_datadir',
outputFormatter: web3._extend.formatters.formatOutputString
}),
new web3._extend.Property({
name: 'chainSyncStatus',
getter: 'admin_chainSyncStatus',
outputFormatter: function(obj) { return obj; }
})
})
]
]
});
});
...
...
rpc/api/miner_args.go
View file @
bd38428f
...
@@ -41,6 +41,10 @@ func (args *SetExtraArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -41,6 +41,10 @@ func (args *SetExtraArgs) UnmarshalJSON(b []byte) (err error) {
return
shared
.
NewDecodeParamError
(
err
.
Error
())
return
shared
.
NewDecodeParamError
(
err
.
Error
())
}
}
if
len
(
obj
)
<
1
{
return
shared
.
NewInsufficientParamsError
(
len
(
obj
),
1
)
}
extrastr
,
ok
:=
obj
[
0
]
.
(
string
)
extrastr
,
ok
:=
obj
[
0
]
.
(
string
)
if
!
ok
{
if
!
ok
{
return
shared
.
NewInvalidTypeError
(
"Price"
,
"not a string"
)
return
shared
.
NewInvalidTypeError
(
"Price"
,
"not a string"
)
...
@@ -60,13 +64,16 @@ func (args *GasPriceArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -60,13 +64,16 @@ func (args *GasPriceArgs) UnmarshalJSON(b []byte) (err error) {
return
shared
.
NewDecodeParamError
(
err
.
Error
())
return
shared
.
NewDecodeParamError
(
err
.
Error
())
}
}
pricestr
,
ok
:=
obj
[
0
]
.
(
string
)
if
len
(
obj
)
<
1
{
if
!
ok
{
return
shared
.
NewInsufficientParamsError
(
len
(
obj
),
1
)
return
shared
.
NewInvalidTypeError
(
"Price"
,
"not a string"
)
}
}
args
.
Price
=
pricestr
if
pricestr
,
ok
:=
obj
[
0
]
.
(
string
);
ok
{
args
.
Price
=
pricestr
return
nil
return
nil
}
return
shared
.
NewInvalidTypeError
(
"Price"
,
"not a string"
)
}
}
type
MakeDAGArgs
struct
{
type
MakeDAGArgs
struct
{
...
...
rpc/api/miner_js.go
View file @
bd38428f
...
@@ -19,13 +19,6 @@ web3._extend({
...
@@ -19,13 +19,6 @@ web3._extend({
inputFormatter: [web3._extend.formatters.formatInputInt],
inputFormatter: [web3._extend.formatters.formatInputInt],
outputFormatter: web3._extend.formatters.formatOutputBool
outputFormatter: web3._extend.formatters.formatOutputBool
}),
}),
new web3._extend.Method({
name: 'getHashrate',
call: 'miner_hashrate',
params: 0,
inputFormatter: [],
outputFormatter: web3._extend.utils.toDecimal
}),
new web3._extend.Method({
new web3._extend.Method({
name: 'setExtra',
name: 'setExtra',
call: 'miner_setExtra',
call: 'miner_setExtra',
...
...
rpc/api/net.go
View file @
bd38428f
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
var
(
var
(
// mapping between methods and handlers
// mapping between methods and handlers
netMapping
=
map
[
string
]
nethandler
{
netMapping
=
map
[
string
]
nethandler
{
"net_
id"
:
(
*
netApi
)
.
Network
Version
,
"net_
version"
:
(
*
netApi
)
.
Version
,
"net_peerCount"
:
(
*
netApi
)
.
PeerCount
,
"net_peerCount"
:
(
*
netApi
)
.
PeerCount
,
"net_listening"
:
(
*
netApi
)
.
IsListening
,
"net_listening"
:
(
*
netApi
)
.
IsListening
,
"net_peers"
:
(
*
netApi
)
.
Peers
,
"net_peers"
:
(
*
netApi
)
.
Peers
,
...
@@ -63,7 +63,7 @@ func (self *netApi) Name() string {
...
@@ -63,7 +63,7 @@ func (self *netApi) Name() string {
}
}
// Network version
// Network version
func
(
self
*
netApi
)
Network
Version
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
func
(
self
*
netApi
)
Version
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
return
self
.
xeth
.
NetworkVersion
(),
nil
return
self
.
xeth
.
NetworkVersion
(),
nil
}
}
...
...
rpc/api/net_js.go
View file @
bd38428f
...
@@ -12,26 +12,12 @@ web3._extend({
...
@@ -12,26 +12,12 @@ web3._extend({
inputFormatter: [web3._extend.utils.formatInputString],
inputFormatter: [web3._extend.utils.formatInputString],
outputFormatter: web3._extend.formatters.formatOutputBool
outputFormatter: web3._extend.formatters.formatOutputBool
}),
}),
new web3._extend.Method({
name: 'id',
call: 'net_id',
params: 0,
inputFormatter: [],
outputFormatter: web3._extend.formatters.formatOutputString
}),
new web3._extend.Method({
new web3._extend.Method({
name: 'getPeerCount',
name: 'getPeerCount',
call: 'net_peerCount',
call: 'net_peerCount',
params: 0,
params: 0,
inputFormatter: [],
inputFormatter: [],
outputFormatter: web3._extend.formatters.formatOutputString
outputFormatter: web3._extend.formatters.formatOutputString
}),
new web3._extend.Method({
name: 'peers',
call: 'net_peers',
params: 0,
inputFormatter: [],
outputFormatter: function(obj) { return obj; }
})
})
],
],
properties:
properties:
...
@@ -45,6 +31,16 @@ web3._extend({
...
@@ -45,6 +31,16 @@ web3._extend({
name: 'peerCount',
name: 'peerCount',
getter: 'net_peerCount',
getter: 'net_peerCount',
outputFormatter: web3._extend.utils.toDecimal
outputFormatter: web3._extend.utils.toDecimal
}),
new web3._extend.Property({
name: 'peers',
getter: 'net_peers',
outputFormatter: function(obj) { return obj; }
}),
new web3._extend.Property({
name: 'version',
getter: 'net_version',
outputFormatter: web3._extend.formatters.formatOutputString
})
})
]
]
});
});
...
...
rpc/api/personal_args.go
View file @
bd38428f
...
@@ -16,13 +16,16 @@ func (args *NewAccountArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -16,13 +16,16 @@ func (args *NewAccountArgs) UnmarshalJSON(b []byte) (err error) {
return
shared
.
NewDecodeParamError
(
err
.
Error
())
return
shared
.
NewDecodeParamError
(
err
.
Error
())
}
}
passhrase
,
ok
:=
obj
[
0
]
.
(
string
)
if
len
(
obj
)
<
1
{
if
!
ok
{
return
shared
.
NewInsufficientParamsError
(
len
(
obj
),
1
)
return
shared
.
NewInvalidTypeError
(
"passhrase"
,
"not a string"
)
}
}
args
.
Passphrase
=
passhrase
if
passhrase
,
ok
:=
obj
[
0
]
.
(
string
);
ok
{
args
.
Passphrase
=
passhrase
return
nil
return
nil
}
return
shared
.
NewInvalidTypeError
(
"passhrase"
,
"not a string"
)
}
}
type
DeleteAccountArgs
struct
{
type
DeleteAccountArgs
struct
{
...
@@ -36,17 +39,21 @@ func (args *DeleteAccountArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -36,17 +39,21 @@ func (args *DeleteAccountArgs) UnmarshalJSON(b []byte) (err error) {
return
shared
.
NewDecodeParamError
(
err
.
Error
())
return
shared
.
NewDecodeParamError
(
err
.
Error
())
}
}
addr
,
ok
:=
obj
[
0
]
.
(
string
)
if
len
(
obj
)
<
2
{
if
!
ok
{
return
shared
.
NewInsufficientParamsError
(
len
(
obj
),
2
)
return
shared
.
NewInvalidTypeError
(
"address"
,
"not a string"
)
}
}
if
addr
,
ok
:=
obj
[
0
]
.
(
string
);
ok
{
args
.
Address
=
addr
args
.
Address
=
addr
}
else
{
return
shared
.
NewInvalidTypeError
(
"address"
,
"not a string"
)
}
passhrase
,
ok
:=
obj
[
1
]
.
(
string
)
if
passhrase
,
ok
:=
obj
[
1
]
.
(
string
);
ok
{
if
!
ok
{
args
.
Passphrase
=
passhrase
}
else
{
return
shared
.
NewInvalidTypeError
(
"passhrase"
,
"not a string"
)
return
shared
.
NewInvalidTypeError
(
"passhrase"
,
"not a string"
)
}
}
args
.
Passphrase
=
passhrase
return
nil
return
nil
}
}
...
@@ -65,17 +72,21 @@ func (args *UnlockAccountArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -65,17 +72,21 @@ func (args *UnlockAccountArgs) UnmarshalJSON(b []byte) (err error) {
args
.
Duration
=
-
1
args
.
Duration
=
-
1
addrstr
,
ok
:=
obj
[
0
]
.
(
string
)
if
len
(
obj
)
<
2
{
if
!
ok
{
return
shared
.
NewInsufficientParamsError
(
len
(
obj
),
2
)
return
shared
.
NewInvalidTypeError
(
"address"
,
"not a string"
)
}
}
if
addrstr
,
ok
:=
obj
[
0
]
.
(
string
);
ok
{
args
.
Address
=
addrstr
args
.
Address
=
addrstr
}
else
{
return
shared
.
NewInvalidTypeError
(
"address"
,
"not a string"
)
}
passphrasestr
,
ok
:=
obj
[
1
]
.
(
string
)
if
passphrasestr
,
ok
:=
obj
[
1
]
.
(
string
);
ok
{
if
!
ok
{
args
.
Passphrase
=
passphrasestr
}
else
{
return
shared
.
NewInvalidTypeError
(
"passphrase"
,
"not a string"
)
return
shared
.
NewInvalidTypeError
(
"passphrase"
,
"not a string"
)
}
}
args
.
Passphrase
=
passphrasestr
return
nil
return
nil
}
}
rpc/api/personal_js.go
View file @
bd38428f
...
@@ -5,13 +5,6 @@ web3._extend({
...
@@ -5,13 +5,6 @@ web3._extend({
property: 'personal',
property: 'personal',
methods:
methods:
[
[
new web3._extend.Method({
name: 'listAccounts',
call: 'personal_listAccounts',
params: 0,
inputFormatter: [],
outputFormatter: function(obj) { return obj; }
}),
new web3._extend.Method({
new web3._extend.Method({
name: 'newAccount',
name: 'newAccount',
call: 'personal_newAccount',
call: 'personal_newAccount',
...
@@ -29,6 +22,11 @@ web3._extend({
...
@@ -29,6 +22,11 @@ web3._extend({
],
],
properties:
properties:
[
[
new web3._extend.Property({
name: 'accounts',
getter: 'personal_listAccounts',
outputFormatter: function(obj) { return obj; }
})
]
]
});
});
`
`
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