Skip to content

Commit

Permalink
fix: decode asset key using cbor before hex formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
guido-ta committed Jan 22, 2021
1 parent 0f2af84 commit 88a0f82
Showing 1 changed file with 4 additions and 1 deletion.
@@ -1,4 +1,5 @@
import CardanoWasm from 'cardano-serialization-lib';
import cbor from 'cbor';
import { Logger } from 'fastify';
import { ADA, ADA_DECIMALS, CurveType, OperationType } from '../constants';
import { mapAmount } from '../data-mapper';
Expand All @@ -23,7 +24,9 @@ const parseInputToOperation = (input: CardanoWasm.TransactionInput, index: numbe

const parseAsset = (logger: Logger, assets: CardanoWasm.Assets, index: number): Components.Schemas.Amount => {
const assetKey = assets.keys().get(index);
const assetSymbol = hexFormatter(Buffer.from(assetKey.to_bytes()));
// Using cbor here because asset name serialization is being done differently than for policy id.
// Just doing Buffer.from would include bytes used by cbor for optimization and end up with unexpected symbol parsing
const assetSymbol = hexFormatter(cbor.decode(Buffer.from(assetKey.to_bytes())));
const assetValue = assets.get(assetKey);
if (!assetValue) {
logger.error(`[parseTokenBundle] asset value for symbol: '${assetSymbol}' not provided`);
Expand Down

0 comments on commit 88a0f82

Please sign in to comment.