Skip to content

Commit

Permalink
Merge pull request #3739 from Emurgo/fix/connector-sign-foreign-utxo
Browse files Browse the repository at this point in the history
Adapt UTXO endpoint for multiple entries
  • Loading branch information
vsubhuman authored Nov 15, 2024
2 parents a3530f7 + 3a3727a commit 40bdc47
Showing 1 changed file with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,34 +551,32 @@ export class RemoteFetcher implements IFetcher {

getUtxoData: GetUtxoDataRequest => Promise<GetUtxoDataResponse> = async (body) => {
const { BackendService } = body.network.Backend;
if (body.utxos.length !== 1) {
throw new Error('the RemoteFetcher.getUtxoData expects 1 UTXO');
}
const { txHash, txIndex } = body.utxos[0];
if (BackendService == null) throw new Error(`${nameof(this.getUtxoData)} missing backend url`);
return axios(
`${BackendService}/api/txs/io/${txHash}/o/${txIndex}`,
{
method: 'get',
timeout: 2 * CONFIG.app.walletRefreshInterval,
headers: {
'yoroi-version': this.getLastLaunchVersion(),
'yoroi-locale': this.getCurrentLocale()
}
}
).then(response => [ response.data ])
.catch((error) => {
if (error.response.status === 404 && error.response.data === 'Transaction not found') {
return [ null ];
return Promise.all(body.utxos.map(({ txHash, txIndex }) => {
return axios(
`${BackendService}/api/txs/io/${txHash}/o/${txIndex}`,
{
method: 'get',
timeout: 2 * CONFIG.app.walletRefreshInterval,
headers: {
'yoroi-version': this.getLastLaunchVersion(),
'yoroi-locale': this.getCurrentLocale()
}
}
Logger.error(`${nameof(RemoteFetcher)}::${nameof(this.getUtxoData)} error: ` + stringifyError(error));
throw new GetUtxoDataError();
});
).then(response => response.data)
.catch((error) => {
if (error.response.status === 404 && error.response.data === 'No outputs found') {
return null;
}
Logger.error(`${nameof(RemoteFetcher)}::${nameof(this.getUtxoData)} error: ` + stringifyError(error));
throw new GetUtxoDataError();
});
}));
}

getLatestBlockBySlot: GetLatestBlockBySlotFunc = async (body) => {
const { BackendService } = body.network.Backend;
if (BackendService == null) throw new Error(`${nameof(this.getUtxoData)} missing backend url`);
if (BackendService == null) throw new Error(`${nameof(this.getLatestBlockBySlot)} missing backend url`);
return axios(
`${BackendService}/api/v2.1/lastBlockBySlot`,
{
Expand Down

0 comments on commit 40bdc47

Please sign in to comment.