Skip to content

Commit

Permalink
feat: support Koios public tier plan
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianbormann committed Apr 25, 2024
1 parent 8ac44a1 commit 12588c4
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/module/src/providers/koios.provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosInstance } from 'axios';
import axios, { AxiosInstance, CreateAxiosDefaults } from 'axios';
import { SUPPORTED_HANDLES } from '@mesh/common/constants';
import { IFetcher, IListener, ISubmitter } from '@mesh/common/contracts';
import {
Expand Down Expand Up @@ -42,12 +42,22 @@ export class KoiosProvider implements IFetcher, IListener, ISubmitter {
},
});
} else {
this._axiosInstance = axios.create({
baseURL: `https://${args[0]}.koios.rest/api/v${args[2] ?? 0}`,
headers: {
let version = 1;
if (typeof args[2] === 'number') {
version = args[2];
}

const config: CreateAxiosDefaults = {
baseURL: `https://${args[0]}.koios.rest/api/v${version}`,
};

if (typeof args[1] === 'string') {
config.headers = {
Authorization: `Bearer ${args[1]}`,
},
});
};
}

this._axiosInstance = axios.create(config);
}
}

Expand Down Expand Up @@ -276,12 +286,10 @@ export class KoiosProvider implements IFetcher, IListener, ISubmitter {
async fetchUTxOs(hash: string): Promise<UTxO[]> {
try {
// TODO: Implement the fetcher
console.log('hi');
const { data, status } = await this._axiosInstance.post('tx_info', {
_tx_hashes: [hash],
});
if (status === 200) {
console.log(data[0]);
const utxos = data[0].outputs.map((utxo) =>
this.toUTxO(utxo, utxo.payment_addr.bech32)
);
Expand Down

0 comments on commit 12588c4

Please sign in to comment.