Skip to content

Commit 15da1a7

Browse files
committed
new builder getter full_size
1 parent cef57f1 commit 15da1a7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

rust/src/tx_builder.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl TransactionBuilder {
523523
}
524524
}
525525

526-
pub fn build(&self) -> Result<TransactionBody, JsError> {
526+
fn build_and_size(&self) -> (TransactionBody, usize) {
527527
let fee = self.fee.ok_or_else(|| JsError::from_str("Fee not specified"))?;
528528
let built = TransactionBody {
529529
inputs: TransactionInputs(self.inputs.iter().map(|ref tx_builder_input| tx_builder_input.input.clone()).collect()),
@@ -548,14 +548,23 @@ impl TransactionBuilder {
548548
// we must build a tx with fake data (of correct size) to check the final Transaction size
549549
let full_tx = fake_full_tx(self, built)?;
550550
let full_tx_size = full_tx.to_bytes().len();
551+
return (full_tx.body, full_tx_size);
552+
}
553+
554+
pub fn full_size(&self) -> usize {
555+
return self.build_and_size().1;
556+
}
557+
558+
pub fn build(&self) -> Result<TransactionBody, JsError> {
559+
let (body, full_tx_size) = self.build_and_size();
551560
if full_tx_size > self.max_tx_size as usize {
552561
Err(JsError::from_str(&format!(
553562
"Maximum transaction size of {} exceeded. Found: {}",
554563
self.max_tx_size,
555564
full_tx_size
556565
)))
557566
} else {
558-
Ok(full_tx.body)
567+
Ok(body)
559568
}
560569
}
561570

0 commit comments

Comments
 (0)