Skip to content

Commit

Permalink
Merge branch '2.0' into missing-account-features
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Nov 20, 2023
2 parents 206f870 + 3ce807a commit 63f8aec
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ pub async fn sync_command(wallet: &Wallet) -> Result<(), Error> {
let balance = wallet
.sync(Some(SyncOptions {
sync_native_token_foundries: true,
sync_implicit_accounts: true,
..Default::default()
}))
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ where
if (address.is_ed25519() && sync_options.wallet.all_outputs())
|| (address.is_nft() && sync_options.nft.all_outputs())
|| (address.is_account() && sync_options.account.all_outputs())
|| (address.is_implicit_account_creation() && sync_options.sync_implicit_accounts)
{
return Ok(self
.client()
Expand Down
16 changes: 12 additions & 4 deletions sdk/src/wallet/operations/syncing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,15 @@ where
key_index: 0,
};

let address_to_sync = vec![wallet_address_with_unspent_outputs];
let address_to_sync = vec![
wallet_address_with_unspent_outputs,
AddressWithUnspentOutputs {
address: self.implicit_account_creation_address().await?,
output_ids: vec![],
internal: false,
key_index: 0,
},
];

let (addresses_with_unspent_outputs, spent_or_not_synced_output_ids, outputs_data): (
Vec<AddressWithUnspentOutputs>,
Expand All @@ -124,11 +132,11 @@ where

// Add the output response to the output ids, the output response is optional, because an output could be
// pruned and then we can't get the metadata
let mut spent_or_unsynced_output_metadata_map: HashMap<OutputId, Option<OutputMetadata>> =
let mut spent_or_unsynced_output_metadata: HashMap<OutputId, Option<OutputMetadata>> =
spent_or_not_synced_output_ids.into_iter().map(|o| (o, None)).collect();
for output_metadata_response in spent_or_unsynced_output_metadata_responses {
let output_id = output_metadata_response.output_id();
spent_or_unsynced_output_metadata_map.insert(*output_id, Some(output_metadata_response));
spent_or_unsynced_output_metadata.insert(*output_id, Some(output_metadata_response));
}

if options.sync_incoming_transactions {
Expand Down Expand Up @@ -156,7 +164,7 @@ where
}

// Updates wallet with balances, output ids, outputs
self.update_after_sync(outputs_data, spent_or_unsynced_output_metadata_map)
self.update_after_sync(outputs_data, spent_or_unsynced_output_metadata)
.await
}

Expand Down
9 changes: 9 additions & 0 deletions sdk/src/wallet/operations/syncing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const DEFAULT_SYNC_INCOMING_TRANSACTIONS: bool = false;
const DEFAULT_SYNC_ONLY_MOST_BASIC_OUTPUTS: bool = false;
const DEFAULT_SYNC_PENDING_TRANSACTIONS: bool = true;
const DEFAULT_SYNC_NATIVE_TOKEN_FOUNDRIES: bool = false;
const DEFAULT_SYNC_IMPLICIT_ACCOUNTS: bool = false;

/// The synchronization options
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
Expand Down Expand Up @@ -41,6 +42,9 @@ pub struct SyncOptions {
/// Sync native token foundries, so their metadata can be returned in the balance.
#[serde(default = "default_sync_native_token_foundries")]
pub sync_native_token_foundries: bool,
/// Sync implicit accounts.
#[serde(default = "default_sync_implicit_accounts")]
pub sync_implicit_accounts: bool,
}

fn default_force_syncing() -> bool {
Expand All @@ -63,6 +67,10 @@ fn default_sync_native_token_foundries() -> bool {
DEFAULT_SYNC_NATIVE_TOKEN_FOUNDRIES
}

fn default_sync_implicit_accounts() -> bool {
DEFAULT_SYNC_IMPLICIT_ACCOUNTS
}

impl Default for SyncOptions {
fn default() -> Self {
Self {
Expand All @@ -74,6 +82,7 @@ impl Default for SyncOptions {
sync_only_most_basic_outputs: default_sync_only_most_basic_outputs(),
sync_native_token_foundries: default_sync_native_token_foundries(),
force_syncing: default_force_syncing(),
sync_implicit_accounts: default_sync_implicit_accounts(),
}
}
}
Expand Down

0 comments on commit 63f8aec

Please sign in to comment.