pub struct ContractDraft {
pub types: Vec<TypeNode>,
pub declarations: Vec<Declaration>,
pub actor: Option<Actor>,
pub producer: Option<ProducerInfo>,
}Expand description
A producer-side Contract draft: the parts an authoring tool supplies, and nothing it must not.
A draft carries only the type graph, named declarations, an optional
actor, and optional producer metadata. It deliberately has no
format/version/profile markers and no identity fields: building stamps
the current CONTRACT_FORMAT/FORMAT_VERSION/SEMANTICS_PROFILE/
CANONICALIZATION_PROFILE constants and calculates fresh identities
under the same validation and canonicalization budgets as every other
entry point, so a draft can never carry a fake, stale, or placeholder
identity. RawContract is the opposite boundary — the serde DTO for
decoded external artifacts, whose supplied identities
Contract::try_from_raw verifies instead of recalculating.
§Serialized shape
A serialized draft contains exactly the four fields above. Unknown keys
are rejected; declarations defaults to empty when absent; actor is
omitted when absent, and an explicit "actor": null is rejected just as
RawContract rejects it; producer is omitted when absent and defaults
at build time to ProducerInfo::current, while a present producer
overrides that default.
use candid_core::{ContractDraft, PrimitiveType, TypeNode};
let contract = ContractDraft::new(
vec![TypeNode::Primitive { primitive: PrimitiveType::Nat }],
vec![candid_core::Declaration { name: "Amount".to_string(), ty: 0 }],
None,
)
.build()?;
assert!(contract.contract_id().starts_with("candid-core:contract:v1:sha256:"));
assert_eq!(contract.producer(), &candid_core::ProducerInfo::current());Fields§
§types: Vec<TypeNode>§declarations: Vec<Declaration>§actor: Option<Actor>An actorless draft omits this property entirely; "actor": null is
rejected on decode, exactly as RawContract rejects it.
producer: Option<ProducerInfo>Untrusted provenance about the authoring tool. None builds with
ProducerInfo::current. Never part of a semantic identity; see
ProducerInfo. An explicit "producer": null is rejected on
decode: absence is the only spelling of “default producer”, mirroring
the actor rule.
Implementations§
Source§impl ContractDraft
impl ContractDraft
pub fn new( types: Vec<TypeNode>, declarations: Vec<Declaration>, actor: Option<Actor>, ) -> Self
Sourcepub fn with_producer(self, producer: ProducerInfo) -> Self
pub fn with_producer(self, producer: ProducerInfo) -> Self
Returns self with an explicit producer, overriding the
ProducerInfo::current default applied at build time.
Sourcepub fn build(self) -> Result<Contract, ContractValidationError>
pub fn build(self) -> Result<Contract, ContractValidationError>
Validate the draft graph, canonicalize it, and calculate its
identities under Limits::default.
Sourcepub fn build_with_limits(
self,
limits: &Limits,
) -> Result<Contract, ContractValidationError>
pub fn build_with_limits( self, limits: &Limits, ) -> Result<Contract, ContractValidationError>
Build under caller-supplied limits.
Sourcepub fn build_with_context(
self,
context: &RuntimeContext,
) -> Result<Contract, ContractValidationError>
pub fn build_with_context( self, context: &RuntimeContext, ) -> Result<Contract, ContractValidationError>
Build under the caller’s context, sharing its budget, deadline, and cancellation token.
Trait Implementations§
Source§impl Clone for ContractDraft
impl Clone for ContractDraft
Source§fn clone(&self) -> ContractDraft
fn clone(&self) -> ContractDraft
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ContractDraft
impl Debug for ContractDraft
Source§impl<'de> Deserialize<'de> for ContractDraft
impl<'de> Deserialize<'de> for ContractDraft
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for ContractDraft
Source§impl PartialEq for ContractDraft
impl PartialEq for ContractDraft
Source§impl Serialize for ContractDraft
impl Serialize for ContractDraft
impl StructuralPartialEq for ContractDraft
Auto Trait Implementations§
impl Freeze for ContractDraft
impl RefUnwindSafe for ContractDraft
impl Send for ContractDraft
impl Sync for ContractDraft
impl Unpin for ContractDraft
impl UnsafeUnpin for ContractDraft
impl UnwindSafe for ContractDraft
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.