pub fn insert_or_get_snapshot(
			icon_address: &types::IconAddress,
			ice_address: &types::IceAddress,
			defi_user: bool,
			amount: types::BalanceOf<T>,
		) -> Result<types::SnapshotInfo<T>, DispatchError> {
			let ice_account =
				Self::to_account_id(ice_address.to_vec().try_into().unwrap()).unwrap();
			let old_snapshot = Self::get_icon_snapshot_map(&icon_address);
			let old_icon_address = Self::get_ice_to_icon_map(&ice_account);

			if let Some(old_icon_address) = old_icon_address {
				ensure!(
					&old_icon_address == icon_address,
					Error::<T>::IconAddressInUse
				);
			}

			if let Some(old_snapshot) = &old_snapshot {
				let old_ice_address = old_snapshot.ice_address;
				ensure!(
					old_ice_address == ice_address.encode().as_slice(),
					Error::<T>::IceAddressInUse
				);
			}

			let icon_address = old_icon_address.as_ref().unwrap_or_else(|| {
				<IceIconMap<T>>::insert(ice_account, icon_address);
				icon_address
			});

			let snapshot = old_snapshot.unwrap_or_else(|| {
				let mut new_snapshot =
					types::SnapshotInfo::<T>::default().ice_address(ice_address.clone());
				new_snapshot.defi_user = defi_user;
				new_snapshot.amount = amount;

				<IconSnapshotMap<T>>::insert(icon_address, &new_snapshot);

				new_snapshot
			});

			Ok(snapshot)
		}
// Insert this address pair if it is new
Insert this address pair if it is new
Insert this address pair if it is new
pub fn insert_or_get_snapshot(
			icon_address: &types::IconAddress,
			ice_address: &types::IceAddress,
			defi_user: bool,
			amount: types::BalanceOf<T>,
		) -> Result<types::SnapshotInfo<T>, DispatchError> {
			let ice_account =
				Self::to_account_id(ice_address.to_vec().try_into().unwrap()).unwrap();
			let old_snapshot = Self::get_icon_snapshot_map(&icon_address);
			let old_icon_address = Self::get_ice_to_icon_map(&ice_account);
			if let Some(old_icon_address) = old_icon_address {
				ensure!(
					&old_icon_address == icon_address,
					Error::<T>::IconAddressInUse
				);
			}
			if let Some(old_snapshot) = &old_snapshot {
				let old_ice_address = old_snapshot.ice_address;
				ensure!(
					old_ice_address == ice_address.encode().as_slice(),
					Error::<T>::IceAddressInUse
				);
			}
			let icon_address = old_icon_address.as_ref().unwrap_or_else(|| {
				<IceIconMap<T>>::insert(ice_account, icon_address);
				icon_address
			});
			let snapshot = old_snapshot.unwrap_or_else(|| {
				let mut new_snapshot =
					types::SnapshotInfo::<T>::default().ice_address(ice_address.clone());
				new_snapshot.defi_user = defi_user;
				new_snapshot.amount = amount;
				<IconSnapshotMap<T>>::insert(icon_address, &new_snapshot);
				new_snapshot
			});
			Ok(snapshot)
		}
pub fn insert_or_get_snapshot ( icon_address : & types :: IconAddress , ice_address : & types :: IceAddress , defi_user : bool , amount : types :: BalanceOf < T > , ) -> Result < types :: SnapshotInfo < T > , DispatchError > { let ice_account = Self :: to_account_id ( ice_address . to_vec ( ) . try_into ( ) . unwrap ( ) ) . unwrap ( ) ; let old_snapshot = Self :: get_icon_snapshot_map ( & icon_address ) ; let old_icon_address = Self :: get_ice_to_icon_map ( & ice_account ) ; if let Some ( old_icon_address ) = old_icon_address { ensure ! ( old_icon_address icon_address Error T IconAddressInUse ) ; } if let Some ( old_snapshot ) = & old_snapshot { let old_ice_address = old_snapshot . ice_address ; ensure ! ( old_ice_address ice_address encode ( ) as_slice ( ) Error T IceAddressInUse ) ; } let icon_address = old_icon_address . as_ref ( ) . unwrap_or_else ( | | { < IceIconMap < T > > :: insert ( ice_account , icon_address ) ; icon_address } ) ; let snapshot = old_snapshot . unwrap_or_else ( | | { let mut new_snapshot = types :: SnapshotInfo :: < T > :: default ( ) . ice_address ( ice_address . clone ( ) ) ; new_snapshot . defi_user = defi_user ; new_snapshot . amount = amount ; < IconSnapshotMap < T > > :: insert ( icon_address , & new_snapshot ) ; new_snapshot } ) ; Ok ( snapshot ) }
Insert this address pair if it is new
Insert this address pair if it is new
icon_address
&types::IconAddress
ice_address
&types::IceAddress
defi_user
bool
amount
types::BalanceOf<T>