Rebuilding Transaction

Rebuilding a transaction starts from obtaining the TxBuilderBody , which can be obtained by either of the methods from TxParser:

  • get_builder_body - get the entire TxBuilderBody of the current transaction parsed

  • get_builder_body_without_change - get the TxBuilderBody without the last output

    • This is the recommended method for rebuilding the transaction since the complete method of TxBuilder would re-calculate the change as per the manipulation. Thus, the rebuilt transaction will be in an expected shape without one extra output.

Full Example

// let body = tx_parser.get_builder_body();
let body = tx_parser.get_builder_body_without_change();

let mut new_tx_builder = TxBuilder::new_core();

// manipulation of the `tx_builder_body` as needed here
new_tx_builder.tx_builder_body = body.clone();

new_tx_builder
    // extra tx building methods as needed here
    .complete_sync(None)
    .unwrap();

Last updated