Skip to content

Commit

Permalink
added burn transition
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Dec 1, 2024
1 parent a34ff06 commit 279d16f
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod document_update_price_transition;
pub mod token_base_transition;
pub mod token_issuance_transition;
pub mod token_transfer_transition;
pub mod token_burn_transition;

use crate::prelude::Revision;
use crate::state_transition::documents_batch_transition::document_base_transition::v0::v0_methods::DocumentBaseTransitionV0Methods;
Expand All @@ -30,12 +31,12 @@ pub use document_transfer_transition::DocumentTransferTransition;
pub use document_purchase_transition::DocumentPurchaseTransition;
pub use document_update_price_transition::DocumentUpdatePriceTransition;
use platform_value::Value;
use crate::state_transition::documents_batch_transition::document_base_transition::document_base_transition_trait::DocumentBaseTransitionAccessors;
use crate::state_transition::documents_batch_transition::document_transition::document_purchase_transition::v0::v0_methods::DocumentPurchaseTransitionV0Methods;
use crate::state_transition::documents_batch_transition::document_transition::document_update_price_transition::v0::v0_methods::DocumentUpdatePriceTransitionV0Methods;

use crate::state_transition::state_transitions::document::documents_batch_transition::document_transition::document_create_transition::v0::v0_methods::DocumentCreateTransitionV0Methods;
use crate::state_transition::state_transitions::document::documents_batch_transition::document_transition::document_replace_transition::v0::v0_methods::DocumentReplaceTransitionV0Methods;
use crate::state_transition::state_transitions::document::documents_batch_transition::document_transition::document_delete_transition::v0::v0_methods::DocumentDeleteTransitionV0Methods;
use crate::state_transition::state_transitions::document::documents_batch_transition::document_transition::document_transfer_transition::v0::v0_methods::DocumentTransferTransitionV0Methods;

pub const PROPERTY_ACTION: &str = "$action";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
pub mod v0;
mod v0_methods;

use bincode::{Decode, Encode};
use derive_more::{Display, From};
#[cfg(feature = "state-transition-serde-conversion")]
use serde::{Deserialize, Serialize};
pub use v0::TokenBurnTransitionV0;

#[derive(Debug, Clone, Encode, Decode, PartialEq, Display, From)]
#[cfg_attr(
feature = "state-transition-serde-conversion",
derive(Serialize, Deserialize)
)]
pub enum TokenBurnTransition {
#[display("V0({})", "_0")]
V0(TokenBurnTransitionV0),
}

impl Default for TokenBurnTransition {
fn default() -> Self {
TokenBurnTransition::V0(TokenBurnTransitionV0::default()) // since only v0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pub mod v0_methods;

use crate::state_transition::documents_batch_transition::token_base_transition::TokenBaseTransition;
use bincode::{Decode, Encode};
use derive_more::Display;
#[cfg(feature = "state-transition-serde-conversion")]
use serde::{Deserialize, Serialize};

mod property_names {
pub const AMOUNT: &str = "$amount";
}
/// The Identifier fields in [`TokenBurnTransition`]
pub use super::super::document_base_transition::IDENTIFIER_FIELDS;

#[derive(Debug, Clone, Default, Encode, Decode, PartialEq, Display)]
#[cfg_attr(
feature = "state-transition-serde-conversion",
derive(Serialize, Deserialize),
serde(rename_all = "camelCase")
)]
#[display("Base: {base}, Amount: {burn_amount}")]
pub struct TokenBurnTransitionV0 {
/// Document Base Transition
#[cfg_attr(feature = "state-transition-serde-conversion", serde(flatten))]
pub base: TokenBaseTransition,

/// How much should we burn
pub burn_amount: u64,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use crate::state_transition::documents_batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors;
use crate::state_transition::documents_batch_transition::token_base_transition::TokenBaseTransition;
use crate::state_transition::documents_batch_transition::token_burn_transition::TokenBurnTransitionV0;

impl TokenBaseTransitionAccessors for TokenBurnTransitionV0 {
fn base(&self) -> &TokenBaseTransition {
&self.base
}

fn base_mut(&mut self) -> &mut TokenBaseTransition {
&mut self.base
}

fn set_base(&mut self, base: TokenBaseTransition) {
self.base = base;
}
}

pub trait TokenBurnTransitionV0Methods: TokenBaseTransitionAccessors {
fn burn_amount(&self) -> u64;

fn set_burn_amount(&mut self, amount: u64);
}

impl TokenBurnTransitionV0Methods for TokenBurnTransitionV0 {
fn burn_amount(&self) -> u64 {
self.burn_amount
}

fn set_burn_amount(&mut self, amount: u64) {
self.burn_amount = amount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::state_transition::documents_batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors;
use crate::state_transition::documents_batch_transition::token_base_transition::TokenBaseTransition;
use crate::state_transition::documents_batch_transition::token_burn_transition::TokenBurnTransition;
use crate::state_transition::documents_batch_transition::token_burn_transition::v0::v0_methods::TokenBurnTransitionV0Methods;

impl TokenBaseTransitionAccessors for TokenBurnTransition {
fn base(&self) -> &TokenBaseTransition {
match self {
TokenBurnTransition::V0(v0) => &v0.base,
}
}

fn base_mut(&mut self) -> &mut TokenBaseTransition {
match self {
TokenBurnTransition::V0(v0) => &mut v0.base,
}
}

fn set_base(&mut self, base: TokenBaseTransition) {
match self {
TokenBurnTransition::V0(v0) => v0.base = base,
}
}
}

impl TokenBurnTransitionV0Methods for TokenBurnTransition {
fn burn_amount(&self) -> u64 {
match self {
TokenBurnTransition::V0(v0) => v0.burn_amount(),
}
}

fn set_burn_amount(&mut self, burn_amount: u64) {
match self {
TokenBurnTransition::V0(v0) => v0.set_burn_amount(burn_amount),
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod convertible;
pub mod v0;
mod v0_methods;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ pub struct TokenIssuanceTransitionV0 {
pub base: TokenBaseTransition,

/// How much should we issue
#[cfg_attr(feature = "state-transition-serde-conversion")]
pub amount: u64,
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ pub use super::super::token_base_transition::IDENTIFIER_FIELDS;
use crate::state_transition::documents_batch_transition::token_base_transition::TokenBaseTransition;

mod property_names {
pub const REVISION: &str = "$revision";

pub const AMOUNT: &str = "$amount";
pub const RECIPIENT_OWNER_ID: &str = "recipientOwnerId";
}

Expand All @@ -24,19 +23,19 @@ mod property_names {
serde(rename_all = "camelCase")
)]
#[display(
"Base: {}, Revision: {}, Recipient: {:?}",
"Base: {}, Amount: {}, Recipient: {:?}",
"base",
"revision",
"amount",
"recipient_owner_id"
)]
pub struct TokenTransferTransitionV0 {
#[cfg_attr(feature = "state-transition-serde-conversion", serde(flatten))]
pub base: TokenBaseTransition,
#[cfg_attr(
feature = "state-transition-serde-conversion",
serde(rename = "$revision")
serde(rename = "$amount")
)]
pub revision: Revision,
pub amount: u64,
#[cfg_attr(
feature = "state-transition-serde-conversion",
serde(rename = "recipientOwnerId")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use platform_value::Identifier;

use crate::prelude::Revision;

use crate::state_transition::documents_batch_transition::document_transition::token_transfer_transition::TokenTransferTransitionV0;
use crate::state_transition::documents_batch_transition::token_base_transition::token_base_transition_accessors::TokenBaseTransitionAccessors;
use crate::state_transition::documents_batch_transition::token_base_transition::TokenBaseTransition;
Expand All @@ -22,10 +20,10 @@ impl TokenBaseTransitionAccessors for TokenTransferTransitionV0 {

pub trait TokenTransferTransitionV0Methods: TokenBaseTransitionAccessors {
/// Returns a reference to the `revision` field of the `DocumentReplaceTransitionV0`.
fn revision(&self) -> Revision;
fn amount(&self) -> u64;

/// Sets the value of the `revision` field in the `DocumentReplaceTransitionV0`.
fn set_revision(&mut self, revision: Revision);
fn set_amount(&mut self, amount: u64);

/// Returns the `recipient_owner_id` field of the `DocumentReplaceTransitionV0`.
fn recipient_owner_id(&self) -> Identifier;
Expand All @@ -38,12 +36,12 @@ pub trait TokenTransferTransitionV0Methods: TokenBaseTransitionAccessors {
}

impl TokenTransferTransitionV0Methods for TokenTransferTransitionV0 {
fn revision(&self) -> Revision {
self.revision
fn amount(&self) -> u64 {
self.amount
}

fn set_revision(&mut self, revision: Revision) {
self.revision = revision;
fn set_amount(&mut self, amount: u64) {
self.amount = amount;
}

fn recipient_owner_id(&self) -> Identifier {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ impl TokenBaseTransitionAccessors for TokenTransferTransition {
}

impl TokenTransferTransitionV0Methods for TokenTransferTransition {
fn revision(&self) -> Revision {
fn amount(&self) -> u64 {
match self {
TokenTransferTransition::V0(v0) => v0.revision,
TokenTransferTransition::V0(v0) => v0.amount,
}
}

fn set_revision(&mut self, revision: Revision) {
fn set_amount(&mut self, amount: u64) {
match self {
TokenTransferTransition::V0(v0) => v0.revision = revision,
TokenTransferTransition::V0(v0) => v0.amount = amount,
}
}

Expand Down
Loading

0 comments on commit 279d16f

Please sign in to comment.