-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve transaction log parsing (#442)
* feat: Adds transaction log parsing * delete unused * add program address in instruction logs * fix types * clean up utils * clean up simulation * formatted log lines * Print logs settings * verbosity tweaks
- Loading branch information
Showing
13 changed files
with
598 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { InstructionLogs } from "@saberhq/solana-contrib"; | ||
import { formatLogEntry } from "@saberhq/solana-contrib"; | ||
import * as colors from "colors/safe"; | ||
|
||
/** | ||
* Formats instruction logs to be printed to the console. | ||
* @param logs | ||
*/ | ||
export const formatInstructionLogs = (logs: readonly InstructionLogs[]) => { | ||
logs | ||
.map((log, i) => { | ||
return [ | ||
[ | ||
colors.bold(colors.blue("=> ")), | ||
colors.bold(colors.white(`Instruction #${i}: `)), | ||
log.programAddress | ||
? colors.yellow(`Program ${log.programAddress}`) | ||
: "System", | ||
].join(""), | ||
...log.logs.map((entry) => { | ||
const entryStr = formatLogEntry(entry, true); | ||
switch (entry.type) { | ||
case "text": | ||
return colors.gray(entryStr); | ||
case "cpi": | ||
return colors.cyan(entryStr); | ||
case "programError": | ||
return colors.red(entryStr); | ||
case "runtimeError": | ||
return colors.red(entryStr); | ||
case "system": | ||
return colors.gray(entryStr); | ||
case "success": | ||
return colors.green(entryStr); | ||
} | ||
}), | ||
].join("\n"); | ||
}) | ||
.join("\n"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export * from "./parseTransactionLogs"; | ||
export * from "./PendingTransaction"; | ||
export * from "./programErr"; | ||
export * from "./TransactionEnvelope"; | ||
export * from "./TransactionReceipt"; | ||
export * from "./utils"; |
46 changes: 46 additions & 0 deletions
46
packages/solana-contrib/src/transaction/parseTransactionLogs.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// <reference types="jest" /> | ||
|
||
import { parseTransactionLogs } from "./parseTransactionLogs"; | ||
|
||
describe("parseTransactionLogs", () => { | ||
it("should parse the logs", () => { | ||
const logs = [ | ||
`Program GAGEa8FYyJNgwULDNhCBEZzW6a8Zfhs6QRxTZ9XQy151 invoke [1]`, | ||
`Program log: Instruction: GaugeCommitVote`, | ||
`Program log: Custom program error: 0x66`, | ||
`Program GAGEa8FYyJNgwULDNhCBEZzW6a8Zfhs6QRxTZ9XQy151 consumed 2778 of 200000 compute units`, | ||
`Program GAGEa8FYyJNgwULDNhCBEZzW6a8Zfhs6QRxTZ9XQy151 failed: custom program error: 0x66`, | ||
]; | ||
|
||
const result = parseTransactionLogs(logs, null); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
programAddress: "GAGEa8FYyJNgwULDNhCBEZzW6a8Zfhs6QRxTZ9XQy151", | ||
logs: [ | ||
{ | ||
type: "text", | ||
depth: 1, | ||
text: "Program log: Instruction: GaugeCommitVote", | ||
}, | ||
{ | ||
type: "text", | ||
depth: 1, | ||
text: "Program log: Custom program error: 0x66", | ||
}, | ||
{ | ||
type: "system", | ||
depth: 1, | ||
text: "Program GAGEa8FYyJNgwULDNhCBEZzW6a8Zfhs6QRxTZ9XQy151 consumed 2778 of 200000 compute units", | ||
}, | ||
{ | ||
type: "programError", | ||
depth: 1, | ||
text: "custom program error: 0x66", | ||
}, | ||
], | ||
failed: true, | ||
}, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.