Skip to content

Commit

Permalink
persistence: use new consensus ordering from RCP-240731A
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Aug 1, 2024
1 parent 3bc0d76 commit 77728ce
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 82 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ features = ["all"]
[patch.crates-io]
bp-consensus = { git = "https://github.com/BP-WG/bp-core", branch = "master" }
bp-invoice = { git = "https://github.com/BP-WG/bp-std.git", branch = "master" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "contract-state2" }
#rgb-core = { path = "../rgb-core" }
#rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "contract-state2" }
rgb-core = { path = "../rgb-core" }
8 changes: 5 additions & 3 deletions src/contract/assignments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::fmt::Debug;
use amplify::confinement::SmallVec;
use commit_verify::Conceal;
use invoice::Amount;
use rgb::vm::TxOrd;
use rgb::vm::WitnessOrd;
use rgb::{
Assign, AssignAttach, AssignData, AssignFungible, AssignRights, AssignmentType, AttachState,
DataState, ExposedSeal, ExposedState, OpId, Opout, RevealedAttach, RevealedData, RevealedValue,
Expand Down Expand Up @@ -153,10 +153,12 @@ impl<State: KnownState> OutputAssignment<State> {
}
}

pub fn check_witness(&self, filter: &HashMap<XWitnessId, TxOrd>) -> bool {
pub fn check_witness(&self, filter: &HashMap<XWitnessId, WitnessOrd>) -> bool {
match self.witness {
None => true,
Some(witness_id) => !matches!(filter.get(&witness_id), None | Some(TxOrd::Archived)),
Some(witness_id) => {
!matches!(filter.get(&witness_id), None | Some(WitnessOrd::Archived))
}
}
}
}
Expand Down
62 changes: 52 additions & 10 deletions src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,64 @@ mod merge_reveal;
pub use assignments::{KnownState, OutputAssignment, TypedAssignsExt};
pub use bundle::{BundleExt, RevealError};
pub use merge_reveal::{MergeReveal, MergeRevealError};
use rgb::vm::AnchoredOpRef;
use rgb::{OpId, XWitnessId};

use crate::LIB_NAME_RGB_STD;

/// Reference to operation element.
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_STD, tags = order)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub enum OpWitness {
#[strict_type(dumb)]
Genesis,
Transition(XWitnessId),
Extension(XWitnessId),
}

impl From<AnchoredOpRef<'_>> for OpWitness {
fn from(aor: AnchoredOpRef) -> Self {
match aor {
AnchoredOpRef::Genesis(_) => OpWitness::Genesis,
AnchoredOpRef::Transition(_, witness_id) => OpWitness::Transition(witness_id),
AnchoredOpRef::Extension(_, witness_id) => OpWitness::Transition(witness_id),
}
}
}

impl OpWitness {
#[inline]
pub fn witness_id(&self) -> Option<XWitnessId> {
match self {
OpWitness::Genesis => None,
OpWitness::Transition(witness_id) | OpWitness::Extension(witness_id) => {
Some(*witness_id)
}
}
}
}

#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_STD)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))]
#[display("{op}/{no}")]
pub struct OpEl {
pub op: OpId,
pub no: u16,
pub witness: Option<XWitnessId>,
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct GlobalOut {
pub opid: OpId,
pub nonce: u8,
pub index: u16,
pub op_witness: OpWitness,
}

impl OpEl {
pub fn new(op: OpId, no: u16, witness: Option<XWitnessId>) -> OpEl { OpEl { op, no, witness } }
impl GlobalOut {
#[inline]
pub fn witness_id(&self) -> Option<XWitnessId> { self.op_witness.witness_id() }
}
9 changes: 9 additions & 0 deletions src/interface/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ impl ContractBuilder {
pub struct TransitionBuilder {
contract_id: ContractId,
builder: OperationBuilder<GraphSeal>,
nonce: u8,
transition_type: TransitionType,
inputs: TinyOrdMap<Input, PersistedState>,
}
Expand Down Expand Up @@ -530,6 +531,7 @@ impl TransitionBuilder {
Self {
contract_id,
builder: OperationBuilder::with(iface, schema, iimpl, types),
nonce: u8::MAX,
transition_type,
inputs: none!(),
}
Expand All @@ -546,6 +548,7 @@ impl TransitionBuilder {
Self {
contract_id,
builder: OperationBuilder::deterministic(iface, schema, iimpl, types),
nonce: u8::MAX,
transition_type,
inputs: none!(),
}
Expand All @@ -555,6 +558,11 @@ impl TransitionBuilder {

pub fn transition_type(&self) -> TransitionType { self.transition_type }

pub fn set_nonce(mut self, nonce: u8) -> Self {
self.nonce = nonce;
self
}

#[inline]
pub fn asset_tag(&self, name: impl Into<FieldName>) -> Result<AssetTag, BuilderError> {
self.builder.asset_tag(name)
Expand Down Expand Up @@ -795,6 +803,7 @@ impl TransitionBuilder {
let transition = Transition {
ffv: none!(),
contract_id: self.contract_id,
nonce: self.nonce,
transition_type: self.transition_type,
metadata: empty!(),
globals: global,
Expand Down
6 changes: 3 additions & 3 deletions src/interface/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// limitations under the License.

use rgb::validation::{ResolveWitness, WitnessResolverError};
use rgb::vm::{TxOrd, XWitnessTx};
use rgb::vm::{WitnessOrd, XWitnessTx};
use strict_encoding::StrictDumb;

use crate::XWitnessId;
Expand All @@ -32,7 +32,7 @@ impl ResolveWitness for DumbResolver {
Ok(XWitnessTx::strict_dumb())
}

fn resolve_pub_witness_ord(&self, _: XWitnessId) -> Result<TxOrd, WitnessResolverError> {
Ok(TxOrd::strict_dumb())
fn resolve_pub_witness_ord(&self, _: XWitnessId) -> Result<WitnessOrd, WitnessResolverError> {
Ok(WitnessOrd::strict_dumb())
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub mod info;

pub use bp::{Outpoint, Txid};
pub use contract::{
BundleExt, KnownState, MergeReveal, MergeRevealError, OpEl, OutputAssignment, RevealError,
BundleExt, KnownState, MergeReveal, MergeRevealError, OutputAssignment, RevealError,
TypedAssignsExt,
};
pub use invoice::{Allocation, Amount, CoinAmount, OwnedFraction, Precision, TokenIndex};
Expand Down
Loading

0 comments on commit 77728ce

Please sign in to comment.