Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
8a0bc02
create mock and testing
asiniscalchi Aug 1, 2023
0fe9a63
first test
asiniscalchi Aug 1, 2023
7ebabef
testing ethereum reserved addresses
asiniscalchi Aug 1, 2023
e964668
refactoring
asiniscalchi Aug 1, 2023
aba874e
refactoring
asiniscalchi Aug 1, 2023
80dd172
refactoring tests
asiniscalchi Aug 1, 2023
9604f6c
fmt
asiniscalchi Aug 1, 2023
390359b
erc721 starting point
asiniscalchi Aug 3, 2023
64c449a
Merge branch 'dev' into feature/precompile_erc_721
asiniscalchi Aug 3, 2023
5dafd9f
fmt
asiniscalchi Aug 3, 2023
e92faae
Merge branch 'dev' into feature/precompile_erc_721
asiniscalchi Aug 3, 2023
21d6842
Merge branch 'feature/solidity_create_collection_return_an_address' i…
asiniscalchi Aug 4, 2023
e06adce
compiling
asiniscalchi Aug 4, 2023
3869690
check selectors
asiniscalchi Aug 4, 2023
d514f88
create trait Erc721
asiniscalchi Aug 4, 2023
2efff92
Erc721Precompile
asiniscalchi Aug 4, 2023
0357938
set mocks
asiniscalchi Aug 4, 2023
cec3cbf
first implermentation
asiniscalchi Aug 4, 2023
b0c10ce
first integration of erc721 in the runtime
asiniscalchi Aug 4, 2023
1420c21
fmt
asiniscalchi Aug 4, 2023
d0c4ce7
check on the collection id
asiniscalchi Aug 4, 2023
aa84dde
test on extract owner form asset_id
asiniscalchi Aug 4, 2023
7e49dae
Merge branch 'dev' into feature/precompile_erc_721
asiniscalchi Aug 5, 2023
0ec72a7
fix tests
asiniscalchi Aug 5, 2023
9be1a5b
test for erc721 trait
asiniscalchi Aug 5, 2023
2427e0d
Merge branch 'feature/precompile_erc_721' into feature/testing_precom…
asiniscalchi Aug 5, 2023
4625aad
fix compilation
asiniscalchi Aug 5, 2023
d858bf0
refactoring
asiniscalchi Aug 5, 2023
6c65ddd
returning address
asiniscalchi Aug 6, 2023
1c9e12a
return value is correctly encoded as a n Address
asiniscalchi Aug 7, 2023
c7ec2ee
Merge branch 'bug/create_collection_logs' into feature/precompile_erc…
asiniscalchi Aug 7, 2023
c39efbd
Merge branch 'feature/testing_precompiles' into feature/precompile_er…
asiniscalchi Aug 7, 2023
9dc0c14
is_erc721_contract is not member of PrecompoileSet
asiniscalchi Aug 7, 2023
b9bba2d
test on precompiled contracts
asiniscalchi Aug 7, 2023
a39432c
erc721 returns hardcoded address
asiniscalchi Aug 7, 2023
c4cd42f
refactoring
asiniscalchi Aug 7, 2023
89af0a0
testing return of asset ownership
asiniscalchi Aug 7, 2023
c6c7810
fix errors
asiniscalchi Aug 7, 2023
5cfb2b5
remove unused use
asiniscalchi Aug 7, 2023
874d2f6
create collection got an uri
asiniscalchi Aug 7, 2023
fa612ab
Merge branch 'dev' into feature/precompile_erc_721
asiniscalchi Aug 7, 2023
d3add5c
Merge branch 'dev' into feature/precompile_erc_721_token_uri
asiniscalchi Aug 7, 2023
0568c47
refactoring
asiniscalchi Aug 7, 2023
b31f1db
rewriting testing mod
asiniscalchi Aug 7, 2023
9a4f100
refactoring
asiniscalchi Aug 7, 2023
09738af
moving check for cllection address in pallet
asiniscalchi Aug 8, 2023
daf2910
collection address prefix changed
asiniscalchi Aug 8, 2023
bd47de2
test passing
asiniscalchi Aug 8, 2023
907ca7e
test passing
asiniscalchi Aug 8, 2023
10557aa
refactoring tests
asiniscalchi Aug 8, 2023
6d38abe
do not panic the runtime
asiniscalchi Aug 8, 2023
daef051
fmt
asiniscalchi Aug 8, 2023
f71eef7
solidity tokenId -> _tokenId
asiniscalchi Aug 8, 2023
15123db
erc721 functions are views
asiniscalchi Aug 8, 2023
4b0ec80
update docs
asiniscalchi Aug 8, 2023
df59324
sp-core in std , removed duplicate function
asiniscalchi Aug 8, 2023
2fbd144
documentaetion
asiniscalchi Aug 8, 2023
96d7374
using compilator type ifer
asiniscalchi Aug 8, 2023
5bf67b0
compiler infer the size of the array
asiniscalchi Aug 8, 2023
2bf2171
added to std feature
asiniscalchi Aug 8, 2023
9e1bf8d
rename variable
asiniscalchi Aug 8, 2023
bee4806
trait documentation
asiniscalchi Aug 8, 2023
7a25ce8
Merge branch 'dev' into refactoring/missing_from_precompile_erc_721
asiniscalchi Aug 9, 2023
874bfae
using pallet errors
asiniscalchi Aug 10, 2023
1322a4f
Erc721Error created
asiniscalchi Aug 10, 2023
1679acb
Erc721Error fix compilation
asiniscalchi Aug 10, 2023
e8e789f
tests green
asiniscalchi Aug 10, 2023
a2763f7
revise docuemntation
asiniscalchi Aug 10, 2023
1f3bf0c
Merge branch 'feature/using_proper_errors' into feature/precompile_er…
asiniscalchi Aug 10, 2023
3308324
fmt
asiniscalchi Aug 10, 2023
790361e
better name of constant
asiniscalchi Aug 10, 2023
dc4f211
create collection has param uri
asiniscalchi Aug 10, 2023
cc5bfdb
Merge branch 'dev' into feature/precompile_erc_721_token_uri
asiniscalchi Aug 11, 2023
2ddf57d
remove unused error
asiniscalchi Aug 11, 2023
4ef9e9c
using sp-std
asiniscalchi Aug 11, 2023
746fed6
using sp-std
asiniscalchi Aug 11, 2023
b0738dd
created CollectionBaseURI
asiniscalchi Aug 11, 2023
053a1ea
created CollectionBaseURI
asiniscalchi Aug 11, 2023
3007682
BaseURILimit is defined
asiniscalchi Aug 11, 2023
d817778
insering the base uri
asiniscalchi Aug 11, 2023
95dac77
insering the base uri
asiniscalchi Aug 11, 2023
d05b7b2
base_uri is set in storage
asiniscalchi Aug 11, 2023
f0dec74
create_collection trait has base_uri as param
asiniscalchi Aug 11, 2023
2a074d0
living_assets_ownership pallet tests are green
asiniscalchi Aug 11, 2023
ffa3835
tests passing
asiniscalchi Aug 11, 2023
c155971
test on base_uri too long
asiniscalchi Aug 11, 2023
cb2c18d
removing use
asiniscalchi Aug 11, 2023
4998cce
use Vec
asiniscalchi Aug 11, 2023
51342a0
testing minimum arguments
asiniscalchi Aug 16, 2023
c39d92f
create_collection has a BondedVec tokenURI
asiniscalchi Aug 16, 2023
a9f7053
removed unued error
asiniscalchi Aug 16, 2023
724d571
fix compilation
asiniscalchi Aug 16, 2023
1d3b5bc
refactoring
asiniscalchi Aug 16, 2023
95a3d07
refactoring
asiniscalchi Aug 16, 2023
e69a2b0
removed legacy doc
asiniscalchi Aug 16, 2023
e8fa0af
BaseURILimit type is not public
asiniscalchi Aug 16, 2023
373e1ba
traits have Error assiciated tyope
asiniscalchi Aug 16, 2023
990d44c
more generiuc signature
asiniscalchi Aug 16, 2023
e9d5b1e
fix compilation
asiniscalchi Aug 16, 2023
e76a680
test moved where concreate impl is tested
asiniscalchi Aug 16, 2023
5ac6078
Merge branch 'dev' into feature/precompile_erc_721_token_uri
asiniscalchi Aug 16, 2023
77120b4
removed harcoded buffer from tests
asiniscalchi Aug 17, 2023
01d7687
refactoring
asiniscalchi Aug 17, 2023
2396f85
checking for BaseURI bounds
asiniscalchi Aug 17, 2023
151dd46
CollectionManager has associated type AssetId
asiniscalchi Aug 18, 2023
ed52b66
removed errors per trait (#128)
asiniscalchi Aug 18, 2023
f49f1f1
trait has BaseURI associated type
asiniscalchi Aug 18, 2023
f41f219
fix compoilation
asiniscalchi Aug 18, 2023
08f9b55
BaseURILimit is int pallet::Config trait
asiniscalchi Aug 18, 2023
397197e
fix compoilation
asiniscalchi Aug 18, 2023
78ca240
documentation for the value of BaseURILimit
asiniscalchi Aug 18, 2023
6b4607d
Merge branch 'dev' into feature/precompile_erc_721_token_uri
asiniscalchi Aug 18, 2023
b3cb754
Base_URI is couled to trai Config
asiniscalchi Aug 18, 2023
039a50e
usi max length to 2015
asiniscalchi Aug 18, 2023
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pallets/living-assets-ownership/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
sp-arithmetic = { workspace = true }
sp-core = { workspace = true }
sp-std = { workspace = true }

[dev-dependencies]
serde = { workspace = true }
Expand All @@ -47,6 +48,7 @@ std = [
"frame-system/std",
"sp-arithmetic/std",
"sp-core/std",
"sp-std/std",
]
try-runtime = [
"frame-system/try-runtime",
Expand Down
9 changes: 5 additions & 4 deletions pallets/living-assets-ownership/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ use sp_core::{H160, U256};

impl<T: Config> Pallet<T> {
/// See [Self::create_collection]
pub fn do_create_collection(who: T::AccountId) -> Result<CollectionId, Error<T>> {
pub fn do_create_collection(
who: T::AccountId,
base_uri: BaseURI<T>,
) -> Result<CollectionId, Error<T>> {
// Retrieve the current collection count to use as the new collection's ID
let collection_id = Self::collection_counter();

// Insert a new entry into the OwnerOfCollection map, mapping the new
// collection's ID to the owner's account ID
OwnerOfCollection::<T>::insert(collection_id, &who);
CollectionBaseURI::<T>::insert(collection_id, base_uri);

// Attempt to increment the collection counter by 1. If this operation
// would result in an overflow, return early with an error
Expand Down
83 changes: 54 additions & 29 deletions pallets/living-assets-ownership/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ pub mod pallet {
use crate::functions::convert_asset_id_to_owner;

use super::*;
use frame_support::pallet_prelude::{OptionQuery, ValueQuery, *};
use frame_support::{
pallet_prelude::{OptionQuery, ValueQuery, *},
BoundedVec,
};
use frame_system::pallet_prelude::*;
use sp_core::{H160, U256};

/// Collection id type
/// TODO: use 256 bits
pub type CollectionId = u64;

/// Base URI type
pub type BaseURI<T> = BoundedVec<u8, <T as Config>::BaseURILimit>;

#[pallet::pallet]
pub struct Pallet<T>(_);

Expand All @@ -30,19 +35,30 @@ pub mod pallet {
pub trait Config: frame_system::Config {
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}

/// Mapping from collection id to owner
#[pallet::storage]
#[pallet::getter(fn owner_of_collection)]
pub(super) type OwnerOfCollection<T: Config> =
StorageMap<_, Blake2_128Concat, CollectionId, T::AccountId, OptionQuery>;
/// Specifies the advised maximum length for a Base URI.
//s
/// The URI standard (RFC 3986) doesn't dictates a limit for the length of URIs.
/// However it seems the max supported length in browsers is 2,048 characters.
///
/// The base should be capped at 2,015 characters in length. This ensures room for
/// the token URI formation, where it combines `BaseURILimit`, a `'/'`, and a `tokenID`
/// (which takes up 33 characters).
#[pallet::constant]
type BaseURILimit: Get<u32>;
}

/// Collection counter
#[pallet::storage]
#[pallet::getter(fn collection_counter)]
pub(super) type CollectionCounter<T: Config> = StorageValue<_, CollectionId, ValueQuery>;

/// Collection base URI
#[pallet::storage]
#[pallet::getter(fn collection_base_uri)]
pub(super) type CollectionBaseURI<T: Config> =
StorageMap<_, Blake2_128Concat, CollectionId, BaseURI<T>, OptionQuery>;

/// Pallet events
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
Expand All @@ -54,9 +70,22 @@ pub mod pallet {

// Errors inform users that something went wrong.
#[pallet::error]
#[derive(PartialEq)]
pub enum Error<T> {
/// Collection id overflow
CollectionIdOverflow,
/// Unexistent collection
UnexistentCollection,
}

impl<T: Config> AsRef<[u8]> for Error<T> {
fn as_ref(&self) -> &[u8] {
match self {
Error::__Ignore(_, _) => b"__Ignore",
Error::CollectionIdOverflow => b"CollectionIdOverflow",
Error::UnexistentCollection => b"UnexistentCollection",
}
}
}

// Dispatchable functions allows users to interact with the pallet and invoke state changes.
Expand All @@ -66,44 +95,40 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())] // TODO set proper weight
pub fn create_collection(origin: OriginFor<T>) -> DispatchResult {
pub fn create_collection(origin: OriginFor<T>, base_uri: BaseURI<T>) -> DispatchResult {
let who = ensure_signed(origin)?;

match Self::do_create_collection(who) {
match Self::do_create_collection(who, base_uri) {
Ok(_) => Ok(()),
Err(err) => Err(err.into()),
}
}
}

impl<T: Config> traits::CollectionManager<T::AccountId> for Pallet<T> {
fn owner_of_collection(collection_id: CollectionId) -> Option<T::AccountId> {
OwnerOfCollection::<T>::get(collection_id)
impl<T: Config> traits::CollectionManager for Pallet<T> {
type Error = Error<T>;
type AccountId = T::AccountId;
type BaseURI = BaseURI<T>;

fn base_uri(collection_id: CollectionId) -> Option<Self::BaseURI> {
CollectionBaseURI::<T>::get(collection_id)
}

fn create_collection(
owner: T::AccountId,
) -> Result<CollectionId, traits::CollectionManagerError> {
match Self::do_create_collection(owner) {
Ok(collection_id) => Ok(collection_id),
Err(err) => match err {
Error::CollectionIdOverflow => {
Err(traits::CollectionManagerError::CollectionIdOverflow)
},
_ => Err(traits::CollectionManagerError::UnknownError),
},
}
base_uri: Self::BaseURI,
) -> Result<CollectionId, Self::Error> {
Self::do_create_collection(owner, base_uri)
}
}

impl<T: Config> traits::Erc721 for Pallet<T> {
fn owner_of(
collection_id: CollectionId,
asset_id: U256,
) -> Result<H160, traits::Erc721Error> {
match OwnerOfCollection::<T>::get(collection_id) {
type Error = Error<T>;

fn owner_of(collection_id: CollectionId, asset_id: U256) -> Result<H160, Self::Error> {
match CollectionBaseURI::<T>::get(collection_id) {
Some(_) => Ok(convert_asset_id_to_owner(asset_id)),
None => Err(traits::Erc721Error::UnexistentCollection),
None => Err(Error::UnexistentCollection),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion pallets/living-assets-ownership/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate as pallet_livingassets_ownership;
use frame_support::traits::{ConstU16, ConstU64};
use sp_core::H256;
use sp_core::{ConstU32, H256};
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
Expand Down Expand Up @@ -46,6 +46,7 @@ impl frame_system::Config for Test {

impl pallet_livingassets_ownership::Config for Test {
type RuntimeEvent = RuntimeEvent;
type BaseURILimit = ConstU32<256>;
}

// Build genesis storage according to the mock runtime.
Expand Down
Loading