Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow applications to hold native tokens (#2978)
* Use `AccountOwner` as the key for `balances` Allow applications to hold native tokens. * Use `AccountOwner` in `ChainInfoRequest` Allow requesting the balance of an application's account. * Allow client to query application balances Update `ChainClient` methods to be able to query an application's balance. * Use `AccountOwner` in `OwnerBalance` request Allow the runtime to request the balance of application accounts. * Update parameter in runtime's `read_owner_balance` Prepare to update the WIT API to be able to query an application's balance. * Update `read_owner_balance` WIT interface Use `AccountOwner` as the parameter instead of `Owner`, in order to support application accounts. * Derive `Hash` for `AccountOwner` Prepare to use the type in `SystemMessage`, which has `Hash` derived for it. * Use `AccountOwner` inside `MockContractRuntime` Prepare to change the runtime interface to use `AccountOwner`. * Use `AccountOwner` inside `MockServiceRuntime` Prepare to change the runtime interface to use `AccountOwner`. * Use `AccountOwner` in runtime's `owner_balance` Update the SDK's runtime API to support querying an application's balance. * Use `AccountOwner` in cached `owner_balances` Prepare the `ServiceRuntime` to use an updated WIT interface that allows querying the balance of application accounts. * Use `AccountOwner` in `OwnerBalances` request Allow the runtime to get a list the balances of application accounts. * Update return type of `read_owner_balances` Prepare to update the WIT API to be able to list application balances. * Update `read_owner_balances` WIT interface Return `AccountOwner` in order to include application accounts. * Update runtime's `owner_balances` signature Include application balances in the result. * Use `AccountOwner` in cached `balance_owners` Prepare the `ServiceRuntime` to use an updated WIT interface that allows querying the balance of application accounts. * Use `AccountOwner` in `BalanceOwners` request Allow the runtime to get a list the accounts including application accounts. * Update return type of `read_balance_owners` Prepare to update the WIT API to be able to list application accounts. * Update `read_balance_owners` WIT interface Return `AccountOwner` in order to include application accounts. * Update runtime's `balance_owners` signature Include application accounts in the result. * Remove redundant authentication check The authentication is checked before the message is sent, so it does not need to be checked again when the message is received, because only the system application can send its own messages. Also prepares to allow applications to initiate transfers and claims, which can't be authorized by the message receiving code. * Use `AccountOwner` in `SystemMessage` Prepare to allow applications to transfer native tokens. * Change `transfer` parameter into `AccountOwner` Prepare to allow applications to transfer native tokens. * Verify application token transfers Ensure that moving an application's account can only be performed by the application that owns the account. * Send application ID to execution state actor Allow it to be used to authenticate transfers. * Accept application transfers in execution actor Update the request message to use `AccountOwner` so that the runtime can request transfers from application accounts. * Update the runtime trait to support app. transfers Replace the `Owner` parameter with `AccountOwner`, so that applications can request transfers from their account. * Update `transfer` WIT interface Use `AccountOwner` instead of `Owner` as the source parameter in order to allow applications to request transfers from their own accounts. * Update `ContractRuntime::transfer` SDK interface Use `AccountOwner` to allow applications to transfer native tokens using the SDK. * Send authenticated application ID to `claim` func. Prepare to allow claiming from application accounts. * Verify application claims Allow the source account to be an application account, and ensure only the application that owns that account can access it. * Send application ID in `ExecutionRequest::Claim` Allow it to be used to authenticate claims from applications. * Tweak `Account` constructors documentation Add documentation links and rephrase a little to provide more details. * Refactor `FromStr` implementation for `Account` Prepare to handle more than one colon in the input string. * Use `AccountOwner` in `Account` type Update `Account` to also represent application accounts. * Box some futures to reduce their size Prevent excessive stack usage by nested futures. * Support app. accounts in native token example Remove normalization of owners, and use `AccountOwner` directly. * Use `AccountOwner` in `SystemExecuteState` helper Update the `balances` map to support applications. * Refactor to move test helpers to `test_utils` Prepare to allow the helpers to be used by a new integration test module. Also, rename the test helpers for consistency. * Test `transfer` contract runtime API Ensure that applications can transfer from their accounts, from the shared chain account, and from the signer's account. * Test `claim` contract runtime API Ensure that applications can claim from their accounts or from the signer account in remote chains. * Derive `Arbitrary` for `Amount` Prepare to use it in property tests. * Test `read_chain_balance` contract runtime API Ensure applications can read the chain balance. * Test `read_owner_balance` contract runtime API Ensure applications can read the balances of individual accounts. * Test `read_owner_balances` contract runtime API Ensure applications can read a list of all account balances. * Test `read_balance_owners` contract runtime API Ensure applications can read a list of all accounts. * Test reading the balance of a missing account The system API should fallback and return zero in that case. * Test unauthorized transfers from applications Ensure that execution fails with the appropriate error. * Test unauthorized claims from applications Ensure that execution fails with the appropriate error. * Add a `create_dummy_query_context` helper function Allow tests to create a dummy context to test queries. * Test `read_chain_balance` service runtime API Ensure applications can read the chain balance. * Move `test_accounts_strategy` to `test_utils` Allow the helper function to be used in other tests. * Test `read_owner_balance` service runtime API Ensure applications can read the balances of individual accounts. * Test `read_owner_balances` service runtime API Ensure applications can read a list of all account balances. * Test `read_balance_owners` service runtime API Ensure applications can read a list of all accounts. * Test reading the balance of a missing account The system API should fallback and return zero in that case. * Replace `ok_or_else` with `context` Simplify the code to generate the error. Co-authored-by: Andreas Fackler <[email protected]> Signed-off-by: Janito Vaqueiro Ferreira Filho <[email protected]> * Expect returned accounts to be sorted The runtime API should be deterministic, so the returned lists of accounts must be sorted. Co-authored-by: Andreas Fackler <[email protected]> Signed-off-by: Janito Vaqueiro Ferreira Filho <[email protected]> --------- Signed-off-by: Janito Vaqueiro Ferreira Filho <[email protected]> Co-authored-by: Andreas Fackler <[email protected]>
- Loading branch information