Skip to content

Commit

Permalink
update koios to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
RaaCT0R committed Nov 5, 2023
1 parent cafa272 commit 4e8c2c9
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 15 additions & 18 deletions packages/networks/cardano-koios/lib/CardanoKoiosNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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,
Expand All @@ -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: `;
Expand Down
4 changes: 2 additions & 2 deletions packages/networks/cardano-koios/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -45,11 +45,7 @@ export const mockAddressAssets = () => {
balance: testData.addressBalance,
},
],
postAddressAssets: async () => [
{
asset_list: testData.addressAssets,
},
],
postAddressAssets: async () => testData.addressAssets,
} as any);
};

Expand Down Expand Up @@ -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);
};

Expand Down Expand Up @@ -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] : []),
Expand Down
17 changes: 14 additions & 3 deletions packages/networks/cardano-koios/tests/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ export const address =
export const addressBalance = '99000000';
export const addressAssets = [
{
address: address,
decimals: 0n,
quantity: '15888202094',
policy_id: '0dad352d8f0d5ce3f5be8b025d6a16141ecceab5a921871792d91f47',
asset_name: '5273455247',
fingerprint: 'asset1p40r0eun2alszlxhj7k4uylya4cj54lxkjjmsm',
},
{
address: address,
decimals: 0n,
quantity: '1866325',
policy_id: '8e3e19131f96c186335b23bf7983ab00867a987ca900abb27ae0f2b9',
Expand All @@ -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 =
Expand Down

0 comments on commit 4e8c2c9

Please sign in to comment.