Skip to content

Commit

Permalink
Merge pull request #820 from input-output-hk/fix/ogmios-to-core-auxil…
Browse files Browse the repository at this point in the history
…iary-data-map

fix: ogmiosToCore auxiliary data map
  • Loading branch information
rhyslbw authored Jul 18, 2023
2 parents 31128fd + 49f9af3 commit 6880f78
Show file tree
Hide file tree
Showing 7 changed files with 917 additions and 2,385 deletions.
30 changes: 19 additions & 11 deletions packages/ogmios/src/ogmiosToCore/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@ import {
} from './util';
import { Base64Blob, HexBlob } from '@cardano-sdk/util';
import { BlockKind, CommonBlock } from './types';
import {
Cardano,
NotImplementedError,
PlutusData,
ProviderUtil,
SerializationError,
SerializationFailure
} from '@cardano-sdk/core';
import { Cardano, NotImplementedError, PlutusData, SerializationError, SerializationFailure } from '@cardano-sdk/core';
import { Schema } from '@cardano-ogmios/client';
import Fraction from 'fraction.js';
import omit from 'lodash/omit';
Expand Down Expand Up @@ -228,16 +221,31 @@ const mapRedeemer = (key: string, redeemer: Schema.Redeemer): Cardano.Redeemer =
};
};

const mapMetadatum = (obj: Schema.Metadatum): Cardano.Metadatum => {
if ('string' in obj) {
return obj.string;
} else if ('map' in obj) {
return new Map(obj.map.map(({ k, v }) => [mapMetadatum(k), mapMetadatum(v)]));
} else if ('list' in obj) {
return obj.list.map(mapMetadatum);
} else if ('int' in obj) {
return obj.int;
} else if ('bytes' in obj) {
return Buffer.from(obj.bytes, 'hex');
}
throw new NotImplementedError(
`Unknown metadatum type: ${typeof obj === 'object' ? Object.keys(obj).join(',') : obj}`
);
};

const mapAuxiliaryData = (
data: Schema.AuxiliaryData | null
): { auxiliaryData: Cardano.AuxiliaryData | undefined; auxiliaryDataHash: Crypto.Hash32ByteBase16 | undefined } => {
if (data === null) return { auxiliaryData: undefined, auxiliaryDataHash: undefined };

const auxiliaryData = {
blob: data.body.blob
? new Map(
Object.entries(data.body.blob).map(([key, value]) => [BigInt(key), ProviderUtil.jsonToMetadatum(value)])
)
? new Map(Object.entries(data.body.blob).map(([key, value]) => [BigInt(key), mapMetadatum(value)]))
: undefined,
scripts: data.body.scripts ? data.body.scripts.map(mapScript) : undefined
};
Expand Down
Loading

0 comments on commit 6880f78

Please sign in to comment.