Skip to content

Commit

Permalink
make capabilities constant
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 7, 2024
1 parent b2e0edd commit d8923a5
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 102 deletions.
99 changes: 44 additions & 55 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ wasm-bindgen-test = "0.3"

[package.metadata.docs.rs]
features = ["all"]

[patch.crates-io]
ultrasonic = { git = "https://github.com/AluVM/ultrasonic" }
15 changes: 7 additions & 8 deletions api/src/articles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// the License.

use strict_encoding::{StrictDeserialize, StrictSerialize, TypeName};
use ultrasonic::{Capabilities, Contract, ContractId};
use ultrasonic::{Contract, ContractId};

use crate::sigs::ContentSigs;
use crate::{Api, Schema, LIB_NAME_SONIC};
Expand All @@ -32,17 +32,17 @@ use crate::{Api, Schema, LIB_NAME_SONIC};
#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_SONIC)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(rename_all = "camelCase"))]
pub struct Articles<C: Capabilities> {
pub contract: Contract<C>,
pub struct Articles<const CAPS: u32> {
pub contract: Contract<CAPS>,
pub contract_sigs: ContentSigs,
#[cfg_attr(feature = "serde", serde(flatten))]
pub schema: Schema,
}

impl<C: Capabilities> StrictSerialize for Articles<C> {}
impl<C: Capabilities> StrictDeserialize for Articles<C> {}
impl<const CAPS: u32> StrictSerialize for Articles<CAPS> {}
impl<const CAPS: u32> StrictDeserialize for Articles<CAPS> {}

impl<C: Capabilities> Articles<C> {
impl<const CAPS: u32> Articles<CAPS> {
pub fn contract_id(&self) -> ContractId { self.contract.contract_id() }

pub fn api(&self, name: &TypeName) -> &Api { self.schema.api(name) }
Expand Down Expand Up @@ -74,11 +74,10 @@ mod _fs {
use std::path::Path;

use strict_encoding::{DeserializeError, SerializeError, StrictDeserialize, StrictSerialize};
use ultrasonic::Capabilities;

use super::Articles;

impl<C: Capabilities> Articles<C> {
impl<const CAPS: u32> Articles<CAPS> {
pub fn load(path: impl AsRef<Path>) -> Result<Self, DeserializeError> {
Self::strict_deserialize_from_file::<{ usize::MAX }>(path)
}
Expand Down
8 changes: 4 additions & 4 deletions api/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use chrono::{DateTime, Utc};
use strict_encoding::TypeName;
use strict_types::{StrictVal, TypeSystem};
use ultrasonic::{
fe256, AuthToken, CallId, Capabilities, CellAddr, CodexId, Contract, ContractId, ContractMeta, ContractName,
Genesis, Identity, Input, Operation, StateCell, StateData, StateValue,
fe256, AuthToken, CallId, CellAddr, CodexId, Contract, ContractId, ContractMeta, ContractName, Genesis, Identity,
Input, Operation, StateCell, StateData, StateValue,
};

use crate::{Api, Articles, DataCell, MethodName, Schema, StateAtom, StateName};
Expand Down Expand Up @@ -65,7 +65,7 @@ impl Schema {
IssueBuilder { builder, schema: self }
}

pub fn issue<C: Capabilities + Default>(self, params: IssueParams) -> Articles<C> {
pub fn issue<const CAPS: u32>(self, params: IssueParams) -> Articles<CAPS> {
let mut builder = self.start_issue(params.core.method);

for NamedState { name, state } in params.core.global {
Expand Down Expand Up @@ -107,7 +107,7 @@ impl IssueBuilder {
self
}

pub fn finish<C: Capabilities + Default>(self, name: impl Into<TypeName>, timestamp: i64) -> Articles<C> {
pub fn finish<const CAPS: u32>(self, name: impl Into<TypeName>, timestamp: i64) -> Articles<CAPS> {
let meta = ContractMeta {
capabilities: default!(),
reserved: zero!(),
Expand Down
Loading

0 comments on commit d8923a5

Please sign in to comment.