pub struct DomainRecordDraft {
pub reference: DomainRecordRef,
pub payload: Value,
pub references: Vec<DomainReference>,
}Fields§
§reference: DomainRecordRef§payload: Value§references: Vec<DomainReference>Implementations§
Source§impl DomainRecordDraft
impl DomainRecordDraft
pub fn new(reference: DomainRecordRef, payload: Value) -> DomainRecordDraft
Sourcepub fn from_typed<T>(
reference: TypedDomainRecordRef<T>,
payload: &<T as DomainRecordType>::Payload,
) -> Result<DomainRecordDraft, CanwuError>
pub fn from_typed<T>( reference: TypedDomainRecordRef<T>, payload: &<T as DomainRecordType>::Payload, ) -> Result<DomainRecordDraft, CanwuError>
Examples found in repository?
examples/governance_transition.rs (lines 266-280)
245fn publish_order(
246 view: &SimulationView<'_>,
247 context: &BoundaryContext,
248) -> Result<BoundaryProposal, CanwuError> {
249 let Some(order_id) = owned_order_ingress(view, context, CENTRAL_PLUGIN, ISSUE_INGRESS)? else {
250 return Ok(BoundaryProposal::default());
251 };
252 if order_id != ORDER_ID {
253 return Err(CanwuError::new(
254 ErrorCode::InvalidBoundary,
255 "the issue ingress names an unexpected relief order",
256 ));
257 }
258 if view.typed_domain_record(&order_reference())?.is_some() {
259 return Err(CanwuError::new(
260 ErrorCode::InvalidBoundary,
261 "the relief order already exists; duplicate issue ingress is invalid",
262 ));
263 }
264 let treasury_hash = action_hash(600)?;
265 let county_hash = action_hash(600)?;
266 let manifest = DomainRecordDraft::from_typed(
267 order_reference(),
268 &ReliefOrder {
269 order_id: ORDER_ID.to_owned(),
270 issued_by: CENTRAL_PLUGIN.to_owned(),
271 treasury_system: "prepare-treasury".to_owned(),
272 treasury_version: 1,
273 treasury_disposition: "committed".to_owned(),
274 treasury_hash,
275 county_system: "prepare-county".to_owned(),
276 county_version: 1,
277 county_disposition: "committed".to_owned(),
278 county_hash,
279 },
280 )?;
281 Ok(BoundaryProposal {
282 directives: vec![
283 BoundaryDirective::MutateRecord {
284 mutation: DomainRecordMutation::Create { record: manifest },
285 summary: "Publish the central relief order manifest".to_owned(),
286 },
287 BoundaryDirective::SchedulePluginIngress {
288 target_plugin: TREASURY_PLUGIN.to_owned(),
289 after: SimDuration::ZERO,
290 packet_type: EXECUTE_INGRESS.to_owned(),
291 priority: 0,
292 payload: json!({"order_id": ORDER_ID}),
293 affected: Vec::new(),
294 },
295 BoundaryDirective::SchedulePluginIngress {
296 target_plugin: COUNTY_PLUGIN.to_owned(),
297 after: SimDuration::ZERO,
298 packet_type: EXECUTE_INGRESS.to_owned(),
299 priority: 0,
300 payload: json!({"order_id": ORDER_ID}),
301 affected: Vec::new(),
302 },
303 ],
304 ..BoundaryProposal::default()
305 })
306}
307
308fn prepare_treasury(
309 view: &SimulationView<'_>,
310 context: &BoundaryContext,
311) -> Result<BoundaryProposal, CanwuError> {
312 prepare_owner(
313 view,
314 context,
315 TREASURY_PLUGIN,
316 "prepare-treasury",
317 treasury_reference(),
318 &action_payload(600),
319 )
320}
321
322fn prepare_county(
323 view: &SimulationView<'_>,
324 context: &BoundaryContext,
325) -> Result<BoundaryProposal, CanwuError> {
326 prepare_owner(
327 view,
328 context,
329 COUNTY_PLUGIN,
330 "prepare-county",
331 county_reference(),
332 &action_payload(600),
333 )
334}
335
336fn prepare_owner<T: DomainRecordType<Payload = ReliefAction>>(
337 view: &SimulationView<'_>,
338 context: &BoundaryContext,
339 plugin: &str,
340 system: &str,
341 reference: TypedDomainRecordRef<T>,
342 payload: &ReliefAction,
343) -> Result<BoundaryProposal, CanwuError> {
344 let Some(order_id) = owned_order_ingress(view, context, plugin, EXECUTE_INGRESS)? else {
345 return Ok(BoundaryProposal::default());
346 };
347 if order_id != ORDER_ID {
348 return Err(CanwuError::new(
349 ErrorCode::InvalidBoundary,
350 format!("{plugin} received an ingress for the wrong order"),
351 ));
352 }
353 let order = order_payload(view)?;
354 let hash = action_hash(payload.grain_units)?;
355 validate_order(&order, system, plugin, &hash)?;
356 let record = DomainRecordDraft::from_typed(reference, payload)?;
357 Ok(BoundaryProposal {
358 directives: vec![BoundaryDirective::MutateRecord {
359 mutation: DomainRecordMutation::Create { record },
360 summary: format!("{plugin} prepares its guarded relief disposition"),
361 }],
362 ..BoundaryProposal::default()
363 })
364}Trait Implementations§
Source§impl Clone for DomainRecordDraft
impl Clone for DomainRecordDraft
Source§fn clone(&self) -> DomainRecordDraft
fn clone(&self) -> DomainRecordDraft
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DomainRecordDraft
impl Debug for DomainRecordDraft
Source§impl<'de> Deserialize<'de> for DomainRecordDraft
impl<'de> Deserialize<'de> for DomainRecordDraft
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<DomainRecordDraft, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<DomainRecordDraft, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for DomainRecordDraft
impl PartialEq for DomainRecordDraft
Source§impl Serialize for DomainRecordDraft
impl Serialize for DomainRecordDraft
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl StructuralPartialEq for DomainRecordDraft
Auto Trait Implementations§
impl Freeze for DomainRecordDraft
impl RefUnwindSafe for DomainRecordDraft
impl Send for DomainRecordDraft
impl Sync for DomainRecordDraft
impl Unpin for DomainRecordDraft
impl UnsafeUnpin for DomainRecordDraft
impl UnwindSafe for DomainRecordDraft
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
Mutably borrows from an owned value. Read more