Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

process consignment: handle attachment assignments #212

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 55 additions & 26 deletions src/bucketd/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use rgb::psbt::RgbExt;
use rgb::schema::{OwnedRightType, TransitionType};
use rgb::seal::Revealed;
use rgb::{
bundle, validation, Anchor, Assignment, BundleId, Consignment, ConsignmentType, ContractId,
ContractState, ContractStateMap, Disclosure, Genesis, InmemConsignment, Node, NodeId,
OwnedRights, PedersenStrategy, Schema, SchemaId, SealEndpoint, StateTransfer, Transition,
TransitionBundle, TypedAssignments, Validator, Validity,
bundle, validation, Anchor, Assignment, AttachmentStrategy, BundleId, Consignment,
ConsignmentType, ContractId, ContractState, ContractStateMap, Disclosure, Genesis,
InmemConsignment, Node, NodeId, OwnedRights, PedersenStrategy, Schema, SchemaId, SealEndpoint,
StateTransfer, Transition, TransitionBundle, TypedAssignments, Validator, Validity,
};
use rgb_rpc::{OutpointFilter, Reveal, TransferFinalize};
use storm::chunk::ChunkIdExt;
Expand Down Expand Up @@ -282,30 +282,59 @@ impl Runtime {

let mut owned_rights: BTreeMap<OwnedRightType, TypedAssignments> = bmap! {};
for (owned_type, assignments) in transition.owned_rights().iter() {
let outpoints = assignments.to_value_assignments();

let mut revealed_assignment: Vec<Assignment<PedersenStrategy>> =
empty!();

for out in outpoints {
if out.commit_conceal().to_confidential_seal()
!= reveal_outpoint.to_concealed_seal()
{
revealed_assignment.push(out);
} else {
let accept = match out.as_revealed_state() {
Some(seal) => Assignment::Revealed {
seal: reveal_outpoint,
state: *seal,
},
_ => out,
};
revealed_assignment.push(accept);
match assignments {
TypedAssignments::Value(outpoints) => {
let mut assignment: Vec<Assignment<PedersenStrategy>> =
empty!();

for out in outpoints.clone() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be more efficient to remove clone here and put in in just a single branch which takes the ownership below (the other branch doesn't need to do the clone).

if out.commit_conceal().to_confidential_seal()
!= reveal_outpoint.to_concealed_seal()
{
assignment.push(out);
} else {
let accept = match out.as_revealed_state() {
Some(seal) => Assignment::Revealed {
seal: reveal_outpoint,
state: *seal,
},
_ => out,
};
assignment.push(accept);
}
}

owned_rights
.insert(*owned_type, TypedAssignments::Value(assignment));
}
TypedAssignments::Attachment(outpoints) => {
let mut assignment: Vec<Assignment<AttachmentStrategy>> =
empty!();

for out in outpoints.clone() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ibid

if out.commit_conceal().to_confidential_seal()
!= reveal_outpoint.to_concealed_seal()
{
assignment.push(out);
} else {
let accept = match out.as_revealed_state() {
Some(seal) => Assignment::Revealed {
seal: reveal_outpoint,
state: seal.clone(),
},
_ => out,
};
assignment.push(accept);
}
}

owned_rights.insert(
*owned_type,
TypedAssignments::Attachment(assignment),
);
}
_ => {}
}

owned_rights
.insert(*owned_type, TypedAssignments::Value(revealed_assignment));
}

let tmp: Transition = Transition::with(
Expand Down