Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: api events #153

Merged
merged 66 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
360bb2a
feat: pop api fungibles pallet
Daanvdplas Jul 19, 2024
e097f80
refactor: comments
Daanvdplas Jul 20, 2024
c8d8b2a
refactor: rebase main, refactor extension with enums
evilrobot-01 Jul 20, 2024
c88387d
refactor
Daanvdplas Jul 21, 2024
224390a
refactor 2
Daanvdplas Jul 22, 2024
43ae445
feat: add fungibles pallet functions
Daanvdplas Jul 22, 2024
bbe01a1
tests: remove transfer_from (transfer copy) and add approve
Daanvdplas Jul 22, 2024
68264da
refactor: primitives
Daanvdplas Jul 22, 2024
2481773
fix: pallet api error + missing docs
Daanvdplas Jul 22, 2024
c10a8d4
fix: integration test after removal fungibles feature primitives
Daanvdplas Jul 22, 2024
a8c4bb5
chore: benchmark approve
Daanvdplas Jul 23, 2024
4419bad
refactor: pallet
Daanvdplas Jul 24, 2024
792fa07
refactor: integration-tests
Daanvdplas Jul 24, 2024
96da2f0
refactor: ink api library
Daanvdplas Jul 24, 2024
cb54a57
refactor: devnet runtime
Daanvdplas Jul 24, 2024
9ec2744
chore: benchmark fungibles approve
Daanvdplas Jul 24, 2024
f0fff97
test: ensure Lookup configuration
Daanvdplas Jul 24, 2024
4a476b0
fix: approve benchmark + weights
Daanvdplas Jul 24, 2024
f3cc83a
refactor: primitives
Daanvdplas Jul 25, 2024
bd85489
refactor: bits and pieces
Daanvdplas Jul 25, 2024
0e49f63
fix: test devnet
Daanvdplas Jul 25, 2024
8f6139c
refactor: apply final comments
Daanvdplas Jul 25, 2024
948e144
chore: benchmark approve
Daanvdplas Jul 23, 2024
88577e4
refactor: read state
Daanvdplas Jul 23, 2024
809e192
refactor: add state query filter
Daanvdplas Jul 23, 2024
ac9714c
fix: test UnknownCall
Daanvdplas Jul 23, 2024
77711ec
refactor: read state functions
Daanvdplas Jul 25, 2024
b50830c
refactor: enums
Daanvdplas Jul 25, 2024
2a8800c
refactor: style docs and using constants for errors in chain extension
Daanvdplas Jul 26, 2024
b93f009
refactor: api integration tests
Daanvdplas Jul 26, 2024
b639e8b
refactor: IT better error handling
Daanvdplas Jul 26, 2024
074b8cf
merge daan/api
Daanvdplas Jul 28, 2024
f72b15a
feat: create & set_metadata
Daanvdplas Jul 30, 2024
7739392
feat: rest of asset management
Daanvdplas Jul 30, 2024
d4f7f99
style: pub function docs
Daanvdplas Jul 30, 2024
6f4da18
fix: remove unnecessary api functions
Daanvdplas Jul 30, 2024
5aec185
merge daan/api
Daanvdplas Jul 31, 2024
602b8bf
merge refactor: integration tests error handling
Daanvdplas Jul 31, 2024
51c38cc
refactor: match statement
Daanvdplas Jul 31, 2024
6084f89
feat: burn and mint
Daanvdplas Jul 31, 2024
406063c
Merge branch 'daan/fix-read_state_error_handling' into daan/feat-asse…
Daanvdplas Jul 31, 2024
584b9c6
feat: create asset in constructor
Daanvdplas Jul 31, 2024
772514c
refactor: IT create token in constructor
Daanvdplas Jul 31, 2024
b164998
merge asset management
Daanvdplas Jul 31, 2024
12e1cf9
test: remove commented out test
Daanvdplas Jul 31, 2024
68ec059
fix: test
Daanvdplas Jul 31, 2024
0311d9a
draft api events
Daanvdplas Jul 31, 2024
95bf679
merge daan/api
Daanvdplas Aug 6, 2024
3a777d5
feat: events to all features + tests
Daanvdplas Aug 6, 2024
bc8181c
feat (api): events fungibles
Daanvdplas Aug 6, 2024
6b10f2a
fix: compilation
Daanvdplas Aug 7, 2024
626b3eb
fix: weight increase_allowance
Daanvdplas Aug 7, 2024
7c0b3fd
refactor: remove duplicated events
Daanvdplas Aug 12, 2024
9862e19
refactor: ink topics + docs to contract events
Daanvdplas Aug 12, 2024
28977a0
fix: incompatible event based on standard
Daanvdplas Aug 12, 2024
9ea2488
refactor: optimization pallet fungibles
Daanvdplas Aug 12, 2024
0904910
fix: weight increase_allowance
Daanvdplas Aug 12, 2024
ea2b461
docs: events contracts
Daanvdplas Aug 12, 2024
5093e88
refactor: remove unnecessary event topic
Daanvdplas Aug 13, 2024
24aa42d
Merge branch 'daan/api' into daan/feat-api_events
Daanvdplas Aug 13, 2024
1d283fd
Merge branch 'daan/api' into daan/feat-api_events
Daanvdplas Aug 13, 2024
221f63d
Merge branch 'daan/api' into daan/feat-api_events
Daanvdplas Aug 13, 2024
3848faa
fix: add asset ID to event
Daanvdplas Aug 13, 2024
6a9cd00
feat: add Create event
Daanvdplas Aug 14, 2024
3b3ae9f
refactor: fungible pallet
Daanvdplas Aug 14, 2024
fa7d258
refactor: consistency
Daanvdplas Aug 14, 2024
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
29 changes: 23 additions & 6 deletions pallets/api/src/fungibles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ pub mod pallet {
/// Amount of tokens transferred (or minted/burned).
value: BalanceOf<T>,
},
/// Event emitted when a token class is created.
Create {
Daanvdplas marked this conversation as resolved.
Show resolved Hide resolved
/// The ID of the asset.
id: AssetIdOf<T>,
/// Creator of the asset.
creator: AccountIdOf<T>,
/// Admin of the asset.
admin: AccountIdOf<T>,
},
}

#[pallet::call]
Expand Down Expand Up @@ -197,7 +206,7 @@ pub mod pallet {
.map_err(|e| e.with_weight(Self::weight_approve(0, 0)))?;
let current_allowance = AssetsOf::<T>::allowance(id.clone(), &owner, &spender);

let return_weight = match value.cmp(&current_allowance) {
let weight = match value.cmp(&current_allowance) {
// If the new value is equal to the current allowance, do nothing.
Equal => Self::weight_approve(0, 0),
// If the new value is greater than the current allowance, approve the difference
Expand Down Expand Up @@ -232,7 +241,7 @@ pub mod pallet {
},
};
Self::deposit_event(Event::Approval { id, owner, spender, value });
Ok(Some(return_weight).into())
Ok(Some(weight).into())
}

/// Increases the allowance of a spender.
Expand Down Expand Up @@ -279,13 +288,13 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
let owner = ensure_signed(origin.clone())
.map_err(|e| e.with_weight(Self::weight_approve(0, 0)))?;
if value.is_zero() {
return Ok(Some(Self::weight_approve(0, 0)).into());
}
let current_allowance = AssetsOf::<T>::allowance(id.clone(), &owner, &spender);
let spender_source = T::Lookup::unlookup(spender.clone());
let id_param: AssetIdParameterOf<T> = id.clone().into();

if value.is_zero() {
return Ok(Some(Self::weight_approve(0, 0)).into());
}
// Cancel the approval and set the new value if `new_allowance` is more than zero.
AssetsOf::<T>::cancel_approval(
origin.clone(),
Expand Down Expand Up @@ -318,7 +327,15 @@ pub mod pallet {
admin: AccountIdOf<T>,
min_balance: BalanceOf<T>,
) -> DispatchResult {
AssetsOf::<T>::create(origin, id.into(), T::Lookup::unlookup(admin), min_balance)
AssetsOf::<T>::create(
origin.clone(),
id.clone().into(),
T::Lookup::unlookup(admin.clone()),
min_balance,
)?;
let creator = ensure_signed(origin)?;
evilrobot-01 marked this conversation as resolved.
Show resolved Hide resolved
Self::deposit_event(Event::Create { id, creator, admin });
Ok(())
}

/// Start the process of destroying a token with a given asset ID.
Expand Down
12 changes: 8 additions & 4 deletions pallets/api/src/fungibles/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{fungibles::Read::*, mock::*};
use codec::Encode;
use frame_support::{
assert_ok,
sp_runtime::traits::Zero,
traits::fungibles::{
approvals::Inspect as ApprovalInspect, metadata::Inspect as MetadataInspect, Inspect,
},
Expand Down Expand Up @@ -132,10 +133,13 @@ fn decrease_allowance_works() {
fn create_works() {
new_test_ext().execute_with(|| {
let id = ASSET;
let creator = ALICE;
let admin = ALICE;

assert!(!Assets::asset_exists(id));
assert_ok!(Fungibles::create(signed(ALICE), id, ALICE, 100));
assert_ok!(Fungibles::create(signed(creator), id, admin, 100));
assert!(Assets::asset_exists(id));
System::assert_last_event(Event::Create { id, creator, admin }.into());
});
}

Expand Down Expand Up @@ -178,9 +182,9 @@ fn clear_metadata_works() {

create_asset_and_set_metadata(ALICE, id, vec![42], vec![42], 42);
assert_ok!(Fungibles::clear_metadata(signed(ALICE), id));
assert_eq!(Assets::name(id), Vec::<u8>::new());
assert_eq!(Assets::symbol(id), Vec::<u8>::new());
assert_eq!(Assets::decimals(id), 0u8);
assert!(Assets::name(id).is_empty());
assert!(Assets::symbol(id).is_empty());
assert!(Assets::decimals(id).is_zero());
});
}

Expand Down
Loading