-
Notifications
You must be signed in to change notification settings - Fork 192
Conversation
neo/api/JSONRPC/JsonRpcApi.py
Outdated
@@ -128,6 +129,21 @@ def parse_uint_str(self, param): | |||
return param[2:] | |||
return param | |||
|
|||
def validateaddress(self, params): | |||
# check for [] parameter or [""] | |||
if params is None or params[0] == '': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code doesn't yet check for an empty list (it is not None). perhaps upgrade to if params is None or len(params) == 0 or params[0] == '':
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have anticipated this as I initially was surprised as well. However, this code is correct given the current gen_rpc_req
implementation. Here's why
req = self._gen_rpc_req("validateaddress", params=[])
returns a dict
without the params
keyword, therefor if params is None
actually tests for the empty list. I'm assuming an actual request will be parsed similarly.
In [3]: def test_list(params=None):
...: if params:
...: print("yes params")
...: else:
...: print("no params")
...:
In [4]: test_list([])
no params
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand what you are saying. but this is not 100% correct. if not params
matches an empty list, if params is None
doesn't. you can just replace this if here with if not params or params[0] == '':
for the intended effect.
neo/api/JSONRPC/JsonRpcApi.py
Outdated
@@ -237,8 +253,7 @@ def json_rpc_method_handler(self, method, params): | |||
raise NotImplementedError() | |||
|
|||
elif method == "validateaddress": | |||
raise NotImplementedError() | |||
|
|||
return self.validateaddress(params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one line whitespace before the next elif would be nice
very nice 👍 |
The way neon-js and c# checks valid address is to convert to scripthash and then back. if it comes back the same it is valid |
@localhuman yeah I'm aware there are much better ways to do it, but I just followed the |
@localhuman I'd like to keep the current validation test until we've implemented |
That works for me. Would you mind fixing conflicts :) |
best commit message ever 🤣 |
What current issue(s) does this address?, or what feature is it adding?
add validate address rpc call + tests
address part of #189
How did you solve this problem?
implement call + tests
How did you make sure your solution works?
tests
Did you add any tests?
yes
Are there any special changes in the code that we should be aware of?
no
Did you run
make lint
andmake test
?yes, no
Are you making a PR to a feature branch or development rather than master?
feature