Skip to content

Commit 2aa3926

Browse files
junderwlonghoangwkm
andcommitted
Fix Transaction Output type
Co-authored-by: longhoang.wkm <[email protected]>
1 parent 41bf2cd commit 2aa3926

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

ts_src/transaction.ts

Lines changed: 6 additions & 13 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 (
@@ -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)
@@ -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)