Skip to main content

dpp/asset_lock/reduced_asset_lock_value/v0/
mod.rs

1use crate::fee::Credits;
2#[cfg(feature = "json-conversion")]
3use crate::serialization::json_safe_fields;
4use bincode::{Decode, DecodeUntrusted, Encode};
5use platform_value::Bytes32;
6
7// `initial_credit_value` / `remaining_credit_value` are `Credits` (u64) and can
8// exceed JS's `MAX_SAFE_INTEGER`; `#[json_safe_fields]` serializes them as
9// strings in human-readable JSON to avoid precision loss when crossing to JS.
10#[cfg_attr(feature = "json-conversion", json_safe_fields)]
11#[derive(
12    Debug, Clone, Encode, Decode, PartialEq, serde::Serialize, serde::Deserialize, DecodeUntrusted,
13)]
14pub struct AssetLockValueV0 {
15    pub(super) initial_credit_value: Credits,
16    pub(super) tx_out_script: Vec<u8>,
17    pub(super) remaining_credit_value: Credits,
18    /// The used tags can represent any token of that we want to say has been used
19    /// In practice for Platform this means that we are storing the asset lock transactions
20    /// to prevent replay attacks.
21    pub(super) used_tags: Vec<Bytes32>,
22}
23
24pub trait AssetLockValueGettersV0 {
25    fn initial_credit_value(&self) -> Credits;
26    fn tx_out_script(&self) -> &Vec<u8>;
27
28    fn tx_out_script_owned(self) -> Vec<u8>;
29    fn remaining_credit_value(&self) -> Credits;
30
31    fn used_tags_ref(&self) -> &Vec<Bytes32>;
32}
33
34pub trait AssetLockValueSettersV0 {
35    fn set_initial_credit_value(&mut self, value: Credits);
36    fn set_tx_out_script(&mut self, value: Vec<u8>);
37    fn set_remaining_credit_value(&mut self, value: Credits);
38
39    fn set_used_tags(&mut self, tags: Vec<Bytes32>);
40    fn add_used_tag(&mut self, tag: Bytes32);
41}