Skip to content

Commit

Permalink
refactor(core)!: nest errors under TxSubmissionErrors object
Browse files Browse the repository at this point in the history
- Preparation for an upcoming util of determining domain errors
- Fixes a typo `UnkownResultError`
- align EraMismatch tx submit error type with ogmios client
  • Loading branch information
rhyslbw committed Mar 25, 2022
1 parent 2cd3f94 commit 6e61857
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 69 deletions.
135 changes: 70 additions & 65 deletions packages/core/src/Cardano/types/TxSubmissionErrors.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,78 @@
import { CustomError } from 'ts-custom-error';
import { TxSubmission } from '@cardano-ogmios/client';

export const EraMismatchError = TxSubmission.EraMismatchError;
export const UnkownResultError = TxSubmission.UnknownResultError;

export const AddressAttributesTooLargeError = TxSubmission.errors.AddressAttributesTooLarge.Error;
export const AlreadyDelegatingError = TxSubmission.errors.AlreadyDelegating.Error;
export const BadInputsError = TxSubmission.errors.BadInputs.Error;
export const CollateralHasNonAdaAssetsError = TxSubmission.errors.CollateralHasNonAdaAssets.Error;
export const CollateralIsScriptError = TxSubmission.errors.CollateralIsScript.Error;
export const CollateralTooSmallError = TxSubmission.errors.CollateralTooSmall.Error;
export const CollectErrorsError = TxSubmission.errors.CollectErrors.Error;
export const DelegateNotRegisteredError = TxSubmission.errors.DelegateNotRegistered.Error;
export const DuplicateGenesisVrfError = TxSubmission.errors.DuplicateGenesisVrf.Error;
export const ExecutionUnitsTooLargeError = TxSubmission.errors.ExecutionUnitsTooLarge.Error;
export const ExpiredUtxoError = TxSubmission.errors.ExpiredUtxo.Error;
export const ExtraDataMismatchError = TxSubmission.errors.ExtraDataMismatch.Error;
export const ExtraRedeemersError = TxSubmission.errors.ExtraRedeemers.Error;
export const FeeTooSmallError = TxSubmission.errors.FeeTooSmall.Error;
export const InsufficientFundsForMirError = TxSubmission.errors.InsufficientFundsForMir.Error;
export const InsufficientGenesisSignaturesError = TxSubmission.errors.InsufficientGenesisSignatures.Error;
export const InvalidMetadataError = TxSubmission.errors.InvalidMetadata.Error;
export const InvalidWitnessesError = TxSubmission.errors.InvalidWitnesses.Error;
export const MirNegativeTransferNotCurrentlyAllowedError =
TxSubmission.errors.MirNegativeTransferNotCurrentlyAllowed.Error;
export const MirProducesNegativeUpdateError = TxSubmission.errors.MirProducesNegativeUpdate.Error;
export const MirTransferNotCurrentlyAllowedError = TxSubmission.errors.MirTransferNotCurrentlyAllowed.Error;
export const MissingAtLeastOneInputUtxoError = TxSubmission.errors.MissingAtLeastOneInputUtxo.Error;
export const MissingCollateralInputsError = TxSubmission.errors.MissingCollateralInputs.Error;
export const MissingDatumHashesForInputsError = TxSubmission.errors.MissingDatumHashesForInputs.Error;
export const MissingRequiredDatumsError = TxSubmission.errors.MissingRequiredDatums.Error;
export const MissingRequiredRedeemersError = TxSubmission.errors.MissingRequiredRedeemers.Error;
export const MissingRequiredSignaturesError = TxSubmission.errors.MissingRequiredSignatures.Error;
export const MissingScriptWitnessesError = TxSubmission.errors.MissingScriptWitnesses.Error;
export const MissingTxMetadataError = TxSubmission.errors.MissingTxMetadata.Error;
export const MissingTxMetadataHashError = TxSubmission.errors.MissingTxMetadataHash.Error;
export const MissingVkWitnessesError = TxSubmission.errors.MissingVkWitnesses.Error;
export const NetworkMismatchError = TxSubmission.errors.NetworkMismatch.Error;
export const NonGenesisVotersError = TxSubmission.errors.NonGenesisVoters.Error;
export const OutputTooSmallError = TxSubmission.errors.OutputTooSmall.Error;
export const OutsideForecastError = TxSubmission.errors.OutsideForecast.Error;
export const OutsideOfValidityIntervalError = TxSubmission.errors.OutsideOfValidityInterval.Error;
export const PoolCostTooSmallError = TxSubmission.errors.PoolCostTooSmall.Error;
export const PoolMetadataHashTooBigError = TxSubmission.errors.PoolMetadataHashTooBig.Error;
export const ProtocolVersionCannotFollowError = TxSubmission.errors.ProtocolVersionCannotFollow.Error;
export const RewardAccountNotEmptyError = TxSubmission.errors.RewardAccountNotEmpty.Error;
export const RewardAccountNotExistingError = TxSubmission.errors.RewardAccountNotExisting.Error;
export const ScriptWitnessNotValidatingError = TxSubmission.errors.ScriptWitnessNotValidating.Error;
export const StakeKeyAlreadyRegisteredError = TxSubmission.errors.StakeKeyAlreadyRegistered.Error;
export const StakeKeyNotRegisteredError = TxSubmission.errors.StakeKeyNotRegistered.Error;
export const StakePoolNotRegisteredError = TxSubmission.errors.StakePoolNotRegistered.Error;
export const TooLateForMirError = TxSubmission.errors.TooLateForMir.Error;
export const TooManyAssetsInOutputError = TxSubmission.errors.TooManyAssetsInOutput.Error;
export const TooManyCollateralInputsError = TxSubmission.errors.TooManyCollateralInputs.Error;
export const TriesToForgeAdaError = TxSubmission.errors.TriesToForgeAda.Error;
export const TxMetadataHashMismatchError = TxSubmission.errors.TxMetadataHashMismatch.Error;
export const TxTooLargeError = TxSubmission.errors.TxTooLarge.Error;
export const UnknownGenesisKeyError = TxSubmission.errors.UnknownGenesisKey.Error;
export const UnknownOrIncompleteWithdrawalsError = TxSubmission.errors.UnknownOrIncompleteWithdrawals.Error;
export const UnspendableDatumsError = TxSubmission.errors.UnspendableDatums.Error;
export const UnspendableScriptInputsError = TxSubmission.errors.UnspendableScriptInputs.Error;
export const UpdateWrongEpochError = TxSubmission.errors.UpdateWrongEpoch.Error;
export const ValidationTagMismatchError = TxSubmission.errors.ValidationTagMismatch.Error;
export const ValueNotConservedError = TxSubmission.errors.ValueNotConserved.Error;
export const WrongCertificateTypeError = TxSubmission.errors.WrongCertificateType.Error;
export const WrongPoolCertificateError = TxSubmission.errors.WrongPoolCertificate.Error;
export const WrongRetirementEpochError = TxSubmission.errors.WrongRetirementEpoch.Error;
export class UnknownTxSubmissionError extends CustomError {
constructor(public innerError: unknown) {
super('Unknown submission error. See "innerError".');
}
}

export const TxSubmissionErrors = {
AddressAttributesTooLargeError: TxSubmission.errors.AddressAttributesTooLarge.Error,
AlreadyDelegatingError: TxSubmission.errors.AlreadyDelegating.Error,
BadInputsError: TxSubmission.errors.BadInputs.Error,
CollateralHasNonAdaAssetsError: TxSubmission.errors.CollateralHasNonAdaAssets.Error,
CollateralIsScriptError: TxSubmission.errors.CollateralIsScript.Error,
CollateralTooSmallError: TxSubmission.errors.CollateralTooSmall.Error,
CollectErrorsError: TxSubmission.errors.CollectErrors.Error,
DelegateNotRegisteredError: TxSubmission.errors.DelegateNotRegistered.Error,
DuplicateGenesisVrfError: TxSubmission.errors.DuplicateGenesisVrf.Error,
EraMismatchError: TxSubmission.errors.EraMismatch.Error,
ExecutionUnitsTooLargeError: TxSubmission.errors.ExecutionUnitsTooLarge.Error,
ExpiredUtxoError: TxSubmission.errors.ExpiredUtxo.Error,
ExtraDataMismatchError: TxSubmission.errors.ExtraDataMismatch.Error,
ExtraRedeemersError: TxSubmission.errors.ExtraRedeemers.Error,
FeeTooSmallError: TxSubmission.errors.FeeTooSmall.Error,
InsufficientFundsForMirError: TxSubmission.errors.InsufficientFundsForMir.Error,
InsufficientGenesisSignaturesError: TxSubmission.errors.InsufficientGenesisSignatures.Error,
InvalidMetadataError: TxSubmission.errors.InvalidMetadata.Error,
InvalidWitnessesError: TxSubmission.errors.InvalidWitnesses.Error,
MirNegativeTransferNotCurrentlyAllowedError: TxSubmission.errors.MirNegativeTransferNotCurrentlyAllowed.Error,
MirProducesNegativeUpdateError: TxSubmission.errors.MirProducesNegativeUpdate.Error,
MirTransferNotCurrentlyAllowedError: TxSubmission.errors.MirTransferNotCurrentlyAllowed.Error,
MissingAtLeastOneInputUtxoError: TxSubmission.errors.MissingAtLeastOneInputUtxo.Error,
MissingCollateralInputsError: TxSubmission.errors.MissingCollateralInputs.Error,
MissingDatumHashesForInputsError: TxSubmission.errors.MissingDatumHashesForInputs.Error,
MissingRequiredDatumsError: TxSubmission.errors.MissingRequiredDatums.Error,
MissingRequiredRedeemersError: TxSubmission.errors.MissingRequiredRedeemers.Error,
MissingRequiredSignaturesError: TxSubmission.errors.MissingRequiredSignatures.Error,
MissingScriptWitnessesError: TxSubmission.errors.MissingScriptWitnesses.Error,
MissingTxMetadataError: TxSubmission.errors.MissingTxMetadata.Error,
MissingTxMetadataHashError: TxSubmission.errors.MissingTxMetadataHash.Error,
MissingVkWitnessesError: TxSubmission.errors.MissingVkWitnesses.Error,
NetworkMismatchError: TxSubmission.errors.NetworkMismatch.Error,
NonGenesisVotersError: TxSubmission.errors.NonGenesisVoters.Error,
OutputTooSmallError: TxSubmission.errors.OutputTooSmall.Error,
OutsideForecastError: TxSubmission.errors.OutsideForecast.Error,
OutsideOfValidityIntervalError: TxSubmission.errors.OutsideOfValidityInterval.Error,
PoolCostTooSmallError: TxSubmission.errors.PoolCostTooSmall.Error,
PoolMetadataHashTooBigError: TxSubmission.errors.PoolMetadataHashTooBig.Error,
ProtocolVersionCannotFollowError: TxSubmission.errors.ProtocolVersionCannotFollow.Error,
RewardAccountNotEmptyError: TxSubmission.errors.RewardAccountNotEmpty.Error,
RewardAccountNotExistingError: TxSubmission.errors.RewardAccountNotExisting.Error,
ScriptWitnessNotValidatingError: TxSubmission.errors.ScriptWitnessNotValidating.Error,
StakeKeyAlreadyRegisteredError: TxSubmission.errors.StakeKeyAlreadyRegistered.Error,
StakeKeyNotRegisteredError: TxSubmission.errors.StakeKeyNotRegistered.Error,
StakePoolNotRegisteredError: TxSubmission.errors.StakePoolNotRegistered.Error,
TooLateForMirError: TxSubmission.errors.TooLateForMir.Error,
TooManyAssetsInOutputError: TxSubmission.errors.TooManyAssetsInOutput.Error,
TooManyCollateralInputsError: TxSubmission.errors.TooManyCollateralInputs.Error,
TriesToForgeAdaError: TxSubmission.errors.TriesToForgeAda.Error,
TxMetadataHashMismatchError: TxSubmission.errors.TxMetadataHashMismatch.Error,
TxTooLargeError: TxSubmission.errors.TxTooLarge.Error,
UnknownGenesisKeyError: TxSubmission.errors.UnknownGenesisKey.Error,
UnknownOrIncompleteWithdrawalsError: TxSubmission.errors.UnknownOrIncompleteWithdrawals.Error,
UnknownTxSubmissionError,
UnspendableDatumsError: TxSubmission.errors.UnspendableDatums.Error,
UnspendableScriptInputsError: TxSubmission.errors.UnspendableScriptInputs.Error,
UpdateWrongEpochError: TxSubmission.errors.UpdateWrongEpoch.Error,
ValidationTagMismatchError: TxSubmission.errors.ValidationTagMismatch.Error,
ValueNotConservedError: TxSubmission.errors.ValueNotConserved.Error,
WrongCertificateTypeError: TxSubmission.errors.WrongCertificateType.Error,
WrongPoolCertificateError: TxSubmission.errors.WrongPoolCertificate.Error,
WrongRetirementEpochError: TxSubmission.errors.WrongRetirementEpoch.Error
};

type TxSubmissionErrorName = keyof typeof TxSubmissionErrors;
type TxSubmissionErrorClass = typeof TxSubmissionErrors[TxSubmissionErrorName];
export type TxSubmissionError = InstanceType<TxSubmissionErrorClass>;
5 changes: 1 addition & 4 deletions packages/core/src/Cardano/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as Ogmios from '@cardano-ogmios/schema';
import { CustomError } from 'ts-custom-error';
import { util } from '../../util';

export { Epoch, Slot, ExUnits } from '@cardano-ogmios/schema';
Expand All @@ -17,11 +16,9 @@ export * from './Block';
export * from './Asset';
export * from './AuxiliaryData';
export * from './Key';
export * as TxSubmissionErrors from './TxSubmissionErrors';
export * from './TxSubmissionErrors';
export * as NativeScriptType from './NativeScriptType';

export type TxSubmissionError = CustomError;

export type ProtocolParametersAlonzo = util.OptionalUndefined<
util.RecursivelyReplaceNullWithUndefined<Ogmios.ProtocolParametersAlonzo>
>;
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/Provider/Provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export interface Provider {
/**
* @throws ProviderError
*/
healthCheck(): Promise<{
ok: boolean;
}>;
Expand Down

0 comments on commit 6e61857

Please sign in to comment.