mirror of
https://github.com/mempool/mempool.git
synced 2026-08-13 12:33:11 +02:00
Merge pull request #6624 from mempool/natsoni/export-utils-witness-program
Some checks failed
Backend Integration Tests with MariaDB / Backend Integration Tests - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Backend (dev) - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Backend (prod) - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Cache assets for builds (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Validate generated backend Docker JSON (push) Has been cancelled
Supply Chain Audit / Backend install-script audit (push) Has been cancelled
Supply Chain Audit / Frontend install-script audit (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Frontend (dev) - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Frontend (prod) - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / E2E tests for liquid (push) Has been cancelled
CI Pipeline for the Backend and Frontend / E2E tests for mempool (push) Has been cancelled
CI Pipeline for the Backend and Frontend / E2E tests for testnet4 (push) Has been cancelled
Some checks failed
Backend Integration Tests with MariaDB / Backend Integration Tests - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Backend (dev) - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Backend (prod) - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Cache assets for builds (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Validate generated backend Docker JSON (push) Has been cancelled
Supply Chain Audit / Backend install-script audit (push) Has been cancelled
Supply Chain Audit / Frontend install-script audit (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Frontend (dev) - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Frontend (prod) - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / E2E tests for liquid (push) Has been cancelled
CI Pipeline for the Backend and Frontend / E2E tests for mempool (push) Has been cancelled
CI Pipeline for the Backend and Frontend / E2E tests for testnet4 (push) Has been cancelled
Export isWitnessProgram and add PSBT_GLOBAL
This commit is contained in:
commit
bb760fa5d6
1 changed files with 17 additions and 3 deletions
|
|
@ -713,7 +713,7 @@ function isNonStandardLegacySigops(tx: Transaction, height?: number, network?: s
|
|||
// A witness program is any valid scriptpubkey that consists of a 1-byte push opcode
|
||||
// followed by a data push between 2 and 40 bytes.
|
||||
// https://github.com/bitcoin/bitcoin/blob/2c79abc7ad4850e9e3ba32a04c530155cda7f980/src/script/script.cpp#L224-L240
|
||||
function isWitnessProgram(scriptpubkey: string): false | { version: number, program: string } {
|
||||
export function isWitnessProgram(scriptpubkey: string): false | { version: number, program: string } {
|
||||
if (scriptpubkey.length < 8 || scriptpubkey.length > 84) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1456,6 +1456,11 @@ function fromBuffer(buffer: Uint8Array, network: string, inputs?: PsbtKeyValueMa
|
|||
export type PsbtKeyValue = { keyData: Uint8Array; value: Uint8Array; };
|
||||
export type PsbtKeyValueMap = Map<number, PsbtKeyValue[]>;
|
||||
|
||||
export const PSBT_GLOBAL = {
|
||||
UNSIGNED_TX: 0x00,
|
||||
GENERIC_SIGNED_MESSAGE: 0x09,
|
||||
};
|
||||
|
||||
export const PSBT_IN = {
|
||||
NON_WITNESS_UTXO: 0x00,
|
||||
WITNESS_UTXO: 0x01,
|
||||
|
|
@ -1601,9 +1606,10 @@ function decodePsbt(psbtBuffer: Uint8Array): { rawTx: Uint8Array; inputs: PsbtKe
|
|||
* @param rawTx - The unsigned transaction as Uint8Array
|
||||
* @param inputs - Array of input maps containing key-value pairs for each input
|
||||
* @param outputs - Array of output maps containing key-value pairs for each output
|
||||
* @param globals - Global key-value pairs for the PSBT
|
||||
* @returns PSBT buffer as Uint8Array
|
||||
*/
|
||||
export function encodePsbt(rawTx: Uint8Array, inputs: PsbtKeyValueMap[], outputs: PsbtKeyValueMap[]): Uint8Array {
|
||||
export function encodePsbt(rawTx: Uint8Array, inputs: PsbtKeyValueMap[], outputs: PsbtKeyValueMap[], globals: PsbtKeyValueMap = new Map()): Uint8Array {
|
||||
const result: number[] = [];
|
||||
|
||||
// Magic bytes: "psbt" in ASCII
|
||||
|
|
@ -1633,7 +1639,15 @@ export function encodePsbt(rawTx: Uint8Array, inputs: PsbtKeyValueMap[], outputs
|
|||
|
||||
// GLOBAL MAP
|
||||
// Add unsigned transaction (key type 0x00)
|
||||
writeKeyValue(0x00, new Uint8Array(), rawTx);
|
||||
writeKeyValue(PSBT_GLOBAL.UNSIGNED_TX, new Uint8Array(), rawTx);
|
||||
for (const [keyType, items] of globals) {
|
||||
if (keyType === PSBT_GLOBAL.UNSIGNED_TX) {
|
||||
throw new Error('PSBT global map must not include UNSIGNED_TX (0x00); provide it via rawTx');
|
||||
}
|
||||
for (const record of items) {
|
||||
writeKeyValue(keyType, record.keyData, record.value);
|
||||
}
|
||||
}
|
||||
|
||||
// End global map
|
||||
result.push(0x00);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue