-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cardano-services): changes the way tx metadatum are read from db…
…, from json to raw bytes
- Loading branch information
Showing
4 changed files
with
53 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
import { Cardano, ProviderUtil } from '@cardano-sdk/core'; | ||
import { CML, Cardano, cmlToCore } from '@cardano-sdk/core'; | ||
import { TxMetadataModel } from './types'; | ||
import { usingAutoFree } from '@cardano-sdk/util'; | ||
|
||
export const mapTxMetadata = (metadataModel: Pick<TxMetadataModel, 'json_value' | 'key'>[]): Cardano.TxMetadata => | ||
export const mapTxMetadata = (metadataModel: Pick<TxMetadataModel, 'bytes' | 'key'>[]): Cardano.TxMetadata => | ||
metadataModel.reduce((map, metadatum) => { | ||
const { key, json_value } = metadatum; | ||
if (!json_value || !key) return map; | ||
map.set(BigInt(key), ProviderUtil.jsonToMetadatum(json_value)); | ||
const { bytes, key } = metadatum; | ||
|
||
if (bytes && key) { | ||
const biKey = BigInt(key); | ||
const metadata = usingAutoFree((_) => cmlToCore.txMetadata(CML.GeneralTransactionMetadata.from_bytes(bytes))); | ||
|
||
if (metadata) { | ||
const datum = metadata.get(biKey); | ||
|
||
if (datum) map.set(biKey, datum); | ||
} | ||
} | ||
|
||
return map; | ||
}, new Map<bigint, Cardano.Metadatum>()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
export const findTxMetadata = ` | ||
SELECT | ||
meta."key" AS "key", | ||
meta."json" AS json_value, | ||
tx.hash AS tx_id | ||
FROM tx_metadata AS meta | ||
JOIN tx ON meta.tx_id = tx.id | ||
WHERE tx.hash = ANY($1) | ||
ORDER BY meta.id ASC`; | ||
SELECT | ||
key, | ||
bytes, | ||
hash AS tx_id | ||
FROM tx_metadata AS meta | ||
JOIN tx ON tx_id = tx.id | ||
WHERE hash = ANY($1) | ||
ORDER BY meta.id ASC`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters