-
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(tx): add new sign_raw_transaction rpc for UTXO and EVM coins #1930
Conversation
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.
Great work! some suggestions from my side
mm2src/coins/utxo/utxo_common.rs
Outdated
hex::decode(args.tx_hex.as_bytes()).map_to_mm(|e| RawTransactionError::InvalidParam(e.to_string()))?; | ||
let tx: UtxoTx = | ||
deserialize(tx_bytes.as_slice()).map_to_mm(|e| RawTransactionError::InvalidParam(e.to_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.
I think these should be TxByteParseError
or DecodeError
mm2src/coins/utxo/utxo_common.rs
Outdated
.map_to_mm(|e| RawTransactionError::InvalidParam(e.to_string()))?, | ||
); | ||
} | ||
|
||
let prev_hash = hex::decode(prev_utxo.tx_hash.as_bytes()) | ||
.map_err(|e| RawTransactionError::InvalidParam(e.to_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.
same as above
mm2src/coins/utxo/utxo_common.rs
Outdated
.filter(|input| !unspents.iter().any(|u| u.outpoint.hash == input.previous_output.hash)) | ||
.map(|input| input.previous_output.hash.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.
what about using filter_map
here once?
mm2src/coins/utxo/utxo_common.rs
Outdated
signature_version, | ||
coin.as_ref().conf.fork_id, | ||
) | ||
.map_err(|err| RawTransactionError::SigningError(err.get_inner().to_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.
why don't we just call err.to_string()
so we get the error trace too
@@ -27,7 +27,7 @@ impl Private { | |||
pub fn sign(&self, message: &Message) -> Result<Signature, Error> { | |||
let secret = SecretKey::from_slice(&*self.secret)?; | |||
let message = SecpMessage::from_slice(&**message)?; | |||
let signature = SECP_SIGN.sign(&message, &secret); | |||
let signature = SECP_SIGN.sign_low_r(&message, &secret); // use low R signing from bitcoin which reduces signature malleability |
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.
// use low R signing from bitcoin which reduces signature malleability
let signature = SECP_SIGN.sign_low_r(&message, &secret);
@dimxy please fix clippy and fmt warnings, you should use |
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.
Thanks a lot for the PR! First review iteration!
okay thank you, I used clippy but apparently with different params that I found in the contrib guide |
Contribution guide needs lots of updates apparently. |
thank you all for your reviews, added new commits following them: used async_trait, fixed formatting, clippy errs, refactored sign_raw_tx (advised function added), improved RawTransactionError |
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.
Thanks a lot for the fixes! Next review iteration!
5d422ab
to
7f01291
Compare
I rebased on the latest dev. I believe I have made all fixes requested by the reviewers |
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! Will do one final review round once these comments are fixed.
@dimxy please note, that this PR started to have conflicts |
Oh, thank you. I have already fixed several conflicts recently but more of them came |
f5afcf8
to
a699167
Compare
just rebased on the latest dev |
Thanks! I'm, still a little confused about the ETH/EVM units. Seems the
|
Docs draft at https://edbbd891.komodo-docs.pages.dev/en/docs/atomicdex/api/v20/sign_raw_transaction/ |
Yes it is in wei and to be directly converted into U256 'value' (as it was supposed to be the 'raw transaction'). |
…saction for ETH type
9cb21d2
to
eb0dfee
Compare
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!
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.
Latest changes approved! Will merge this after 2.0.0-beta
is released.
@@ -216,7 +216,7 @@ impl FromStr for Address { | |||
} | |||
|
|||
impl From<&'static str> for Address { | |||
fn from(s: &'static str) -> Self { s.parse().unwrap() } |
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.
Ideally this should be conditionally compiled for tests only.
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, here is a PR for refactoring this struct and a discussion on this unwrap in it: #1960 (comment)
* dev: (22 commits) chore(config): remove vscode launchjson (KomodoPlatform#2040) feat(trading-proto-upgrade): wasm DB, kickstart, refund states, v2 RPCs (KomodoPlatform#2015) feat(UTXO): balance event streaming for Electrum clients (KomodoPlatform#2013) feat(tx): add new sign_raw_transaction rpc for UTXO and EVM coins (KomodoPlatform#1930) fix(p2p): handle encode_and_sign errors (KomodoPlatform#2038) chore(release): add changelog entries for v2.0.0-beta (KomodoPlatform#2037) chore(network): write network information to stdout (KomodoPlatform#2034) fix(price_endpoints): add cached url (KomodoPlatform#2032) deps(network): sync with upstream yamux (KomodoPlatform#2030) fix(config): accept a string as rpcport value (KomodoPlatform#2026) feat(nft): move db lock, add tx fee and confirmations (KomodoPlatform#1989) chore(network): update seednodes for netid 8762 (KomodoPlatform#2024) chore(network): add todo on peer storage behaviour (KomodoPlatform#2025) chore(network): exclude `168.119.236.249` from the seednode list (KomodoPlatform#2021) feat(network): deprecate 7777 network (KomodoPlatform#2020) chore(release): bump mm2 version to 2.0.0-beta (KomodoPlatform#2018) feat(UTXO swaps): kmd burn plan impl (KomodoPlatform#2006) chore(docs): fix the link to simple market maker in README.md (KomodoPlatform#2011) refactor(cli): cli dependency updates and warn on bad config perm (KomodoPlatform#1956) chore(containers and docs): update docs and container images (KomodoPlatform#2003) ... # Conflicts: # mm2src/mm2_main/tests/mm2_tests/mm2_tests_inner.rs # mm2src/mm2_test_helpers/src/for_tests.rs
* dev: (24 commits) chore(release): bump mm2 version to 2.1.0-beta (KomodoPlatform#2044) feat(trezor): add segwit support for withdraw with trezor (KomodoPlatform#1984) chore(config): remove vscode launchjson (KomodoPlatform#2040) feat(trading-proto-upgrade): wasm DB, kickstart, refund states, v2 RPCs (KomodoPlatform#2015) feat(UTXO): balance event streaming for Electrum clients (KomodoPlatform#2013) feat(tx): add new sign_raw_transaction rpc for UTXO and EVM coins (KomodoPlatform#1930) fix(p2p): handle encode_and_sign errors (KomodoPlatform#2038) chore(release): add changelog entries for v2.0.0-beta (KomodoPlatform#2037) chore(network): write network information to stdout (KomodoPlatform#2034) fix(price_endpoints): add cached url (KomodoPlatform#2032) deps(network): sync with upstream yamux (KomodoPlatform#2030) fix(config): accept a string as rpcport value (KomodoPlatform#2026) feat(nft): move db lock, add tx fee and confirmations (KomodoPlatform#1989) chore(network): update seednodes for netid 8762 (KomodoPlatform#2024) chore(network): add todo on peer storage behaviour (KomodoPlatform#2025) chore(network): exclude `168.119.236.249` from the seednode list (KomodoPlatform#2021) feat(network): deprecate 7777 network (KomodoPlatform#2020) chore(release): bump mm2 version to 2.0.0-beta (KomodoPlatform#2018) feat(UTXO swaps): kmd burn plan impl (KomodoPlatform#2006) chore(docs): fix the link to simple market maker in README.md (KomodoPlatform#2011) ...
* evm-hd-wallet: (27 commits) Fix todo comments Fix HDAddressOps::Address trait bounds fix(indexeddb): fix IDB cursor.continue_() call after drop (KomodoPlatform#2028) security bump for `h2` (KomodoPlatform#2062) fix(makerbot): allow more than one prices url in makerbot (KomodoPlatform#2027) fix(wasm worker env): refactor direct usage of `window` (KomodoPlatform#1953) feat(nft): nft abi in withdraw_nft RPC, clear_nft_db RPC (KomodoPlatform#2039) refactor(utxo): refactor utxo output script creation (KomodoPlatform#1960) feat(ETH): balance event streaming for ETH (KomodoPlatform#2041) chore(release): bump mm2 version to 2.1.0-beta (KomodoPlatform#2044) feat(trezor): add segwit support for withdraw with trezor (KomodoPlatform#1984) chore(config): remove vscode launchjson (KomodoPlatform#2040) feat(trading-proto-upgrade): wasm DB, kickstart, refund states, v2 RPCs (KomodoPlatform#2015) feat(UTXO): balance event streaming for Electrum clients (KomodoPlatform#2013) feat(tx): add new sign_raw_transaction rpc for UTXO and EVM coins (KomodoPlatform#1930) fix(p2p): handle encode_and_sign errors (KomodoPlatform#2038) chore(release): add changelog entries for v2.0.0-beta (KomodoPlatform#2037) chore(network): write network information to stdout (KomodoPlatform#2034) fix(price_endpoints): add cached url (KomodoPlatform#2032) deps(network): sync with upstream yamux (KomodoPlatform#2030) ...
Adds new sign_raw_transaction rpc method for UTXO coins.
Currently supports P2PKH and P2WPKH spent outputs.
Closes #1407
TODO:
support more previous output types
support several signing keys
update docs to add rpc desc
signing with trezor