Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment interfaces for rgb20 #156

Merged
merged 6 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions src/interface/iimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,32 @@ impl IfacePair {
pub fn with(iface: Iface, iimpl: IfaceImpl) -> IfacePair { IfacePair { iface, iimpl } }

pub fn iface_id(&self) -> IfaceId { self.iface.iface_id() }

pub fn impl_id(&self) -> ImplId { self.iimpl.impl_id() }

pub fn global_type(&self, name: &FieldName) -> Option<GlobalStateType> {
self.iimpl.global_type(name)
}

pub fn global_name(&self, global_type: &GlobalStateType) -> Option<&FieldName> {
self.iimpl.global_name(global_type.to_owned())
}

pub fn assignments_type(&self, name: &FieldName) -> Option<AssignmentType> {
self.iimpl.assignments_type(name)
}

pub fn assignment_name(&self, assignment_type: &AssignmentType) -> Option<&FieldName> {
self.iimpl.assignment_name(assignment_type.to_owned())
}

pub fn transition_type(&self, name: &TypeName) -> Option<TransitionType> {
self.iimpl.transition_type(name)
}

pub fn transition_name(&self, transition_type: &TransitionType) -> Option<&TypeName> {
self.iimpl.transition_name(transition_type.to_owned())
}
}

pub trait IssuerClass {
Expand Down
40 changes: 38 additions & 2 deletions src/interface/rgb20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use strict_types::{CompileError, LibBuilder, TypeLib};

use super::{
AssignIface, BuilderError, ContractBuilder, GenesisIface, GlobalIface, Iface, IfaceClass,
IfaceOp, IssuerClass, OwnedIface, Req, SchemaIssuer, StateChange, TransitionIface, VerNo,
WitnessFilter,
IfaceOp, IssuerClass, OwnedIface, Req, RightsAllocation, SchemaIssuer, StateChange,
TransitionIface, VerNo, WitnessFilter,
};
use crate::containers::Contract;
use crate::interface::builder::TxOutpoint;
Expand Down Expand Up @@ -378,6 +378,42 @@ impl Rgb20 {
.expect("RGB20 interface requires `assetOwner` state")
}

pub fn inflation_allowance_allocations<'c>(
&'c self,
filter: impl OutpointFilter + 'c,
) -> impl Iterator<Item = FungibleAllocation> + 'c {
self.0
.fungible("inflationAllowance", filter)
.expect("RGB20 interface requires `inflationAllowance` state")
}

pub fn update_right<'c>(
&'c self,
filter: impl OutpointFilter + 'c,
) -> impl Iterator<Item = RightsAllocation> + 'c {
self.0
.rights("updateRight", filter)
.expect("RGB20 interface requires `updateRight` state")
}

pub fn burn_epoch<'c>(
&'c self,
filter: impl OutpointFilter + 'c,
) -> impl Iterator<Item = RightsAllocation> + 'c {
self.0
.rights("burnEpoch", filter)
.expect("RGB20 interface requires `burnEpoch` state")
}

pub fn burn_right<'c>(
&'c self,
filter: impl OutpointFilter + 'c,
) -> impl Iterator<Item = RightsAllocation> + 'c {
self.0
.rights("burnRight", filter)
.expect("RGB20 interface requires `updateRight` state")
}

pub fn contract_data(&self) -> ContractData {
let strict_val = &self
.0
Expand Down
20 changes: 20 additions & 0 deletions src/interface/rgb21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ pub struct EngravingData {
pub content: EmbeddedMedia,
}

impl EngravingData {
pub fn from_strict_val_unchecked(value: &StrictVal) -> Self {
let index = TokenIndex(value.unwrap_struct("index").unwrap_num().unwrap_uint());
let content = EmbeddedMedia::from_strict_val_unchecked(value.unwrap_struct("content"));

Self {
applied_to: index,
content,
}
}
}

#[derive(Clone, Eq, PartialEq, Hash, Debug)]
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB21)]
Expand Down Expand Up @@ -532,6 +544,14 @@ impl Rgb21 {
Timestamp::from_strict_val_unchecked(strict_val)
}

pub fn engarving_data(&self) -> EngravingData {
let strict_val = &self
.0
.global("engravings")
.expect("RGB21 interface requires global state `engravings`")[0];
EngravingData::from_strict_val_unchecked(strict_val)
}

pub fn allocations<'c>(
&'c self,
filter: impl OutpointFilter + 'c,
Expand Down
Loading