Skip to content

Commit

Permalink
♻️ Extract function to check tx is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
doitian committed Feb 28, 2024
1 parent 163fa3f commit 3ebc213
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/lib/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export function importTransaction(jsonContent) {
throw new Error("Unknown JSON format");
}

export function checkIsReady(transaction) {
if (transaction.state === "pending" && isReady(transaction)) {
transaction.state = "ready";
}
}

export function resolvePendingSecp256k1Signatures(transaction) {
const lockActions = [];
const witnesses = [];
Expand All @@ -74,6 +80,7 @@ export function resolvePendingSecp256k1Signatures(transaction) {

mergeLockActions(transaction, lockActions);
mergeWitnesses(transaction, witnesses);
checkIsReady(transaction);
}

export function isReady(transaction) {
Expand Down Expand Up @@ -161,9 +168,7 @@ export function mergeTransaction(target, from) {

if (target.buildingPacket.value.resolved_inputs.outputs.length > 0) {
resolvePendingSecp256k1Signatures(target);
}

if (target.state === "pending" && isReady(target)) {
target.state = "ready";
} else {
checkIsReady(target);
}
}

0 comments on commit 3ebc213

Please sign in to comment.