* feat(web3): add send transaction error with logs #18277 * fix: logs type * refactor: prettier
This commit is contained in:
parent
90f8cf0920
commit
33066d254e
|
@ -26,6 +26,7 @@ import {IWSRequestParams} from 'rpc-websockets/dist/lib/client';
|
|||
|
||||
import {AgentManager} from './agent-manager';
|
||||
import {EpochSchedule} from './epoch-schedule';
|
||||
import {SendTransactionError} from './errors';
|
||||
import {NonceAccount} from './nonce-account';
|
||||
import {PublicKey} from './publickey';
|
||||
import {Signer} from './keypair';
|
||||
|
@ -3444,7 +3445,19 @@ export class Connection {
|
|||
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
||||
const res = create(unsafeRes, SimulatedTransactionResponseStruct);
|
||||
if ('error' in res) {
|
||||
throw new Error('failed to simulate transaction: ' + res.error.message);
|
||||
let logs;
|
||||
if ('data' in res.error) {
|
||||
logs = res.error.data.logs;
|
||||
if (logs && Array.isArray(logs)) {
|
||||
const traceIndent = '\n ';
|
||||
const logTrace = traceIndent + logs.join(traceIndent);
|
||||
console.error(res.error.message, logTrace);
|
||||
}
|
||||
}
|
||||
throw new SendTransactionError(
|
||||
'failed to simulate transaction: ' + res.error.message,
|
||||
logs,
|
||||
);
|
||||
}
|
||||
return res.result;
|
||||
}
|
||||
|
@ -3528,15 +3541,19 @@ export class Connection {
|
|||
const unsafeRes = await this._rpcRequest('sendTransaction', args);
|
||||
const res = create(unsafeRes, SendTransactionRpcResult);
|
||||
if ('error' in res) {
|
||||
let logs;
|
||||
if ('data' in res.error) {
|
||||
const logs = res.error.data.logs;
|
||||
logs = res.error.data.logs;
|
||||
if (logs && Array.isArray(logs)) {
|
||||
const traceIndent = '\n ';
|
||||
const logTrace = traceIndent + logs.join(traceIndent);
|
||||
console.error(res.error.message, logTrace);
|
||||
}
|
||||
}
|
||||
throw new Error('failed to send transaction: ' + res.error.message);
|
||||
throw new SendTransactionError(
|
||||
'failed to send transaction: ' + res.error.message,
|
||||
logs,
|
||||
);
|
||||
}
|
||||
return res.result;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
export class SendTransactionError extends Error {
|
||||
logs: string[] | undefined;
|
||||
|
||||
constructor(message: string, logs?: string[]) {
|
||||
super(message);
|
||||
|
||||
this.logs = logs;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue