Skip to content

Commit

Permalink
[cli] dev section: deprecate old submit command
Browse files Browse the repository at this point in the history
functionality should be covered by new set of commands
  • Loading branch information
Alex Orlov authored and phoenix-o committed Jul 23, 2019
1 parent e2fd9dc commit 7f3b7fa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 117 deletions.
81 changes: 4 additions & 77 deletions client/src/client_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ use num_traits::{
cast::{FromPrimitive, ToPrimitive},
identities::Zero,
};
use proto_conv::{FromProtoBytes, IntoProto};
use proto_conv::IntoProto;
use rust_decimal::Decimal;
use serde_json;
use std::{
collections::HashMap,
convert::TryFrom,
fmt,
fs::{self, File},
io::{stdout, Read, Write},
fmt, fs,
io::{stdout, Write},
path::Path,
process::Command,
str::FromStr,
Expand All @@ -41,9 +40,7 @@ use types::{
},
account_state_blob::{AccountStateBlob, AccountStateWithProof},
contract_event::{ContractEvent, EventWithProof},
transaction::{
parse_as_transaction_argument, Program, RawTransaction, SignedTransaction, Version,
},
transaction::{parse_as_transaction_argument, Program, SignedTransaction, Version},
transaction_helpers::{create_signed_txn, TransactionSigner},
validator_verifier::ValidatorVerifier,
};
Expand Down Expand Up @@ -517,76 +514,6 @@ impl ClientProxy {
)
}

/// Submit a transaction to the network.
pub fn submit_transaction_from_disk(
&mut self,
space_delim_strings: &[&str],
is_blocking: bool,
) -> Result<IndexAndSequence> {
let signer_account_address =
self.get_account_address_from_parameter(space_delim_strings[1])?;

let txn = {
let mut file = File::open(space_delim_strings[2]).map_err(|_| {
format_err!("Cannot open file located at {}", space_delim_strings[2])
})?;
let mut buf = vec![];
file.read_to_end(&mut buf).map_err(|_| {
format_err!("Cannot read file located at {}", space_delim_strings[2])
})?;
RawTransaction::from_proto_bytes(&buf).map_err(|_| {
format_err!(
"Cannot deserialize file located at {} as RawTransaction",
space_delim_strings[2]
)
})?
};
self.submit_custom_transaction(signer_account_address, txn, is_blocking)
}

fn submit_custom_transaction(
&mut self,
signer_address: AccountAddress,
txn: RawTransaction,
is_blocking: bool,
) -> Result<IndexAndSequence> {
let sender_address;
let sender_sequence;
{
let signer_account_ref_id = self.get_account_ref_id(&signer_address)?;
let signer_account = self.accounts.get(signer_account_ref_id).ok_or_else(|| {
format_err!("Unable to find sender account: {}", signer_account_ref_id)
})?;
let signer: Box<&dyn TransactionSigner> = match &signer_account.key_pair {
Some(key_pair) => Box::new(key_pair),
None => Box::new(&self.wallet),
};
let mut req = SubmitTransactionRequest::new();
let txn = signer.sign_txn(txn).map_err(|_| {
format_err!(
"Account #{} failed to sign transaction",
signer_account_ref_id
)
})?;
sender_address = txn.sender();
sender_sequence = txn.sequence_number();

req.set_signed_txn(txn.into_proto());
self.client.submit_transaction(None, &req)?;
}

if is_blocking {
self.wait_for_transaction(sender_address, sender_sequence);
}

Ok(IndexAndSequence {
account_index: AccountEntry::Address(sender_address),
// The signer has nothing to do with the sequence here. The sequence number that we are
// looking for should just be the sequence number in the sent transaction.
sequence_number: sender_sequence,
})
}

/// Get the latest account state from validator.
pub fn get_latest_account_state(
&mut self,
Expand Down
40 changes: 0 additions & 40 deletions client/src/dev_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ impl Command for DevCommand {
Box::new(DevCommandCompile {}),
Box::new(DevCommandPublish {}),
Box::new(DevCommandExecute {}),
Box::new(SubmitTransactionFromDiskCommand {}),
];
subcommand_execute(&params[0], commands, client, &params[1..]);
}
Expand Down Expand Up @@ -105,42 +104,3 @@ impl Command for DevCommandExecute {
}
}
}

pub struct SubmitTransactionFromDiskCommand {}

impl Command for SubmitTransactionFromDiskCommand {
fn get_aliases(&self) -> Vec<&'static str> {
vec!["submit", "submitb", "s", "sb"]
}
fn get_description(&self) -> &'static str {
"Load a RawTransaction from file and submit to the network"
}
fn get_params_help(&self) -> &'static str {
"\n\t<signer_account_address>|<signer_account_ref_id> <path_to_raw_transaction> Suffix 'b' is for blocking. "
}
fn execute(&self, client: &mut ClientProxy, params: &[&str]) {
if params.len() != 3 {
println!(
"Invalid number of arguments for submitting transaction, got {}",
params.len()
);
return;
}
let is_blocking = blocking_cmd(&params[0]);
match client.submit_transaction_from_disk(params, is_blocking) {
Ok(index_and_seq) => {
if is_blocking {
println!("Finished transaction!");
} else {
println!("Transaction submitted to validator");
}
println!(
"To query for transaction status, run: query txn_acc_seq {} {} \
<fetch_events=true|false>",
index_and_seq.account_index, index_and_seq.sequence_number
);
}
Err(e) => report_error("Failed to perform transaction", e),
}
}
}

0 comments on commit 7f3b7fa

Please sign in to comment.