Apply suggestions from code review

Co-authored-by: str4d <thestr4d@gmail.com>
This commit is contained in:
Kris Nuttycombe 2022-09-14 12:20:39 -06:00 committed by GitHub
parent d0062a87d4
commit 75eb082203
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 7 deletions

View File

@ -270,12 +270,24 @@ pub struct SentTransactionOutput<'a> {
/// This trait encapsulates the write capabilities required to update stored
/// wallet data.
pub trait WalletWrite: WalletRead {
/// Creates a new account-level spending authority by derivation from the provided
/// seed using the next available unused account identifier, and returns this identifier
/// along with the generated unified spending key.
/// Tells the wallet to track the next available account-level spend authority, given
/// the current set of [ZIP 316] account identifiers known to the wallet database.
///
/// Returns the account identifier for the newly-created wallet database entry, along
/// with the associated [`UnifiedSpendingKey`].
///
/// If `seed` was imported from a backup and this method is being used to restore a
/// previous wallet state, you should use this method to add all of the desired
/// accounts before scanning the chain from the seed's birthday height.
///
/// By convention, wallets should only allow a new account to be generated after funds
/// have been received by the currently-available account (in order to enable
/// automated account recovery).
///
/// [ZIP 316]: https://zips.z.cash/zip-0316
fn create_account(
&mut self,
seed: SecretVec<u8>,
seed: &SecretVec<u8>,
) -> Result<(AccountId, UnifiedSpendingKey), Self::Error>;
/// Generates and persists the next available diversified address, given the current
@ -535,7 +547,7 @@ pub mod testing {
impl WalletWrite for MockWalletDb {
fn create_account(
&mut self,
seed: SecretVec<u8>,
seed: &SecretVec<u8>,
) -> Result<(AccountId, UnifiedSpendingKey), Self::Error> {
let account = AccountId::from(0);
UnifiedSpendingKey::from_seed(&self.network, seed.expose_secret(), account)

View File

@ -405,7 +405,7 @@ impl<'a, P: consensus::Parameters> DataConnStmtCache<'a, P> {
impl<'a, P: consensus::Parameters> WalletWrite for DataConnStmtCache<'a, P> {
fn create_account(
&mut self,
seed: SecretVec<u8>,
seed: &SecretVec<u8>,
) -> Result<(AccountId, UnifiedSpendingKey), Self::Error> {
self.transactionally(|stmts| {
let account = wallet::get_max_account_id(stmts.wallet_db)?

View File

@ -523,7 +523,9 @@ fn init_wallet_db_internal<P: consensus::Parameters + 'static>(
/// Initialises the data database with the given set of account [`UnifiedFullViewingKey`]s.
///
/// **WARNING** This method should be used with care, and should ordinarily be unnecessary.
/// Prefer to use [`zcash_client_backend::data_api::WalletWrite::create_account`] instead.
/// Prefer to use [`WalletWrite::create_account`] instead.
///
/// [`WalletWrite::create_account`]: zcash_client_backend::data_api::WalletWrite::create_account
///
/// The [`UnifiedFullViewingKey`]s are stored internally and used by other APIs such as
/// [`get_address`], [`scan_cached_blocks`], and [`create_spend_to_address`]. Account identifiers