Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Add ValidateAddress RPCClient to NBitcoin#1072

Merged
fassadlr merged 16 commits intostratisproject:masterfrom
DanGould:feature/rpc-verifyaddress
Feb 5, 2018
Merged

Add ValidateAddress RPCClient to NBitcoin#1072
fassadlr merged 16 commits intostratisproject:masterfrom
DanGould:feature/rpc-verifyaddress

Conversation

@DanGould
Copy link
Copy Markdown
Contributor

@DanGould DanGould commented Jan 17, 2018

  • tested for bitcoind Mainnet
  • Return type for ValidateAddress
  • Sister pull to BreezeProject#25

It seems like RPCClientTests.cs has changed (EstimateFeeRate is gone) What's the best process to incorporate this into that lib?

{
using (var builder = NodeBuilder.Create())
{
var node = builder.CreateNode();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

108,111,113 - unvar please.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanGould Just fix these and we are good to go 👍

@dangershony
Copy link
Copy Markdown
Contributor

Apart for @noescape00 comments looks good to me

Copy link
Copy Markdown
Collaborator

@fassadlr fassadlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets look at incorporating JsonResult now 💯


namespace NBitcoin
{
public class ValidatedAddress
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ;)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

[ActionName("validateaddress")]
[ActionDescription("Returns information about a bech32 or base58 bitcoin address")]
public JObject ValidateAddress(string address)
public ValidatedAddress ValidateAddress(string address)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can really just return a boolean here ;)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@mikedennis
Copy link
Copy Markdown
Contributor

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

@bokobza
Copy link
Copy Markdown
Contributor

bokobza commented Jan 31, 2018

@DanGould Are you able to work on this PR? If not, please let us know. Thank you 😃

@DanGould
Copy link
Copy Markdown
Contributor Author

@bokobza I will have time Thursday & Friday. Classes just started and I've just about found the groove.

@fassadlr
Copy link
Copy Markdown
Collaborator

fassadlr commented Feb 1, 2018

@DanGould please check the comments from @noescape00 and once that is fixed we can merge this change 👍

{
using (var builder = NodeBuilder.Create())
{
var node = builder.CreateNode();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanGould Just fix these and we are good to go 👍

@bokobza
Copy link
Copy Markdown
Contributor

bokobza commented Feb 2, 2018

@fassadlr I'd like to see the JsonProperty in ValidatedAddress.cs as well, please. Before you merge this.

@fassadlr
Copy link
Copy Markdown
Collaborator

fassadlr commented Feb 2, 2018

@bokobza will do 💯

@DanGould DanGould force-pushed the feature/rpc-verifyaddress branch 2 times, most recently from 0836455 to e0cfe2d Compare February 2, 2018 22:52
@DanGould DanGould force-pushed the feature/rpc-verifyaddress branch from e0cfe2d to a0f4bdb Compare February 2, 2018 23:13
Copy link
Copy Markdown
Collaborator

@fassadlr fassadlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of small changes

var res = new JObject();
res["isvalid"] = false;
var res = new ValidatedAddress();
res.IsValid = false;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to:

/// <returns><see cref="ValidatedAddress"/> containing a boolean indicating address validity.</returns>

@bokobza
Copy link
Copy Markdown
Contributor

bokobza commented Feb 5, 2018

@fassadlr do you mind if we push this as it is? @DanGould doesn't have much time between his classes.
Worst case we can do a quick follow-up PR.

@fassadlr
Copy link
Copy Markdown
Collaborator

fassadlr commented Feb 5, 2018

@bokobza OK sweet 👍

@fassadlr fassadlr merged commit 5740871 into stratisproject:master Feb 5, 2018
kogot pushed a commit to kogot/StratisBitcoinFullNode that referenced this pull request May 10, 2018
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants