Fix Transaction Output type
Co-authored-by: longhoang.wkm <longhoang@wakumo.vn>
This commit is contained in:
parent
41bf2cd03d
commit
2aa3926616
2 changed files with 7 additions and 20 deletions
|
@ -36,18 +36,13 @@ const ONE: Buffer = Buffer.from(
|
|||
'hex',
|
||||
);
|
||||
const VALUE_UINT64_MAX: Buffer = Buffer.from('ffffffffffffffff', 'hex');
|
||||
const BLANK_OUTPUT: BlankOutput = {
|
||||
const BLANK_OUTPUT = {
|
||||
script: EMPTY_SCRIPT,
|
||||
valueBuffer: VALUE_UINT64_MAX,
|
||||
};
|
||||
|
||||
function isOutput(out: Output | BlankOutput): out is Output {
|
||||
return (out as Output).value !== undefined;
|
||||
}
|
||||
|
||||
export interface BlankOutput {
|
||||
script: Buffer;
|
||||
valueBuffer: Buffer;
|
||||
function isOutput(out: Output): boolean {
|
||||
return out.value !== undefined;
|
||||
}
|
||||
|
||||
export interface Output {
|
||||
|
@ -55,8 +50,6 @@ export interface Output {
|
|||
value: number;
|
||||
}
|
||||
|
||||
type OpenOutput = Output | BlankOutput;
|
||||
|
||||
export interface Input {
|
||||
hash: Buffer;
|
||||
index: number;
|
||||
|
@ -185,7 +178,7 @@ export class Transaction {
|
|||
version: number = 1;
|
||||
locktime: number = 0;
|
||||
ins: Input[] = [];
|
||||
outs: OpenOutput[] = [];
|
||||
outs: Output[] = [];
|
||||
|
||||
isCoinbase(): boolean {
|
||||
return (
|
||||
|
@ -333,7 +326,7 @@ export class Transaction {
|
|||
|
||||
// "blank" outputs before
|
||||
for (let i = 0; i < inIndex; i++) {
|
||||
txTmp.outs[i] = BLANK_OUTPUT;
|
||||
(txTmp.outs as any)[i] = BLANK_OUTPUT;
|
||||
}
|
||||
|
||||
// ignore sequence numbers (except at inIndex)
|
||||
|
@ -602,7 +595,7 @@ export class Transaction {
|
|||
if (isOutput(txOut)) {
|
||||
writeUInt64(txOut.value);
|
||||
} else {
|
||||
writeSlice(txOut.valueBuffer);
|
||||
writeSlice((txOut as any).valueBuffer);
|
||||
}
|
||||
|
||||
writeVarSlice(txOut.script);
|
||||
|
|
8
types/transaction.d.ts
vendored
8
types/transaction.d.ts
vendored
|
@ -1,12 +1,7 @@
|
|||
export interface BlankOutput {
|
||||
script: Buffer;
|
||||
valueBuffer: Buffer;
|
||||
}
|
||||
export interface Output {
|
||||
script: Buffer;
|
||||
value: number;
|
||||
}
|
||||
declare type OpenOutput = Output | BlankOutput;
|
||||
export interface Input {
|
||||
hash: Buffer;
|
||||
index: number;
|
||||
|
@ -28,7 +23,7 @@ export declare class Transaction {
|
|||
version: number;
|
||||
locktime: number;
|
||||
ins: Input[];
|
||||
outs: OpenOutput[];
|
||||
outs: Output[];
|
||||
isCoinbase(): boolean;
|
||||
addInput(hash: Buffer, index: number, sequence?: number, scriptSig?: Buffer): number;
|
||||
addOutput(scriptPubKey: Buffer, value: number): number;
|
||||
|
@ -56,4 +51,3 @@ export declare class Transaction {
|
|||
private __byteLength;
|
||||
private __toBuffer;
|
||||
}
|
||||
export {};
|
||||
|
|
Loading…
Reference in a new issue