Skip to content

Commit 9eb3031

Browse files
authored
Merge pull request #511 from Oyl-Wallet/hude/investigate_fee
getEstimatedFee tapscript
2 parents a5ac171 + 9ebb983 commit 9eb3031

File tree

5 files changed

+48
-11
lines changed

5 files changed

+48
-11
lines changed

lib/alkanes/alkanes.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/psbt/psbt.js

Lines changed: 24 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/psbt/psbt.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/alkanes/alkanes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,6 @@ export const createDeployCommitPsbt = async ({
789789
}
790790

791791
await addInputUtxosToPsbt(gatheredUtxos.utxos, psbt, account, provider);
792-
793792
psbt.addOutput({
794793
value: revealTxFee,
795794
address: inscriberInfo.address,

src/psbt/psbt.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,28 @@ export const getEstimatedFee = async ({
5858
})
5959

6060
psbtObj.data.inputs.forEach((input, index) => {
61-
if (input.tapInternalKey) {
62-
tx.setWitness(index, [Buffer.alloc(65)])
63-
} else if (input.witnessUtxo) {
64-
tx.setWitness(index, [Buffer.alloc(107)])
61+
if (input.witnessUtxo) {
62+
const scriptLen = input.witnessUtxo.script.length;
63+
if (scriptLen === 34) { // P2TR
64+
if (input.tapLeafScript && input.tapLeafScript.length > 0) {
65+
// Script-path spend (e.g., inscription reveal)
66+
const leafScript = input.tapLeafScript[0];
67+
const witness = [
68+
Buffer.alloc(64), // Signature (can be 65, but 64 is common)
69+
leafScript.script,
70+
leafScript.controlBlock,
71+
];
72+
tx.setWitness(index, witness);
73+
} else {
74+
// Key-path spend
75+
tx.setWitness(index, [Buffer.alloc(65)]); // schnorr signature
76+
}
77+
} else if (scriptLen === 22) { // P2WPKH
78+
tx.setWitness(index, [Buffer.alloc(107)]);
79+
}
80+
} else if (input.tapInternalKey) {
81+
// Fallback for key-path spend if witnessUtxo is not present
82+
tx.setWitness(index, [Buffer.alloc(65)]);
6583
}
6684
})
6785

0 commit comments

Comments
 (0)