I have a question regarding the retrieval of transaction parameters, specifically LOCK_TIME
and witnessScript
, for a P2WSH transaction I created.
Below is the relevant code snippet for generating the locking script using a specific LOCK_TIME:
const TEN_MINUTES = 10 * 60;
const LOCK_TIME = bip65.encode({ utc: Math.floor(Date.now() / 1000) + TEN_MINUTES });
const LOCKING_SCRIPT = script.compile([
script.number.encode(LOCK_TIME),
opcodes.OP_CHECKLOCKTIMEVERIFY,
opcodes.OP_DROP,
]);
When I want to spend from the address generated with this script, I understand that I need to know the exact witnessUtxo.script
and witnessScript
I used to lock the funds.
For the unlocking part, here’s how I am adding the input in my PSBT:
PSBT.addInput({
hash: TX_HASH,
index: 0,
sequence: 0xffffffff - 1,
witnessUtxo: {
// script: P2WSH.output!,
script: Buffer.from('0020a3a67b9adeba96fba9717446c3c4e61a26d867f7defa602593004a5daa87f2ea'),
value: VALUE,
},
//witnessScript: LOCKING_SCRIPT,
witnessScript: Buffer.from('04a9806b66b175', 'hex'),
});
I noticed I can easily retrieve the witnessUtxoScript
by checking the txId on my node. However, I am unable to locate the witnessScript
anywhere. It seems the only way to recreate it is by knowing the exact LOCK_TIME that was previously set.
Is my understanding correct? Moreover, is there any way to find either the LOCK_TIME or the witnessScript once a transaction has been mined?
Thank you for your help.