Use AssetHolder instead of PortfolioId#1890
Use AssetHolder instead of PortfolioId#1890HenriqueNogara wants to merge 15 commits intodevelop_v8from
AssetHolder instead of PortfolioId#1890Conversation
f2a0cad to
d2e3192
Compare
d4fb284 to
2b9cb61
Compare
AssetHolder instead of PortfolioId
| return weight; | ||
| } | ||
|
|
||
| Weight::zero() |
There was a problem hiding this comment.
should we count reads/writes and return actual weight here? migrate_to_v7 also returns zero weight
| polymesh_primitives::storage_migrate_on!(StorageVersion::<T>, 4, { | ||
| migrations::migrate_to_v4::<T>(); | ||
| }); | ||
| Weight::zero() |
There was a problem hiding this comment.
should we return the actual weight here? migrate_to_v4 actually counts reads/writes but we just return zero
| )?; | ||
|
|
||
| let updated_balance = BalanceOf::<T>::get(asset_id, portfolio.did) - value; | ||
| let updated_did_balance = BalanceOf::<T>::get(asset_id, holder_did) - value; |
There was a problem hiding this comment.
should we use checked_sub for substraction here?
There was a problem hiding this comment.
If the code checks the available balance before this, then we can just use saturating_* instead of checked_* ops.
| &[(issuer_did, current_issuer_balance)], | ||
| )?; | ||
|
|
||
| let new_issuer_balance = current_issuer_balance + amount_to_issue; |
There was a problem hiding this comment.
should we avoid unchecked operations and use checked_add instead?
| pub type Error = Vec<u8>; | ||
|
|
||
| sp_api::decl_runtime_apis! { | ||
| #[api_version(4)] |
There was a problem hiding this comment.
should we bump api_version because of the changes?
|
|
||
| sp_api::decl_runtime_apis! { | ||
|
|
||
| #[api_version(2)] |
There was a problem hiding this comment.
should we bump api_version because of the changes?
| use polymesh_primitives::AssetHolder; | ||
|
|
||
| sp_api::decl_runtime_apis! { | ||
| #[api_version(2)] |
There was a problem hiding this comment.
should we bump api_version because of the changes?
| None, | ||
| ); | ||
|
|
||
| if let Some(cursor) = result.maybe_cursor { |
There was a problem hiding this comment.
should we instead loop until maybe_cursor returns None?
Neopallium
left a comment
There was a problem hiding this comment.
First round of review.
| - run: | ||
| name: Upgrade chain to current version. | ||
| command: cargo run --locked --bin tools -- upgrade_chain ../assets/ci-runtime/polymesh_runtime_develop.compact.compressed.wasm | ||
| command: cargo run --features current_release --locked --bin tools -- upgrade_chain ../assets/ci-runtime/polymesh_runtime_develop.compact.compressed.wasm |
There was a problem hiding this comment.
Since this needs to run/compile against the old chain, we need to use previous_release here.
| sender_portfolio: PortfolioId, | ||
| receiver_portfolio: PortfolioId, | ||
| sender: AssetHolder, | ||
| receiver: AssetHolder, |
There was a problem hiding this comment.
Need to bump the version of this Runtime API method.
| fn transfer_report( | ||
| sender_portfolio: PortfolioId, | ||
| receiver_portfolio: PortfolioId, | ||
| sender: AssetHolder, | ||
| receiver: AssetHolder, |
There was a problem hiding this comment.
Same here. Bump the version. And the other Runtime API methods below.
| fn transfer_report( | ||
| &self, | ||
| sender_portfolio: PortfolioId, | ||
| receiver_portfolio: PortfolioId, | ||
| sender: AssetHolder, | ||
| receiver: AssetHolder, | ||
| asset_id: AssetId, | ||
| transfer_value: Balance, | ||
| skip_locked_check: bool, | ||
| at: Option<<Block as BlockT>::Hash>, | ||
| ) -> RpcResult<Vec<DispatchError>> { |
There was a problem hiding this comment.
I would like to start dropping these RPC endpoints, since it is much better for clients to directly call the Runtime APIs instead. Otherwise this RPC impl. needs to be updated to translate the new AssetHolder type to the old Runtime API call which only supports PortfolioId.
| let primary_key = pallet_identity::Pallet::<T>::get_primary_key(primary_did) | ||
| .ok_or(Error::<T>::KeyNotFoundForDid)?; | ||
|
|
||
| ensure!(primary_key == account_id, Error::<T>::UnauthorizedHolderKey); |
There was a problem hiding this comment.
If secondary_key is None the caller should always be the primary key. We could avoid looking up the DID's primary key by checking the caller account.
| /// - The transfer is between different DIDs; | ||
| /// - If [`AssetHolder::Portfolio`], it must exist; | ||
| /// - The sender has sufficient balance for the transfer (taking into account locks). | ||
| pub fn ensure_valid_holdings( |
There was a problem hiding this comment.
We might have to allow transfers (settlements) when the sender/receiver are the same DID. Otherwise this is going to trip up integrator. If the sender/receiver DIDs are the same, we can skip the more expensive compliance checks and stats updates.
changelog
modified external API
Replace
PortfolioIdfor `AssetHolder;Asset Pallet:
ControllerTransfer,AssetBalanceUpdated;issue,redeem,controller_transfer;InvalidTransferSenderDidMatchesReceiverDid,UnauthorizedHolderKey,KeyNotFoundForDid,InsufficientTokensLocked;Identity Pallet:
IdentityNotFoundForAccountPortfolio;NFT Pallet:
NFTHoldingsUpdatedNFTOwner;issue_nft,redeem_nft,controller_transfer;NFTIsNotLocked;Settlement Pallet:
InstructionAffirmed,AffirmationWithdrawn,InstructionAutomaticallyAffirmed;MaxNumberOfPortfoliosforMaxNumberOfAssetHolders;AffirmsReceived,UserAffirmations;affirm_with_receipts,execute_manual_instruction,add_and_affirm_instruction,affirm_instruction,withdraw_affirmation,reject_instruction,affirm_with_receipts_with_count,affirm_instruction_with_count,reject_instruction_with_count,withdraw_affirmation_with_count,add_and_affirm_with_mediators,Runtime Api
transfer_report;transfer_report;get_affirmation_count