From a647798333f18959ef0ec2dde20cc37ec62519a2 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Fri, 1 Mar 2024 17:34:04 +0100 Subject: [PATCH] sync options --- sdk/src/wallet/operations/syncing/options.rs | 106 +++++++++---------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/sdk/src/wallet/operations/syncing/options.rs b/sdk/src/wallet/operations/syncing/options.rs index 029557f412..1da0a204ce 100644 --- a/sdk/src/wallet/operations/syncing/options.rs +++ b/sdk/src/wallet/operations/syncing/options.rs @@ -3,13 +3,6 @@ use serde::{Deserialize, Serialize}; -const DEFAULT_FORCE_SYNCING: bool = false; -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)] #[serde(rename_all = "camelCase")] @@ -17,14 +10,14 @@ pub struct SyncOptions { /// Usually syncing is skipped if it's called in between 200ms, because there can only be new changes every /// milestone and calling it twice "at the same time" will not return new data /// When this to true, we will sync anyways, even if it's called 0ms after the las sync finished. - #[serde(default)] + #[serde(default = "yes")] pub force_syncing: bool, /// Try to sync transactions from incoming outputs with their inputs. Some data may not be obtained if it has been /// pruned. - #[serde(default = "default_sync_incoming_transactions")] + #[serde(default = "no")] pub sync_incoming_transactions: bool, /// Checks pending transactions and reissues them if necessary. - #[serde(default = "default_sync_pending_transactions")] + #[serde(default = "yes")] pub sync_pending_transactions: bool, /// Specifies what outputs should be synced for the ed25519 address from the wallet. #[serde(default)] @@ -37,52 +30,28 @@ pub struct SyncOptions { pub nft: NftSyncOptions, /// Specifies if only basic outputs with an AddressUnlockCondition alone should be synced, will overwrite /// `wallet`, `account` and `nft` options. - #[serde(default = "default_sync_only_most_basic_outputs")] + #[serde(default = "no")] pub sync_only_most_basic_outputs: bool, /// Sync native token foundries, so their metadata can be returned in the balance. - #[serde(default = "default_sync_native_token_foundries")] + #[serde(default = "no")] pub sync_native_token_foundries: bool, /// Sync implicit accounts. - #[serde(default = "default_sync_implicit_accounts")] + #[serde(default = "no")] pub sync_implicit_accounts: bool, } -const fn default_force_syncing() -> bool { - DEFAULT_FORCE_SYNCING -} - -const fn default_sync_incoming_transactions() -> bool { - DEFAULT_SYNC_INCOMING_TRANSACTIONS -} - -const fn default_sync_only_most_basic_outputs() -> bool { - DEFAULT_SYNC_ONLY_MOST_BASIC_OUTPUTS -} - -const fn default_sync_pending_transactions() -> bool { - DEFAULT_SYNC_PENDING_TRANSACTIONS -} - -const fn default_sync_native_token_foundries() -> bool { - DEFAULT_SYNC_NATIVE_TOKEN_FOUNDRIES -} - -const fn default_sync_implicit_accounts() -> bool { - DEFAULT_SYNC_IMPLICIT_ACCOUNTS -} - impl Default for SyncOptions { fn default() -> Self { Self { - sync_incoming_transactions: default_sync_incoming_transactions(), - sync_pending_transactions: default_sync_pending_transactions(), + force_syncing: yes(), + sync_incoming_transactions: no(), + sync_pending_transactions: yes(), wallet: WalletSyncOptions::default(), account: AccountSyncOptions::default(), nft: NftSyncOptions::default(), - 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(), + sync_only_most_basic_outputs: no(), + sync_native_token_foundries: no(), + sync_implicit_accounts: no(), } } } @@ -91,19 +60,23 @@ impl Default for SyncOptions { #[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] #[serde(default, rename_all = "camelCase")] pub struct WalletSyncOptions { + #[serde(default = "yes")] pub basic_outputs: bool, + #[serde(default = "yes")] pub account_outputs: bool, + #[serde(default = "yes")] pub nft_outputs: bool, + #[serde(default = "yes")] pub delegation_outputs: bool, } impl Default for WalletSyncOptions { fn default() -> Self { Self { - basic_outputs: true, - account_outputs: true, - nft_outputs: true, - delegation_outputs: true, + basic_outputs: yes(), + account_outputs: yes(), + nft_outputs: yes(), + delegation_outputs: yes(), } } } @@ -118,10 +91,15 @@ impl WalletSyncOptions { #[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] #[serde(default, rename_all = "camelCase")] pub struct AccountSyncOptions { + #[serde(default = "no")] pub basic_outputs: bool, + #[serde(default = "no")] pub account_outputs: bool, + #[serde(default = "yes")] pub foundry_outputs: bool, + #[serde(default = "no")] pub nft_outputs: bool, + #[serde(default = "no")] pub delegation_outputs: bool, } @@ -129,11 +107,11 @@ impl Default for AccountSyncOptions { // Sync only foundries fn default() -> Self { Self { - basic_outputs: false, - account_outputs: false, - foundry_outputs: true, - nft_outputs: false, - delegation_outputs: false, + basic_outputs: no(), + account_outputs: no(), + foundry_outputs: yes(), + nft_outputs: no(), + delegation_outputs: no(), } } } @@ -149,17 +127,39 @@ impl AccountSyncOptions { } /// Sync options for addresses from NFT outputs -#[derive(Debug, Default, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] #[serde(default, rename_all = "camelCase")] pub struct NftSyncOptions { + #[serde(default = "no")] pub basic_outputs: bool, + #[serde(default = "no")] pub account_outputs: bool, + #[serde(default = "no")] pub nft_outputs: bool, + #[serde(default = "no")] pub delegation_outputs: bool, } +impl Default for NftSyncOptions { + fn default() -> Self { + Self { + basic_outputs: no(), + account_outputs: no(), + nft_outputs: no(), + delegation_outputs: no(), + } + } +} impl NftSyncOptions { pub(crate) fn all_outputs(&self) -> bool { self.basic_outputs && self.account_outputs && self.nft_outputs && self.delegation_outputs } } + +const fn yes() -> bool { + true +} + +const fn no() -> bool { + false +}