Browse Source

Remove the cached buffer getter

psbt
junderw 6 years ago
parent
commit
1326e0cc42
No known key found for this signature in database GPG Key ID: B256185D3A971908
  1. 20
      src/psbt.js
  2. 23
      ts_src/psbt.ts
  3. 1
      types/psbt.d.ts

20
src/psbt.js

@ -73,23 +73,6 @@ class Psbt {
const c = this.__CACHE;
c.__TX = this.data.globalMap.unsignedTx.tx;
if (this.data.inputs.length === 0) this.setVersion(2);
// set cache
this.unsignedTx = Buffer.from([]);
Object.defineProperty(this, 'unsignedTx', {
enumerable: true,
get() {
const buf = c.__TX_BUF_CACHE;
if (buf !== undefined) {
return buf;
} else {
c.__TX_BUF_CACHE = c.__TX.toBuffer();
return c.__TX_BUF_CACHE;
}
},
set(_data) {
c.__TX_BUF_CACHE = _data;
},
});
// Make data hidden when enumerating
const dpew = (obj, attr, enumerable, writable) =>
Object.defineProperty(obj, attr, {
@ -137,7 +120,6 @@ class Psbt {
checkInputsForPartialSig(this.data.inputs, 'setVersion');
const c = this.__CACHE;
c.__TX.version = version;
c.__TX_BUF_CACHE = undefined;
c.__EXTRACTED_TX = undefined;
return this;
}
@ -146,7 +128,6 @@ class Psbt {
checkInputsForPartialSig(this.data.inputs, 'setLocktime');
const c = this.__CACHE;
c.__TX.locktime = locktime;
c.__TX_BUF_CACHE = undefined;
c.__EXTRACTED_TX = undefined;
return this;
}
@ -158,7 +139,6 @@ class Psbt {
throw new Error('Input index too high');
}
c.__TX.ins[inputIndex].sequence = sequence;
c.__TX_BUF_CACHE = undefined;
c.__EXTRACTED_TX = undefined;
return this;
}

23
ts_src/psbt.ts

@ -96,7 +96,6 @@ export class Psbt {
return psbt;
}
unsignedTx: Buffer;
private __CACHE: PsbtCache = {
__NON_WITNESS_UTXO_TX_CACHE: [],
__NON_WITNESS_UTXO_BUF_CACHE: [],
@ -115,24 +114,6 @@ export class Psbt {
c.__TX = (this.data.globalMap.unsignedTx as PsbtTransaction).tx;
if (this.data.inputs.length === 0) this.setVersion(2);
// set cache
this.unsignedTx = Buffer.from([]);
Object.defineProperty(this, 'unsignedTx', {
enumerable: true,
get(): Buffer {
const buf = c.__TX_BUF_CACHE;
if (buf !== undefined) {
return buf;
} else {
c.__TX_BUF_CACHE = c.__TX.toBuffer();
return c.__TX_BUF_CACHE;
}
},
set(_data: Buffer): void {
c.__TX_BUF_CACHE = _data;
},
});
// Make data hidden when enumerating
const dpew = (
obj: any,
@ -174,7 +155,6 @@ export class Psbt {
checkInputsForPartialSig(this.data.inputs, 'setVersion');
const c = this.__CACHE;
c.__TX.version = version;
c.__TX_BUF_CACHE = undefined;
c.__EXTRACTED_TX = undefined;
return this;
}
@ -184,7 +164,6 @@ export class Psbt {
checkInputsForPartialSig(this.data.inputs, 'setLocktime');
const c = this.__CACHE;
c.__TX.locktime = locktime;
c.__TX_BUF_CACHE = undefined;
c.__EXTRACTED_TX = undefined;
return this;
}
@ -197,7 +176,6 @@ export class Psbt {
throw new Error('Input index too high');
}
c.__TX.ins[inputIndex].sequence = sequence;
c.__TX_BUF_CACHE = undefined;
c.__EXTRACTED_TX = undefined;
return this;
}
@ -533,7 +511,6 @@ interface PsbtCache {
__NON_WITNESS_UTXO_BUF_CACHE: Buffer[];
__TX_IN_CACHE: { [index: string]: number };
__TX: Transaction;
__TX_BUF_CACHE?: Buffer;
__FEE_RATE?: number;
__EXTRACTED_TX?: Transaction;
}

1
types/psbt.d.ts

@ -41,7 +41,6 @@ export declare class Psbt {
static fromBase64(data: string, opts?: PsbtOptsOptional): Psbt;
static fromHex(data: string, opts?: PsbtOptsOptional): Psbt;
static fromBuffer(buffer: Buffer, opts?: PsbtOptsOptional): Psbt;
unsignedTx: Buffer;
private __CACHE;
private opts;
constructor(opts?: PsbtOptsOptional, data?: PsbtBase);

Loading…
Cancel
Save