Skip to content
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

Refactor basewallet and corresponding consumers #843

Merged
merged 3 commits into from
Jun 9, 2023

Conversation

tech-bash
Copy link
Contributor

@tech-bash tech-bash commented May 14, 2023

fix: #814

  • All JSON strings inputs replaced with rust structs.
  • consumers of BaseWallet in the code base updated to use the new types rather than the JSON strings

@codecov-commenter
Copy link

codecov-commenter commented May 14, 2023

Codecov Report

Merging #843 (ed38d6a) into main (1222ef7) will decrease coverage by 3.81%.
The diff coverage is 16.12%.

@@            Coverage Diff             @@
##             main     #843      +/-   ##
==========================================
- Coverage   48.96%   45.16%   -3.81%     
==========================================
  Files         429      429              
  Lines       34225    34238      +13     
  Branches     7594     7590       -4     
==========================================
- Hits        16759    15464    -1295     
- Misses      12208    13848    +1640     
+ Partials     5258     4926     -332     
Flag Coverage Δ
unittests-aries-vcx 45.15% <16.12%> (-3.78%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ries_vcx/src/utils/mockdata/profile/mock_wallet.rs 0.00% <0.00%> (-19.36%) ⬇️
aries_vcx_core/src/wallet/agency_client_wallet.rs 17.82% <0.00%> (-0.55%) ⬇️
aries_vcx_core/src/wallet/base_wallet.rs 42.85% <ø> (ø)
aries_vcx_core/src/wallet/indy_wallet.rs 55.23% <26.66%> (-2.93%) ⬇️
aries_vcx_core/src/anoncreds/credx_anoncreds.rs 56.48% <50.00%> (ø)

... and 55 files with indirect coverage changes

@tech-bash tech-bash force-pushed the refactor/base_wallet branch 4 times, most recently from 7b5b067 to 7982800 Compare May 14, 2023 18:00
@Patrik-Stas
Copy link
Contributor

hi @tech-bash note the failing jobs - take a look how we run those in CI and try to reproduce locally

@tech-bash
Copy link
Contributor Author

tech-bash commented May 15, 2023

Yes sir, on it already!

@tech-bash tech-bash force-pushed the refactor/base_wallet branch 7 times, most recently from c4fd1a7 to baa011e Compare May 21, 2023 04:56
Copy link
Contributor

@gmulhearn gmulhearn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, nice work so far!

I noticed in some places you've changed the parameters of BaseWallet methods to take String instead of &str. For consistency, could you please change them back?

E.g.
you've changed:

async fn update_wallet_record_value(&self, xtype: &str, id: &str, value: &str)

to:

async fn update_wallet_record_value(&self, xtype: &str, id: &str, value: String)

but value should stay as &str.

This happens in a few other places too, just have a look thru the diff on this PR. thanks!

@tech-bash tech-bash force-pushed the refactor/base_wallet branch from c3585d6 to cf856b9 Compare May 23, 2023 12:42
@tech-bash tech-bash requested a review from gmulhearn May 24, 2023 05:21
Copy link
Contributor

@gmulhearn gmulhearn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good just 1 comment for now

libvcx_core/src/api_vcx/api_global/wallet.rs Outdated Show resolved Hide resolved
Signed-off-by: Bhavy Airi <airiragahv@gmail.com>
@tech-bash tech-bash force-pushed the refactor/base_wallet branch from e505514 to 31e0346 Compare May 24, 2023 15:21
Copy link
Contributor

@Patrik-Stas Patrik-Stas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for PR, left some comments.

  • One to address
  • Second one to consider as bit more advanced improvement

async fn add_wallet_record_tags(&self, xtype: &str, id: &str, tags_json: &str) -> VcxCoreResult<()> {
indy::wallet::add_wallet_record_tags(self.wallet_handle, xtype, id, tags_json).await
async fn add_wallet_record_tags(&self, xtype: &str, id: &str, tags: HashMap<String, String>) -> VcxCoreResult<()> {
let tags_json = serde_json::to_string(&tags)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We serialize hashamp to string, just to deserialize it inside subsequent add_wallet_record_tags into Hashmap again. Can we avoid this?

Copy link
Contributor Author

@tech-bash tech-bash May 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are taking the typed parameters and then converting them back to JSON before passing them to indy::wallet::abc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you intending to say that we should only have hashmap as the parameter type and not &str?


async fn get_wallet_record(&self, xtype: &str, id: &str, options_json: &str) -> VcxCoreResult<String>;
async fn get_wallet_record(&self, xtype: &str, id: &str, options: &str) -> VcxCoreResult<String>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options could actually be well typed, but its type depends on what kind of options the underlying implementation accepts.

This is slightly more advanced, but we could use associated types here. You would defined something like

 pub trait BaseWallet: std::fmt::Debug + Send + Sync {
    type GetRecordOptions;
    type AddRecordOptions;

   ...
   ...
}

Then in particular implementation of the trait, for example in impl IndySdkWallet , you would inject the actual types. And of course, you would have to create those types (you can find out what the option objects should look like if you dig into libvdrtools code)

So not a hard requirement, but if you could do this it would be really great!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright!

@Patrik-Stas
Copy link
Contributor

I am merging as is due inactivity. If you wold like to further continue improving this area, feel free to do so in a new PR.

@Patrik-Stas Patrik-Stas merged commit 65cc7a4 into hyperledger:main Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typed interfaces/traits for BaseWallet
4 participants