Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Chiguireitor
addrindexrs
Commits
909802e6
Unverified
Commit
909802e6
authored
May 02, 2018
by
Roman Zeyde
Browse files
Refactor RPC parameter parsing
parent
993ab96b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
src/rpc.rs
src/rpc.rs
+6
-6
No files found.
src/rpc.rs
View file @
909802e6
...
...
@@ -20,8 +20,8 @@ struct Handler<'a> {
}
// TODO: Sha256dHash should be a generic hash-container (since script hash is single SHA256)
fn
hash_from_
params
(
params
:
&
[
Value
]
)
->
Result
<
Sha256dHash
>
{
let
script_hash
=
params
.get
(
0
)
.chain_err
(||
"missing hash"
)
?
;
fn
hash_from_
value
(
val
:
Option
<&
Value
>
)
->
Result
<
Sha256dHash
>
{
let
script_hash
=
val
.chain_err
(||
"missing hash"
)
?
;
let
script_hash
=
script_hash
.as_str
()
.chain_err
(||
"non-string hash"
)
?
;
let
script_hash
=
Sha256dHash
::
from_hex
(
script_hash
)
.chain_err
(||
"non-hex hash"
)
?
;
Ok
(
script_hash
)
...
...
@@ -128,7 +128,7 @@ impl<'a> Handler<'a> {
}
fn
blockchain_scripthash_subscribe
(
&
self
,
params
:
&
[
Value
])
->
Result
<
Value
>
{
let
script_hash
=
hash_from_
params
(
&
params
)
.chain_err
(||
"bad script_hash"
)
?
;
let
script_hash
=
hash_from_
value
(
params
.get
(
0
)
)
.chain_err
(||
"bad script_hash"
)
?
;
let
status
=
self
.query
.status
(
&
script_hash
[
..
]);
Ok
(
match
hash_from_status
(
&
status
)
{
...
...
@@ -138,13 +138,13 @@ impl<'a> Handler<'a> {
}
fn
blockchain_scripthash_get_balance
(
&
self
,
params
:
&
[
Value
])
->
Result
<
Value
>
{
let
script_hash
=
hash_from_
params
(
&
params
)
.chain_err
(||
"bad script_hash"
)
?
;
let
script_hash
=
hash_from_
value
(
params
.get
(
0
)
)
.chain_err
(||
"bad script_hash"
)
?
;
let
status
=
self
.query
.status
(
&
script_hash
[
..
]);
Ok
(
json!
({
"confirmed"
:
status
.balance
}))
// TODO: "unconfirmed"
}
fn
blockchain_scripthash_get_history
(
&
self
,
params
:
&
[
Value
])
->
Result
<
Value
>
{
let
script_hash
=
hash_from_
params
(
&
params
)
.chain_err
(||
"bad script_hash"
)
?
;
let
script_hash
=
hash_from_
value
(
params
.get
(
0
)
)
.chain_err
(||
"bad script_hash"
)
?
;
let
status
=
self
.query
.status
(
&
script_hash
[
..
]);
Ok
(
json!
(
Value
::
Array
(
history_from_status
(
&
status
)
...
...
@@ -156,7 +156,7 @@ impl<'a> Handler<'a> {
fn
blockchain_transaction_get
(
&
self
,
params
:
&
[
Value
])
->
Result
<
Value
>
{
// TODO: handle 'verbose' param
let
tx_hash
=
hash_from_
params
(
params
)
.chain_err
(||
"bad tx_hash"
)
?
;
let
tx_hash
=
hash_from_
value
(
params
.get
(
0
)
)
.chain_err
(||
"bad tx_hash"
)
?
;
let
tx_hex
=
util
::
hexlify
(
&
self
.query
.get_tx
(
&
tx_hash
));
Ok
(
json!
(
tx_hex
))
}
...
...
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