diff --git a/package-lock.json b/package-lock.json index 039f4ba..834cc66 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2473,9 +2473,9 @@ "link": true }, "node_modules/@rosen-clients/cardano-koios": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@rosen-clients/cardano-koios/-/cardano-koios-1.0.3.tgz", - "integrity": "sha512-Ytlh9Jj+vtJCmrYW28i6rNdEVRopLuCTyKJLo1eopsosJ7taHKnL2J5bxabFBf3GZ9leYoEXALZj3IIOSlaenQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@rosen-clients/cardano-koios/-/cardano-koios-2.0.0.tgz", + "integrity": "sha512-sTb8MY990w0GNYpYV9cXfBDsPGOzxbtfXl4tBSFzDskluc4ysaaZGNyzrQmohm1RuMD2Yh/L3CiaXqmBtDpJNA==", "dependencies": { "@types/json-bigint": "^1.0.1", "axios": "^1.3.4", @@ -8484,7 +8484,7 @@ }, "packages/networks/cardano-koios": { "name": "@rosen-chains/cardano-koios-network", - "version": "2.2.1", + "version": "3.0.0", "license": "GPL-3.0", "dependencies": { "@emurgo/cardano-serialization-lib-nodejs": "^11.3.1", @@ -8494,7 +8494,7 @@ "@rosen-bridge/tokens": "^1.0.0", "@rosen-chains/abstract-chain": "^2.2.1", "@rosen-chains/cardano": "^2.2.1", - "@rosen-clients/cardano-koios": "^1.0.3" + "@rosen-clients/cardano-koios": "^2.0.0" }, "devDependencies": { "@babel/preset-env": "^7.19.0", diff --git a/packages/networks/cardano-koios/lib/CardanoKoiosNetwork.ts b/packages/networks/cardano-koios/lib/CardanoKoiosNetwork.ts index ccf21b7..528adcf 100644 --- a/packages/networks/cardano-koios/lib/CardanoKoiosNetwork.ts +++ b/packages/networks/cardano-koios/lib/CardanoKoiosNetwork.ts @@ -35,11 +35,12 @@ class CardanoKoiosNetwork extends AbstractCardanoNetwork { koiosUrl: string, lockAddress: string, tokens: RosenTokens, + authToken?: string, logger?: AbstractLogger ) { super(logger); this.extractor = new CardanoRosenExtractor(lockAddress, tokens, logger); - this.client = cardanoKoiosClientFactory(koiosUrl); + this.client = cardanoKoiosClientFactory(koiosUrl, authToken); } /** @@ -156,19 +157,14 @@ class CardanoKoiosNetwork extends AbstractCardanoNetwork { throw new UnexpectedApiError(baseError + e.message); } } - if (addressAssets.length !== 0) { - if (!addressAssets[0].asset_list) - throw new KoiosNullValueError('Address asset_list is null'); - const assets = addressAssets[0].asset_list; - tokens = assets.map((asset) => { - if (!asset.fingerprint || !asset.quantity) - throw new KoiosNullValueError('Asset info is null'); - return { - id: asset.fingerprint, - value: BigInt(asset.quantity), - }; - }); - } + tokens = addressAssets.map((asset) => { + if (!asset.fingerprint || !asset.quantity) + throw new KoiosNullValueError('Asset info is null'); + return { + id: asset.fingerprint, + value: BigInt(asset.quantity), + }; + }); return { nativeToken: nativeToken, @@ -190,10 +186,11 @@ class CardanoKoiosNetwork extends AbstractCardanoNetwork { res )}` ); - const txIds = res[0].tx_hashes; - if (!txIds) - throw new KoiosNullValueError(`Block tx hashes list is null`); - return txIds; + return res.map((block) => { + const txId = block.tx_hash; + if (!txId) throw new KoiosNullValueError(`Block tx hash is null`); + return txId; + }); }) .catch((e) => { const baseError = `Failed to get block [${blockId}] transaction ids from Koios: `; diff --git a/packages/networks/cardano-koios/package.json b/packages/networks/cardano-koios/package.json index c28ac05..7f3bd32 100644 --- a/packages/networks/cardano-koios/package.json +++ b/packages/networks/cardano-koios/package.json @@ -1,6 +1,6 @@ { "name": "@rosen-chains/cardano-koios-network", - "version": "2.2.1", + "version": "3.0.0", "description": "cardano koios network package for rosen cardano chain", "main": "dist/lib/index.js", "types": "dist/lib/index.d.ts", @@ -27,7 +27,7 @@ "@rosen-bridge/tokens": "^1.0.0", "@rosen-chains/abstract-chain": "^2.2.1", "@rosen-chains/cardano": "^2.2.1", - "@rosen-clients/cardano-koios": "^1.0.3" + "@rosen-clients/cardano-koios": "^2.0.0" }, "devDependencies": { "@babel/preset-env": "^7.19.0", diff --git a/packages/networks/cardano-koios/tests/CardanoKoiosNetwork.spec.ts b/packages/networks/cardano-koios/tests/CardanoKoiosNetwork.spec.ts index e9cbc93..e01f31f 100644 --- a/packages/networks/cardano-koios/tests/CardanoKoiosNetwork.spec.ts +++ b/packages/networks/cardano-koios/tests/CardanoKoiosNetwork.spec.ts @@ -219,7 +219,7 @@ describe('CardanoKoiosNetwork', () => { const result = await network.getBlockTransactionIds(testData.blockId); // check returned value - expect(result).toEqual(testData.txHashes); + expect(result).toEqual(testData.txHashes.map((block) => block.tx_hash)); }); }); diff --git a/packages/networks/cardano-koios/tests/mocked/CardanoKoiosClient.mock.ts b/packages/networks/cardano-koios/tests/mocked/CardanoKoiosClient.mock.ts index 3757a1b..7c24e36 100644 --- a/packages/networks/cardano-koios/tests/mocked/CardanoKoiosClient.mock.ts +++ b/packages/networks/cardano-koios/tests/mocked/CardanoKoiosClient.mock.ts @@ -2,7 +2,7 @@ import cardanoKoiosClientFactory from '@rosen-clients/cardano-koios'; import * as testData from '../testData'; import { AddressInfoItemUtxoSetItem, - CredentialUtxos, + CredentialUtxosBody, TxInfoItem, TxUtxos, } from '@rosen-clients/cardano-koios'; @@ -45,11 +45,7 @@ export const mockAddressAssets = () => { balance: testData.addressBalance, }, ], - postAddressAssets: async () => [ - { - asset_list: testData.addressAssets, - }, - ], + postAddressAssets: async () => testData.addressAssets, } as any); }; @@ -84,11 +80,7 @@ export const mockNoHistoryAddressAssets = () => { */ export const mockPostBlockTxs = () => { jest.mocked(cardanoKoiosClientFactory).mockReturnValueOnce({ - postBlockTxs: async () => [ - { - tx_hashes: testData.txHashes, - }, - ], + postBlockTxs: async () => testData.txHashes, } as any); }; @@ -143,7 +135,7 @@ export const mockPostAddressInfo = (utxoSet: AddressInfoItemUtxoSetItem[]) => { */ export const mockUtxoValidation = ( txUtxos: TxUtxos | undefined, - credentialUtxos: CredentialUtxos + credentialUtxos: CredentialUtxosBody ) => { jest.mocked(cardanoKoiosClientFactory).mockReturnValueOnce({ postTxInfo: async () => (txUtxos ? [txUtxos] : []), diff --git a/packages/networks/cardano-koios/tests/testData.ts b/packages/networks/cardano-koios/tests/testData.ts index b2bd4f4..69bd00a 100644 --- a/packages/networks/cardano-koios/tests/testData.ts +++ b/packages/networks/cardano-koios/tests/testData.ts @@ -9,6 +9,7 @@ export const address = export const addressBalance = '99000000'; export const addressAssets = [ { + address: address, decimals: 0n, quantity: '15888202094', policy_id: '0dad352d8f0d5ce3f5be8b025d6a16141ecceab5a921871792d91f47', @@ -16,6 +17,7 @@ export const addressAssets = [ fingerprint: 'asset1p40r0eun2alszlxhj7k4uylya4cj54lxkjjmsm', }, { + address: address, decimals: 0n, quantity: '1866325', policy_id: '8e3e19131f96c186335b23bf7983ab00867a987ca900abb27ae0f2b9', @@ -28,9 +30,18 @@ export const blockId = export const parentBlockId = '6dc89c6e28360410df837ddebad0b8c2a7c73f561cd4ba66a976dc3d3bce'; export const txHashes = [ - '65eebe2262738d1c3a2ac57ce7aa7987613cd8835e7ffe1b44be6cc513464e9a', - 'ffc5558b0041a0531c2e99ced50c066c77afb56c0608716632bde93e92572d95', - '51b640cf0a9b5a241d3fd39174ce414e53b375c1f53904951dd59fa420c29141', + { + block_hash: blockId, + tx_hash: '65eebe2262738d1c3a2ac57ce7aa7987613cd8835e7ffe1b44be6cc513464e9a', + }, + { + block_hash: blockId, + tx_hash: 'ffc5558b0041a0531c2e99ced50c066c77afb56c0608716632bde93e92572d95', + }, + { + block_hash: blockId, + tx_hash: '51b640cf0a9b5a241d3fd39174ce414e53b375c1f53904951dd59fa420c29141', + }, ]; export const oldBlockheight = 7000000n; export const noMetadataTxId =