/// If there is a proposal for a new conversion rate, the function makes
/// sure that the timestamp of the proposed conversion rate record is
/// larger than the current timestamp in the current record.
If there is a proposal for a new conversion rate, the function makes
sure that the timestamp of the proposed conversion rate record is
larger than the current timestamp in the current record.
If there is a proposal for a new conversion rate the function makes sure that the timestamp of the proposed conversion rate record is larger than the current timestamp in the current record .
fn check_conversion_rate_invariants(&self, snapshot: &RegistrySnapshot) {
        // Check if there is a conversion rate in the mutated snapshot:
        if let Some(proposed_conversion_rate_bytes) =
            snapshot.get(&make_icp_xdr_conversion_rate_record_key().into_bytes())
        {
            // Decode the proposed conversion rate:
            let proposed_conversion_rate = decode_registry_value::<IcpXdrConversionRateRecord>(
                proposed_conversion_rate_bytes.clone(),
            );
            // Assert that the rate is positive (this is an additional sanity check as the
            // rate should always be at least `minimum_icp_xdr_rate`):
            assert!(proposed_conversion_rate.xdr_permyriad_per_icp > 0);
            // Check if there is a conversion rate in the registry (without mutations):
            if let Some(conversion_rate_bytes) = self.get(
                &make_icp_xdr_conversion_rate_record_key().into_bytes(),
                self.latest_version(),
            ) {
                // Decode the current conversion rate:
                let conversion_rate = decode_registry_value::<IcpXdrConversionRateRecord>(
                    conversion_rate_bytes.clone().value,
                );
                // Assert that the records are equal, i.e., there is no mutation, or the
                // timestamp is larger in the proposed conversion rate:
                assert!(
                    proposed_conversion_rate == conversion_rate
                        || proposed_conversion_rate.timestamp_seconds
                            > conversion_rate.timestamp_seconds
                );
            }
        }
    }
fn check_conversion_rate_invariants ( & self , snapshot : & RegistrySnapshot ) { // Check if there is a conversion rate in the mutated snapshot: if let Some ( proposed_conversion_rate_bytes ) = snapshot . get ( & make_icp_xdr_conversion_rate_record_key ( ) . into_bytes ( ) ) { // Decode the proposed conversion rate: let proposed_conversion_rate = decode_registry_value :: < IcpXdrConversionRateRecord > ( proposed_conversion_rate_bytes . clone ( ) , ) ; // Assert that the rate is positive (this is an additional sanity check as the // rate should always be at least `minimum_icp_xdr_rate`): assert ! ( proposed_conversion_rate xdr_permyriad_per_icp 0 ) ; // Check if there is a conversion rate in the registry (without mutations): if let Some ( conversion_rate_bytes ) = self . get ( & make_icp_xdr_conversion_rate_record_key ( ) . into_bytes ( ) , self . latest_version ( ) , ) { // Decode the current conversion rate: let conversion_rate = decode_registry_value :: < IcpXdrConversionRateRecord > ( conversion_rate_bytes . clone ( ) . value , ) ; // Assert that the records are equal, i.e., there is no mutation, or the // timestamp is larger in the proposed conversion rate: assert ! ( proposed_conversion_rate conversion_rate proposed_conversion_rate timestamp_seconds conversion_rate timestamp_seconds ) ; } } }
If there is a proposal for a new conversion rate, the function makes
sure that the timestamp of the proposed conversion rate record is
larger than the current timestamp in the current record.
If there is a proposal for a new conversion rate the function makes sure that the timestamp of the proposed conversion rate record is larger than the current timestamp in the current record .
&self
snapshot
&RegistrySnapshot