pub fn create_policy_op(
        &mut self,
        policy: P,
        source: PublicKey,
    ) -> Result<CrdtPolicyOperation<A, P>> {
        //TODO: this should not be applied locally yet, until sig applied + verified
        let (new_lseq, prev_policy_id) = match self.policy.last_entry() {
            None => {
                // Create an empty LSeq since there are no items yet for this Policy
                let actor = self.policy.actor();
                (
                    LSeq::new_with_args(actor, LSEQ_TREE_BASE, LSEQ_BOUNDARY),
                    None,
                )
            }
            Some(cur_policy) => match self.data.get(&cur_policy.id) {
                Some(lseq) => (lseq.clone(), Some(cur_policy.id.clone())),
                None => {
                    // Create an empty LSeq since there are no items yet for this Policy
                    let actor = self.policy.actor();
                    (
                        LSeq::new_with_args(actor, LSEQ_TREE_BASE, LSEQ_BOUNDARY),
                        Some(cur_policy.id.clone()),
                    )
                }
            },
        };

        // Last item in current Sequence to be used as causal info for new Policy
        let cur_last_item = new_lseq.last_entry().map(|entry| entry.id.clone());

        // Append the new Policy to the history
        let crdt_op = self.policy.append((policy, cur_last_item.clone()));

        let policy_id = crdt_op.id().clone();
        let _ = self.data.insert(policy_id, new_lseq);

        // Causality info for this Policy op includes current Policy and item Identifiers
        let ctx = prev_policy_id.map(|policy_id| (policy_id, cur_last_item));

        // We return the operation as it may need to be broadcasted to other replicas
        Ok(CrdtPolicyOperation {
            address: *self.address(),
            crdt_op,
            source,
            ctx,
            signature: None,
        })
    }
/// Create a new crdt policy op
Create a new crdt policy op
Create a new crdt policy op
pub fn create_policy_op(
        &mut self,
        policy: P,
        source: PublicKey,
    ) -> Result<CrdtPolicyOperation<A, P>> {
        //TODO: this should not be applied locally yet, until sig applied + verified
        let (new_lseq, prev_policy_id) = match self.policy.last_entry() {
            None => {
                // Create an empty LSeq since there are no items yet for this Policy
                let actor = self.policy.actor();
                (
                    LSeq::new_with_args(actor, LSEQ_TREE_BASE, LSEQ_BOUNDARY),
                    None,
                )
            }
            Some(cur_policy) => match self.data.get(&cur_policy.id) {
                Some(lseq) => (lseq.clone(), Some(cur_policy.id.clone())),
                None => {
                    // Create an empty LSeq since there are no items yet for this Policy
                    let actor = self.policy.actor();
                    (
                        LSeq::new_with_args(actor, LSEQ_TREE_BASE, LSEQ_BOUNDARY),
                        Some(cur_policy.id.clone()),
                    )
                }
            },
        };
        // Last item in current Sequence to be used as causal info for new Policy
        let cur_last_item = new_lseq.last_entry().map(|entry| entry.id.clone());
        // Append the new Policy to the history
        let crdt_op = self.policy.append((policy, cur_last_item.clone()));
        let policy_id = crdt_op.id().clone();
        let _ = self.data.insert(policy_id, new_lseq);
        // Causality info for this Policy op includes current Policy and item Identifiers
        let ctx = prev_policy_id.map(|policy_id| (policy_id, cur_last_item));
        // We return the operation as it may need to be broadcasted to other replicas
        Ok(CrdtPolicyOperation {
            address: *self.address(),
            crdt_op,
            source,
            ctx,
            signature: None,
        })
    }
pub fn create_policy_op ( & mut self , policy : P , source : PublicKey , ) -> Result < CrdtPolicyOperation < A , P > > { //TODO: this should not be applied locally yet, until sig applied + verified let ( new_lseq , prev_policy_id ) = match self . policy . last_entry ( ) { None => { // Create an empty LSeq since there are no items yet for this Policy let actor = self . policy . actor ( ) ; ( LSeq :: new_with_args ( actor , LSEQ_TREE_BASE , LSEQ_BOUNDARY ) , None , ) } Some ( cur_policy ) => match self . data . get ( & cur_policy . id ) { Some ( lseq ) => ( lseq . clone ( ) , Some ( cur_policy . id . clone ( ) ) ) , None => { // Create an empty LSeq since there are no items yet for this Policy let actor = self . policy . actor ( ) ; ( LSeq :: new_with_args ( actor , LSEQ_TREE_BASE , LSEQ_BOUNDARY ) , Some ( cur_policy . id . clone ( ) ) , ) } } , } ; // Last item in current Sequence to be used as causal info for new Policy let cur_last_item = new_lseq . last_entry ( ) . map ( | entry | entry . id . clone ( ) ) ; // Append the new Policy to the history let crdt_op = self . policy . append ( ( policy , cur_last_item . clone ( ) ) ) ; let policy_id = crdt_op . id ( ) . clone ( ) ; let _ = self . data . insert ( policy_id , new_lseq ) ; // Causality info for this Policy op includes current Policy and item Identifiers let ctx = prev_policy_id . map ( | policy_id | ( policy_id , cur_last_item ) ) ; // We return the operation as it may need to be broadcasted to other replicas Ok ( CrdtPolicyOperation { address : * self . address ( ) , crdt_op , source , ctx , signature : None , } ) }
Create a new crdt policy op
Create a new crdt policy op
&mut self
policy
P
source
PublicKey
&mut self
policy
P
source
PublicKey