Skip to content

Commit

Permalink
[cli] events to add formatting option
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaloup committed Sep 26, 2024
1 parent 22fabca commit 8b726c9
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/validator-bonds-cli/src/commands/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,15 @@ export function installShowEvent(program: Command) {
.command('show-event')
.description('Showing data of anchor event')
.argument('<event-data>', 'base64 data of anchor event')
.option('-t, --event-type <init>', 'Type of event to decode', 'init')
.action(async (eventData: string) => {
.option(
`-f, --format <${FORMAT_TYPE_DEF.join('|')}>`,
'Format of output',
'json'
)
.action(async (eventData: string, { format }: { format: FormatType }) => {
await showEvent({
eventData,
format,
})
})
}
Expand Down Expand Up @@ -535,8 +540,14 @@ async function showSettlement({
print_data(reformatted, format)
}

async function showEvent({ eventData }: { eventData: string }) {
const { program, logger } = getCliContext()
async function showEvent({
eventData,
format,
}: {
eventData: string
format: FormatType
}) {
const { program } = getCliContext()

// checking if base data is decodable
// if not, trying to decode the data without the first 8 bytes as Anchor constant CPI discriminator
Expand All @@ -556,7 +567,7 @@ async function showEvent({ eventData }: { eventData: string }) {
}

const reformattedData = reformat(decodedData)
print_data(reformattedData, 'text')
print_data(reformattedData, format)
}

/**
Expand Down

0 comments on commit 8b726c9

Please sign in to comment.