Skip to content

centralized tx processing store #3902

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

Open
wants to merge 41 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5558968
remove unused pre-revamp code
yushih Jan 23, 2025
56f5284
refactor: unify entry point of sending tx for hardware and mnemonic w…
yushih Jan 25, 2025
b1cdeb5
remove unused pre-revamp components
yushih Jan 26, 2025
f598277
remove some unnecessary methods
yushih Jan 26, 2025
ca3b038
deduplicate ledger transaction signing code
yushih Jan 28, 2025
f50e6e9
deduplicate trezor transaction signing code
yushih Jan 29, 2025
b68515a
Merge branch 'develop' into refactor/hw-wallet-tx
Nebyt Jan 30, 2025
1818967
lint
yushih Jan 30, 2025
d012f24
lint
yushih Jan 30, 2025
77696bc
format
yushih Jan 30, 2025
7ade897
fix
yushih Feb 1, 2025
37d3a90
fix send error handling
yushih Feb 1, 2025
3097d0c
fix change address path
yushih Feb 3, 2025
3d1afd1
fix: withdraw dialog not closed after tx submission
yushih Feb 3, 2025
586eea6
close transfer dialog after transaction submission
yushih Feb 3, 2025
77caf35
fix catalyst registration
yushih Feb 3, 2025
7e6dce4
fix "reference inputs not allowed in TransactionSigningMode.ORDINARY_…
yushih Feb 4, 2025
7c62d6a
fix catalyst voting transaction
yushih Feb 5, 2025
73e5f88
lint
yushih Feb 5, 2025
4c56c3a
Merge remote-tracking branch 'origin/develop' into refactor/hw-wallet-tx
yushih Feb 19, 2025
16a339a
fix Byron transfer for ledger
yushih Feb 20, 2025
df6e38d
Merge remote-tracking branch 'origin/develop' into refactor/hw-wallet-tx
yushih Feb 23, 2025
1c88773
simplify
yushih Feb 23, 2025
aa2929b
re-organize store code
yushih Mar 20, 2025
f4cdca7
remove dead code
yushih Mar 20, 2025
d9e201d
remove dead code
yushih Mar 20, 2025
0a0bcb5
Merge branch 'develop' into refactor/hw-wallet-tx
yushih Mar 21, 2025
15f8124
Merge branch 'refactor/hw-wallet-tx' into refact/YOEXT-1391/centraliz…
yushih Mar 21, 2025
b268653
unify transaction processing
yushih Mar 21, 2025
15e2b48
wip
yushih Mar 24, 2025
54e1ef4
fix previous merge
yushih Mar 24, 2025
fa18ed1
wip
yushih Mar 24, 2025
1a32deb
wip
yushih Mar 24, 2025
479d49c
fix
yushih Mar 24, 2025
86ca284
Merge remote-tracking branch 'origin/sorin/YOEXT-1389/transaction-rev…
yushih Mar 24, 2025
fbcc2f6
lint
yushih Mar 24, 2025
7d42845
fix
yushih Mar 24, 2025
0e54fe9
fix test
yushih Mar 24, 2025
92c6fb6
Merge remote-tracking branch 'origin/sorin/YOEXT-1389/transaction-rev…
yushih Apr 2, 2025
7c7eeb0
Merge remote-tracking branch 'origin/sorin/YOEXT-1389/transaction-rev…
yushih Apr 10, 2025
959f4a4
Merge remote-tracking branch 'origin/develop' into refact/YOEXT-1391/…
yushih Apr 17, 2025
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
91 changes: 29 additions & 62 deletions packages/yoroi-extension/app/api/ada/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import type {
IPublicDeriver,
UsedStatus,
Value,
QueriedUtxo,
} from './lib/storage/models/PublicDeriver/interfaces';
import type {
BaseGetTransactionsRequest,
Expand All @@ -83,8 +84,8 @@ import { generateAdaMnemonic, generateWalletRootKey, } from './lib/cardanoCrypto
import { buildCoseSign1FromSignature, cip8Sign, makeCip8Key, v4PublicToV2 } from './lib/cardanoCrypto/utils';
import { isValidBip39Mnemonic, } from './lib/cardanoCrypto/wallet';
import type { CardanoSignTransaction } from 'trezor-connect-flow';
import { createTrezorSignTxPayload, toTrezorSignRequest, } from './transactions/shelley/trezorTx';
import { createLedgerSignTxPayload, toLedgerSignRequest, } from './transactions/shelley/ledgerTx';
import { toTrezorSignRequest, } from './transactions/shelley/trezorTx';
import { toLedgerSignRequest, } from './transactions/shelley/ledgerTx';
import {
GenericApiError,
IncorrectWalletPasswordError,
Expand Down Expand Up @@ -157,7 +158,7 @@ import type { DefaultTokenEntry } from '../common/lib/MultiToken';
import { MultiToken } from '../common/lib/MultiToken';
import { getReceiveAddress } from '../../stores/stateless/addressStores';
import { generateRegistrationMetadata } from './lib/cardanoCrypto/catalyst';
import { bytesToHex, fail, hexToBytes, hexToUtf, iterateLenGet } from '../../coreUtils';
import { bytesToHex, fail, hexToBytes, hexToUtf, iterateLenGet, first, sorted } from '../../coreUtils';
import type { PersistedSubmittedTransaction } from '../localStorage';
import type WalletTransaction from '../../domain/WalletTransaction';
import { derivePrivateByAddressing, derivePublicByAddressing } from './lib/cardanoCrypto/deriveByAddressing';
Expand Down Expand Up @@ -256,8 +257,11 @@ export type CreateHWSignTxDataRequestFromRawTx = {|
txBodyHex: string,
network: $ReadOnly<NetworkRow>,
addressingMap: string => (void | $PropertyType<Addressing, 'addressing'>),
changeAddrs: Array<{| ...Address, ...Value, ...Addressing |}>,
senderUtxos: Array<CardanoAddressedUtxo>,
additionalRequiredSigners?: Array<string>,
ledgerSupportsCip36?: boolean,
catalystData?: LedgerNanoCatalystRegistrationTxSignData,
|};

// createUnsignedTx
Expand Down Expand Up @@ -519,7 +523,8 @@ export type GetTransactionRowsToExportFunc = (
export type ForeignUtxoFetcher = (Array<string>) => Promise<Array<?RemoteUnspentOutput>>;

export const FETCH_TXS_BATCH_SIZE = 20;
const MIN_REORG_OUTPUT_AMOUNT = '1000000';
const MIN_REORG_OUTPUT_AMOUNT = '1000000';
const MAX_PICKED_COLLATERAL_UTXO_ADA = 10_000_000; // 10 ADA

export default class AdaApi {

Expand Down Expand Up @@ -747,63 +752,6 @@ export default class AdaApi {
}
}

createTrezorSignTxData(request: {|
signRequest: HaskellShelleyTxSignRequest,
network: $ReadOnly<NetworkRow>,
|}): CreateTrezorSignTxDataResponse {
try {
Logger.debug(`${nameof(AdaApi)}::${nameof(this.createTrezorSignTxData)} called`);

const config = getCardanoHaskellBaseConfig(
request.network
).reduce((acc, next) => Object.assign(acc, next), {});

const trezorSignTxPayload = createTrezorSignTxPayload(
request.signRequest,
config.ByronNetworkId,
Number.parseInt(config.ChainNetworkId, 10),
);
Logger.debug(`${nameof(AdaApi)}::${nameof(this.createTrezorSignTxData)} success: ` + stringifyData(trezorSignTxPayload));
return {
trezorSignTxPayload,
};
} catch (error) {
Logger.error(`${nameof(AdaApi)}::${nameof(this.createTrezorSignTxData)} error: ` + stringifyError(error));
if (error instanceof LocalizableError) throw error;
throw new GenericApiError();
}
}

createLedgerSignTxData(
request: CreateLedgerSignTxDataRequest
): CreateLedgerSignTxDataResponse {
try {
Logger.debug(`${nameof(AdaApi)}::${nameof(this.createLedgerSignTxData)} called`);

const config = getCardanoHaskellBaseConfig(
request.network
).reduce((acc, next) => Object.assign(acc, next), {});

const ledgerSignTxPayload = createLedgerSignTxPayload({
signRequest: request.signRequest,
byronNetworkMagic: config.ByronNetworkId,
networkId: Number.parseInt(config.ChainNetworkId, 10),
addressingMap: request.addressingMap,
cip36: request.cip36,
});

Logger.debug(`${nameof(AdaApi)}::${nameof(this.createLedgerSignTxData)} success: ` + stringifyData(ledgerSignTxPayload));
return {
ledgerSignTxPayload
};
} catch (error) {
Logger.error(`${nameof(AdaApi)}::${nameof(this.createLedgerSignTxData)} error: ` + stringifyError(error));

if (error instanceof LocalizableError) throw error;
throw new GenericApiError();
}
}

createHwSignTxDataFromRawTx(
hw: 'ledger' | 'trezor',
request: CreateHWSignTxDataRequestFromRawTx
Expand All @@ -826,8 +774,11 @@ export default class AdaApi {
Number(config.ChainNetworkId),
protocolMagic,
addressMap,
request.changeAddrs ?? [],
request.senderUtxos,
request.additionalRequiredSigners ?? [],
request.ledgerSupportsCip36,
request.catalystData,
);

Logger.debug(`${nameof(AdaApi)}::${nameof(this.createHwSignTxDataFromRawTx)} success: ` + stringifyData(ledgerSignTxPayload));
Expand All @@ -840,7 +791,9 @@ export default class AdaApi {
Number(config.ChainNetworkId),
protocolMagic,
addressMap,
request.changeAddrs ?? [],
request.senderUtxos,
request.catalystData,
);
Logger.debug(`${nameof(AdaApi)}::${nameof(this.createHwSignTxDataFromRawTx)} success: ` + stringifyData(trezorSignTxPayload));
return { hw, result: { trezorSignTxPayload } };
Expand Down Expand Up @@ -1873,7 +1826,7 @@ export default class AdaApi {
network,
});
}

const cip1852Wallet = await Cip1852Wallet.createCip1852Wallet(
db,
wallet.cip1852WrapperRow,
Expand Down Expand Up @@ -2535,6 +2488,20 @@ export default class AdaApi {
});
};
};

pickCollateralUtxo: ({| wallet: WalletState |}) => Promise<?QueriedUtxo> = async ({ wallet }) => {
const allUtxos = wallet.utxos;
if (allUtxos.length === 0) {
fail('Cannot pick a collateral utxo! No utxo available at all in the wallet!');
}
const utxoDefaultCoinAmount = (u: QueriedUtxo): BigNumber =>
new BigNumber(u.output.tokens.find(x => x.Token.Identifier === '')?.TokenList.Amount ?? 0);
const compareDefaultCoins = (a: QueriedUtxo, b: QueriedUtxo): number =>
utxoDefaultCoinAmount(a).comparedTo(utxoDefaultCoinAmount(b));
const smallPureUtxos = allUtxos
.filter(u => u.output.tokens.length === 1 && utxoDefaultCoinAmount(u).lte(MAX_PICKED_COLLATERAL_UTXO_ADA));
return first(sorted(smallPureUtxos, compareDefaultCoins));
}
}
// ========== End of class AdaApi =========

Expand Down
Loading