# All files / lib/messages OracleEventContainerV0.ts

97.44% Statements 38/39
100% Branches 0/0
75% Functions 3/4
97.44% Lines 38/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    901x

    1x
    1x

    1x
    1x

    1x
    1x

    1x
    1x

    1x
    1x

    1x
    1x
    1x

    1x
    1x
    1x

    1x

    1x

    1x
    1x
    1x

    1x

    2x

    1x
    1x

    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x

    1x
    1x

    1x

     import { BufferReader, BufferWriter } from '@node-dlc/bufio';

    import { MessageType } from '../MessageType';
    import { getTlv } from '../serialize/getTlv';
    import { IDlcMessage } from './DlcMessage';
    import { OracleAnnouncementV0 } from './OracleAnnouncementV0';
    import { OracleAttestationV0 } from './OracleAttestationV0';

    /**
     * OracleEventContainer contains information about the oracles to be used in
     * executing a DLC.
     */
    export class OracleEventContainerV0 implements IDlcMessage {
      public static type = MessageType.OracleEventContainerV0;

      /**
       * Deserializes an oracle_info_v0 message
       * @param buf
       */
      public static deserialize(buf: Buffer): OracleEventContainerV0 {
        const instance = new OracleEventContainerV0();
        const reader = new BufferReader(buf);

        reader.readBigSize(); // read type
        instance.length = reader.readBigSize();

        const oracleNameLength = reader.readBigSize();
        const oracleNameBuf = reader.readBytes(Number(oracleNameLength));
        instance.oracleName = oracleNameBuf.toString();

        const uriLength = reader.readBigSize();
        const uriBuf = reader.readBytes(Number(uriLength));
        instance.uri = uriBuf.toString();

        instance.announcement = OracleAnnouncementV0.deserialize(getTlv(reader));

        instance.attestation = OracleAttestationV0.deserialize(getTlv(reader));

        const outcomeLength = reader.readBigSize();
        const outcomeBuf = reader.readBytes(Number(outcomeLength));
        instance.outcome = outcomeBuf.toString();

        return instance;
      }

      /**
       * The type for oracle_info_v0 message. oracle_info_v0 = 42770
       */
      public type = OracleEventContainerV0.type;

      public length: bigint;

      public oracleName: string;

      public uri: string;

      public announcement: OracleAnnouncementV0;

      public attestation: OracleAttestationV0;

      public outcome: string;

      public validate(): void {
        this.announcement.validate();
      }

      /**
       * Serializes the oracle_info_v0 message into a Buffer
       */
      public serialize(): Buffer {
        const writer = new BufferWriter();
        writer.writeBigSize(this.type);

        const dataWriter = new BufferWriter();
        dataWriter.writeBigSize(this.oracleName.length);
        dataWriter.writeBytes(Buffer.from(this.oracleName));
        dataWriter.writeBigSize(this.uri.length);
        dataWriter.writeBytes(Buffer.from(this.uri));
        dataWriter.writeBytes(this.announcement.serialize());
        dataWriter.writeBytes(this.attestation.serialize());
        dataWriter.writeBigSize(this.outcome.length);
        dataWriter.writeBytes(Buffer.from(this.outcome));

        writer.writeBigSize(dataWriter.size);
        writer.writeBytes(dataWriter.toBuffer());

        return writer.toBuffer();
      }
    }