@node-dlc/messaging
Version:
DLC Messaging Protocol
122 lines (121 loc) • 4.57 kB
TypeScript
/// <reference types="node" />
import { ContractDescriptorType, MessageType } from '../MessageType';
import { IDlcMessage } from './DlcMessage';
import { PayoutFunction, PayoutFunctionV0JSON } from './PayoutFunction';
import { IRoundingIntervalsJSON, RoundingIntervals } from './RoundingIntervals';
export declare abstract class ContractDescriptor {
static deserialize(buf: Buffer): EnumeratedDescriptor | NumericalDescriptor;
/**
* Creates a ContractDescriptor from JSON data (e.g., from test vectors)
* @param json JSON object representing a contract descriptor
*/
static fromJSON(json: any): ContractDescriptor;
abstract contractDescriptorType: ContractDescriptorType;
abstract type: number;
abstract toJSON(): EnumeratedDescriptorJSON | NumericalDescriptorJSON;
abstract serialize(): Buffer;
}
/**
* EnumeratedContractDescriptor contains information about a contract's outcomes
* and their corresponding payouts (for enumerated outcomes).
* This corresponds to the previous ContractDescriptorV0.
*/
export declare class EnumeratedDescriptor extends ContractDescriptor implements IDlcMessage {
static contractDescriptorType: ContractDescriptorType;
/**
* Creates an EnumeratedContractDescriptor from JSON data
* @param json JSON object representing an enumerated contract descriptor
*/
static fromJSON(json: any): EnumeratedDescriptor;
/**
* Deserializes an enumerated_contract_descriptor message
* @param buf
*/
static deserialize(buf: Buffer): EnumeratedDescriptor;
/**
* The type for enumerated_contract_descriptor message - using MessageType for IDlcMessage compatibility
*/
type: MessageType;
/**
* The contract descriptor type for new format
*/
contractDescriptorType: ContractDescriptorType;
outcomes: IOutcome[];
/**
* Converts enumerated_contract_descriptor to JSON
*/
toJSON(): EnumeratedDescriptorJSON;
/**
* Serializes the enumerated_contract_descriptor message into a Buffer
*/
serialize(): Buffer;
}
/**
* NumericOutcomeContractDescriptor contains information about a contract's outcomes
* and their corresponding payouts (for numeric outcomes).
* This corresponds to the previous ContractDescriptorV1.
*/
export declare class NumericalDescriptor extends ContractDescriptor implements IDlcMessage {
static contractDescriptorType: ContractDescriptorType;
/**
* Creates a NumericOutcomeContractDescriptor from JSON data
* @param json JSON object representing a numeric outcome contract descriptor
*/
static fromJSON(json: any): NumericalDescriptor;
/**
* Deserializes a numeric_outcome_contract_descriptor message
* @param buf
*/
static deserialize(buf: Buffer): NumericalDescriptor;
/**
* The type for numeric_outcome_contract_descriptor message - using MessageType for IDlcMessage compatibility
*/
type: MessageType;
/**
* The contract descriptor type for new format
*/
contractDescriptorType: ContractDescriptorType;
numDigits: number;
payoutFunction: PayoutFunction;
roundingIntervals: RoundingIntervals;
/**
* 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 numeric_outcome_contract_descriptor to JSON
*/
toJSON(): NumericalDescriptorJSON;
/**
* Serializes the numeric_outcome_contract_descriptor message into a Buffer
*/
serialize(): Buffer;
}
export declare const ContractDescriptorV0: typeof EnumeratedDescriptor;
export declare const ContractDescriptorV1: typeof NumericalDescriptor;
export type ContractDescriptorV0 = EnumeratedDescriptor;
export type ContractDescriptorV1 = NumericalDescriptor;
interface IOutcome {
outcome: string;
localPayout: bigint;
}
export interface EnumeratedDescriptorJSON {
enumeratedContractDescriptor: {
payouts: Array<{
outcome: string;
offerPayout: number;
}>;
};
}
export interface NumericalDescriptorJSON {
numericOutcomeContractDescriptor: {
numDigits: number;
payoutFunction: PayoutFunctionV0JSON;
roundingIntervals: IRoundingIntervalsJSON;
};
}
export type ContractDescriptorV0JSON = EnumeratedDescriptorJSON;
export type ContractDescriptorV1JSON = NumericalDescriptorJSON;
export {};