Add ValidateAddress RPCClient to NBitcoin#1072
Add ValidateAddress RPCClient to NBitcoin#1072fassadlr merged 16 commits intostratisproject:masterfrom
Conversation
only returns {isvalid} for P2PKH & P2SH Addresses
…ld/StratisBitcoinFullNode into feature/rpc-verifyaddress
src/NBitcoin.Tests/RPCClientTests.cs
Outdated
| { | ||
| using (var builder = NodeBuilder.Create()) | ||
| { | ||
| var node = builder.CreateNode(); |
There was a problem hiding this comment.
108,111,113 - unvar please.
There was a problem hiding this comment.
@DanGould Just fix these and we are good to go 👍
|
Apart for @noescape00 comments looks good to me |
fassadlr
left a comment
There was a problem hiding this comment.
Lets look at incorporating JsonResult now 💯
|
|
||
| namespace NBitcoin | ||
| { | ||
| public class ValidatedAddress |
There was a problem hiding this comment.
I'm not sure whether we should be adding to NBitcoin like this @DanGould . We are in the process of porting over the library to the full node ;)
There was a problem hiding this comment.
I think this is OK, just add [JsonProperty(PropertyName = "isvalid")] on top of the property in order to define the exact format of this json field.
| [ActionName("validateaddress")] | ||
| [ActionDescription("Returns information about a bech32 or base58 bitcoin address")] | ||
| public JObject ValidateAddress(string address) | ||
| public ValidatedAddress ValidateAddress(string address) |
There was a problem hiding this comment.
@DanGould this is already much better. But lets just return JsonResult here. Then, in the method return the boolean like so:
var isAddressValid = false;
return JsonResult(isAddressValid);
There was a problem hiding this comment.
There is more to it than just a boolean.
Look here:
https://bitcoin.org/en/developer-reference#validateaddress.
For now that's enough, but I think we can easily add more to it.
There was a problem hiding this comment.
@bokobza my apologies, I wasn't aware of the bitcoin developer reference! In that case yes returning ValidateAddress is good 👍
| /// </summary> | ||
| /// <param name="address">a Bitcoin Address</param> | ||
| /// <returns>{ IsValid }</returns> | ||
| public ValidatedAddress ValidateAddress(BitcoinAddress address) |
There was a problem hiding this comment.
You can really just return a boolean here ;)
There was a problem hiding this comment.
Not really. See my other comment.
| public ValidatedAddress ValidateAddress(BitcoinAddress address) | ||
| { | ||
| RPCResponse res = SendCommand(RPCOperations.validateaddress, address.ToString()); | ||
| return JsonConvert.DeserializeObject<ValidatedAddress>(res.Result.ToString()); |
There was a problem hiding this comment.
And then you don't have to deserialize the result to a class like this. res.Result should be a boolean... So just cast it?
|
There have been fairly recent changes to NBitcoin with RPC fee rate tests. There now seem to be some estimatesmartfee tests. I don't believe I migrated those across as I think they target a newer version of bitcoin RPC. See MetacoSA/NBitcoin@0d683ce#diff-280b17ef00043f2fb2b29ad882a40452 |
|
@DanGould Are you able to work on this PR? If not, please let us know. Thank you 😃 |
|
@bokobza I will have time Thursday & Friday. Classes just started and I've just about found the groove. |
|
@DanGould please check the comments from @noescape00 and once that is fixed we can merge this change 👍 |
src/NBitcoin.Tests/RPCClientTests.cs
Outdated
| { | ||
| using (var builder = NodeBuilder.Create()) | ||
| { | ||
| var node = builder.CreateNode(); |
There was a problem hiding this comment.
@DanGould Just fix these and we are good to go 👍
|
@fassadlr I'd like to see the JsonProperty in ValidatedAddress.cs as well, please. Before you merge this. |
|
@bokobza will do 💯 |
0836455 to
e0cfe2d
Compare
e0cfe2d to
a0f4bdb
Compare
fassadlr
left a comment
There was a problem hiding this comment.
A couple of small changes
| var res = new JObject(); | ||
| res["isvalid"] = false; | ||
| var res = new ValidatedAddress(); | ||
| res.IsValid = false; |
There was a problem hiding this comment.
This is implied if the bool is not specifically set to false ;) so you can remove this line 👍
| /// </summary> | ||
| /// <param name="address">bech32 or base58 BitcoinAddress to validate.</param> | ||
| /// <returns>JObject containing a boolean indicating address validity</returns> | ||
| /// <returns>ValidatedAddress containing a boolean indicating address validity</returns> |
There was a problem hiding this comment.
Change this to:
/// <returns><see cref="ValidatedAddress"/> containing a boolean indicating address validity.</returns>
|
@bokobza OK sweet 👍 |
* simple implement validateaddresses
only returns {isvalid} for P2PKH & P2SH Addresses
* support verify bech32 addresses
* delete innacurate comment
* fix invalid method doc markup
* fassadlr's clean code recommendations
* validateaddress only for passed expectedNetwork
* remove redundant FormatExceptions
* network to expectedNetwork so builds
* make ValidatedAddress return type
* add VerifyAddress to NBitcoin RPCClient
* unvar ValidateAddress RPCTest
* define ValidatedAddress JsonProperty isvalid
It seems like RPCClientTests.cs has changed (EstimateFeeRate is gone) What's the best process to incorporate this into that lib?