Skip to content

Commit

Permalink
containers: refactor transfer id generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Feb 16, 2024
1 parent 006d052 commit 6fd24b1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ bp-dbc = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
bp-seals = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
bp-core = { git = "https://github.com/BP-WG/bp-core", branch = "v0.11" }
bp-invoice = { git = "https://github.com/BP-WG/bp-std", branch = "v0.11" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "vesper" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "disclose" }
aluvm = { git = "https://github.com/AluVM/rust-aluvm", branch = "v0.11" }
20 changes: 19 additions & 1 deletion src/containers/consignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::collections::BTreeMap;
use std::iter;

use amplify::confinement::{LargeVec, MediumBlob, SmallOrdMap, TinyOrdMap, TinyOrdSet};
use bp::Tx;
use rgb::validation::{self};
use rgb::{
AnchoredBundle, AssetTag, AssignmentType, AttachId, BundleId, ContractHistory, ContractId,
Expand All @@ -31,7 +32,9 @@ use rgb::{
};
use strict_encoding::{StrictDeserialize, StrictDumb, StrictSerialize};

use super::{Bindle, BindleContent, ContainerVer, ContentId, ContentSigs, Terminal};
use super::{
Bindle, BindleContent, ContainerVer, ContentId, ContentSigs, Terminal, TerminalDisclose,
};
use crate::accessors::BundleExt;
use crate::interface::{ContractSuppl, IfaceId, IfacePair};
use crate::resolvers::ResolveHeight;
Expand Down Expand Up @@ -93,9 +96,11 @@ pub struct Consignment<const TYPE: bool> {
pub terminals: SmallOrdMap<BundleId, Terminal>,

/// Data on all anchored state transitions contained in the consignments.
// TODO: Make set
pub bundles: LargeVec<AnchoredBundle>,

/// Data on all state extensions contained in the consignments.
// TODO: Make set
pub extensions: LargeVec<Extension>,

/// Data containers coming with this consignment. For the purposes of
Expand Down Expand Up @@ -167,6 +172,19 @@ impl<const TYPE: bool> Consignment<TYPE> {
.find(|&extension| extension.id() == opid)
}

pub fn terminals_disclose(&self) -> impl Iterator<Item = TerminalDisclose> + '_ {
self.terminals.iter().flat_map(|(id, term)| {
term.seals.iter().map(|seal| TerminalDisclose {
bundle_id: *id,
seal: seal.clone(),
witness_id: term
.witness_tx
.as_ref()
.map(|witness| witness.map_ref(Tx::txid)),
})
})
}

pub fn validation_status(&self) -> Option<&validation::Status> {
self.validation_status.as_ref()
}
Expand Down
2 changes: 1 addition & 1 deletion src/containers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ pub use disclosure::Disclosure;
pub use indexed::IndexedConsignment;
pub use partials::{Batch, CloseMethodSet, Fascia, TransitionInfo};
pub use seal::{BuilderSeal, TerminalSeal, VoutSeal};
pub use util::{ContainerVer, Terminal};
pub use util::{ContainerVer, Terminal, TerminalDisclose};
26 changes: 25 additions & 1 deletion src/containers/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@

use std::str::FromStr;

use amplify::confinement::{LargeOrdSet, SmallOrdSet, TinyOrdSet};
use amplify::{ByteArray, Bytes32};
use baid58::{Baid58ParseError, Chunking, FromBaid58, ToBaid58, CHUNKING_32};
use commit_verify::{CommitEncode, CommitEngine, CommitId, CommitmentId, DigestExt, Sha256};
use rgb::{Extension, Operation};

use super::Transfer;
use crate::LIB_NAME_RGB_STD;
Expand Down Expand Up @@ -73,7 +75,29 @@ impl TransferId {
impl CommitEncode for Transfer {
type CommitmentId = TransferId;

fn commit_encode(&self, e: &mut CommitEngine) { e.commit_to(self); }
fn commit_encode(&self, e: &mut CommitEngine) {
e.commit_to(&self.version);
e.commit_to(&self.transfer);

e.commit_to(&self.contract_id());
e.commit_to(&self.genesis.disclose_hash());
e.commit_to(&TinyOrdSet::from_iter_unsafe(
self.ifaces.values().map(|pair| pair.iimpl.impl_id()),
));

e.commit_to(&LargeOrdSet::from_iter_unsafe(
self.bundles.iter().map(|ab| ab.bundle.disclose_hash()),
));
e.commit_to(&LargeOrdSet::from_iter_unsafe(
self.extensions.iter().map(Extension::disclose_hash),
));
e.commit_to(&SmallOrdSet::from_iter_unsafe(self.terminals_disclose()));

e.commit_to(&SmallOrdSet::from_iter_unsafe(self.attachments.keys().copied()));
e.commit_to(&self.supplements);
e.commit_to(&self.asset_tags);
e.commit_to(&self.signatures);
}
}

impl Transfer {
Expand Down
16 changes: 15 additions & 1 deletion src/containers/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,25 @@
// limitations under the License.

use amplify::confinement::SmallOrdSet;
use rgb::{XChain, XPubWitness};
use rgb::{BundleId, WitnessId, XChain, XPubWitness};

use super::TerminalSeal;
use crate::LIB_NAME_RGB_STD;

#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_STD)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct TerminalDisclose {
pub bundle_id: BundleId,
pub seal: XChain<TerminalSeal>,
pub witness_id: Option<WitnessId>,
}

#[derive(Clone, Eq, PartialEq, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_STD)]
Expand Down

0 comments on commit 6fd24b1

Please sign in to comment.