Skip to content

Commit

Permalink
Merge pull request #88 from RGB-WG/develop
Browse files Browse the repository at this point in the history
Modifications to containers: witness tx in consignments and type libs in ifaces
  • Loading branch information
dr-orlovsky authored Jul 14, 2023
2 parents 32b13c5 + 044069e commit ecaf760
Show file tree
Hide file tree
Showing 23 changed files with 1,057 additions and 310 deletions.
10 changes: 5 additions & 5 deletions std/src/containers/bindle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub use _fs::*;
use amplify::confinement::{Confined, TinyVec, U24};
use baid58::Baid58ParseError;
use base64::Engine;
use rgb::{ContractId, Schema, SchemaId, SchemaRoot};
use rgb::{BundleId, ContractId, Schema, SchemaId, SchemaRoot};
use strict_encoding::{
StrictDecode, StrictDeserialize, StrictDumb, StrictEncode, StrictSerialize, StrictType,
};
Expand Down Expand Up @@ -81,8 +81,8 @@ impl BindleContent for Contract {
bmap! {
"Version" => self.version.to_string(),
"Terminals" => self.terminals
.iter()
.map(|t| t.seal.to_string())
.keys()
.map(BundleId::to_string)
.collect::<Vec<_>>()
.join(",\n "),
}
Expand All @@ -99,8 +99,8 @@ impl BindleContent for Transfer {
"Version" => self.version.to_string(),
"ContractId" => self.contract_id().to_string(),
"Terminals" => self.terminals
.iter()
.map(|t| t.seal.to_string())
.keys()
.map(BundleId::to_string)
.collect::<Vec<_>>()
.join(",\n "),
}
Expand Down
13 changes: 8 additions & 5 deletions std/src/containers/consignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
use std::collections::{BTreeMap, BTreeSet};
use std::{iter, slice};

use amplify::confinement::{
LargeVec, MediumBlob, SmallOrdMap, SmallOrdSet, TinyOrdMap, TinyOrdSet,
};
use amplify::confinement::{LargeVec, MediumBlob, SmallOrdMap, TinyOrdMap, TinyOrdSet};
use commit_verify::Conceal;
use rgb::validation::{AnchoredBundle, ConsignmentApi};
use rgb::{
Expand Down Expand Up @@ -93,7 +91,7 @@ pub struct Consignment<const TYPE: bool> {
pub genesis: Genesis,

/// Set of seals which are history terminals.
pub terminals: SmallOrdSet<Terminal>,
pub terminals: SmallOrdMap<BundleId, Terminal>,

/// Data on all anchored state transitions contained in the consignments.
pub bundles: LargeVec<AnchoredBundle>,
Expand Down Expand Up @@ -279,7 +277,12 @@ impl<const TYPE: bool> ConsignmentApi for Consignment<TYPE> {
fn terminals(&self) -> BTreeSet<(BundleId, SecretSeal)> {
self.terminals
.iter()
.map(|terminal| (terminal.bundle_id, terminal.seal.conceal()))
.flat_map(|(bundle_id, terminal)| {
terminal
.seals
.iter()
.map(|seal| (*bundle_id, seal.conceal()))
})
.collect()
}

Expand Down
7 changes: 7 additions & 0 deletions std/src/containers/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ impl TerminalSeal {
pub fn new_vout(method: CloseMethod, vout: impl Into<Vout>) -> TerminalSeal {
TerminalSeal::WitnessVout(VoutSeal::new(method, vout))
}

pub fn secret_seal(&self) -> Option<SecretSeal> {
match self {
TerminalSeal::ConcealedUtxo(seal) => Some(*seal),
TerminalSeal::WitnessVout(_) => None,
}
}
}

impl Conceal for TerminalSeal {
Expand Down
12 changes: 8 additions & 4 deletions std/src/containers/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
use std::io;
use std::str::FromStr;

use amplify::confinement::SmallOrdSet;
use amplify::{Bytes32, RawArray};
use baid58::{Baid58ParseError, FromBaid58, ToBaid58};
use commit_verify::{CommitEncode, CommitmentId, Conceal};
use strict_encoding::{StrictEncode, StrictWriter};

use crate::containers::Transfer;
use crate::containers::{TerminalSeal, Transfer};
use crate::LIB_NAME_RGB_STD;

/// Transfer identifier.
Expand Down Expand Up @@ -64,9 +65,12 @@ impl CommitEncode for Transfer {
let mut writer = StrictWriter::with(usize::MAX, e);
writer = self.transfer.strict_encode(writer)?;
writer = self.contract_id().strict_encode(writer)?;
for terminal in &self.terminals {
writer = terminal.seal.conceal().strict_encode(writer)?;
writer = terminal.bundle_id.strict_encode(writer)?;
for (bundle_id, terminal) in &self.terminals {
writer = bundle_id.strict_encode(writer)?;
let seals =
SmallOrdSet::try_from_iter(terminal.seals.iter().map(TerminalSeal::conceal))
.expect("same size iterator");
writer = seals.strict_encode(writer)?;
}
for attach_id in self.attachments.keys() {
writer = attach_id.strict_encode(writer)?;
Expand Down
22 changes: 17 additions & 5 deletions std/src/containers/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use rgb::BundleId;
use amplify::confinement::SmallOrdSet;
use bp::Tx;

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

#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
#[derive(Clone, Eq, PartialEq, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_STD)]
#[cfg_attr(
Expand All @@ -33,12 +34,23 @@ use crate::LIB_NAME_RGB_STD;
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct Terminal {
pub bundle_id: BundleId,
pub seal: TerminalSeal,
pub seals: SmallOrdSet<TerminalSeal>,
pub tx: Option<Tx>,
}

impl Terminal {
pub fn with(bundle_id: BundleId, seal: TerminalSeal) -> Self { Terminal { bundle_id, seal } }
pub fn new(seal: TerminalSeal) -> Self {
Terminal {
seals: small_bset![seal],
tx: None,
}
}
pub fn with(seal: TerminalSeal, tx: Tx) -> Self {
Terminal {
seals: small_bset![seal],
tx: Some(tx),
}
}
}

#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display, Default)]
Expand Down
Loading

0 comments on commit ecaf760

Please sign in to comment.