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

tx history head/tail fix #3385

Merged
merged 8 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 23 additions & 28 deletions packages/yoroi-extension/app/api/ada/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import type { Network, } from '../../../config/config-types';
import { createHardwareWallet, createStandardBip44Wallet, } from './lib/storage/bridge/walletBuilder/byron';
import { createHardwareCip1852Wallet, createStandardCip1852Wallet, } from './lib/storage/bridge/walletBuilder/shelley';
import type { ReferenceTx } from './lib/storage/bridge/updateTransactions';
import {
getAllTransactions,
getForeignAddresses,
Expand All @@ -41,11 +42,7 @@ 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,
asGetAllUtxos,
} from './lib/storage/models/PublicDeriver/traits';
import { asDisplayCutoff, asGetAllUtxos, asHasLevels, } 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 @@ -111,28 +108,28 @@ import type {
CardanoUtxoScriptWitness,
V4UnsignedTxAddressedUtxoResponse,
} from './transactions/types';
import {
HaskellShelleyTxSignRequest,
} from './transactions/shelley/HaskellShelleyTxSignRequest';
import type {
LedgerNanoCatalystRegistrationTxSignData,
TrezorTCatalystRegistrationTxSignData,
} from './transactions/shelley/HaskellShelleyTxSignRequest';
import { HaskellShelleyTxSignRequest, } from './transactions/shelley/HaskellShelleyTxSignRequest';
import type { SignTransactionRequest } from '@cardano-foundation/ledgerjs-hw-app-cardano';
import { WrongPassphraseError } from './lib/cardanoCrypto/cryptoErrors';

import type {
AccountStateFunc,
AddressUtxoFunc,
BestBlockFunc,
GetRecentTransactionHashesFunc,
GetTransactionsByHashesFunc,
HistoryFunc,
MultiAssetMintMetadataFunc,
MultiAssetSupplyFunc,
RemoteUnspentOutput,
SendFunc,
SignedRequest,
SignedResponse,
TokenInfoFunc,
RemoteUnspentOutput,
GetRecentTransactionHashesFunc,
GetTransactionsByHashesFunc, MultiAssetSupplyFunc,
} 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 @@ -241,9 +238,10 @@ export type AdaGetTransactionsRequest = {|
getTokenInfo: TokenInfoFunc,
getMultiAssetMetadata: MultiAssetMintMetadataFunc,
getMultiAssetSupply: MultiAssetSupplyFunc,
afterTxs?: ?Array<WalletTransaction>,
afterTx?: ?WalletTransaction,
getRecentTransactionHashes: GetRecentTransactionHashesFunc,
getTransactionsByHashes: GetTransactionsByHashesFunc,
getTransactionHistory: HistoryFunc,
|};

// notices
Expand Down Expand Up @@ -670,10 +668,9 @@ export default class AdaApi {

/*
3 scenarios when this function is invoked:
1. To load locally the initial txs: isLocalRequest === true, afterTxs == null;
2. To fetch the newest transactions from network: isLocalRequest === false, afterTxs == null,
3. To fetch transactions after some transactions from network:
isLocalRequest = false, afterTxs != null
1. To load locally the initial txs: isLocalRequest === true, afterTx == null, beforeTx == null;
2. To fetch the newest transactions from network: isLocalRequest === false, afterTx != null,
3. To fetch older transactions: isLocalRequest = false, beforeTx != null
*/
async refreshTransactions(
request: {|
Expand All @@ -692,7 +689,7 @@ export default class AdaApi {
limit: FETCH_TXS_BATCH_SIZE,
});
} else {
if (!request.afterTxs) {
if (!request.beforeTx) {
await updateUtxos(
request.publicDeriver.getDb(),
request.publicDeriver,
Expand All @@ -703,28 +700,26 @@ export default class AdaApi {
);
}

let after;
if (request.afterTxs && request.afterTxs.length > 0) {
const lastTx = request.afterTxs[request.afterTxs.length - 1];
if (lastTx.block) {
after = {
blockHash: lastTx.block.Hash,
txHash: lastTx.txid,
};
}
}
const resolveReference: ?WalletTransaction => ?ReferenceTx = ref => {
return ref?.block ? {
blockHash: ref.block.Hash,
txHash: ref.txid,
} : undefined;
};

fetchedTxs = await updateTransactions(
request.publicDeriver.getDb(),
request.publicDeriver,
request.checkAddressesInUse,
request.getTransactionHistory,
request.getRecentTransactionHashes,
request.getTransactionsByHashes,
request.getBestBlock,
request.getTokenInfo,
request.getMultiAssetMetadata,
request.getMultiAssetSupply,
after,
resolveReference(request.afterTx),
resolveReference(request.beforeTx),
);
}
Logger.debug(`${nameof(AdaApi)}::${nameof(this.refreshTransactions)} success: ` + stringifyData(fetchedTxs));
Expand Down
15 changes: 8 additions & 7 deletions packages/yoroi-extension/app/api/ada/lib/state-fetch/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,15 @@ export type GetRecentTransactionHashesRequest = {|
|},
|};

export type TxSummary = {|
txHash: string,
blockHash: string,
txBlockIndex: number,
epoch: number,
slot: number,
|};
export type GetRecentTransactionHashesResponse = {|
[address: string]: Array<{|
txHash: string,
blockHash: string,
txBlockIndex: number,
epoch: number,
slot: number,
|}>
[address: string]: Array<TxSummary>
|};

export type GetRecentTransactionHashesFunc = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
genGetMultiAssetMetadata,
MockUtxoApi,
genGetRecentTransactionHashes,
genGetTransactionsByHashes, genGetMultiAssetSupply,
genGetTransactionsByHashes, genGetMultiAssetSupply, genGetTransactionsHistoryForAddresses,
} from '../../../state-fetch/mockNetwork';
import { loadLovefieldDB } from '../../database/index';

Expand Down Expand Up @@ -401,6 +401,7 @@ async function syncingSimpleTransaction(
const getTokenInfo = genGetTokenInfo();
const getMultiAssetMetadata = genGetMultiAssetMetadata();
const getMultiAssetSupply = genGetMultiAssetSupply();
const getTransactionsHistoryForAddresses = genGetTransactionsHistoryForAddresses(txHistory, network);
const getRecentTransactionHashes = genGetRecentTransactionHashes(txHistory);
const getTransactionsByHashes = genGetTransactionsByHashes(txHistory);

Expand Down Expand Up @@ -429,6 +430,7 @@ async function syncingSimpleTransaction(
db,
withUtxos1,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -479,6 +481,7 @@ async function syncingSimpleTransaction(
db,
withUtxos2,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -516,6 +519,7 @@ async function syncingSimpleTransaction(
db,
withUtxos2,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -570,6 +574,7 @@ async function syncingSimpleTransaction(
db,
withUtxos2,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
genGetMultiAssetMetadata,
MockUtxoApi,
genGetRecentTransactionHashes,
genGetTransactionsByHashes, genGetMultiAssetSupply,
genGetTransactionsByHashes, genGetMultiAssetSupply, genGetTransactionsHistoryForAddresses,
} from '../../../state-fetch/mockNetwork';
import {
HARD_DERIVATION_START,
Expand Down Expand Up @@ -227,6 +227,7 @@ async function syncingSimpleTransaction(
const getTokenInfo = genGetTokenInfo();
const getMultiAssetMetadata = genGetMultiAssetMetadata();
const getMultiAssetSupply = genGetMultiAssetSupply();
const getTransactionsHistoryForAddresses = genGetTransactionsHistoryForAddresses(txHistory, network);
const getRecentTransactionHashes = genGetRecentTransactionHashes(txHistory);
const getTransactionsByHashes = genGetTransactionsByHashes(txHistory);

Expand Down Expand Up @@ -256,6 +257,7 @@ async function syncingSimpleTransaction(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -362,6 +364,7 @@ async function syncingSimpleTransaction(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
genGetMultiAssetMetadata,
MockUtxoApi,
genGetRecentTransactionHashes,
genGetTransactionsByHashes, genGetMultiAssetSupply,
genGetTransactionsByHashes, genGetMultiAssetSupply, genGetTransactionsHistoryForAddresses,
} from '../../../state-fetch/mockNetwork';
import {
HARD_DERIVATION_START,
Expand Down Expand Up @@ -318,6 +318,7 @@ async function syncingSimpleTransaction(
const getTokenInfo = genGetTokenInfo();
const getMultiAssetMetadata = genGetMultiAssetMetadata();
const getMultiAssetSupply = genGetMultiAssetSupply();
const getTransactionsHistoryForAddresses = genGetTransactionsHistoryForAddresses(txHistory, network);
const getRecentTransactionHashes = genGetRecentTransactionHashes(txHistory);
const getTransactionsByHashes = genGetTransactionsByHashes(txHistory);

Expand Down Expand Up @@ -348,6 +349,7 @@ async function syncingSimpleTransaction(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -454,6 +456,7 @@ async function syncingSimpleTransaction(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -593,6 +596,7 @@ async function syncingSimpleTransaction(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -644,6 +648,7 @@ async function syncingSimpleTransaction(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -685,6 +690,7 @@ async function syncingSimpleTransaction(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -736,6 +742,7 @@ async function syncingSimpleTransaction(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -809,6 +816,7 @@ async function utxoCreatedAndUsed(
const getTokenInfo = genGetTokenInfo();
const getMultiAssetMetadata = genGetMultiAssetMetadata();
const getMultiAssetSupply = genGetMultiAssetSupply();
const getTransactionsHistoryForAddresses = genGetTransactionsHistoryForAddresses(txHistory, network);
const getRecentTransactionHashes = genGetRecentTransactionHashes(txHistory);
const getTransactionsByHashes = genGetTransactionsByHashes(txHistory);

Expand Down Expand Up @@ -841,6 +849,7 @@ async function utxoCreatedAndUsed(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
genGetMultiAssetMetadata,
MockUtxoApi,
genGetRecentTransactionHashes,
genGetTransactionsByHashes, genGetMultiAssetSupply,
genGetTransactionsByHashes, genGetMultiAssetSupply, genGetTransactionsHistoryForAddresses,
} from '../../../state-fetch/mockNetwork';
import { loadLovefieldDB } from '../../database/index';
import {
Expand Down Expand Up @@ -325,6 +325,7 @@ async function baseTest(
const getTokenInfo = genGetTokenInfo();
const getMultiAssetMetadata = genGetMultiAssetMetadata();
const getMultiAssetSupply = genGetMultiAssetSupply();
const getTransactionsHistoryForAddresses = genGetTransactionsHistoryForAddresses(networkTransactions, network);
const getRecentTransactionHashes = genGetRecentTransactionHashes(networkTransactions);
const getTransactionsByHashes = genGetTransactionsByHashes(networkTransactions);

Expand All @@ -350,6 +351,7 @@ async function baseTest(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -407,6 +409,7 @@ async function baseTest(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -544,6 +547,7 @@ async function baseTest(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -736,6 +740,7 @@ async function baseTest(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -917,6 +922,7 @@ async function baseTest(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down Expand Up @@ -1071,6 +1077,7 @@ async function pendingDropped(
const getTokenInfo = genGetTokenInfo();
const getMultiAssetMetadata = genGetMultiAssetMetadata();
const getMultiAssetSupply = genGetMultiAssetSupply();
const getTransactionsHistoryForAddresses = genGetTransactionsHistoryForAddresses(networkTransactions, network);
const getRecentTransactionHashes = genGetRecentTransactionHashes(networkTransactions);
const getTransactionsByHashes = genGetTransactionsByHashes(networkTransactions);

Expand All @@ -1093,6 +1100,7 @@ async function pendingDropped(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand All @@ -1117,6 +1125,7 @@ async function pendingDropped(
db,
basePubDeriver,
checkAddressesInUse,
getTransactionsHistoryForAddresses,
getRecentTransactionHashes,
getTransactionsByHashes,
getBestBlock,
Expand Down
Loading
Loading