import { IValidationResponse, IResponsePayload } from "./interfaces/validation-response.i"; /** * @description Contains all information about a transfer request and as some enhanced properties to help make sens of the transfer request data */ export class TransferRequest { public readonly timestamp = new Date(); constructor(private readonly _validationResponse: IValidationResponse) { } get source(): IResponsePayload { return this._validationResponse.source; } get ticker() { return this._validationResponse.ticker; } get dest(): IResponsePayload { return this._validationResponse.dest; } get id() { return this._validationResponse.id; } get isSourceCompleted() { return !!(this._validationResponse.source && this._validationResponse.source.currentNbConf >= this._validationResponse.source.requiredNbConf); } get isDestCompleted() { return !!(this._validationResponse.dest && this._validationResponse.dest.currentNbConf >= this._validationResponse.dest.requiredNbConf); } /** * @returns True if the source and destination transaction are completed */ get isCompleted() { return this.isSourceCompleted && this.isDestCompleted; } /** * @returns True if the transfer request is completed and the source and destination amount are equal */ get isValid() { return !!(this._validationResponse.source && this._validationResponse.dest && this._validationResponse.dest.amount === this._validationResponse.source.amount); } toJSON() { return { ...this._validationResponse, validatorReceivedAt: this.timestamp, } } }