Skip to content

Commit

Permalink
Fix issues with tx input/output ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Symphonic3 committed Aug 20, 2023
1 parent 1e69178 commit df9b9d9
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -1873,10 +1873,10 @@ class Plug {

}

connectLogically(index) {
connectLogically(index, side) {

if (!this.fullyConnected()) return true;
return this.childConnectLogically(index);
return this.childConnectLogically(index, side);

}

Expand Down Expand Up @@ -1913,7 +1913,7 @@ class Plug {
if (element.maxplugs <= (side == ButtonSide.LEFT ? element.rightPlugs : element.leftPlugs).length) return;
if (side == ButtonSide.LEFT) this.left = element;
else this.right = element;
if (this.connectLogically(index)) {
if (this.connectLogically(index, side)) {
element.addVisualPlug(side == ButtonSide.LEFT ? ButtonSide.RIGHT : ButtonSide.LEFT, this, index);
} else {
if (side == ButtonSide.LEFT) this.left = null;
Expand Down Expand Up @@ -2003,7 +2003,7 @@ class Plug {
throw new Error("This needs to be implemented by subclass!");
}

childConnectLogically(index) {
childConnectLogically(index, side) {
throw new Error("This needs to be implemented by subclass!");
}

Expand Down Expand Up @@ -2038,12 +2038,11 @@ class TransactionOutPlug extends Plug {

}

childConnectLogically(index) {
childConnectLogically(index, side) {

if (this.editable) {
let arr = this.left.transaction.outputs;
if (index != -1) arr.splice(index, 0, this.right.utxo);
else arr.push(this.right.utxo);
if (side == ButtonSide.LEFT) arr.splice(index, 0, this.right.utxo); else arr.splice(this.left.rightPlugs.indexOf(this), 0, this.right.utxo);
this.right.utxo.tx = this.left.transaction;
}

Expand Down Expand Up @@ -2087,15 +2086,14 @@ class TransactionInPlug extends Plug {

}

childConnectLogically(index) {
childConnectLogically(index, side) {

if (this.editable) {
if (!this.left.utxo.getTXID()) {
return false;
}
let arr = this.right.transaction.inputs;
if (index != -1) arr.splice(index, 0, this.left.utxo);
else arr.push(this.left.utxo);
if (side == ButtonSide.RIGHT) arr.splice(index, 0, this.left.utxo); else arr.splice(this.right.leftPlugs.indexOf(this), 0, this.left.utxo);
this.left.utxo.spendertx = this.right.transaction;
}

Expand Down

0 comments on commit df9b9d9

Please sign in to comment.