-
Notifications
You must be signed in to change notification settings - Fork 94
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
feat(zcoin): allow ARRR/ZCOIN compilation in wasm #1805
Conversation
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
@borngraced can you please fix the clippy warnings related to wasm? |
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
# Conflicts: # mm2src/coins/z_coin.rs
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.
Thank you for starting this important feature! First review iteration.
mm2src/coins/z_coin/z_rpc.rs
Outdated
#[cfg(not(target_arch = "wasm32"))] | ||
pub struct BlockDb(Connection); | ||
#[cfg(target_arch = "wasm32")] | ||
pub struct BlockDb(String); | ||
|
||
#[cfg(not(target_arch = "wasm32"))] |
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.
please follow BlockHeaderStorageOps example https://github.com/KomodoPlatform/atomicDEX-API/blob/d01dd41e91ccf7e353a4cdb4e2135bdeb8dfc3de/mm2src/mm2_bitcoin/spv_validation/src/storage.rs#L87
by creating a common trait that should be implemented for both struct BlockDb(Connection)
and pub struct BlockDb(String);
. Shouldn't pub struct BlockDb(String);
use IndexedDb
and not a String
? You can change these structs as you see fit.
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.
To start with, I use obvious string just to make WASM
build pass as I wouldn't want to implement the storages. structure in this pr to not look messy or too complex to review.
BlockDb
can't be implemented like the way BlockHeaderStorageOps
is done because BlockDb
additionally needs to implement a trait with a generic function.
https://github.com/KomodoPlatform/atomicDEX-API/blob/46535e882896e10aa16f3d6364007ba2a8c0cc3d/mm2src/coins/z_coin/z_rpc.rs#L363-L372
which makes doing these impossible with the current rust
Meanwhile, I already completed the implementation structure in another branch, so I got it covered 💯
https://github.com/KomodoPlatform/atomicDEX-API/blob/daa1b650b0ae319c79923ee0f651f889a7a438cc/mm2src/coins/z_coin/storage/blockdb/mod.rs#L30-L38
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.
Meanwhile, I already completed the implementation structure in another branch, so I got it covered
May be it worth adding this implementation in this PR with todos if you have it? So we can see the whole picture.
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.
Ok cool, after Omar's comment
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.
BlockDb can't be implemented like the way BlockHeaderStorageOps is done because BlockDb additionally needs to implement a trait with a generic function.
BlockDb can implement multiple traits, I don't see the problem. It doesn't have to be exactly like BlockHeaderStorageOps
/BlockHeaderStorage
but I meant to take it as an example. Another example is the LightningDB
trait which I plan to implement for IndexedDB later and have a common interface. https://github.com/KomodoPlatform/atomicDEX-API/blob/a1fc8f7c92819f68c0dcdf7b1c650d86cdf945ad/mm2src/coins/lightning/ln_db.rs#L200
May be it worth adding this implementation in this PR with todos if you have it? So we can see the whole picture.
As discussed with @borngraced on DM, he will add them to this PR, as for the above suggestion about following BlockHeaderStorageOps
/LightningDB
/etc.. you can try that in the next PRs since it will be tricky dealing with generics.
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
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.
Next review iteration!
async fn get_spendable_notes(&self) -> Result<Vec<SpendableNote>, MmError<ZcashClientError>> { | ||
let db = self.z_fields.light_wallet_db.clone(); | ||
#[cfg(target_arch = "wasm32")] | ||
async fn my_balance_sat(&self) -> Result<u64, MmError<ZCoinBalanceError>> { todo!() } |
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.
my_balance_sat
wasm implementation shouldn't return a different error from the native implementation. I understand that ZcashClientError
is SqliteClientError
, please consider implementing a common error type for both wasm and native implementation in the next PR, you can then implement From
this new error type for SqliteClientError
, etc..
I guess having a common interface as discussed here #1805 (comment) helps in this.
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.
yes I understand 💯 that was always the plan
Signed-off-by: borngraced <samuelonoja970@gmail.com>
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.
Next review iteration!
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
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.
LGTM at this stage! Only some minor non-blocker comments!
@borngraced please don't forget to add some unit tests for IndexedDb
implementations in the next PRs.
@laruh please do a final review of this when you can.
pub enum WalletDbError { | ||
ZcoinClientInitError(ZcoinClientInitError), | ||
ZCoinBuildError(String), | ||
IndexedDBError(String), |
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.
IndexedDBError
should probably be for wasm target only too
@borngraced please fix the PR title to make it inline with conventional commits :) |
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.
LGTM! Thanks for your work!
I have some non blocker notes and suggestions for next PR.
In next implementations may be there is a need in trait Ops for BlockDbImpl
, to impl common fns like get_latest_block, insert_block, rewind_to_height etc for two targets.
And perhaps it is worth separating the database implementations for different targets into different modules (I mean not to keep both of them in mod.rs). Lets see.
yeah, you're right... my comment to Omar here is related to this too #1805 (comment) |
Signed-off-by: borngraced <samuelonoja970@gmail.com>
@borngraced can you please resolve the conflicts introduced due to merging this PR #1853 |
# Conflicts: # mm2src/coins/Cargo.toml # mm2src/coins/z_coin.rs # mm2src/coins/z_coin/z_rpc.rs
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
Signed-off-by: borngraced <samuelonoja970@gmail.com>
This PR allows ARRR to be compiled in WASM.
After this PR, I will start implementing the empty/todo fn and storages