git.delta.rocks / unique-network / refs/commits / da952fd3c8fb

difftreelog

initial commit

PraetorP2022-07-11parent: #5ffdcf0.patch.diff
in: master

14 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
71 at: Option<BlockHash>,71 at: Option<BlockHash>,
72 ) -> Result<Option<CrossAccountId>>;72 ) -> Result<Option<CrossAccountId>>;
73
74 #[method(name = "unique_tokenOwners")]
75 fn token_owners(
76 &self,
77 collection: CollectionId,
78 token: TokenId,
79 at: Option<BlockHash>,
80 ) -> Result<Vec<CrossAccountId>>;
81
73 #[method(name = "unique_topmostTokenOwner")]82 #[method(name = "unique_topmostTokenOwner")]
74 fn topmost_token_owner(83 fn topmost_token_owner(
473 pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);482 pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);
474 pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>, unique_api);483 pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>, unique_api);
475 pass_method!(total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<u128>, unique_api);484 pass_method!(total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<u128>, unique_api);
485 pass_method!(token_owners(collection: CollectionId, token: TokenId) -> Vec<CrossAccountId>, unique_api);
476}486}
477487
478#[allow(deprecated)]488#[allow(deprecated)]
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
1748 /// * `token` - The token for which you need to find out the owner.1748 /// * `token` - The token for which you need to find out the owner.
1749 fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId>;1749 fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId>;
1750
1751 /// Token owners
1752 fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId>;
17501753
1751 /// Get the value of the token property by key.1754 /// Get the value of the token property by key.
1752 ///1755 ///
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
362 None362 None
363 }363 }
364
365 fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId> {
366 <Pallet<T>>::token_owners(self.id, token).unwrap_or_else(|| vec![])
367 }
364368
365 fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option<PropertyValue> {369 fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option<PropertyValue> {
366 None370 None
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
95use pallet_evm_coder_substrate::WithRecorder;95use pallet_evm_coder_substrate::WithRecorder;
96use sp_core::H160;96use sp_core::H160;
97use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};97use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
98use sp_std::{collections::btree_map::BTreeMap};98use sp_std::{collections::btree_map::BTreeMap, vec::Vec};
9999
100pub use pallet::*;100pub use pallet::*;
101101
614 )614 )
615 }615 }
616
617 pub fn token_owners(
618 collection: CollectionId,
619 _token: TokenId,
620 ) -> Option<Vec<T::CrossAccountId>> {
621 let res: Vec<T::CrossAccountId> = <Balance<T>>::iter_prefix((collection,))
622 .map(|r| r.0)
623 .take(10)
624 .collect();
625
626 if res.len() == 0 {
627 None
628 } else {
629 Some(res)
630 }
631 }
616}632}
617633
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
26 weights::WeightInfo as _,26 weights::WeightInfo as _,
27};27};
28use sp_runtime::DispatchError;28use sp_runtime::DispatchError;
29use sp_std::vec::Vec;29use sp_std::{vec::Vec, vec};
3030
31use crate::{31use crate::{
32 AccountBalance, Allowance, Config, CreateItemData, Error, NonfungibleHandle, Owned, Pallet,32 AccountBalance, Allowance, Config, CreateItemData, Error, NonfungibleHandle, Owned, Pallet,
422 <TokenData<T>>::get((self.id, token)).map(|t| t.owner)422 <TokenData<T>>::get((self.id, token)).map(|t| t.owner)
423 }423 }
424
425 fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId> {
426 self.token_owner(token).map_or_else(|| vec![], |t| vec![t])
427 }
424428
425 fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue> {429 fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue> {
426 <Pallet<T>>::token_properties((self.id, token_id))430 <Pallet<T>>::token_properties((self.id, token_id))
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
438 <Pallet<T>>::token_owner(self.id, token)438 <Pallet<T>>::token_owner(self.id, token)
439 }439 }
440
441 fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId> {
442 <Pallet<T>>::token_owners(self.id, token).unwrap_or_else(|| vec![])
443 }
440444
441 fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option<PropertyValue> {445 fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option<PropertyValue> {
442 None446 None
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
1135 <PalletCommon<T>>::set_token_property_permissions(collection, sender, property_permissions)1135 <PalletCommon<T>>::set_token_property_permissions(collection, sender, property_permissions)
1136 }1136 }
1137
1138 pub fn token_owners(
1139 collection_id: CollectionId,
1140 token: TokenId,
1141 ) -> Option<Vec<T::CrossAccountId>> {
1142 let res: Vec<T::CrossAccountId> = <Balance<T>>::iter_prefix((collection_id, token))
1143 .map(|r| r.0)
1144 .take(10)
1145 .collect();
1146
1147 if res.len() == 0 {
1148 None
1149 } else {
1150 Some(res)
1151 }
1152 }
1137}1153}
11381154
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
81 fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;81 fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;
82 fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;82 fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;
83 fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Result<Option<u128>>;83 fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Result<Option<u128>>;
84 fn token_owners(collection: CollectionId, token: TokenId) -> Result<Vec::<CrossAccountId>>;
84 }85 }
85}86}
8687
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
41 dispatch_unique_runtime!(collection.token_owner(token))41 dispatch_unique_runtime!(collection.token_owner(token))
42 }42 }
43
44 fn token_owners(collection: CollectionId, token: TokenId) -> Result<Vec::<CrossAccountId>, DispatchError> {
45 dispatch_unique_runtime!(collection.token_owners(token))
46 }
47
43 fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {48 fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>, DispatchError> {
44 let budget = up_data_structs::budget::Value::new(10);49 let budget = up_data_structs::budget::Value::new(10);
modifiedtests/package.jsondiffbeforeafterboth
80 "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",80 "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",
81 "testEthCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createCollection.test.ts",81 "testEthCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createCollection.test.ts",
82 "testRFT": "mocha --timeout 9999999 -r ts-node/register ./**/refungible.test.ts",82 "testRFT": "mocha --timeout 9999999 -r ts-node/register ./**/refungible.test.ts",
83 "testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",
83 "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",84 "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",
84 "polkadot-types-from-defs": "ts-node ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",85 "polkadot-types-from-defs": "ts-node ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",
85 "polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",86 "polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",
modifiedtests/src/interfaces/augment-api-rpc.tsdiffbeforeafterboth
708 * Get token owner708 * Get token owner
709 **/709 **/
710 tokenOwner: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Option<PalletEvmAccountBasicCrossAccountIdRepr>>>;710 tokenOwner: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Option<PalletEvmAccountBasicCrossAccountIdRepr>>>;
711 /**
712 * Get token owners
713 **/
714 tokenOwners: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Vec<PalletEvmAccountBasicCrossAccountIdRepr>>>;
711 /**715 /**
712 * Get token properties716 * Get token properties
713 **/717 **/
modifiedtests/src/interfaces/unique/definitions.tsdiffbeforeafterboth
49 balance: fun('Get amount of specific account token', [collectionParam, crossAccountParam(), tokenParam], 'u128'),49 balance: fun('Get amount of specific account token', [collectionParam, crossAccountParam(), tokenParam], 'u128'),
50 allowance: fun('Get allowed amount', [collectionParam, crossAccountParam('sender'), crossAccountParam('spender'), tokenParam], 'u128'),50 allowance: fun('Get allowed amount', [collectionParam, crossAccountParam('sender'), crossAccountParam('spender'), tokenParam], 'u128'),
51 tokenOwner: fun('Get token owner', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),51 tokenOwner: fun('Get token owner', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),
52 tokenOwners: fun('Get token owners', [collectionParam, tokenParam], `Vec<${CROSS_ACCOUNT_ID_TYPE}>`),
52 topmostTokenOwner: fun('Get token owner, in case of nested token - find parent recursive', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),53 topmostTokenOwner: fun('Get token owner, in case of nested token - find parent recursive', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),
53 tokenChildren: fun('Get tokens nested directly into the token', [collectionParam, tokenParam], 'Vec<UpDataStructsTokenChild>'),54 tokenChildren: fun('Get tokens nested directly into the token', [collectionParam, tokenParam], 'Vec<UpDataStructsTokenChild>'),
54 constMetadata: fun('Get token constant metadata', [collectionParam, tokenParam], 'Vec<u8>'),55 constMetadata: fun('Get token constant metadata', [collectionParam, tokenParam], 'Vec<u8>'),
modifiedtests/src/refungible.test.tsdiffbeforeafterboth
70 });70 });
71 });71 });
7272
73 it('RPC method tokenOnewrs for refungible collection and token', async () => {
74 await usingApi(async (api, privateKeyWrapper) => {
75 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};
76 const facelessCrowd = Array.from(Array(7).keys()).map(i => normalizeAccountId(privateKeyWrapper(i.toString())));
77
78 const createCollectionResult = await createCollection(api, alice, {mode: {type: 'ReFungible'}});
79 const collectionId = createCollectionResult.collectionId;
80
81 const result = await createRefungibleToken(api, alice, collectionId, 10_000n);
82 const aliceTokenId = result.itemId;
83
84
85 await transfer(api, collectionId, aliceTokenId, alice, bob, 1000n);
86 await transfer(api, collectionId, aliceTokenId, alice, ethAcc, 900n);
87
88 for (let i = 0; i < 7; i++) {
89 await transfer(api, collectionId, aliceTokenId, alice, facelessCrowd[i], 50*(i+1));
90 }
91
92 const owners = await api.rpc.unique.tokenOwners(collectionId, aliceTokenId);
93 const ids = (owners.toJSON() as CrossAccountId[]).map(s => normalizeAccountId(s));
94
95 const aliceID = normalizeAccountId(alice);
96 const bobId = normalizeAccountId(bob);
97
98 // What to expect
99 // tslint:disable-next-line:no-unused-expression
100 expect(ids).to.deep.include.members([aliceID, ethAcc, bobId, ...facelessCrowd]);
101 expect(owners.length == 10).to.be.true;
102 });
103 });
104
73 it('Transfer token pieces', async () => {105 it('Transfer token pieces', async () => {
74 await usingApi(async api => {106 await usingApi(async api => {
modifiedtests/src/rpc.test.tsdiffbeforeafterboth
1import {IKeyringPair} from '@polkadot/types/types';
1import {expect} from 'chai';2import {expect} from 'chai';
2import usingApi from './substrate/substrate-api';3import usingApi from './substrate/substrate-api';
3import {createCollectionExpectSuccess, getTokenOwner} from './util/helpers';4import {createCollection, createCollectionExpectSuccess, createFungibleItemExpectSuccess, CrossAccountId, getTokenOwner, normalizeAccountId, transfer, U128_MAX} from './util/helpers';
5
6let alice: IKeyringPair;
7let bob: IKeyringPair;
8
49
5describe('getTokenOwner', () => {10describe('integration test: RPC methods', () => {
11 before(async () => {
12 await usingApi(async (api, privateKeyWrapper) => {
13 alice = privateKeyWrapper('//Alice');
14 bob = privateKeyWrapper('//Bob');
15 });
16 });
17
18
6 it('returns None for fungible collection', async () => {19 it('returns None for fungible collection', async () => {
10 });23 });
11 });24 });
25
26 it('RPC method tokenOnewrs for fungible collection and token', async () => {
27 await usingApi(async (api, privateKeyWrapper) => {
28 const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};
29 const facelessCrowd = Array.from(Array(7).keys()).map(i => normalizeAccountId(privateKeyWrapper(i.toString())));
30
31 const createCollectionResult = await createCollection(api, alice, {mode: {type: 'Fungible', decimalPoints: 0}});
32 const collectionId = createCollectionResult.collectionId;
33 const aliceTokenId = await createFungibleItemExpectSuccess(alice, collectionId, {Value: U128_MAX}, alice.address);
34
35 await transfer(api, collectionId, aliceTokenId, alice, bob, 1000n);
36 await transfer(api, collectionId, aliceTokenId, alice, ethAcc, 900n);
37
38 for (let i = 0; i < 7; i++) {
39 await transfer(api, collectionId, aliceTokenId, alice, facelessCrowd[i], 1);
40 }
41
42 const owners = await api.rpc.unique.tokenOwners(collectionId, aliceTokenId);
43 const ids = (owners.toJSON() as CrossAccountId[]).map(s => normalizeAccountId(s));
44 const aliceID = normalizeAccountId(alice);
45 const bobId = normalizeAccountId(bob);
46
47 // What to expect
48 // tslint:disable-next-line:no-unused-expression
49 expect(ids).to.deep.include.members([aliceID, ethAcc, bobId, ...facelessCrowd]);
50 expect(owners.length == 10).to.be.true;
51 });
52 });
12});53});