Hi guys!
I have a system app.
I want to receive zcash from users and move them to the zcash master address.
So, I have a master zcash address and this is the main flow:
If the user request a deposit, the system will gen a new temp address (use z_getnewaddress function and sapling format).
Then the user send some zcash to the temp address.
Then the system (cron job) will check the balance of the temp address (use z_getbalance function).
The system moves all balances of the temp address to the master address.
Bla bla…
Transfer: send to the user: use the method: sendtoaddress or z_sendmany?
So everything is ok for me?
And how do I move all balances from temp address to master address? Is there a way to move them quickly? (do not use the transfer function) .
Thank you so much!
This is going to quickly cause a big slowdown in your node, because z_getnewaddress gets a new spending key, and the speed of node scanning is linear in the number of spending keys.
For your given workflow, I would instead recommend generating diversified addresses. This allows you to generate multiple payment addresses backed by the same spending key. You would generate a diversified address for each user (could be one per user, or a fresh one every time), and then when a user sends you funds, you can detect which address the funds came from (to determine which user sent the funds).
With diversified addresses, there is no need to move funds to the master address, because the funds are already there
zcashd doesn’t support generating diversified addresses, but it does support receiving funds from them. So what I’d recommend is that you export your Sapling full viewing key from zcashd, and use the Rust libraries to generate diversified addresses from it to give to users.
I have 3 cmd, but can’t gen a diversified address from the viewing key.
the error: Invalid mainnet Sapling viewing key
But I want to gen a testnet diversified address
Can you check for me? Many many thanks!
woa, it works for me. Thank you I love you.
ah how to build this to an execute file.
ex: cargo run --example diversify-address --<viewing_key> <index>
to: ./gen_diversify_address --<viewing_key> <index>
Yes, this is expected: not every diversifier index results in a valid Sapling address (on average half of the 288 diversifiers will be invalid).
The example tool starts searching for the next Sapling address starting from the index you provide, and it returns the closest index for which it could find a valid address. You will need to account for this in your code.