-
Notifications
You must be signed in to change notification settings - Fork 27
Improve multisig UX: Add --out-file parameter and enhance sign-tx
#1127
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
Open
ladamesny
wants to merge
7
commits into
master
Choose a base branch
from
enhancement/option-to-save-tx-cbor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4505f58
enhancement: add option to save transaction to be signed output to a …
ladamesny 40a10b4
enhancement: use path buf with clap for better output path setting ac…
ladamesny b9c2763
output-file option - updated docs and changelog
ladamesny 10c04eb
tests: fix formatting errors
ladamesny 14aff7d
Merge branch 'master' of github.com:input-output-hk/partner-chains in…
ladamesny 12b3b08
Merge branch 'master' into enhancement/option-to-save-tx-cbor
ladamesny 7f784ef
Merge branch 'master' into enhancement/option-to-save-tx-cbor
ladamesny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,9 +6,12 @@ use sidechain_domain::TransactionCbor; | |
| #[derive(Clone, Debug, clap::Parser)] | ||
| /// Command for signing a cardano transaction | ||
| pub struct SignTxCmd { | ||
| #[arg(long)] | ||
| /// Hex-encoded transaction CBOR (with or without 0x prefix) | ||
| transaction: TransactionCbor, | ||
| #[arg( | ||
| long, | ||
| value_hint = clap::ValueHint::AnyPath, | ||
| help = "Transaction input: hex string, JSON with transaction_to_sign, or file path to JSON" | ||
| )] | ||
| transaction: String, | ||
| #[clap(flatten)] | ||
| /// Path to the Cardano Signing Key file that you want to sign the transaction with | ||
| payment_key_file: PaymentFilePath, | ||
|
|
@@ -19,7 +22,13 @@ impl SignTxCmd { | |
| pub async fn execute(self) -> crate::SubCmdResult { | ||
| let payment_key = self.payment_key_file.read_key()?; | ||
|
|
||
| let vkey_witness = sign_tx(self.transaction.0, &payment_key)?; | ||
| // Try to extract cborHex from the input | ||
| let cbor_hex = extract_cbor_hex(&self.transaction)?; | ||
| let transaction_cbor: TransactionCbor = cbor_hex | ||
| .parse() | ||
| .map_err(|e| anyhow::anyhow!("Failed to parse transaction CBOR: {}", e))?; | ||
|
|
||
| let vkey_witness = sign_tx(transaction_cbor.0, &payment_key)?; | ||
|
|
||
| let json = json!( | ||
| { | ||
|
|
@@ -31,3 +40,49 @@ impl SignTxCmd { | |
| Ok(json) | ||
| } | ||
| } | ||
|
|
||
| /// Extracts cborHex from the input string. | ||
| /// Uses deterministic order: file path -> JSON parsing -> hex string | ||
| fn extract_cbor_hex(input: &str) -> Result<String, Box<dyn std::error::Error + Send + Sync>> { | ||
| let trimmed = input.trim(); | ||
|
|
||
| // Case 1: Check if it's a file path that exists | ||
| let json_str = if std::path::Path::new(trimmed).exists() { | ||
| std::fs::read_to_string(trimmed) | ||
| .map_err(|e| format!("Failed to read file '{}': {}", trimmed, e))? | ||
| } else if let Ok(json_value) = serde_json::from_str::<serde_json::Value>(trimmed) { | ||
| // Case 2: Try parsing as JSON directly | ||
| return extract_cbor_from_json(&json_value); | ||
| } else { | ||
| // Case 3: Treat as direct hex string | ||
| return Ok(trimmed.to_string()); | ||
| }; | ||
|
|
||
| // If we read from file, parse the JSON and extract cborHex | ||
| let json_value: serde_json::Value = serde_json::from_str(&json_str) | ||
| .map_err(|e| format!("Failed to parse JSON from file: {}", e))?; | ||
|
|
||
| extract_cbor_from_json(&json_value) | ||
| } | ||
|
|
||
| /// Extracts cborHex from a JSON value | ||
| fn extract_cbor_from_json( | ||
| json_value: &serde_json::Value, | ||
| ) -> Result<String, Box<dyn std::error::Error + Send + Sync>> { | ||
| // Try to extract cborHex from transaction_to_sign format | ||
| if let Some(cbor_hex) = json_value | ||
| .get("transaction_to_sign") | ||
| .and_then(|v| v.get("tx")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A this point I would parse |
||
| .and_then(|v| v.get("cborHex")) | ||
| .and_then(|v| v.as_str()) | ||
| { | ||
| return Ok(cbor_hex.to_string()); | ||
| } | ||
|
|
||
| // Try to extract cborHex from direct tx format | ||
| if let Some(cbor_hex) = json_value.get("cborHex").and_then(|v| v.as_str()) { | ||
| return Ok(cbor_hex.to_string()); | ||
| } | ||
|
|
||
| Err("Could not extract cborHex from JSON. Expected 'transaction_to_sign.tx.cborHex' or 'cborHex' field.".into()) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You have tx_data.tx that are bytes. Then you serialized it Cardano file JSON and then you take this field containing bytes of the transaction instead of using it directly.
You could just
hex::encode(tx_data.tx), couldn't you?