Skip to content

Commit 48f7951

Browse files
fix: add to BaseWallet re-submit exceptions CredentialAlreadyRegistered and DrepAlreadyRegistered errors
1 parent 7314269 commit 48f7951

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed

packages/core/src/CardanoNode/types/CardanoNodeErrors.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CustomError } from 'ts-custom-error';
22
import type * as Cardano from '../../Cardano';
3+
import type * as Crypto from '@cardano-sdk/crypto';
34

45
export enum GeneralCardanoNodeErrorCode {
56
ServerNotReady = 503,
@@ -129,3 +130,11 @@ export type IncompleteWithdrawalsData = {
129130
export type UnknownOutputReferencesData = {
130131
unknownOutputReferences: Cardano.TxIn[];
131132
};
133+
134+
export type CredentialAlreadyRegisteredData = {
135+
hash: Crypto.Hash28ByteBase16;
136+
};
137+
138+
export type DRepAlreadyRegisteredData = {
139+
hash: Crypto.Hash28ByteBase16;
140+
};

packages/core/src/CardanoNode/util/cardanoNodeErrors.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import {
33
ChainSyncError,
44
ChainSyncErrorCode,
5+
CredentialAlreadyRegisteredData,
6+
DRepAlreadyRegisteredData,
57
GeneralCardanoNodeError,
68
GeneralCardanoNodeErrorCode,
79
IncompleteWithdrawalsData,
@@ -124,3 +126,11 @@ export const isUnknownOutputReferences = (
124126
error: unknown
125127
): error is TxSubmissionError<UnknownOutputReferencesData | null> =>
126128
error instanceof TxSubmissionError && error.code === TxSubmissionErrorCode.UnknownOutputReferences;
129+
130+
export const isCredentialAlreadyRegistered = (
131+
error: unknown
132+
): error is TxSubmissionError<CredentialAlreadyRegisteredData | null> =>
133+
error instanceof TxSubmissionError && error.code === TxSubmissionErrorCode.CredentialAlreadyRegistered;
134+
135+
export const isDrepAlreadyRegistered = (error: unknown): error is TxSubmissionError<DRepAlreadyRegisteredData | null> =>
136+
error instanceof TxSubmissionError && error.code === TxSubmissionErrorCode.DRepAlreadyRegistered;

packages/core/test/CardanoNode/util/cardanoNodeErrors.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ describe('util/cardanoNodeErrors', () => {
7878
new TxSubmissionError(TxSubmissionErrorCode.OutsideOfValidityInterval, null, '')
7979
)
8080
).toBe(true);
81+
expect(
82+
CardanoNodeUtil.isCredentialAlreadyRegistered(
83+
new TxSubmissionError(TxSubmissionErrorCode.CredentialAlreadyRegistered, null, '')
84+
)
85+
).toBe(true);
86+
expect(
87+
CardanoNodeUtil.isDrepAlreadyRegistered(
88+
new TxSubmissionError(TxSubmissionErrorCode.DRepAlreadyRegistered, null, '')
89+
)
90+
).toBe(true);
8191
});
8292
it('returns false if error type or code does not match', () => {
8393
expect(CardanoNodeUtil.isValueNotConservedError(generalError)).toBe(false);
@@ -98,6 +108,16 @@ describe('util/cardanoNodeErrors', () => {
98108
new TxSubmissionError(TxSubmissionErrorCode.IncompleteWithdrawals, null, '')
99109
)
100110
).toBe(false);
111+
expect(
112+
CardanoNodeUtil.isCredentialAlreadyRegistered(
113+
new TxSubmissionError(TxSubmissionErrorCode.IncompleteWithdrawals, null, '')
114+
)
115+
).toBe(false);
116+
expect(
117+
CardanoNodeUtil.isDrepAlreadyRegistered(
118+
new TxSubmissionError(TxSubmissionErrorCode.IncompleteWithdrawals, null, '')
119+
)
120+
).toBe(false);
101121
});
102122
});
103123
});

packages/e2e/test/wallet_epoch_3/PersonalWallet/conwayTransactions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const paramsUpdate: Cardano.ProtocolParametersUpdateConway = {
135135
treasuryExpansion: '0.25'
136136
};
137137

138-
describe.skip('PersonalWallet/conwayTransactions', () => {
138+
describe('PersonalWallet/conwayTransactions', () => {
139139
let dRepWallet: BaseWallet;
140140
let wallet: BaseWallet;
141141

packages/ogmios/src/CardanoNode/queries.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {
22
Cardano,
33
CardanoNodeUtil,
44
ChainSyncError,
5+
CredentialAlreadyRegisteredData,
6+
DRepAlreadyRegisteredData,
57
GeneralCardanoNodeError,
68
GeneralCardanoNodeErrorCode,
79
IncompleteWithdrawalsData,
@@ -17,6 +19,8 @@ import {
1719
import { LedgerStateQuery } from '@cardano-ogmios/client';
1820
import { Logger } from 'ts-log';
1921
import {
22+
SubmitTransactionFailureCredentialAlreadyRegistered,
23+
SubmitTransactionFailureDRepAlreadyRegistered,
2024
SubmitTransactionFailureIncompleteWithdrawals,
2125
SubmitTransactionFailureOutsideOfValidityInterval,
2226
SubmitTransactionFailureUnknownOutputReferences,
@@ -25,6 +29,7 @@ import {
2529
import { eraSummary, genesis } from '../ogmiosToCore';
2630
import { isConnectionError } from '@cardano-sdk/util';
2731
import { mapTxIn, mapValue, mapWithdrawals } from '../ogmiosToCore/tx';
32+
import type * as Crypto from '@cardano-sdk/crypto';
2833

2934
const errorDataToCore = (data: unknown, code: number) => {
3035
switch (code) {
@@ -57,6 +62,23 @@ const errorDataToCore = (data: unknown, code: number) => {
5762
unknownOutputReferences: typedData.unknownOutputReferences.map(mapTxIn)
5863
} as UnknownOutputReferencesData;
5964
}
65+
case TxSubmissionErrorCode.CredentialAlreadyRegistered: {
66+
const typedData = data as SubmitTransactionFailureCredentialAlreadyRegistered['data'];
67+
68+
return {
69+
hash: typedData.knownCredential as Crypto.Hash28ByteBase16
70+
} as CredentialAlreadyRegisteredData;
71+
}
72+
case TxSubmissionErrorCode.DRepAlreadyRegistered: {
73+
const typedData = data as SubmitTransactionFailureDRepAlreadyRegistered['data'];
74+
75+
if (typedData.knownDelegateRepresentative.type === 'registered') {
76+
return {
77+
hash: typedData.knownDelegateRepresentative.id as Crypto.Hash28ByteBase16
78+
} as DRepAlreadyRegisteredData;
79+
}
80+
return null;
81+
}
6082
default:
6183
// Mapper not implemented
6284
return data;

packages/wallet/src/Wallets/BaseWallet.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,9 @@ export class BaseWallet implements ObservableWallet {
685685
// TODO: check if IncompleteWithdrawals available withdrawal amount === wallet's reward acc balance?
686686
// Not sure what the 'Withdrawals' in error data is exactly: value being withdrawed, or reward acc balance
687687
CardanoNodeUtil.isIncompleteWithdrawalsError(error.innerError) ||
688-
CardanoNodeUtil.isUnknownOutputReferences(error.innerError))
688+
CardanoNodeUtil.isUnknownOutputReferences(error.innerError) ||
689+
CardanoNodeUtil.isCredentialAlreadyRegistered(error.innerError) ||
690+
CardanoNodeUtil.isDrepAlreadyRegistered(error.innerError))
689691
) {
690692
this.#logger.debug(
691693
`Transaction ${outgoingTx.id} failed with ${error.innerError}, but it appears to be already submitted...`

0 commit comments

Comments
 (0)