Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hnt-pub
Miner
Commits
0c7e0a97
Unverified
Commit
0c7e0a97
authored
3 years ago
by
Marc Nijdam
Committed by
GitHub
3 years ago
Browse files
Options
Download
Plain Diff
Merge pull request #1256 from helium/jsc/jsonrpc-b58-fixes
Fix JSONRPC B58 translations for gateway txns.
parents
7e90707c
dd1341d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/jsonrpc/miner_jsonrpc_txn.erl
+17
-11
src/jsonrpc/miner_jsonrpc_txn.erl
with
17 additions
and
11 deletions
+17
-11
src/jsonrpc/miner_jsonrpc_txn.erl
+
17
-
11
View file @
0c7e0a97
...
...
@@ -30,11 +30,11 @@ handle_rpc(<<"txn_queue">>, []) ->
end
;
handle_rpc
(
<<
"txn_add_gateway"
>>
,
#
{
<<
"owner"
>>
:
=
OwnerB58
}
=
Params
)
->
try
Payer
=
case
maps
:
get
(
payer
,
Params
,
undefined
)
of
undefined
->
undefined
;
PayerB58
->
?
B58_TO_BIN
(
PayerB58
)
end
,
{
ok
,
Bin
}
=
blockchain
:
add_gateway_txn
(
?
B58_TO_BIN
(
Owner
B58
)
,
Payer
),
Payer
=
optional_binary_to_list
(
maps
:
get
(
payer
,
Params
,
undefined
)
)
,
Owner
=
binary_to_list
(
OwnerB58
)
,
{
ok
,
Bin
}
=
blockchain
:
add_gateway_txn
(
Owner
,
Payer
),
B64
=
base64
:
encode
(
Bin
),
#
{
<<
"result"
>>
=>
B64
}
catch
...
...
@@ -46,17 +46,16 @@ handle_rpc(<<"txn_add_gateway">>, #{ <<"owner">> := OwnerB58 } = Params) ->
end
;
handle_rpc
(
<<
"txn_assert_location"
>>
,
#
{
<<
"owner"
>>
:
=
OwnerB58
}
=
Params
)
->
try
Payer
=
case
maps
:
get
(
payer
,
Params
,
undefined
)
of
undefined
->
undefined
;
PayerB58
->
?
B58_TO_BIN
(
PayerB58
)
end
,
Payer
=
optional_binary_to_list
(
maps
:
get
(
payer
,
Params
,
undefined
)
)
,
Owner
=
binary_to_list
(
OwnerB58
)
,
H3String
=
case
parse_location
(
Params
)
of
{
error
,
_}
=
Err
->
throw
(
Err
);
{
ok
,
S
}
->
S
end
,
Nonce
=
maps
:
get
(
nonce
,
Params
,
1
),
{
ok
,
Bin
}
=
blockchain
:
assert_loc_txn
(
H3String
,
?
B58_TO_BIN
(
OwnerB58
),
Payer
,
Nonce
),
{
ok
,
Bin
}
=
blockchain
:
assert_loc_txn
(
H3String
,
Owner
,
Payer
,
Nonce
),
B64
=
base64
:
encode
(
Bin
),
#
{
<<
"result"
>>
=>
B64
}
catch
...
...
@@ -69,6 +68,13 @@ handle_rpc(<<"txn_assert_location">>, #{ <<"owner">> := OwnerB58 } = Params) ->
handle_rpc
(_,
_)
->
?
jsonrpc_error
(
method_not_found
).
-
spec
optional_binary_to_list
(
undefined
|
binary
())
->
undefined
|
string
().
optional_binary_to_list
(
PossibleBinary
)
->
case
PossibleBinary
of
undefined
->
undefined
;
Bin
->
binary_to_list
(
Bin
)
end
.
parse_location
(
#
{
<<
"h3"
>>
:
=
H3
})
->
try
%% h3 literally expects a string, not a binary string, so...
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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
Menu
Explore
Projects
Groups
Snippets