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

Export more utility functions and structures #44

Merged
12 changes: 12 additions & 0 deletions packages/auto-consensus/src/types/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type ActionEvents = string | string[]
export type Events = ActionEvents | ActionEvents[]

// Define specific extrinsic keys for events
export type EventKeys =
| 'transfer'
| 'operatorRegistered'
| 'operatorNominated'
| 'operatorDeRegistered'
marc-aurele-besner marked this conversation as resolved.
Show resolved Hide resolved
| 'withdrawStake'
| 'unlockFunds'
| 'forceDomainEpochTransition'
1 change: 1 addition & 0 deletions packages/auto-consensus/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './events'
118 changes: 118 additions & 0 deletions packages/auto-consensus/src/utils/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import type { ActionEvents, EventKeys } from '../types/events'

// Enum for Event Types
export const enum Type {
system = 'system',
balances = 'balances',
transactionPayment = 'transactionPayment',
domains = 'domains',
sudo = 'sudo',
}

// Utility Function for Event Names
export const eventName = (type: Type, event: string) => `${type}.${event}`

// System Events
const system: {
[key: string]: string
} = {
failure: eventName(Type.system, 'ExtrinsicFailed'),
newAccount: eventName(Type.system, 'NewAccount'),
success: eventName(Type.system, 'ExtrinsicSuccess'),
}

// Balances Events
const balances: {
[key: string]: string
} = {
deposit: eventName(Type.balances, 'Deposit'),
endowed: eventName(Type.balances, 'Endowed'),
transfer: eventName(Type.balances, 'Transfer'),
withdraw: eventName(Type.balances, 'Withdraw'),
}

// Transaction Payment Events
const transactionPayment: {
[key: string]: string
} = {
feePaid: eventName(Type.transactionPayment, 'TransactionFeePaid'),
}

// Domains Events
const domains: {
[key: string]: string
} = {
forceDomainEpochTransition: eventName(Type.domains, 'ForceDomainEpochTransition'),
fundsUnlocked: eventName(Type.domains, 'FundsUnlocked'),
operatorDeregistered: eventName(Type.domains, 'OperatorDeregistered'),
operatorNominated: eventName(Type.domains, 'OperatorNominated'),
operatorRegistered: eventName(Type.domains, 'OperatorRegistered'),
operatorUnlocked: eventName(Type.domains, 'OperatorUnlocked'),
storageFeeDeposited: eventName(Type.domains, 'StorageFeeDeposited'),
withdrawStake: eventName(Type.domains, 'WithdrewStake'),
}

// Sudo Events
const sudo: {
[key: string]: string
} = {
sudid: eventName(Type.sudo, 'Sudid'),
}

// Group of Events
export const eventsGroup = {
system,
balances,
transactionPayment,
domains,
sudo,
}

// Export a default success event
export const expectSuccessfulTxEvent = [system.success]

// Events Mappings
export const events: { [key in EventKeys]: ActionEvents } = {
transfer: [balances.withdraw, balances.transfer, transactionPayment.feePaid, system.success],
operatorRegistered: [
balances.withdraw,
domains.storageFeeDeposited,
domains.operatorRegistered,
transactionPayment.feePaid,
system.success,
],
operatorNominated: [
balances.withdraw,
balances.transfer,
domains.storageFeeDeposited,
domains.operatorNominated,
transactionPayment.feePaid,
system.success,
],
operatorDeRegistered: [
balances.withdraw,
domains.operatorDeregistered,
transactionPayment.feePaid,
system.success,
],
withdrawStake: [
balances.withdraw,
domains.withdrawStake,
transactionPayment.feePaid,
system.success,
],
unlockFunds: [
balances.withdraw,
domains.fundsUnlocked,
transactionPayment.feePaid,
system.success,
],
forceDomainEpochTransition: [
balances.withdraw,
domains.forceDomainEpochTransition,
sudo.sudid,
balances.deposit,
transactionPayment.feePaid,
system.success,
],
}