Skip to content

Commit f1fc3bc

Browse files
committed
standards: add DRC721 primitive and reference
1 parent f0d65b5 commit f1fc3bc

11 files changed

Lines changed: 1573 additions & 1 deletion

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
STANDARDS_EXAMPLES := standards/examples/drc20_roles_pausable standards/examples/multisig_controller
1+
STANDARDS_EXAMPLES := standards/examples/drc20_roles_pausable standards/examples/drc721_collection standards/examples/multisig_controller
22
STANDARDS_WASM_CONTRACTS := $(STANDARDS_EXAMPLES)
33
LEGACY_SUBDIRS := tests/alice tests/bob tests/charlie genesis/transfer genesis/stake tests/host_fn
44
STANDARDS_PROPTEST_CASES ?= 8192

standards/Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

standards/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
members = [
33
"dusk-contract-standards",
44
"examples/drc20_roles_pausable",
5+
"examples/drc721_collection",
56
"examples/multisig_controller",
67
]
78

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
//
5+
// Copyright (c) DUSK NETWORK. All rights reserved.
6+
7+
//! DRC721 event payloads.
8+
9+
use bytecheck::CheckBytes;
10+
use rkyv::{Archive, Deserialize, Serialize};
11+
12+
use crate::core::Principal;
13+
14+
/// Transfer event topic.
15+
pub const TRANSFER_TOPIC: &str = "drc721/transfer";
16+
/// Approval event topic.
17+
pub const APPROVAL_TOPIC: &str = "drc721/approval";
18+
/// Approval-for-all event topic.
19+
pub const APPROVAL_FOR_ALL_TOPIC: &str = "drc721/approval_for_all";
20+
/// Default royalty set event topic.
21+
pub const DEFAULT_ROYALTY_SET_TOPIC: &str = "drc721/default_royalty_set";
22+
/// Default royalty cleared event topic.
23+
pub const DEFAULT_ROYALTY_CLEARED_TOPIC: &str =
24+
"drc721/default_royalty_cleared";
25+
/// Token royalty set event topic.
26+
pub const TOKEN_ROYALTY_SET_TOPIC: &str = "drc721/token_royalty_set";
27+
/// Token royalty cleared event topic.
28+
pub const TOKEN_ROYALTY_CLEARED_TOPIC: &str = "drc721/token_royalty_cleared";
29+
30+
/// Transfer event.
31+
#[derive(
32+
Archive, Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq,
33+
)]
34+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
35+
#[archive_attr(derive(CheckBytes))]
36+
pub struct Transfer {
37+
/// Sender.
38+
pub from: Principal,
39+
/// Recipient.
40+
pub to: Principal,
41+
/// Token id.
42+
pub token_id: u64,
43+
}
44+
45+
/// Approval event.
46+
#[derive(
47+
Archive, Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq,
48+
)]
49+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
50+
#[archive_attr(derive(CheckBytes))]
51+
pub struct Approval {
52+
/// Owner.
53+
pub owner: Principal,
54+
/// Approved account.
55+
pub approved: Principal,
56+
/// Token id.
57+
pub token_id: u64,
58+
}
59+
60+
/// Approval-for-all event.
61+
#[derive(
62+
Archive, Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq,
63+
)]
64+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
65+
#[archive_attr(derive(CheckBytes))]
66+
pub struct ApprovalForAll {
67+
/// Owner.
68+
pub owner: Principal,
69+
/// Operator.
70+
pub operator: Principal,
71+
/// Approval.
72+
pub approved: bool,
73+
}
74+
75+
/// Default royalty set event.
76+
#[derive(
77+
Archive, Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq,
78+
)]
79+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
80+
#[archive_attr(derive(CheckBytes))]
81+
pub struct DefaultRoyaltySet {
82+
/// Principal that authorized the royalty change.
83+
pub operator: Principal,
84+
/// Royalty receiver.
85+
pub receiver: Principal,
86+
/// Royalty basis points.
87+
pub basis_points: u16,
88+
}
89+
90+
/// Default royalty cleared event.
91+
#[derive(
92+
Archive, Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq,
93+
)]
94+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
95+
#[archive_attr(derive(CheckBytes))]
96+
pub struct DefaultRoyaltyCleared {
97+
/// Principal that authorized the royalty change.
98+
pub operator: Principal,
99+
}
100+
101+
/// Token royalty set event.
102+
#[derive(
103+
Archive, Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq,
104+
)]
105+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
106+
#[archive_attr(derive(CheckBytes))]
107+
pub struct TokenRoyaltySet {
108+
/// Principal that authorized the royalty change.
109+
pub operator: Principal,
110+
/// Token id.
111+
pub token_id: u64,
112+
/// Royalty receiver.
113+
pub receiver: Principal,
114+
/// Royalty basis points.
115+
pub basis_points: u16,
116+
}
117+
118+
/// Token royalty cleared event.
119+
#[derive(
120+
Archive, Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq,
121+
)]
122+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
123+
#[archive_attr(derive(CheckBytes))]
124+
pub struct TokenRoyaltyCleared {
125+
/// Principal that authorized the royalty change.
126+
pub operator: Principal,
127+
/// Token id.
128+
pub token_id: u64,
129+
}
130+
131+
impl dusk_forge::ContractEvent for Transfer {
132+
const TOPICS: &'static [&'static str] = &[TRANSFER_TOPIC];
133+
}
134+
135+
impl dusk_forge::ContractEvent for Approval {
136+
const TOPICS: &'static [&'static str] = &[APPROVAL_TOPIC];
137+
}
138+
139+
impl dusk_forge::ContractEvent for ApprovalForAll {
140+
const TOPICS: &'static [&'static str] = &[APPROVAL_FOR_ALL_TOPIC];
141+
}
142+
143+
impl dusk_forge::ContractEvent for DefaultRoyaltySet {
144+
const TOPICS: &'static [&'static str] = &[DEFAULT_ROYALTY_SET_TOPIC];
145+
}
146+
147+
impl dusk_forge::ContractEvent for DefaultRoyaltyCleared {
148+
const TOPICS: &'static [&'static str] = &[DEFAULT_ROYALTY_CLEARED_TOPIC];
149+
}
150+
151+
impl dusk_forge::ContractEvent for TokenRoyaltySet {
152+
const TOPICS: &'static [&'static str] = &[TOKEN_ROYALTY_SET_TOPIC];
153+
}
154+
155+
impl dusk_forge::ContractEvent for TokenRoyaltyCleared {
156+
const TOPICS: &'static [&'static str] = &[TOKEN_ROYALTY_CLEARED_TOPIC];
157+
}

0 commit comments

Comments
 (0)