Skip to content

Commit 760a35b

Browse files
committed
fix: correct ogmiosToCore auxiliaryData mapping
ogmiosToCore used jsonToMetadatum util, which mapping json that is of different format from ogmios schema
1 parent e26637a commit 760a35b

File tree

7 files changed

+916
-2378
lines changed

7 files changed

+916
-2378
lines changed

packages/ogmios/src/ogmiosToCore/tx.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { BlockKind, CommonBlock } from './types';
1919
import {
2020
Cardano,
2121
NotImplementedError,
22-
ProviderUtil,
2322
Serialization,
2423
SerializationError,
2524
SerializationFailure
@@ -228,16 +227,31 @@ const mapRedeemer = (key: string, redeemer: Schema.Redeemer): Cardano.Redeemer =
228227
};
229228
};
230229

230+
const mapMetadatum = (obj: Schema.Metadatum): Cardano.Metadatum => {
231+
if ('string' in obj) {
232+
return obj.string;
233+
} else if ('map' in obj) {
234+
return new Map(obj.map.map(({ k, v }) => [mapMetadatum(k), mapMetadatum(v)]));
235+
} else if ('list' in obj) {
236+
return obj.list.map(mapMetadatum);
237+
} else if ('int' in obj) {
238+
return obj.int;
239+
} else if ('bytes' in obj) {
240+
return Buffer.from(obj.bytes, 'hex');
241+
}
242+
throw new NotImplementedError(
243+
`Unknown metadatum type: ${typeof obj === 'object' ? Object.keys(obj).join(',') : obj}`
244+
);
245+
};
246+
231247
const mapAuxiliaryData = (
232248
data: Schema.AuxiliaryData | null
233249
): { auxiliaryData: Cardano.AuxiliaryData | undefined; auxiliaryDataHash: Crypto.Hash32ByteBase16 | undefined } => {
234250
if (data === null) return { auxiliaryData: undefined, auxiliaryDataHash: undefined };
235251

236252
const auxiliaryData = {
237253
blob: data.body.blob
238-
? new Map(
239-
Object.entries(data.body.blob).map(([key, value]) => [BigInt(key), ProviderUtil.jsonToMetadatum(value)])
240-
)
254+
? new Map(Object.entries(data.body.blob).map(([key, value]) => [BigInt(key), mapMetadatum(value)]))
241255
: undefined,
242256
scripts: data.body.scripts ? data.body.scripts.map(mapScript) : undefined
243257
};

0 commit comments

Comments
 (0)