-
Notifications
You must be signed in to change notification settings - Fork 89
Support bech32 addresses in rpc methods #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,7 +167,7 @@ public async Task<uint256> SendTransactionAsync(string hex) | |
| /// Uses the first wallet and account. | ||
| /// </summary> | ||
| /// <param name="account">Parameter is deprecated.</param> | ||
| /// <param name="addressType">Address type, currently only 'legacy' is supported.</param> | ||
| /// <param name="addressType">Address type, currently only 'legacy' and 'bech32' is supported.</param> | ||
| /// <returns>The new address.</returns> | ||
| [ActionName("getnewaddress")] | ||
| [ActionDescription("Returns a new wallet address for receiving payments.")] | ||
|
|
@@ -178,26 +178,28 @@ public NewAddressModel GetNewAddress(string account = "", string addressType = " | |
|
|
||
| if (!string.IsNullOrEmpty(addressType)) | ||
| { | ||
| // Currently segwit and bech32 addresses are not supported. | ||
| if (!addressType.Equals("legacy", StringComparison.InvariantCultureIgnoreCase)) | ||
| throw new RPCServerException(RPCErrorCode.RPC_METHOD_NOT_FOUND, "Only address type 'legacy' is currently supported."); | ||
| // Currently segwit addresses are not supported. | ||
| if (!addressType.Equals("legacy", StringComparison.InvariantCultureIgnoreCase) && !addressType.Equals("bech32", StringComparison.InvariantCultureIgnoreCase)) | ||
| throw new RPCServerException(RPCErrorCode.RPC_METHOD_NOT_FOUND, "Only address type 'legacy' and 'bech32' are currently supported."); | ||
| } | ||
|
|
||
| WalletAccountReference accountReference = this.GetWalletAccountReference(); | ||
|
|
||
| HdAddress hdAddress = this.walletManager.GetUnusedAddresses(accountReference, 1, alwaysnew: true).Single(); | ||
|
|
||
| string base58Address = hdAddress.Address; | ||
| string address = hdAddress.Address; // legacy address | ||
| if (addressType != null && addressType.Equals("bech32", StringComparison.InvariantCultureIgnoreCase)) | ||
| address = hdAddress.Bech32Address; | ||
|
|
||
| return new NewAddressModel(base58Address); | ||
| return new NewAddressModel(address); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// RPC method that gets the last unused address for receiving payments. | ||
| /// Uses the first wallet and account. | ||
| /// </summary> | ||
| /// <param name="account">Parameter is deprecated.</param> | ||
| /// <param name="addressType">Address type, currently only 'legacy' is supported.</param> | ||
| /// <param name="addressType">Address type, currently only 'legacy' and 'bech32' are supported.</param> | ||
| /// <returns>The new address.</returns> | ||
| [ActionName("getunusedaddress")] | ||
| [ActionDescription("Returns the last unused address for receiving payments.")] | ||
|
|
@@ -207,15 +209,18 @@ public NewAddressModel GetUnusedAddress(string account, string addressType) | |
| throw new RPCServerException(RPCErrorCode.RPC_METHOD_DEPRECATED, "Use of 'account' parameter has been deprecated"); | ||
|
|
||
| if (!string.IsNullOrEmpty(addressType)) | ||
| { | ||
| // Currently segwit and bech32 addresses are not supported. | ||
| if (!addressType.Equals("legacy", StringComparison.InvariantCultureIgnoreCase)) | ||
| throw new RPCServerException(RPCErrorCode.RPC_METHOD_NOT_FOUND, "Only address type 'legacy' is currently supported."); | ||
| { | ||
| // Currently segwit addresses are not supported. | ||
| if (!addressType.Equals("legacy", StringComparison.InvariantCultureIgnoreCase) && !addressType.Equals("bech32", StringComparison.InvariantCultureIgnoreCase)) | ||
| throw new RPCServerException(RPCErrorCode.RPC_METHOD_NOT_FOUND, "Only address type 'legacy' and 'bech32' are currently supported."); | ||
| } | ||
| HdAddress hdAddress = this.walletManager.GetUnusedAddress(this.GetWalletAccountReference()); | ||
| string base58Address = hdAddress.Address; | ||
|
|
||
| return new NewAddressModel(base58Address); | ||
| string address = hdAddress.Address; // legacy address | ||
| if (addressType != null && addressType.Equals("bech32", StringComparison.InvariantCultureIgnoreCase)) | ||
| address = hdAddress.Bech32Address; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be simplified to avoid performing two get operations every time the user request bech32 address. The assignment should depend on the conditional check. |
||
|
|
||
| return new NewAddressModel(address); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Doesn't Bech32 imply segwit?
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.
Maybe should clarify as p2sh-segwit addresses are not supported. Not sure we need to worry about them as bech32 seems to have been well adopted