Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/dapi-grpc/protos/platform/v0/platform.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,8 @@ message GetGroupActionsResponse {
// Burn event
message BurnEvent {
uint64 amount = 1; // Amount to burn
optional string public_note = 2; // Public note
bytes burn_from_id = 2; // The identifier to burn from
optional string public_note = 3; // Public note
}

// Freeze event
Expand Down
8 changes: 8 additions & 0 deletions packages/rs-dpp/src/group/group_action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub enum GroupAction {

pub trait GroupActionAccessors {
fn contract_id(&self) -> Identifier;

fn proposer_id(&self) -> Identifier;
fn token_contract_position(&self) -> TokenContractPosition;
fn event(&self) -> &GroupActionEvent;
}
Expand All @@ -28,6 +30,12 @@ impl GroupActionAccessors for GroupAction {
}
}

fn proposer_id(&self) -> Identifier {
match self {
GroupAction::V0(inner) => inner.proposer_id(),
}
}

fn token_contract_position(&self) -> TokenContractPosition {
match self {
GroupAction::V0(inner) => inner.token_contract_position(),
Expand Down
5 changes: 5 additions & 0 deletions packages/rs-dpp/src/group/group_action/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use platform_value::Identifier;
#[platform_serialize(unversioned)] //versioned directly, no need to use platform_version
pub struct GroupActionV0 {
pub contract_id: Identifier,
pub proposer_id: Identifier,
pub token_contract_position: TokenContractPosition,
pub event: GroupActionEvent,
}
Expand All @@ -21,6 +22,10 @@ impl GroupActionAccessors for GroupActionV0 {
self.contract_id
}

fn proposer_id(&self) -> Identifier {
self.proposer_id
}

fn token_contract_position(&self) -> TokenContractPosition {
self.token_contract_position
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,9 @@ impl TokenTransitionV0Methods for TokenTransition {
) -> Result<TokenEvent, ProtocolError> {
Ok(match self {
TokenTransition::Burn(burn) => {
TokenEvent::Burn(burn.burn_amount(), burn.public_note().cloned())
// The owner id might be incorrect when doing group actions
// However it will be fixed in verify_state_transition was executed area.
TokenEvent::Burn(burn.burn_amount(), owner_id, burn.public_note().cloned())
}
TokenTransition::Mint(mint) => {
let recipient = match mint.issued_to_identity_id() {
Expand Down
21 changes: 16 additions & 5 deletions packages/rs-dpp/src/tokens/token_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ use crate::ProtocolError;
/// Alias representing the identity that will receive tokens or other effects from a token operation.
pub type RecipientIdentifier = Identifier;

/// Alias representing the identity that will have tokens burned from their account.
pub type BurnFromIdentifier = Identifier;

/// Alias representing the identity performing a token purchase.
pub type PurchaserIdentifier = Identifier;

Expand Down Expand Up @@ -65,8 +68,9 @@ pub enum TokenEvent {
/// Event representing the burning of tokens, removing them from circulation.
///
/// - `TokenAmount`: The amount of tokens burned.
/// - `BurnFromIdentifier`: The account to burn from.
/// - `TokenEventPublicNote`: Optional note associated with the event.
Burn(TokenAmount, TokenEventPublicNote),
Burn(TokenAmount, BurnFromIdentifier, TokenEventPublicNote),

/// Event representing freezing of tokens for a specific identity.
///
Expand Down Expand Up @@ -144,8 +148,14 @@ impl fmt::Display for TokenEvent {
TokenEvent::Mint(amount, recipient, note) => {
write!(f, "Mint {} to {}{}", amount, recipient, format_note(note))
}
TokenEvent::Burn(amount, note) => {
write!(f, "Burn {}{}", amount, format_note(note))
TokenEvent::Burn(amount, burn_from_identifier, note) => {
write!(
f,
"Burn {} from {}{}",
amount,
burn_from_identifier,
format_note(note)
)
}
TokenEvent::Freeze(identity, note) => {
write!(f, "Freeze {}{}", identity, format_note(note))
Expand Down Expand Up @@ -219,7 +229,7 @@ impl TokenEvent {
pub fn public_note(&self) -> Option<&str> {
match self {
TokenEvent::Mint(_, _, Some(note))
| TokenEvent::Burn(_, Some(note))
| TokenEvent::Burn(_, _, Some(note))
| TokenEvent::Freeze(_, Some(note))
| TokenEvent::Unfreeze(_, Some(note))
| TokenEvent::DestroyFrozenFunds(_, _, Some(note))
Expand Down Expand Up @@ -266,9 +276,10 @@ impl TokenEvent {
}
properties
}
TokenEvent::Burn(burn_amount, public_note) => {
TokenEvent::Burn(burn_amount, burn_from_identifier, public_note) => {
let mut properties = BTreeMap::from([
("tokenId".to_string(), token_id.into()),
("burnFromId".to_string(), burn_from_identifier.into()),
("amount".to_string(), burn_amount.into()),
]);
if let Some(note) = public_note {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ impl<C> Platform<C> {
let action_id = Identifier::new([32; 32]);
let group_action = GroupAction::V0(GroupActionV0 {
contract_id: DATA_CONTRACT_ID,
proposer_id: IDENTITY_ID_1,
token_contract_position: 2,
event: GroupActionEvent::TokenEvent(TokenEvent::Burn(10, Some("world on fire".into()))),
event: GroupActionEvent::TokenEvent(TokenEvent::Burn(
10,
IDENTITY_ID_1,
Some("world on fire".into()),
)),
});

self.drive.add_group_action(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl TokenBurnTransitionActionStateValidationV0 for TokenBurnTransitionAction {
}

if let Some(original_group_action) = self.base().original_group_action() {
if let GroupActionEvent::TokenEvent(TokenEvent::Burn(old_group_action_amount, _)) =
if let GroupActionEvent::TokenEvent(TokenEvent::Burn(old_group_action_amount, _, _)) =
original_group_action.event()
{
if old_group_action_amount != &self.burn_amount() {
Expand Down Expand Up @@ -111,7 +111,7 @@ impl TokenBurnTransitionActionStateValidationV0 for TokenBurnTransitionAction {
.drive
.fetch_identity_token_balance(
self.token_id().to_buffer(),
owner_id.to_buffer(),
self.burn_from_identifier().to_buffer(),
transaction,
platform_version,
)?
Expand All @@ -123,7 +123,7 @@ impl TokenBurnTransitionActionStateValidationV0 for TokenBurnTransitionAction {
ConsensusError::StateError(StateError::IdentityDoesNotHaveEnoughTokenBalanceError(
IdentityDoesNotHaveEnoughTokenBalanceError::new(
self.token_id(),
owner_id,
self.burn_from_identifier(),
self.burn_amount(),
balance,
"burn".to_string(),
Expand Down
Loading