UNPKG

@node-dlc/messaging

Version:
136 lines (135 loc) 4.82 kB
/// <reference types="node" /> import { ContractInfoType, MessageType } from '../MessageType'; import { ContractDescriptor, ContractDescriptorV0JSON, ContractDescriptorV1JSON } from './ContractDescriptor'; import { DlcMessage, IDlcMessage } from './DlcMessage'; import { MultiOracleInfoJSON, OracleInfo, SingleOracleInfoJSON } from './OracleInfo'; export declare abstract class ContractInfo extends DlcMessage { static deserialize(buf: Buffer): SingleContractInfo | DisjointContractInfo; /** * Creates a ContractInfo from JSON data (e.g., from test vectors) * @param json JSON object representing contract info */ static fromJSON(json: any): ContractInfo; abstract contractInfoType: ContractInfoType; abstract totalCollateral: bigint; abstract validate(): void; abstract toJSON(): ISingleContractInfoJSON | IDisjointContractInfoJSON; abstract serialize(): Buffer; getTotalCollateral(): bigint; } /** * SingleContractInfo contains information about a contract's outcomes, * their corresponding payouts, and the oracles to be used. * This corresponds to the previous ContractInfoV0. */ export declare class SingleContractInfo extends ContractInfo implements IDlcMessage { static contractInfoType: ContractInfoType; static type: MessageType; /** * Creates a SingleContractInfo from JSON data * @param json JSON object representing single contract info */ static fromJSON(json: any): SingleContractInfo; /** * Deserializes a single_contract_info message * @param buf */ static deserialize(buf: Buffer): SingleContractInfo; /** * The type for single_contract_info message - using MessageType for IDlcMessage compatibility */ type: MessageType; /** * The contract info type for new format */ contractInfoType: ContractInfoType; totalCollateral: bigint; contractDescriptor: ContractDescriptor; oracleInfo: OracleInfo; get length(): bigint; /** * Validates correctness of all fields in the message * @throws Will throw an error if validation fails */ validate(): void; /** * Converts single_contract_info to JSON */ toJSON(): ISingleContractInfoJSON; /** * Serializes the single_contract_info message into a Buffer */ serialize(): Buffer; } /** * DisjointContractInfo contains information about multiple disjoint contract events. * This corresponds to the previous ContractInfoV1. */ export declare class DisjointContractInfo extends ContractInfo implements IDlcMessage { static contractInfoType: ContractInfoType; static type: MessageType; /** * Creates a DisjointContractInfo from JSON data * @param json JSON object representing disjoint contract info */ static fromJSON(json: any): DisjointContractInfo; /** * Deserializes a disjoint_contract_info message * @param buf */ static deserialize(buf: Buffer): DisjointContractInfo; /** * The type for disjoint_contract_info message - using MessageType for IDlcMessage compatibility */ type: MessageType; /** * The contract info type for new format */ contractInfoType: ContractInfoType; totalCollateral: bigint; contractOraclePairs: IContractOraclePair[]; get length(): bigint; /** * Validates correctness of all fields in the message * @throws Will throw an error if validation fails */ validate(): void; /** * Converts disjoint_contract_info to JSON */ toJSON(): IDisjointContractInfoJSON; /** * Serializes the disjoint_contract_info message into a Buffer */ serialize(): Buffer; } export declare const ContractInfoV0: typeof SingleContractInfo; export declare const ContractInfoV1: typeof DisjointContractInfo; export type ContractInfoV0 = SingleContractInfo; export type ContractInfoV1 = DisjointContractInfo; interface IContractOraclePair { contractDescriptor: ContractDescriptor; oracleInfo: OracleInfo; } interface IContractOraclePairJSON { contractDescriptor: ContractDescriptorV0JSON | ContractDescriptorV1JSON; oracleInfo: SingleOracleInfoJSON | MultiOracleInfoJSON; } export interface ISingleContractInfoJSON { singleContractInfo: { totalCollateral: number; contractInfo: { contractDescriptor: ContractDescriptorV0JSON | ContractDescriptorV1JSON; oracleInfo: SingleOracleInfoJSON | MultiOracleInfoJSON; }; }; } export interface IDisjointContractInfoJSON { disjointContractInfo: { totalCollateral: number; contractInfos: IContractOraclePairJSON[]; }; } export type IContractInfoV0JSON = ISingleContractInfoJSON; export type IContractInfoV1JSON = IDisjointContractInfoJSON; export {};