@node-dlc/messaging
Version:
DLC Messaging Protocol
92 lines (91 loc) • 2.88 kB
TypeScript
/// <reference types="node" />
import { MessageType } from '../MessageType';
import { IDlcMessage } from './DlcMessage';
import { PayoutFunction, PayoutFunctionV0JSON } from './PayoutFunction';
import { IRoundingIntervalsV0JSON, RoundingIntervalsV0 } from './RoundingIntervalsV0';
export declare abstract class ContractDescriptor {
static deserialize(buf: Buffer): ContractDescriptorV0 | ContractDescriptorV1;
abstract type: number;
abstract length: bigint;
abstract toJSON(): ContractDescriptorV0JSON | ContractDescriptorV1JSON;
abstract serialize(): Buffer;
}
/**
* ContractDescriptor V0 contains information about a contract's outcomes
* and their corresponding payouts.
*/
export declare class ContractDescriptorV0 extends ContractDescriptor implements IDlcMessage {
static type: MessageType;
/**
* Deserializes an contract_descriptor_v0 message
* @param buf
*/
static deserialize(buf: Buffer): ContractDescriptorV0;
/**
* The type for contract_descriptor_v0 message. contract_descriptor_v0 = 42768
*/
type: MessageType;
length: bigint;
outcomes: IOutcome[];
/**
* Converts contract_descriptor_v0 to JSON
*/
toJSON(): ContractDescriptorV0JSON;
/**
* Serializes the contract_descriptor_v0 message into a Buffer
*/
serialize(): Buffer;
}
/**
* ContractDescriptor V1 contains information about a contract's outcomes
* and their corresponding payouts.
*/
export declare class ContractDescriptorV1 extends ContractDescriptor implements IDlcMessage {
static type: MessageType;
/**
* Deserializes an contract_descriptor_v1 message
* @param buf
*/
static deserialize(buf: Buffer): ContractDescriptorV1;
/**
* The type for contract_descriptor_v1 message. contract_descriptor_v1 = 42784
*/
type: MessageType;
length: bigint;
numDigits: number;
payoutFunction: PayoutFunction;
roundingIntervals: RoundingIntervalsV0;
/**
* Validates correctness of all fields in the message
* https://github.com/discreetlogcontracts/dlcspecs/blob/master/Messaging.md#the-contract_descriptor-type
* @throws Will throw an error if validation fails
*/
validate(): void;
/**
* Converts contract_descriptor_v1 to JSON
*/
toJSON(): ContractDescriptorV1JSON;
/**
* Serializes the contract_descriptor_v1 message into a Buffer
*/
serialize(): Buffer;
}
interface IOutcome {
outcome: Buffer;
localPayout: bigint;
}
interface IOutcomeJSON {
outcome: string;
localPayout: number;
}
export interface ContractDescriptorV0JSON {
type: number;
outcomes: IOutcomeJSON[];
}
export interface ContractDescriptorV1JSON {
type: number;
numDigits: number;
payoutFunction: PayoutFunctionV0JSON;
roundingIntervals: IRoundingIntervalsV0JSON;
}
export {};