zcash / zcash

Zcash - Internet Money
https://z.cash/
Other
4.92k stars 2.03k forks source link

Alternative for getnewaddress #6444

Open gades opened 1 year ago

gades commented 1 year ago

This functions is going to be depricated in the future but we need something like this one for generation p2pkh address. This feature request is related to this one https://github.com/zcash/zcash/issues/6421

Can zcash team provide any alternative way with one RPC call to generate new p2pkh address ?

Also, where we can read the reason of removing getnewaddress from core ?

nuttycom commented 1 year ago

The getnewaddress method has been deprecated because its semantics are incompatible with HD derivation.

In the Bitcoin wallet at the time of the zcash fork, all addresses were treated as feeding into a single, undifferentiated bucket of funds, and consequently there was no concept of the balance associated with a given address. However, HD derivation from a mnemonic phrase according to BIP 44 requires the use of an "account" identifier, where each distinct account identifier represents a unique bucket of funds. getnewaddress doesn't provide a way to provide this identifier, and consequently it doesn't fit nicely into the HD derivation scheme; in particular, we're forced to use a workaround (picking the highest possible account identifier) that is nonstandard and likely to be skipped by wallets that attempt to restore from a mnemonic seed without being aware of zcashd's particular semantics here.

For this reason, we have deprecated getnewaddress in favor of two new methods: z_getnewaccount and z_getaddressforaccount. z_getnewaccount can be used to generate a new account (which will be treated as a single bucket of of ZEC), and then z_getaddressforaccount can be used repeatedly to generate distinct Unified addresses for that account. If you wish to extract just the P2PKH component of this address, you can do so using the z_listunifiedreceivers method; however, it is recommended that you just use Unified addresses when possible.

Note that each distinct unified account in the wallet introduces an additional scanning cost, so it is not recommended to use large numbers of distinct accounts; instead, prefer to use distinct diversified addresses within a single account. While the account is treated as a single bucket of funds (and each address therefore is not treated as having a distinct balance) it is still possible to identify which address is associated with each output of each received transaction. This is similar to the original getnewaddress functionality.

nuttycom commented 1 year ago

One other note here; the z_listunifiedreceivers API method does not depend upon wallet state, and can be implemented locally as specified in ZIP 316.

anurag-iitk commented 1 year ago

You can use z_getnewaccount this generate a new account, and then z_getaddressforaccount this can generate a unique address for the generated account.

gades commented 1 year ago

Any option to create new simple RPC like z_getp2pkh account_id where will be

zcash-cli z_getaddressforaccount account_id result p2pkh from zcash-cli z_listunifiedreceivers addressfrom z_getaddressforaccount