Skip to content

Commit

Permalink
Allow inserting inputs/outputs at specified positions
Browse files Browse the repository at this point in the history
While the positions of inputs and outputs don't usually matter, they do
matter in covenant constructions. This allows easier construction rather
than creating a new vec or swapping things around
  • Loading branch information
sanket1729 committed Aug 9, 2022
1 parent 7bc95f4 commit 648e22e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/pset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ impl PartiallySignedTransaction {
self.inputs.push(inp);
}

/// Add an input to pset at position i. This also updates the
/// pset global input count
/// Panics if index is more than length.
pub fn insert_input(&mut self, inp: Input, pos: usize) {
self.global.tx_data.input_count += 1;
self.inputs.insert(pos, inp);
}

/// Read accessor to inputs
pub fn inputs(&self) -> &[Input] {
&self.inputs
Expand Down Expand Up @@ -127,6 +135,14 @@ impl PartiallySignedTransaction {
self.outputs.push(out);
}

/// Add an output to pset at position i. This also updates the
/// pset global output count
/// Panics if index is more than length.
pub fn insert_output(&mut self, out: Output, pos: usize) {
self.global.tx_data.output_count += 1;
self.outputs.insert(pos, out);
}

/// read accessor to outputs
pub fn outputs(&self) -> &[Output] {
&self.outputs
Expand Down

0 comments on commit 648e22e

Please sign in to comment.