From 648e22e82f012fd2dd5699d9ce10b40a74e872dd Mon Sep 17 00:00:00 2001 From: sanket1729 Date: Tue, 9 Aug 2022 10:53:01 -0700 Subject: [PATCH] Allow inserting inputs/outputs at specified positions 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 --- src/pset/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/pset/mod.rs b/src/pset/mod.rs index 5f759e28..e6edcf20 100644 --- a/src/pset/mod.rs +++ b/src/pset/mod.rs @@ -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 @@ -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