Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release / 4.13.0 #2843

Merged
merged 122 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
28be72a
augment getting UTxOs API with submitted txs
yushih Mar 11, 2022
fd7b634
augment used & unused addresses with submitted txs
yushih Mar 12, 2022
69f8eeb
augment create tx with submitted txs
yushih Mar 14, 2022
213e3ad
augment recording submitted tx with submitted txs
yushih Mar 14, 2022
6aa3a78
augment signing tx UI with submitted txs
yushih Mar 14, 2022
8fd48ba
augment tx signing with submitted txs
yushih Mar 14, 2022
57500a8
Merge remote-tracking branch 'origin/develop' into yushi/submitted-tx…
yushih Mar 15, 2022
c9ff962
Merge remote-tracking branch 'origin/yushi/connector-collateral' into…
yushih Mar 15, 2022
83585a9
augment collateral API with submitted txs
yushih Mar 15, 2022
710171f
avoid duplicate outputs
yushih Mar 16, 2022
85e558f
bug fix
yushih Mar 16, 2022
2d36106
lint
yushih Mar 16, 2022
49e15f4
lint
yushih Mar 16, 2022
dbb558a
CIP30 signData implementation
yushih Mar 21, 2022
31207d5
Update actions layout
neuodev Apr 5, 2022
fac158b
separate walelts list into ergo and cardano
neuodev Apr 5, 2022
f966363
Update list styles
neuodev Apr 5, 2022
2b8d0e9
Sort wallets list
neuodev Apr 5, 2022
6f3a464
Add sorted wallets to local storage
neuodev Apr 5, 2022
b58d8d8
Add section header
neuodev Apr 6, 2022
5d6ee33
Display header conditionally
neuodev Apr 6, 2022
41e4fce
Change localsorage key value name
neuodev Apr 6, 2022
2849417
Remove wallet from localstorage
neuodev Apr 6, 2022
f1912bc
Add wallet to the quick access menu
neuodev Apr 6, 2022
a12d83c
Update actions layouts
neuodev Apr 6, 2022
7f88a96
Update navbar wallet header
neuodev Apr 6, 2022
ebf44e3
Update wallet nav design
neuodev Apr 6, 2022
327e6a9
Remove unused imports
neuodev Apr 7, 2022
6ffccc2
Update buy ada button revamp
neuodev Apr 7, 2022
5bc1496
Create add Wallet button
neuodev Apr 7, 2022
b03ac39
Update Topbar layout
neuodev Apr 7, 2022
9aa1af8
Add QuickAccessHeader component
neuodev Apr 7, 2022
a0343e7
Create small utils to display wallet info
neuodev Apr 7, 2022
cbd331d
Add quick access wallets list
neuodev Apr 7, 2022
b1bea74
Display wallet types
neuodev Apr 8, 2022
e061bb9
Display wallet balance
neuodev Apr 8, 2022
aa128df
Finalize all quick access wallets list
neuodev Apr 8, 2022
275c004
Move renderAmountDisplay into its own component
neuodev Apr 8, 2022
b6f948c
Replace renderAmountDisplay with AmountDisplay component
neuodev Apr 8, 2022
6accc0e
Render spinner
neuodev Apr 8, 2022
3f58e81
Update BuyAda button style
neuodev Apr 8, 2022
46e1504
Render fiat amount
neuodev Apr 11, 2022
b0612fb
Render fiat amount in the topbar
neuodev Apr 11, 2022
a97a741
Remove unused imports
neuodev Apr 11, 2022
b61144f
Merge branch 'develop' of https://github.com/Emurgo/yoroi-frontend in…
neuodev Apr 11, 2022
7064377
Flow
neuodev Apr 11, 2022
b810cb8
connector signing handles foreign inputs
yushih Apr 15, 2022
f6aff57
Merge branch 'develop' into Ahmed/all-wallets-dialog
neuodev Apr 18, 2022
d88bbe9
Merge branch 'develop' into yushi/submitted-txs-utxos
yushih Apr 22, 2022
a41c9fa
Merge branch 'yushi/submitted-txs-utxos' into yushi/validate-inputs
yushih Apr 22, 2022
b290c8f
return utxo spent error if signing tx input is used by submitted txs
yushih Apr 22, 2022
ffde3d0
Added signing reject step
Nebyt Apr 22, 2022
e7bd243
Split checking errors feature into 2 files
Nebyt Apr 22, 2022
60395f4
Renamed scenarios
Nebyt Apr 22, 2022
a3415dc
Little improvement in setting first tab name
Nebyt Apr 22, 2022
b300662
Added types to locators and added two locators
Nebyt Apr 22, 2022
d28d566
Renamed the step: I open the mock dApp -> I open the mock dApp tab
Nebyt Apr 22, 2022
c4d87f7
Added step-descriptions
Nebyt Apr 22, 2022
1245298
Added the test "No wallets in the beginning"
Nebyt Apr 22, 2022
691c0b8
Fixed the error when closing a tab
Nebyt Apr 22, 2022
17e71ec
Added a step-description for checking wallet connection in the extension
Nebyt Apr 22, 2022
32ae9cf
mock dApp improvements
Nebyt Apr 25, 2022
bd5a080
windowManager improvements
Nebyt Apr 25, 2022
64ebd06
Added the refresh dApp page step and there is no pop-up window checking
Nebyt Apr 25, 2022
bb2e0ca
Added two tests with refreshing the dApp page
Nebyt Apr 25, 2022
233fbf1
Added two tests for canceling signing a transaction
Nebyt Apr 25, 2022
459fa0c
prettify
Nebyt Apr 25, 2022
391a04f
Merge branch 'develop' into denis/YOEXT-121-1
Nebyt Apr 25, 2022
b15bf9e
Try to fix tests
Nebyt Apr 25, 2022
fe50f5a
Try to fix tests 2
Nebyt Apr 25, 2022
f3b972e
Try to fix tests 3
Nebyt Apr 25, 2022
e2f213d
Merge branch 'develop' of https://github.com/Emurgo/yoroi-frontend in…
neuodev Apr 25, 2022
f1141b4
Add eye icons
neuodev Apr 25, 2022
eafe6b9
Import and use `eye` icon
neuodev Apr 25, 2022
3f6cd49
Use MUI button instead of regular buttons
neuodev Apr 25, 2022
c7ebb83
Added logs to mock dApp page
Nebyt Apr 25, 2022
c0c167f
Added the simple-node-logger to the devPackages
Nebyt Apr 25, 2022
bb9974e
Debugging
Nebyt Apr 25, 2022
4a7ffbf
Try to fix 4
Nebyt Apr 26, 2022
2daa3b0
Merge remote-tracking branch 'origin/develop' into ruslan/collateral-…
vsubhuman Apr 26, 2022
f215a6c
Package-lock update
vsubhuman Apr 26, 2022
522bcb7
Merge pull request #2737 from Emurgo/ruslan/collateral-coin-selection
vsubhuman Apr 26, 2022
eab8ec0
Added more logs
Nebyt Apr 27, 2022
8dd749b
Improved logging
Nebyt Apr 27, 2022
e4a788a
Debugging
Nebyt Apr 27, 2022
a1d22ff
Merge branch 'develop' into denis/YOEXT-121-1
Nebyt Apr 27, 2022
a98dd62
Debugging
Nebyt Apr 27, 2022
716ca56
Merge remote-tracking branch 'origin/develop' into release/4.12
vsubhuman Apr 27, 2022
77f94c3
Merge pull request #2834 from Emurgo/release/4.12
vsubhuman Apr 27, 2022
572b38f
Merge remote-tracking branch 'origin/develop' into denis/YOEXT-121-1
vsubhuman Apr 27, 2022
b1d0b5c
Package-lock update
vsubhuman Apr 27, 2022
620e20c
Connector error reporting fixed
vsubhuman Apr 27, 2022
fde4872
Set null instead of false
Nebyt Apr 27, 2022
035e46c
Merge branch 'denis/YOEXT-121-1' of https://github.com/Emurgo/yoroi-f…
Nebyt Apr 27, 2022
6df5e72
Added missing wasm loading in one connector function
vsubhuman Apr 27, 2022
260fe72
Merge branch 'denis/YOEXT-121-1' of https://github.com/Emurgo/yoroi-f…
Nebyt Apr 27, 2022
fb62ddd
package-lock.json is updated, continue debugging
Nebyt Apr 27, 2022
d454018
rollback changes
Nebyt Apr 27, 2022
098f815
pop-up windows update
Nebyt Apr 27, 2022
d531545
changed the isEnabled()
Nebyt Apr 27, 2022
6e6570d
flow fixes
Nebyt Apr 27, 2022
8733a98
Merge pull request #2836 from Emurgo/production
vsubhuman Apr 28, 2022
84b56d7
Version bump: 4.12.101 (nightly)
vsubhuman Apr 29, 2022
b9e4bb6
Merge branch 'develop' into denis/YOEXT-121-1
vsubhuman May 3, 2022
e05d7c8
Merge pull request #2830 from Emurgo/denis/YOEXT-121-1
vsubhuman May 3, 2022
0628348
Merge remote-tracking branch 'origin/develop' into yushi/connector-si…
vsubhuman May 3, 2022
774e906
Merge branch 'develop' into Ahmed/all-wallets-dialog
vsubhuman May 3, 2022
14262ce
Merge pull request #2782 from Emurgo/yushi/connector-sign-data
vsubhuman May 3, 2022
7b7e436
Merge remote-tracking branch 'origin/develop' into yushi/foreign-inputs
vsubhuman May 3, 2022
d699f37
Merge branch 'develop' into Ahmed/all-wallets-dialog
vsubhuman May 3, 2022
f5c8a58
Merge pull request #2814 from Emurgo/Ahmed/all-wallets-dialog
vsubhuman May 3, 2022
c92a363
Merge remote-tracking branch 'origin/develop' into yushi/foreign-inputs
vsubhuman May 3, 2022
c10c0eb
Flow fixes
vsubhuman May 3, 2022
3c85dfe
Merge pull request #2819 from Emurgo/yushi/foreign-inputs
vsubhuman May 3, 2022
e71fe9b
Merge remote-tracking branch 'origin/develop' into yushi/submitted-tx…
vsubhuman May 3, 2022
3d187ec
Merge pull request #2773 from Emurgo/yushi/submitted-txs-utxos
vsubhuman May 5, 2022
693f7be
Merge remote-tracking branch 'origin/develop' into yushi/validate-inputs
vsubhuman May 5, 2022
7feee1f
Merge pull request #2828 from Emurgo/yushi/validate-inputs
vsubhuman May 5, 2022
b6fa809
Version bump: 4.12.102 (nightly)
vsubhuman May 5, 2022
fa6a5f0
error message fix
vsubhuman May 12, 2022
d9f2649
updating dapp example a bit
vsubhuman May 12, 2022
f761ed3
Version bump: 4.13.0
vsubhuman May 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/yoroi-ergo-connector/example-cardano/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ <h1 class="display-4 text-center">Cardano dApp Example</h1>
<div class="col-6 mb-4">
<button id="get-collateral-utxos" class="btn btn-light w-100">Get collateral UTXOS</button>
</div>
<div class="col-6 mb-4">
<input class="w-40" type="text" value="sign me" id="sign-data-payload" />
<button id="sign-data" class="btn btn-light w-50">Sign data</button>
</div>
<div class="col-6 mb-4">
<a href="/subpage.html">Go to a subpage</a>
</div>
Expand Down
51 changes: 50 additions & 1 deletion packages/yoroi-ergo-connector/example-cardano/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const submitTx = document.querySelector('#submit-tx')
const signTx = document.querySelector('#sign-tx')
const createTx = document.querySelector('#create-tx')
const getCollateralUtxos = document.querySelector('#get-collateral-utxos')
const signData = document.querySelector('#sign-data')
const alertEl = document.querySelector('#alert')
const spinner = document.querySelector('#spinner')

Expand All @@ -30,6 +31,7 @@ let cardanoApi
let returnType = 'cbor'
let utxos
let usedAddresses
let unusedAddresses
let changeAddress
let unsignedTransactionHex
let transactionHex
Expand Down Expand Up @@ -199,6 +201,10 @@ function addressesFromCborIfNeeded(addresses) {
CardanoWasm.Address.from_bytes(hexToBytes(a)).to_bech32()) : addresses;
}

function addressToCbor(address) {
return bytesToHex(CardanoWasm.Address.from_bech32(address).to_bytes());
}

getUnUsedAddresses.addEventListener('click', () => {
if(!accessGranted) {
alertError('Should request access first')
Expand All @@ -211,6 +217,7 @@ getUnUsedAddresses.addEventListener('click', () => {
return;
}
addresses = addressesFromCborIfNeeded(addresses)
unusedAddresses = addresses
alertSuccess(`Address: `)
alertEl.innerHTML = '<h2>Unused addresses:</h2><pre>' + JSON.stringify(addresses, undefined, 2) + '</pre>'
});
Expand Down Expand Up @@ -626,11 +633,12 @@ createTx.addEventListener('click', () => {

getCollateralUtxos.addEventListener('click', () => {
toggleSpinner('show');

if (!accessGranted) {
alertError('Should request access first');
return;
}

const amount = '4900000';
cardanoApi.getCollateralUtxos(
Buffer.from(
Expand All @@ -649,6 +657,47 @@ getCollateralUtxos.addEventListener('click', () => {
})
})

signData.addEventListener('click', () => {
toggleSpinner('show');

if (!accessGranted) {
alertError('Should request access first');
return;
}

let address;
if (usedAddresses && usedAddresses.length > 0) {
address = usedAddresses[0];
} else if (unusedAddresses && unusedAddresses.length > 0) {
address = unusedAddresses[0];
} else {
alertError('Should request used or unused addresses first');
return;
}

if (isCBOR()) {
address = addressToCbor(address);
}

const payload = document.querySelector('#sign-data-payload').value;
let payloadHex;
if (payload.startsWith('0x')) {
payloadHex = Buffer.from(payload.replace('^0x', ''), 'hex').toString('hex');
} else {
payloadHex = Buffer.from(payload, 'utf8').toString('hex');
}

console.log('address >>> ', address);
cardanoApi.signData(address, payloadHex).then(sig => {
alertSuccess('Signature:' + JSON.stringify(sig))
}).catch(error => {
console.error(error);
alertError(error.info);
}).then(() => {
toggleSpinner('hide');
});
});

function alertError (text) {
toggleSpinner('hide');
alertEl.className = 'alert alert-danger'
Expand Down
5 changes: 2 additions & 3 deletions packages/yoroi-ergo-connector/src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,8 @@ class CardanoAPI {
return this._cardano_rpc_call('sign_tx/cardano', [{ tx, partialSign, returnTx }]);
}

signData(address, sigStructure) {
// TODO
throw new Error('Not implemented yet');
signData(address, payload) {
return this._cardano_rpc_call("sign_data", [address, payload]);
}

getCollateralUtxos(requiredAmount) {
Expand Down
6 changes: 2 additions & 4 deletions packages/yoroi-extension/app/actions/profile-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
import { AsyncAction, Action } from './lib/Action';
import type { NetworkRow } from '../api/ada/lib/storage/database/primitives/tables';
import BaseProfileActions from './base/base-profile-actions';

import type { WalletsNavigation } from '../api/localStorage';
// ======= PROFILE ACTIONS =======

export default class ProfileActions extends BaseProfileActions {
acceptTermsOfUse: AsyncAction<void> = new AsyncAction();
acceptUriScheme: AsyncAction<void> = new AsyncAction();
toggleSidebar: AsyncAction<void> = new AsyncAction();
updateSortedWalletList: AsyncAction<{|
sortedWallets: Array<number>,
|}> = new AsyncAction();
updateSortedWalletList: AsyncAction<WalletsNavigation> = new AsyncAction();
setSelectedNetwork: Action<void | $ReadOnly<NetworkRow>> = new Action();
}
147 changes: 140 additions & 7 deletions packages/yoroi-extension/app/api/ada/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ import { CoreAddressTypes, TxStatusCodes, } from './lib/storage/database/primiti
import type { NetworkRow, TokenRow, } from './lib/storage/database/primitives/tables';
import { TransactionType } from './lib/storage/database/primitives/tables';
import { PublicDeriver, } from './lib/storage/models/PublicDeriver/index';
import { asDisplayCutoff, asHasLevels, } from './lib/storage/models/PublicDeriver/traits';
import {
asDisplayCutoff,
asHasLevels,
asGetAllUtxos,
} from './lib/storage/models/PublicDeriver/traits';
import { ConceptualWallet } from './lib/storage/models/ConceptualWallet/index';
import type { IHasLevels } from './lib/storage/models/ConceptualWallet/interfaces';
import type {
Expand Down Expand Up @@ -116,7 +120,8 @@ import type {
SendFunc,
SignedRequest,
SignedResponse,
TokenInfoFunc
TokenInfoFunc,
RemoteUnspentOutput,
} from './lib/state-fetch/types';
import type { FilterFunc, } from '../common/lib/state-fetch/currencySpecificTypes';
import { getChainAddressesForDisplay, } from './lib/storage/models/utils';
Expand Down Expand Up @@ -153,6 +158,7 @@ import { GetAddress, GetPathWithSpecific, } from './lib/storage/database/primiti
import { getAllSchemaTables, mapToTables, raii, } from './lib/storage/database/utils';
import { GetDerivationSpecific, } from './lib/storage/database/walletTypes/common/api/read';
import { bytesToHex, hexToBytes, hexToUtf } from '../../coreUtils';
import type { PersistedSubmittedTransaction } from '../localStorage';

// ADA specific Request / Response params

Expand Down Expand Up @@ -338,8 +344,9 @@ export type CardanoTxRequest = {|
|};
export type CreateUnsignedTxForConnectorRequest = {|
cardanoTxRequest: CardanoTxRequest,
publicDeriver: IPublicDeriver<ConceptualWallet> & IGetAllUtxos & IHasUtxoChains,
publicDeriver: PublicDeriver<>,
absSlotNumber: BigNumber,
submittedTxs: Array<PersistedSubmittedTransaction>,
utxos: Array<CardanoAddressedUtxo>,
|};
export type CreateUnsignedTxResponse = HaskellShelleyTxSignRequest;
Expand Down Expand Up @@ -1149,7 +1156,12 @@ export default class AdaApi {
}
}

const { utxos } = request;
const utxos = await this.addressedUtxosWithSubmittedTxs(
request.utxos,
request.publicDeriver,
request.submittedTxs
);

const allUtxoIds = new Set(utxos.map(utxo => utxo.utxo_id));
const utxoIdSet = new Set((includeInputs||[]).filter(utxoId => {
if (!allUtxoIds.has(utxoId)) {
Expand Down Expand Up @@ -2246,7 +2258,10 @@ export default class AdaApi {
txId: string,
defaultNetworkId: number,
defaultToken: $ReadOnly<TokenRow>,
): Promise<CardanoShelleyTransaction> {
): Promise<{|
transaction: CardanoShelleyTransaction,
usedUtxos: Array<{| txHash: string, index: number |}>
|}> {
const p = asHasLevels<ConceptualWallet>(publicDeriver);
if (!p) {
throw new Error(`${nameof(this.createSubmittedTransactionData)} publicDerviver traits missing`);
Expand Down Expand Up @@ -2296,8 +2311,10 @@ export default class AdaApi {
isIntraWallet = false;
}
}

return CardanoShelleyTransaction.fromData({
const usedUtxos = signRequest.senderUtxos.map(utxo => (
{ txHash: utxo.tx_hash, index: utxo.tx_index }
));
const transaction = CardanoShelleyTransaction.fromData({
txid: txId,
type: isIntraWallet ? 'self' : 'expend',
amount,
Expand All @@ -2321,6 +2338,122 @@ export default class AdaApi {
})),
isValid: true,
});
return { usedUtxos, transaction };
}

utxosWithSubmittedTxs(
originalUtxos: Array<RemoteUnspentOutput>,
publicDeriverId: number,
submittedTxs: Array<PersistedSubmittedTransaction>,
): Array<RemoteUnspentOutput> {
const filteredSubmittedTxs = submittedTxs.filter(
submittedTxRecord => submittedTxRecord.publicDeriverId === publicDeriverId
);
const usedUtxoIds = new Set(
filteredSubmittedTxs.flatMap(({ usedUtxos }) => usedUtxos.map(({ txHash, index }) => `${txHash}${index}`))
);
// take out UTxOs consumed by submitted transactions
const utxos = originalUtxos.filter(utxo => !usedUtxoIds.has(utxo.utxo_id));
// put in UTxOs produced by submitted transactions
for (const { transaction } of filteredSubmittedTxs) {
for (const [index, { address, value }] of transaction.addresses.to.entries()) {
if (utxos.find(utxo => utxo.utxo_id === `${transaction.txid}${index}`)) {
// this output is already included
continue;
}

const amount = value.values.find(
({ identifier }) => identifier === value.defaults.defaultIdentifier
)?.amount || '0';
const assets = value.values
.filter(({ identifier }) => identifier !== value.defaults.defaultIdentifier)
.map(v => {
const [policyId, name = ''] = v.identifier.split('.');
return {
policyId,
name,
amount: v.amount,
assetId: v.identifier,
};
});
utxos.push({
utxo_id: `${transaction.txid}${index}`,
tx_hash: transaction.txid,
tx_index: index,
receiver: address,
amount,
assets,
});
}
}
return utxos;
}

async addressedUtxosWithSubmittedTxs(
originalUtxos: Array<CardanoAddressedUtxo>,
publicDeriver: PublicDeriver<>,
submittedTxs: Array<PersistedSubmittedTransaction>,
): Promise<Array<CardanoAddressedUtxo>> {
const filteredSubmittedTxs = submittedTxs.filter(
submittedTxRecord => submittedTxRecord.publicDeriverId === publicDeriver.publicDeriverId
);
const usedUtxoIds = new Set(
filteredSubmittedTxs.flatMap(({ usedUtxos }) => usedUtxos.map(({ txHash, index }) => `${txHash}${index}`))
);
// take out UTxOs consumed by submitted transactions
const utxos = originalUtxos.filter(utxo => !usedUtxoIds.has(utxo.utxo_id));
// put in UTxOs produced by submitted transactions
const withUtxos = asGetAllUtxos(publicDeriver);
if (!withUtxos) {
throw new Error('unable to get UTxO addresses from public deriver');
}
const allAddresses = await withUtxos.getAllUtxoAddresses();

for (const { transaction } of filteredSubmittedTxs) {
for (const [index, { address, value }] of transaction.addresses.to.entries()) {
if (utxos.find(utxo => utxo.utxo_id === `${transaction.txid}${index}`)) {
// this output is already included
continue;
}

const amount = value.values.find(
({ identifier }) => identifier === value.defaults.defaultIdentifier
)?.amount || '0';
const assets = value.values
.filter(({ identifier }) => identifier !== value.defaults.defaultIdentifier)
.map(v => {
const [policyId, name = ''] = v.identifier.split('.');
return {
policyId,
name,
amount: v.amount,
assetId: v.identifier,
};
});
const findAddressing = () => {
for (const { addrs, addressing } of allAddresses) {
for (const { Hash } of addrs) {
if (Hash === address) {
return addressing;
}
}
}
};
const addressing = findAddressing();
if (addressing) {
utxos.push({
utxo_id: `${transaction.txid}${index}`,
tx_hash: transaction.txid,
tx_index: index,
receiver: address,
amount,
assets,
addressing,
});
} // else { should not happen }
}
}
return utxos;
}
}
// ========== End of class AdaApi =========
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
BestBlockRequest, BestBlockResponse,
TokenInfoRequest, TokenInfoResponse,
MultiAssetMintMetadataRequest, MultiAssetMintMetadataResponse,
GetUtxoDataRequest, GetUtxoDataResponse,
} from './types';
import type {
FilterUsedRequest, FilterUsedResponse,
Expand All @@ -33,4 +34,5 @@ export interface IFetcher {
checkAddressesInUse(body: FilterUsedRequest): Promise<FilterUsedResponse>;
getMultiAssetMintMetadata(body: MultiAssetMintMetadataRequest)
: Promise<MultiAssetMintMetadataResponse>;
getUtxoData(body: GetUtxoDataRequest): Promise<GetUtxoDataResponse>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import type {
UtxoSumFunc,
RemoteTransaction,
MultiAssetMintMetadataRequest,
MultiAssetMintMetadataResponse
MultiAssetMintMetadataResponse,
GetUtxoDataFunc, GetUtxoDataRequest, GetUtxoDataResponse,
} from './types';
import type {
FilterFunc, FilterUsedRequest, FilterUsedResponse,
Expand Down Expand Up @@ -123,6 +124,10 @@ export class BatchedFetcher implements IFetcher {
getCatalystRoundInfo: CatalystRoundInfoRequest => Promise<CatalystRoundInfoResponse> = (body) => (
batchGetCatalystRoundInfo(this.baseFetcher.getCatalystRoundInfo)(body)
)

getUtxoData: GetUtxoDataRequest => Promise<GetUtxoDataResponse> = (body) => (
batchGetUtxoData(this.baseFetcher.getUtxoData)(body)
)
}

/** Sum up the UTXO for a list of addresses by batching backend requests */
Expand Down Expand Up @@ -491,3 +496,20 @@ export function batchGetTokenInfo(
}
};
}

function batchGetUtxoData(
getUtxoData: GetUtxoDataFunc,
): GetUtxoDataFunc {
return async function (body: GetUtxoDataRequest): Promise<GetUtxoDataResponse> {
return (await Promise.all(
body.utxos.map(
({ txHash, txIndex }) => getUtxoData(
{
network: body.network,
utxos: [ { txHash, txIndex } ],
}
)
)
)).flat();
};
}
Loading