explorer: fix missing logs error for old transactions (#22350)

This commit is contained in:
Justin Starry 2022-01-07 08:48:20 +08:00 committed by GitHub
parent b2687b7e70
commit 08e64c88ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 11 deletions

View File

@ -15,7 +15,11 @@ export function ProgramLogSection({ signature }: SignatureProps) {
const logMessages = transaction.meta?.logMessages || null; const logMessages = transaction.meta?.logMessages || null;
const err = transaction.meta?.err || null; const err = transaction.meta?.err || null;
const prettyLogs = prettyProgramLogs(logMessages, err, cluster);
let prettyLogs = null;
if (logMessages !== null) {
prettyLogs = prettyProgramLogs(logMessages, err, cluster);
}
return ( return (
<> <>
@ -23,11 +27,17 @@ export function ProgramLogSection({ signature }: SignatureProps) {
<div className="card-header"> <div className="card-header">
<h3 className="card-header-title">Program Logs</h3> <h3 className="card-header-title">Program Logs</h3>
</div> </div>
<ProgramLogsCardBody {prettyLogs !== null ? (
message={message} <ProgramLogsCardBody
logs={prettyLogs} message={message}
cluster={cluster} logs={prettyLogs}
/> cluster={cluster}
/>
) : (
<div className="card-body">
Logs not supported for this transaction
</div>
)}
</div> </div>
</> </>
); );

View File

@ -101,6 +101,9 @@ function useSimulator(message: Message) {
// Simulate without signers to skip signer verification // Simulate without signers to skip signer verification
const resp = await connection.simulateTransaction(tx); const resp = await connection.simulateTransaction(tx);
if (resp.value.logs === null) {
throw new Error("Expected to receive logs from simulation");
}
// Prettify logs // Prettify logs
setLogs(prettyProgramLogs(resp.value.logs, resp.value.err, cluster)); setLogs(prettyProgramLogs(resp.value.logs, resp.value.err, cluster));

View File

@ -15,7 +15,7 @@ export type InstructionLogs = {
}; };
export function prettyProgramLogs( export function prettyProgramLogs(
logs: string[] | null, logs: string[],
error: TransactionError | null, error: TransactionError | null,
cluster: Cluster cluster: Cluster
): InstructionLogs[] { ): InstructionLogs[] {
@ -27,10 +27,7 @@ export function prettyProgramLogs(
}; };
let prettyError; let prettyError;
if (!logs) { if (error) {
if (error) throw new Error(JSON.stringify(error));
throw new Error("No logs detected");
} else if (error) {
prettyError = getTransactionInstructionError(error); prettyError = getTransactionInstructionError(error);
} }