You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is a proposal to include an approval mechanism to ARC-0721 the same vein as ARC-0020 #42.
It also introduces a different way to handle settings and collection ownership.
program nft.aleo;
record Token:
owner as address.private;
data as Data.private;
edition as scalar.private;
struct Data:
data0 as u128;
data1 as u128;
data2 as u128;
data3 as u128;
struct Settings:
royalty_fees as u64;
royalty_address as address;
metadata_uri as Data;
base_uri as Data;
publicizable as boolean;
updatable as boolean;
owner_address as address;
struct Approval:
approver as address;
spender as address;
mapping for_all_approvals:
key as field.public;
value as bool.public;
mapping token_approvals:
key as field.public;
value as address.public;
mapping token_owners:
key as field.public;
value as address.public;
mapping balances:
key as field.public;
value as u128.public;
mapping settings:
key as bool.public;
value as Settings.public;
function set_approval_for_all:
input r0 as address.public; // spender
input r1 as bool.public; // new approval status
cast self.caller r0 into r2 as Approval;
hash.bhp256 r2 into r3 as field;
async set_approval_for_all r3 r1 into r4;
output r4 as nft.aleo/set_approval_for_all.future;
finalize set_approval_for_all:
input r0 as field.public;
input r1 as bool.public;
set r1 into for_all_approvals[r0];
function approve:
input r0 as address.public; // spender
input r1 as field.public; // token hash
async approve r0 r1 into r2;
output r2 as nft.aleo/approve.future;
finalize approve:
input r0 as address.public;
input r1 as field.public;
get token_owners[r1] into r2;
assert.eq self.caller r2;
set r0 into token_approvals[field];
/* Getters */
function assert_approved:
input r0 as address.public; // spender
input r1 as field.public; // token hash
async assert_approved r0 r1 into r2;
output r2 as nft.aleo/assert_approved.future;
finalize assert_approved:
input r0 as address.public;
input r1 as field.public;
get token_approvals[r1] into r2;
assert.eq r2 r0;
function assert_balance:
input r0 as address.public; // owner
input r1 as 128.public; // balance
async assert_balance r0 r1 into r2;
output r2 as nft.aleo/assert_balance.future;
finalize assert_balance:
input r0 as address.public;
input r1 as 128.public;
get balances[r0] into r2;
assert.eq r2 r1;
function assert_owner:
input r0 as address.public; // spender
input r1 as field.public; // token hash
async assert_owner r0 r1 into r2;
output r2 as nft.aleo/assert_owner.future;
finalize assert_owner:
input r0 as address.public;
input r1 as field.public;
get token_owners[r1] into r2;
assert.eq r2 r0;
function assert_approved_for_all:
input r0 as address.public; // approver
input r1 as address.public; // spender
cast r0 r1 into r2 as Approval;
hash.bhp256 r2 into r3 as field;
async assert_approved_for_all r3 into r4;
output r4 as nft.aleo/assert_approved_for_all.future;
finalize assert_approved_for_all:
input r0 as field.public;
get for_all_approvals[r0] into r1;
assert.eq r1 true;
function transfer_from_public:
input r0 as address.public; // from the approver
input r1 as address.public; // to the receiver
input r2 as field.public; // token to transfer
cast r0 self.caller into r3 as Approval;
hash.bhp256 r3 into r4 as field; // hash approval
async transfer_from_public r4 r0 r1 r2 into r5;
output r5 as nft.aleo/transfer_from_public.future;
finalize transfer_from_public:
input r0 as field.public; // approval
input r1 as address.public; // from the approver
input r2 as address.public; // to the receiver
input r3 as field.public; // token to transfer
get.or_use for_all_approvals[r0] false into r4;
set false into for_all_approvals[r0];
get.or_use token_approvals[r3] aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc into r5;
remove token_approvals[r3];
is.eq self.caller r5 into r6;
or r4 r5 into r7;
assert.eq r7 true;
get token_owners[r3] into r8;
assert.eq r8 r1;
set r2 into token_owners[r3];
function transfer_public:
input r0 as address.public; // to the receiver
input r1 as field.public; // token to transfer
async transfer_public self.caller r0 r1 into r2;
output r2 as nft.aleo/transfer_public.future;
finalize transfer_public:
input r0 as address.public; // sender
input r1 as address.public; // to the receiver
input r2 as field.public; // token to transfer
remove token_approvals[r2];
get token_owners[r2] into r3;
assert.eq r3 r0;
set r1 into token_owners[r2];
function transfer_private:
input r0 as Token.record;
input r1 as address.private;
cast r1 r0.data r0.edition into r2 as Token.record;
output r2 as Token.record;
function transfer_private_to_public:
input r0 as Token.record;
input r1 as address.public;
hash.bhp256 r0.data into r2 as field;
commit.bhp256 r2 r0.edition into r3 as field;
async transfer_private_to_public r1 r3 into r4;
output r4 as nft.aleo/transfer_private_to_public.future;
finalize transfer_private_to_public:
input r0 as address.public;
input r1 as field.public;
set r0 into account[r1];
function transfer_public_to_private:
input r0 as address.public; // to the receiver
input r1 as Data.private; // data
input r2 as scalar.private; // edition
hash.bhp256 r1 into r3 as field;
commit.bhp256 r3 r2 into r4 as field;
cast r0 r1 r2 into r5 as Token.record;
async transfer_public_to_private self.caller r4 into r6;
output r5 as Token.record;
output r6 as nft.aleo/transfer_public_to_private.future;
finalize transfer_public_to_private:
input r0 as address.public;
input r1 as field.public;
remove token_approvals[r1];
get token_owners[r1] into r2;
assert.eq r2 r0;
remove token_owners[r1];
function set_settings:
input r0 as Settings.public; // settings
async set_settings r0 into r2;
output r2 as nft.aleo/set_settings.future;
finalize set_settings:
input r0 as Settings.public;
cast 0u128 0u128 0u128 0u128 into r1 as Data;
cast
0u64
aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc
r1
r1
false
true
aleo1wamjqlka7d0gazlxdys6n8e8zeee3ymedwvw8elvh7529kwd45rq0plgax // Replace with initial owner
into r2 as Settings;
get.or_use settings[true] r2 into r3 as Settings;
assert.eq r3.owner_address self.caller;
assert.eq r3.updatable true;
set r0 into settings[true];
function assert_settings:
input r0 as Settings.public;
async assert_settings r0 into r1;
output r1 as nft.aleo/assert_settings.future;
finalize assert_settings:
input r0 as Settings.public;
get settings[true] into r1 as Settings;
assert.eq r0 r1;
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Here is a proposal to include an approval mechanism to ARC-0721 the same vein as ARC-0020 #42.
It also introduces a different way to handle settings and collection ownership.
Beta Was this translation helpful? Give feedback.
All reactions