@@ -167,7 +167,7 @@ public async Task<uint256> SendTransactionAsync(string hex)
167167 /// Uses the first wallet and account.
168168 /// </summary>
169169 /// <param name="account">Parameter is deprecated.</param>
170- /// <param name="addressType">Address type, currently only 'legacy' is supported.</param>
170+ /// <param name="addressType">Address type, currently only 'legacy' and 'bech32' is supported.</param>
171171 /// <returns>The new address.</returns>
172172 [ ActionName ( "getnewaddress" ) ]
173173 [ ActionDescription ( "Returns a new wallet address for receiving payments." ) ]
@@ -178,26 +178,28 @@ public NewAddressModel GetNewAddress(string account = "", string addressType = "
178178
179179 if ( ! string . IsNullOrEmpty ( addressType ) )
180180 {
181- // Currently segwit and bech32 addresses are not supported.
182- if ( ! addressType . Equals ( "legacy" , StringComparison . InvariantCultureIgnoreCase ) )
183- throw new RPCServerException ( RPCErrorCode . RPC_METHOD_NOT_FOUND , "Only address type 'legacy' is currently supported." ) ;
181+ // Currently segwit addresses are not supported.
182+ if ( ! addressType . Equals ( "legacy" , StringComparison . InvariantCultureIgnoreCase ) && ! addressType . Equals ( "bech32" , StringComparison . InvariantCultureIgnoreCase ) )
183+ throw new RPCServerException ( RPCErrorCode . RPC_METHOD_NOT_FOUND , "Only address type 'legacy' and 'bech32' are currently supported." ) ;
184184 }
185185
186186 WalletAccountReference accountReference = this . GetWalletAccountReference ( ) ;
187187
188188 HdAddress hdAddress = this . walletManager . GetUnusedAddresses ( accountReference , 1 , alwaysnew : true ) . Single ( ) ;
189189
190- string base58Address = hdAddress . Address ;
190+ string address = hdAddress . Address ; // legacy address
191+ if ( addressType != null && addressType . Equals ( "bech32" , StringComparison . InvariantCultureIgnoreCase ) )
192+ address = hdAddress . Bech32Address ;
191193
192- return new NewAddressModel ( base58Address ) ;
194+ return new NewAddressModel ( address ) ;
193195 }
194196
195197 /// <summary>
196198 /// RPC method that gets the last unused address for receiving payments.
197199 /// Uses the first wallet and account.
198200 /// </summary>
199201 /// <param name="account">Parameter is deprecated.</param>
200- /// <param name="addressType">Address type, currently only 'legacy' is supported.</param>
202+ /// <param name="addressType">Address type, currently only 'legacy' and 'bech32' are supported.</param>
201203 /// <returns>The new address.</returns>
202204 [ ActionName ( "getunusedaddress" ) ]
203205 [ ActionDescription ( "Returns the last unused address for receiving payments." ) ]
@@ -207,15 +209,18 @@ public NewAddressModel GetUnusedAddress(string account, string addressType)
207209 throw new RPCServerException ( RPCErrorCode . RPC_METHOD_DEPRECATED , "Use of 'account' parameter has been deprecated" ) ;
208210
209211 if ( ! string . IsNullOrEmpty ( addressType ) )
210- {
211- // Currently segwit and bech32 addresses are not supported.
212- if ( ! addressType . Equals ( "legacy" , StringComparison . InvariantCultureIgnoreCase ) )
213- throw new RPCServerException ( RPCErrorCode . RPC_METHOD_NOT_FOUND , "Only address type 'legacy' is currently supported." ) ;
212+ {
213+ // Currently segwit addresses are not supported.
214+ if ( ! addressType . Equals ( "legacy" , StringComparison . InvariantCultureIgnoreCase ) && ! addressType . Equals ( "bech32" , StringComparison . InvariantCultureIgnoreCase ) )
215+ throw new RPCServerException ( RPCErrorCode . RPC_METHOD_NOT_FOUND , "Only address type 'legacy' and 'bech32' are currently supported." ) ;
214216 }
215217 HdAddress hdAddress = this . walletManager . GetUnusedAddress ( this . GetWalletAccountReference ( ) ) ;
216- string base58Address = hdAddress . Address ;
217218
218- return new NewAddressModel ( base58Address ) ;
219+ string address = hdAddress . Address ; // legacy address
220+ if ( addressType != null && addressType . Equals ( "bech32" , StringComparison . InvariantCultureIgnoreCase ) )
221+ address = hdAddress . Bech32Address ;
222+
223+ return new NewAddressModel ( address ) ;
219224 }
220225
221226 /// <summary>
0 commit comments