-
Notifications
You must be signed in to change notification settings - Fork 89
feat: Support foreign accounts #1486
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
Changes from 2 commits
8638784
9df9847
7a13e15
485f543
014ffb4
8135b4f
454043f
ae1b914
d22e32e
be374a1
5d92060
c025849
aa59a0e
31a30c5
a07d656
5b0e863
95faf66
243a28e
27f7919
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,17 @@ impl DataStore for TransactionInputsDataStore { | |
| foreign_account_id: AccountId, | ||
| _ref_block: BlockNumber, | ||
| ) -> impl FutureMaybeSend<Result<AccountInputs, DataStoreError>> { | ||
| async move { Err(DataStoreError::AccountNotFound(foreign_account_id)) } | ||
| async move { | ||
| if foreign_account_id == self.tx_inputs.account().id() { | ||
| // todo(currentpr): proper error | ||
| return Err(DataStoreError::AccountNotFound(foreign_account_id)); | ||
| } | ||
|
|
||
| let foreign_inputs = | ||
| self.tx_inputs.read_foreign_account_inputs(foreign_account_id).unwrap(); // todo unwrap | ||
|
||
|
|
||
| Ok(foreign_inputs) | ||
| } | ||
| } | ||
|
|
||
| fn get_vault_asset_witnesses( | ||
|
|
@@ -63,31 +73,21 @@ impl DataStore for TransactionInputsDataStore { | |
| vault_keys: BTreeSet<AssetVaultKey>, | ||
| ) -> impl FutureMaybeSend<Result<Vec<AssetWitness>, DataStoreError>> { | ||
| async move { | ||
| if self.tx_inputs.account().id() != account_id { | ||
| return Err(DataStoreError::AccountNotFound(account_id)); | ||
| } | ||
|
|
||
| if self.tx_inputs.account().vault().root() != vault_root { | ||
| return Err(DataStoreError::Other { | ||
| error_msg: "vault root mismatch".into(), | ||
| source: None, | ||
| }); | ||
| } | ||
sergerad marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Result::<Vec<_>, _>::from_iter(vault_keys.into_iter().map(|vault_key| { | ||
| match self.tx_inputs.account().vault().open(vault_key) { | ||
| Ok(vault_proof) => { | ||
| AssetWitness::new(vault_proof.into()).map_err(|err| DataStoreError::Other { | ||
| error_msg: "failed to open vault asset tree".into(), | ||
| source: Some(err.into()), | ||
| }) | ||
| }, | ||
| Err(err) => Err(DataStoreError::Other { | ||
| error_msg: "failed to open vault".into(), | ||
| source: Some(err.into()), | ||
| }), | ||
| } | ||
| })) | ||
| // Get asset witnessess from local or foreign account. | ||
| if self.tx_inputs.account().id() == account_id { | ||
| get_asset_witnesses_from_account(self.tx_inputs.account(), vault_keys) | ||
| } else { | ||
| let foreign_inputs = | ||
| self.tx_inputs.read_foreign_account_inputs(account_id).unwrap(); // todo unwrap | ||
| get_asset_witnesses_from_account(foreign_inputs.account(), vault_keys) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -123,3 +123,26 @@ impl MastForestStore for TransactionInputsDataStore { | |
| self.mast_store.get(procedure_hash) | ||
| } | ||
| } | ||
|
|
||
| // HELPERS | ||
| // ================================================================================================ | ||
|
|
||
| fn get_asset_witnesses_from_account( | ||
| account: &PartialAccount, | ||
| vault_keys: BTreeSet<AssetVaultKey>, | ||
| ) -> Result<Vec<AssetWitness>, DataStoreError> { | ||
| Result::<Vec<_>, _>::from_iter(vault_keys.into_iter().map(|vault_key| { | ||
| match account.vault().open(vault_key) { | ||
| Ok(vault_proof) => { | ||
| AssetWitness::new(vault_proof.into()).map_err(|err| DataStoreError::Other { | ||
| error_msg: "failed to open vault asset tree".into(), | ||
| source: Some(err.into()), | ||
| }) | ||
| }, | ||
| Err(err) => Err(DataStoreError::Other { | ||
| error_msg: "failed to open vault".into(), | ||
| source: Some(err.into()), | ||
| }), | ||
| } | ||
| })) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bobbinth assuming we expect to get foreign account inputs from tx inputs, is it possible to do so here? Should we somehow retrieve the tx inputs through the store or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we can get foreign account inputs from the original TX inputs - or at least it may not always work.
I think to get foreign account inputs, we'd need to make a request to the store and load the account from there. We may also want to cache the foreign account
NtxDataStoreso that if there are additional requests, we won't need to go to the store again for the same data.There is one nuance here though: currently, we are able to fetch the full account from the store, but this functionality will go away after the refactoring @drahnr is working on. So, it may make sense to add a dedicated endpoint to the data store that would return the data sufficient to construct
AccountInputs(i.e., thePartialAccountandAccountWitnessstructs).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any advice on how to do this? Seems like we would have to get the full account from store state, convert that to partial account + get account witness somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we have the ability to get the full account from the store, things should be pretty easy:
impl From<&Account> for PartialAccountimplemented).AccountTree- that should be pretty straight-forward too.I think both of these we should be able to get from the current
GetAccountProofendpoint. But soon, the ability to get full account will go away.After a series of @drahnr's PRs gets merged,
GetAccountProofbecomesGetAccountand it no longer would return the full account. But it would still return enough info to build aPartialAccount+ account witness. For partial account, all we really need isaccount_id, vault root, storage header, code, and nonce - and I believe all of this should be available from theGetAccountendpoint.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this will be available once #1385 is merged as
GetAccount