provider.sendAll fetches transaction error logs (#2302)

Just like provider.sendAndConfirm

Co-authored-by: Tristyn <tristynstimpson@gmail.com>
Co-authored-by: henrye <henry@notanemail>
This commit is contained in:
Henry-E 2022-12-06 12:05:38 +00:00 committed by GitHub
parent 1bb1969d60
commit b6ad53f628
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 3 deletions

View File

@ -210,9 +210,33 @@ export class AnchorProvider implements Provider {
for (let k = 0; k < txs.length; k += 1) {
const tx = signedTxs[k];
const rawTx = tx.serialize();
sigs.push(
await sendAndConfirmRawTransaction(this.connection, rawTx, opts)
);
try {
sigs.push(
await sendAndConfirmRawTransaction(this.connection, rawTx, opts)
);
} catch (err) {
// thrown if the underlying 'confirmTransaction' encounters a failed tx
// the 'confirmTransaction' error does not return logs so we make another rpc call to get them
if (err instanceof ConfirmError) {
// choose the shortest available commitment for 'getTransaction'
// (the json RPC does not support any shorter than "confirmed" for 'getTransaction')
// because that will see the tx sent with `sendAndConfirmRawTransaction` no matter which
// commitment `sendAndConfirmRawTransaction` used
const failedTx = await this.connection.getTransaction(
bs58.encode(tx.signature!),
{ commitment: "confirmed" }
);
if (!failedTx) {
throw err;
} else {
const logs = failedTx.meta?.logMessages;
throw !logs ? err : new SendTransactionError(err.message, logs);
}
} else {
throw err;
}
}
}
return sigs;