Skip to content

Commit

Permalink
wip - parse transaction pbjson
Browse files Browse the repository at this point in the history
  • Loading branch information
sambukowski committed Oct 18, 2024
1 parent 41e7aaf commit 4d9e4c6
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions crates/astria-cli/src/sequencer/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
// use astria_core::protocol::transaction::v1::TransactionBody;
use astria_core::{
self,
generated::protocol::transaction::v1::TransactionBody as TransactionBodyProto,
protocol::transaction::v1::TransactionBody,
generated::protocol::transaction::v1::{
Transaction as TransactionProto,
TransactionBody as TransactionBodyProto,
},
protocol::transaction::v1::{
Transaction,
TransactionBody,
},
};
use astria_sequencer_client::{
HttpClient,
Expand All @@ -29,37 +35,47 @@ pub(super) struct Command {
default_value = crate::DEFAULT_SEQUENCER_RPC
)]
sequencer_url: String,
/// The private key of account being sent from
#[arg(long, env = "SEQUENCER_PRIVATE_KEY")]
// TODO: https://github.com/astriaorg/astria/issues/594
// Don't use a plain text private, prefer wrapper like from
// the secrecy crate with specialized `Debug` and `Drop` implementations
// that overwrite the key on drop and don't reveal it when printing.
private_key: String,
// /// The private key of account being sent from
// #[arg(long, env = "SEQUENCER_PRIVATE_KEY")]
// // TODO: https://github.com/astriaorg/astria/issues/594
// // Don't use a plain text private, prefer wrapper like from
// // the secrecy crate with specialized `Debug` and `Drop` implementations
// // that overwrite the key on drop and don't reveal it when printing.
// private_key: String,
}

impl Command {
pub(super) async fn run(self) -> eyre::Result<()> {
let sequencer_client = HttpClient::new(self.sequencer_url.as_str())
.wrap_err("failed constructing http sequencer client")?;

let sequencer_key = signing_key_from_private_key(self.private_key.as_str())?;
// let sequencer_key = signing_key_from_private_key(self.private_key.as_str())?;

let tx_body: TransactionBodyProto = serde_json::from_str(self.pbjson.as_str())
.wrap_err("failed to parse pbjson into TransactionBody")?;
// let tx_body: TransactionBodyProto = serde_json::from_str(self.pbjson.as_str())
// .wrap_err("failed to parse pbjson into TransactionBody")?;

let tx = TransactionBody::try_from_raw(tx_body.clone())
.wrap_err("failed to convert to TransactionBody from raw")?
.sign(&sequencer_key);
// let tx = TransactionBody::try_from_raw(tx_body.clone())
// .wrap_err("failed to convert to TransactionBody from raw")?
// .sign(&sequencer_key);

// println!(
// "{}",
// serde_json::to_string_pretty(&tx_body)
// .wrap_err("failed to serialize TransactionBody")?
// );
let tx_raw: TransactionProto = serde_json::from_str(self.pbjson.as_str())
.wrap_err("failed to parse pbjson into raw Transaction")?;

// let tx = TransactionBody::try_from_raw(tx_body.clone())
// .wrap_err("failed to convert to TransactionBody from raw")?
// .sign(&sequencer_key);

let transaction = Transaction::try_from_raw(tx_raw.clone())
.wrap_err("failed to convert to transaction")?;

println!(
"{}",
serde_json::to_string_pretty(&tx_raw)
.wrap_err("failed to serialize TransactionBody")?
);

let res = sequencer_client
.submit_transaction_sync(tx)
.submit_transaction_sync(transaction)
.await
.wrap_err("failed to submit transaction")?;

Expand Down

0 comments on commit 4d9e4c6

Please sign in to comment.