Skip to content

Commit 29e3195

Browse files
authored
Merge pull request #1506 from longhoangwkm/fix-property-doesnt-exist-error-types
Fix error TS2339: Property valueBuffer does not exist on type OpenOutput
2 parents 41bf2cd + 22d5831 commit 29e3195

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

ts_src/transaction.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,20 @@ const ONE: Buffer = Buffer.from(
3636
'hex',
3737
);
3838
const VALUE_UINT64_MAX: Buffer = Buffer.from('ffffffffffffffff', 'hex');
39-
const BLANK_OUTPUT: BlankOutput = {
39+
const BLANK_OUTPUT = {
4040
script: EMPTY_SCRIPT,
4141
valueBuffer: VALUE_UINT64_MAX,
4242
};
4343

44-
function isOutput(out: Output | BlankOutput): out is Output {
45-
return (out as Output).value !== undefined;
46-
}
47-
48-
export interface BlankOutput {
49-
script: Buffer;
50-
valueBuffer: Buffer;
44+
function isOutput(out: Output): boolean {
45+
return out.value !== undefined;
5146
}
5247

5348
export interface Output {
5449
script: Buffer;
5550
value: number;
5651
}
5752

58-
type OpenOutput = Output | BlankOutput;
59-
6053
export interface Input {
6154
hash: Buffer;
6255
index: number;
@@ -185,7 +178,7 @@ export class Transaction {
185178
version: number = 1;
186179
locktime: number = 0;
187180
ins: Input[] = [];
188-
outs: OpenOutput[] = [];
181+
outs: Output[] = [];
189182

190183
isCoinbase(): boolean {
191184
return (
@@ -275,7 +268,7 @@ export class Transaction {
275268
newTx.outs = this.outs.map(txOut => {
276269
return {
277270
script: txOut.script,
278-
value: (txOut as Output).value,
271+
value: txOut.value,
279272
};
280273
});
281274

@@ -333,7 +326,7 @@ export class Transaction {
333326

334327
// "blank" outputs before
335328
for (let i = 0; i < inIndex; i++) {
336-
txTmp.outs[i] = BLANK_OUTPUT;
329+
(txTmp.outs as any)[i] = BLANK_OUTPUT;
337330
}
338331

339332
// ignore sequence numbers (except at inIndex)
@@ -445,7 +438,7 @@ export class Transaction {
445438
toffset = 0;
446439

447440
this.outs.forEach(out => {
448-
writeUInt64((out as Output).value);
441+
writeUInt64(out.value);
449442
writeVarSlice(out.script);
450443
});
451444

@@ -458,7 +451,7 @@ export class Transaction {
458451

459452
tbuffer = Buffer.allocUnsafe(8 + varSliceSize(output.script));
460453
toffset = 0;
461-
writeUInt64((output as Output).value);
454+
writeUInt64(output.value);
462455
writeVarSlice(output.script);
463456

464457
hashOutputs = bcrypto.hash256(tbuffer);
@@ -602,7 +595,7 @@ export class Transaction {
602595
if (isOutput(txOut)) {
603596
writeUInt64(txOut.value);
604597
} else {
605-
writeSlice(txOut.valueBuffer);
598+
writeSlice((txOut as any).valueBuffer);
606599
}
607600

608601
writeVarSlice(txOut.script);

types/transaction.d.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
export interface BlankOutput {
2-
script: Buffer;
3-
valueBuffer: Buffer;
4-
}
51
export interface Output {
62
script: Buffer;
73
value: number;
84
}
9-
declare type OpenOutput = Output | BlankOutput;
105
export interface Input {
116
hash: Buffer;
127
index: number;
@@ -28,7 +23,7 @@ export declare class Transaction {
2823
version: number;
2924
locktime: number;
3025
ins: Input[];
31-
outs: OpenOutput[];
26+
outs: Output[];
3227
isCoinbase(): boolean;
3328
addInput(hash: Buffer, index: number, sequence?: number, scriptSig?: Buffer): number;
3429
addOutput(scriptPubKey: Buffer, value: number): number;
@@ -56,4 +51,3 @@ export declare class Transaction {
5651
private __byteLength;
5752
private __toBuffer;
5853
}
59-
export {};

0 commit comments

Comments
 (0)