Conversation
onur-ozkan
left a comment
There was a problem hiding this comment.
Thanks!
Some notes from the first review from my end:
mm2src/coins/lp_coins.rs
Outdated
| /// Returns the WIF prefix for the coin. | ||
| fn wif_prefix(&self) -> Option<u8> { None } | ||
|
|
||
| fn is_utxo(&self) -> bool { false } |
There was a problem hiding this comment.
These shouldn't be defined in MarketCoinOps. I don't think we need to define them anywhere at all; we can simply derive the UTXO coin from MmCoinEnum.
mm2src/coins/priv_key.rs
Outdated
| #[display(fmt = "No such coin: {}", _0)] | ||
| NoSuchCoin(String), | ||
| #[display(fmt = "Coin {} doesn't support HD wallet derivation", _0)] | ||
| CoinDoesntSupportDerivation(String), | ||
| #[display(fmt = "Hardware/remote wallet doesn't allow exporting private keys")] | ||
| HwWalletNotAllowed, | ||
| #[display(fmt = "Internal error: {}", _0)] | ||
| Internal(String), |
There was a problem hiding this comment.
It would be more clear to use struct-like errors instead if tuple-like ones, e.g.,:
NoSuchCoin {
ticker: String,
},
Internal {
reason: String,
}
so we can know what are the inner values are about without having to look use-cases.
| "myipaddr": env::var ("BOB_TRADE_IP") .ok(), | ||
| "rpcip": env::var ("BOB_TRADE_IP") .ok(), | ||
| "canbind": env::var ("BOB_TRADE_PORT") .ok().map (|s| s.parse::<i64>().unwrap()), |
There was a problem hiding this comment.
Can you remove white spaces?
We should also unwrap instead of calling ok to fail the test when BOB_TRADE_IP and BOB_TRADE_PORT isn't present.
There was a problem hiding this comment.
Done in 79e632c
FWIW, the rest of the file uses .ok() and similar white spacing throughout. Should I fix up those also while I'm here?
mm2src/coins/priv_key.rs
Outdated
| #[async_trait] | ||
| pub trait DerivePrivKeyV2: MmCoin + CoinWithPrivKeyPolicy + CoinWithDerivationMethod + Sized { | ||
| async fn derive_priv_key(&self, req: &DerivePrivKeyReq) -> Result<DerivedPrivKey, MmError<DerivePrivKeyError>>; | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl<Coin> DerivePrivKeyV2 for Coin | ||
| where | ||
| Coin: MmCoin + CoinWithPrivKeyPolicy + CoinWithDerivationMethod + MarketCoinOps + Sync, | ||
| { |
There was a problem hiding this comment.
If derive_priv_key can take MmCoinEnum as a parameter, that would greatly simplify the implementation so we don't have to do all the generic-dances here (also in priv_key::derive_priv_key).
|
is this impl-ed so to
|
yes, this was implemented to let users export privkeys for HD wallet. we do need to do it as users will need the privkeys in case they need to do anything komodo wallet doesn't do. or if they need to access their coins in case the electrum servers we have are down. Even if there are no active electrum servers, users can import their privkey in native wallets with full blockchain history to move their coins |
|
i mean if we already have a way to expose the wallet seed, we then dont need to expose individual private keys. i dont know of a wallet that can work with a single private key (if there is, it will probably even consider it as legacy address, so no segwit coins etc... will be visible) |
|
you can import a single private key in komodo ocean wallet for KMD. in any native full node wallet for most other utxo coins. even for ethereum, you can do it in trust wallet or meta mask |
| })?; | ||
|
|
||
| let private = Private { | ||
| prefix: 0, // ETH doesn't use WIF format |
There was a problem hiding this comment.
Is this the only difference compare to UTXO implementation?
|
closing in favor of #2542 |
The legacy
show_priv_keymethod did not take input for account/address id, and would only return the zero index WIF for HD wallets, so I've added a v2derive_priv_keymethod which accepts these inputs.Request:
{ "userpass": "{{userpass}}", "mmrpc": "2.0", "method": "derive_priv_key", "params": { "coin": "MATIC", "account_id": 0, "address_id": 3 } }Response:
{ "mmrpc": "2.0", "result": { "coin": "MATIC", "address": "0x1e8B4aA6a8B8a376E0357504cF2ebC11Bc02288b", "derivation_path": "m/44'/60'/0'/0/3", "priv_key": "0x932ec93805200317394d6f63216791cf6052e6bb7412153f799c0b0660086e24", "pub_key": "0x036b521bb1f9e845301f8bcb1f025151784ac2ea54b95fa50b9c491aced4a34c04" }, "id": null }To test:
derive_priv_key.