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, 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(Debug, Clone, Encode, Decode, PartialEq, serde::Serialize, serde::Deserialize)]
12pub struct AssetLockValueV0 {
13    pub(super) initial_credit_value: Credits,
14    pub(super) tx_out_script: Vec<u8>,
15    pub(super) remaining_credit_value: Credits,
16    /// The used tags can represent any token of that we want to say has been used
17    /// In practice for Platform this means that we are storing the asset lock transactions
18    /// to prevent replay attacks.
19    pub(super) used_tags: Vec<Bytes32>,
20}
21
22pub trait AssetLockValueGettersV0 {
23    fn initial_credit_value(&self) -> Credits;
24    fn tx_out_script(&self) -> &Vec<u8>;
25
26    fn tx_out_script_owned(self) -> Vec<u8>;
27    fn remaining_credit_value(&self) -> Credits;
28
29    fn used_tags_ref(&self) -> &Vec<Bytes32>;
30}
31
32pub trait AssetLockValueSettersV0 {
33    fn set_initial_credit_value(&mut self, value: Credits);
34    fn set_tx_out_script(&mut self, value: Vec<u8>);
35    fn set_remaining_credit_value(&mut self, value: Credits);
36
37    fn set_used_tags(&mut self, tags: Vec<Bytes32>);
38    fn add_used_tag(&mut self, tag: Bytes32);
39}