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
c3f6c322
Commit
c3f6c322
authored
Jun 16, 2015
by
Bas van Kervel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added DB api
parent
5c25403b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
295 additions
and
5 deletions
+295
-5
admin.go
rpc/api/admin.go
+3
-3
api.go
rpc/api/api.go
+3
-2
db.go
rpc/api/db.go
+128
-0
db_args.go
rpc/api/db_args.go
+110
-0
db_js.go
rpc/api/db_js.go
+41
-0
utils.go
rpc/api/utils.go
+10
-0
No files found.
rpc/api/admin.go
View file @
c3f6c322
...
...
@@ -222,10 +222,10 @@ func (self *adminApi) ChainSyncStatus(req *shared.Request) (interface{}, error)
pending
,
cached
,
importing
,
estimate
:=
self
.
ethereum
.
Downloader
()
.
Stats
()
return
map
[
string
]
interface
{}{
"blocksAvailable"
:
pending
,
"blocksAvailable"
:
pending
,
"blocksWaitingForImport"
:
cached
,
"importing"
:
importing
,
"estimate"
:
estimate
.
String
(),
"importing"
:
importing
,
"estimate"
:
estimate
.
String
(),
},
nil
}
...
...
rpc/api/api.go
View file @
c3f6c322
...
...
@@ -9,6 +9,7 @@ import (
const
(
AdminApiName
=
"admin"
EthApiName
=
"eth"
DbApiName
=
"db"
DebugApiName
=
"debug"
MergedApiName
=
"merged"
MinerApiName
=
"miner"
...
...
@@ -21,12 +22,12 @@ const (
var
(
DefaultHttpRpcApis
=
strings
.
Join
([]
string
{
EthApiName
,
NetApiName
,
Web3ApiName
,
DbApiName
,
EthApiName
,
NetApiName
,
Web3ApiName
,
},
","
)
// List with all API's which are offered over the IPC interface by default
DefaultIpcApis
=
strings
.
Join
([]
string
{
AdminApiName
,
EthApiName
,
DebugApiName
,
MinerApiName
,
NetApiName
,
AdminApiName
,
DbApiName
,
EthApiName
,
DebugApiName
,
MinerApiName
,
NetApiName
,
ShhApiName
,
TxPoolApiName
,
PersonalApiName
,
Web3ApiName
,
},
","
)
)
...
...
rpc/api/db.go
0 → 100644
View file @
c3f6c322
package
api
import
(
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/xeth"
)
const
(
DbApiversion
=
"1.0"
)
var
(
// mapping between methods and handlers
DbMapping
=
map
[
string
]
dbhandler
{
"db_getString"
:
(
*
dbApi
)
.
GetString
,
"db_putString"
:
(
*
dbApi
)
.
PutString
,
"db_getHex"
:
(
*
dbApi
)
.
GetHex
,
"db_putHex"
:
(
*
dbApi
)
.
PutHex
,
}
)
// db callback handler
type
dbhandler
func
(
*
dbApi
,
*
shared
.
Request
)
(
interface
{},
error
)
// db api provider
type
dbApi
struct
{
xeth
*
xeth
.
XEth
ethereum
*
eth
.
Ethereum
methods
map
[
string
]
dbhandler
codec
codec
.
ApiCoder
}
// create a new db api instance
func
NewDbApi
(
xeth
*
xeth
.
XEth
,
ethereum
*
eth
.
Ethereum
,
coder
codec
.
Codec
)
*
dbApi
{
return
&
dbApi
{
xeth
:
xeth
,
ethereum
:
ethereum
,
methods
:
DbMapping
,
codec
:
coder
.
New
(
nil
),
}
}
// collection with supported methods
func
(
self
*
dbApi
)
Methods
()
[]
string
{
methods
:=
make
([]
string
,
len
(
self
.
methods
))
i
:=
0
for
k
:=
range
self
.
methods
{
methods
[
i
]
=
k
i
++
}
return
methods
}
// Execute given request
func
(
self
*
dbApi
)
Execute
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
if
callback
,
ok
:=
self
.
methods
[
req
.
Method
];
ok
{
return
callback
(
self
,
req
)
}
return
nil
,
&
shared
.
NotImplementedError
{
req
.
Method
}
}
func
(
self
*
dbApi
)
Name
()
string
{
return
DbApiName
}
func
(
self
*
dbApi
)
ApiVersion
()
string
{
return
DbApiversion
}
func
(
self
*
dbApi
)
GetString
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
DbArgs
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
}
if
err
:=
args
.
requirements
();
err
!=
nil
{
return
nil
,
err
}
ret
,
err
:=
self
.
xeth
.
DbGet
([]
byte
(
args
.
Database
+
args
.
Key
))
return
string
(
ret
),
err
}
func
(
self
*
dbApi
)
PutString
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
DbArgs
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
}
if
err
:=
args
.
requirements
();
err
!=
nil
{
return
nil
,
err
}
return
self
.
xeth
.
DbPut
([]
byte
(
args
.
Database
+
args
.
Key
),
args
.
Value
),
nil
}
func
(
self
*
dbApi
)
GetHex
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
DbHexArgs
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
}
if
err
:=
args
.
requirements
();
err
!=
nil
{
return
nil
,
err
}
if
res
,
err
:=
self
.
xeth
.
DbGet
([]
byte
(
args
.
Database
+
args
.
Key
));
err
==
nil
{
return
newHexData
(
res
),
nil
}
else
{
return
nil
,
err
}
}
func
(
self
*
dbApi
)
PutHex
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
DbHexArgs
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
}
if
err
:=
args
.
requirements
();
err
!=
nil
{
return
nil
,
err
}
return
self
.
xeth
.
DbPut
([]
byte
(
args
.
Database
+
args
.
Key
),
args
.
Value
),
nil
}
rpc/api/db_args.go
0 → 100644
View file @
c3f6c322
package
api
import
(
"encoding/json"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rpc/shared"
)
type
DbArgs
struct
{
Database
string
Key
string
Value
[]
byte
}
func
(
args
*
DbArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
interface
{}
if
err
:=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
return
shared
.
NewDecodeParamError
(
err
.
Error
())
}
if
len
(
obj
)
<
2
{
return
shared
.
NewInsufficientParamsError
(
len
(
obj
),
2
)
}
var
objstr
string
var
ok
bool
if
objstr
,
ok
=
obj
[
0
]
.
(
string
);
!
ok
{
return
shared
.
NewInvalidTypeError
(
"database"
,
"not a string"
)
}
args
.
Database
=
objstr
if
objstr
,
ok
=
obj
[
1
]
.
(
string
);
!
ok
{
return
shared
.
NewInvalidTypeError
(
"key"
,
"not a string"
)
}
args
.
Key
=
objstr
if
len
(
obj
)
>
2
{
objstr
,
ok
=
obj
[
2
]
.
(
string
)
if
!
ok
{
return
shared
.
NewInvalidTypeError
(
"value"
,
"not a string"
)
}
args
.
Value
=
[]
byte
(
objstr
)
}
return
nil
}
func
(
a
*
DbArgs
)
requirements
()
error
{
if
len
(
a
.
Database
)
==
0
{
return
shared
.
NewValidationError
(
"Database"
,
"cannot be blank"
)
}
if
len
(
a
.
Key
)
==
0
{
return
shared
.
NewValidationError
(
"Key"
,
"cannot be blank"
)
}
return
nil
}
type
DbHexArgs
struct
{
Database
string
Key
string
Value
[]
byte
}
func
(
args
*
DbHexArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
interface
{}
if
err
:=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
return
shared
.
NewDecodeParamError
(
err
.
Error
())
}
if
len
(
obj
)
<
2
{
return
shared
.
NewInsufficientParamsError
(
len
(
obj
),
2
)
}
var
objstr
string
var
ok
bool
if
objstr
,
ok
=
obj
[
0
]
.
(
string
);
!
ok
{
return
shared
.
NewInvalidTypeError
(
"database"
,
"not a string"
)
}
args
.
Database
=
objstr
if
objstr
,
ok
=
obj
[
1
]
.
(
string
);
!
ok
{
return
shared
.
NewInvalidTypeError
(
"key"
,
"not a string"
)
}
args
.
Key
=
objstr
if
len
(
obj
)
>
2
{
objstr
,
ok
=
obj
[
2
]
.
(
string
)
if
!
ok
{
return
shared
.
NewInvalidTypeError
(
"value"
,
"not a string"
)
}
args
.
Value
=
common
.
FromHex
(
objstr
)
}
return
nil
}
func
(
a
*
DbHexArgs
)
requirements
()
error
{
if
len
(
a
.
Database
)
==
0
{
return
shared
.
NewValidationError
(
"Database"
,
"cannot be blank"
)
}
if
len
(
a
.
Key
)
==
0
{
return
shared
.
NewValidationError
(
"Key"
,
"cannot be blank"
)
}
return
nil
}
rpc/api/db_js.go
0 → 100644
View file @
c3f6c322
package
api
const
Db_JS
=
`
web3._extend({
property: 'db',
methods:
[
new web3._extend.Method({
name: 'getString',
call: 'db_getString',
params: 2,
inputFormatter: [web3._extend.formatters.formatInputString, web3._extend.formatters.formatInputString],
outputFormatter: web3._extend.formatters.formatOutputString
}),
new web3._extend.Method({
name: 'putString',
call: 'db_putString',
params: 3,
inputFormatter: [web3._extend.formatters.formatInputString, web3._extend.formatters.formatInputString, web3._extend.formatters.formatInputString],
outputFormatter: web3._extend.formatters.formatOutputBool
}),
new web3._extend.Method({
name: 'getHex',
call: 'db_getHex',
params: 2,
inputFormatter: [web3._extend.formatters.formatInputString, web3._extend.formatters.formatInputString],
outputFormatter: web3._extend.formatters.formatOutputString
}),
new web3._extend.Method({
name: 'putHex',
call: 'db_putHex',
params: 3,
inputFormatter: [web3._extend.formatters.formatInputString, web3._extend.formatters.formatInputString, web3._extend.formatters.formatInputString],
outputFormatter: web3._extend.formatters.formatOutputBool
}),
],
properties:
[
]
});
`
rpc/api/utils.go
View file @
c3f6c322
...
...
@@ -24,6 +24,12 @@ var (
"setSolc"
,
"datadir"
,
},
"db"
:
[]
string
{
"getString"
,
"putString"
,
"getHex"
,
"putHex"
,
},
"debug"
:
[]
string
{
"dumpBlock"
,
"getBlockRlp"
,
...
...
@@ -137,6 +143,8 @@ func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth.
apis
[
i
]
=
NewAdminApi
(
xeth
,
eth
,
codec
)
case
DebugApiName
:
apis
[
i
]
=
NewDebugApi
(
xeth
,
eth
,
codec
)
case
DbApiName
:
apis
[
i
]
=
NewDbApi
(
xeth
,
eth
,
codec
)
case
EthApiName
:
apis
[
i
]
=
NewEthApi
(
xeth
,
codec
)
case
MinerApiName
:
...
...
@@ -165,6 +173,8 @@ func Javascript(name string) string {
return
Admin_JS
case
DebugApiName
:
return
Debug_JS
case
DbApiName
:
return
Db_JS
case
MinerApiName
:
return
Miner_JS
case
NetApiName
:
...
...
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