UNPKG

@mutants/cardano-tx-builder

Version:

A package that provides utility functions to build and destructure a cardano transaction

50 lines (49 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decodeOutput = void 0; const cbor_1 = require("cbor"); const cardano_utils_1 = require("@mutants/cardano-utils"); const decodeValue_1 = require("./decodeValue"); const types_1 = require("./types"); const decodeOutput = (output) => { let address = ""; let value; let datumInlined; let datumHash; // Post Alonzo format if (output instanceof Map) { const addr = output.get(0); address = (0, cardano_utils_1.toPaymentAddress)(addr.toString("hex")); value = output.get(1); if (Array.isArray(output.get(2))) { const datumOption = output.get(2); if (datumOption[0] === types_1.DatumOption.Inline) { const datumValue = datumOption[1]; if (datumValue instanceof Buffer) { datumInlined = datumValue.toString("hex"); } else if (datumValue instanceof cbor_1.Tagged) { datumInlined = datumValue.value.toString("hex"); } } else if (datumOption[0] === types_1.DatumOption.Hash) { datumHash = datumOption[1].toString("hex"); } } } else { // Pre Alonzo format address = (0, cardano_utils_1.toPaymentAddress)(output[0].toString("hex")); value = output[1]; if (output[2]) { datumHash = output[2].toString("hex"); } } return { address, datumInlined, datumHash, value: (0, decodeValue_1.decodeValue)(value), }; }; exports.decodeOutput = decodeOutput;