|
1 | 1 | import BN from "bn.js"; |
| 2 | +import { fromBase64 } from "@mysten/bcs"; |
2 | 3 | import { CoinStruct, SuiClient } from "@mysten/sui/client"; |
3 | 4 | import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions"; |
4 | 5 | import { SUI_CLOCK_OBJECT_ID, SUI_TYPE_ARG } from "@mysten/sui/utils"; |
@@ -114,7 +115,34 @@ export default class SuiStreamClient extends BaseStreamClient { |
114 | 115 | }); |
115 | 116 | txs.push(digest); |
116 | 117 |
|
117 | | - if (effects!.status.status === "failure") { |
| 118 | + // effects may be string according to Sui Wallet standard |
| 119 | + // https://github.com/MystenLabs/ts-sdks/blob/main/packages/wallet-standard/src/features/suiSignAndExecuteTransaction.ts#L34 |
| 120 | + // Loosely ported from https://github.com/MystenLabs/ts-sdks/blob/main/packages/graphql-transport/src/mappers/transaction-block.ts#L376 |
| 121 | + let effectsShort: { status: "success" | "failure"; error?: string } | undefined = undefined; |
| 122 | + if (typeof effects === "string") { |
| 123 | + const parsedEffects = bcs.TransactionEffects.parse(fromBase64(effects)); |
| 124 | + const currentEffects = parsedEffects.V2 || parsedEffects.V1; |
| 125 | + if (currentEffects) { |
| 126 | + effectsShort = currentEffects.status.Success |
| 127 | + ? { |
| 128 | + status: "success", |
| 129 | + } |
| 130 | + : { |
| 131 | + status: "failure", |
| 132 | + error: currentEffects.status.$kind, |
| 133 | + }; |
| 134 | + } |
| 135 | + } else if (effects && effects.status) { |
| 136 | + effectsShort = { |
| 137 | + status: effects.status.status, |
| 138 | + error: effects.status.error, |
| 139 | + }; |
| 140 | + } |
| 141 | + if (!effectsShort) { |
| 142 | + console.warn(`Got no effects from the transaction ${digest}, raw: ${effects}`); |
| 143 | + } |
| 144 | + |
| 145 | + if (effectsShort?.status === "failure") { |
118 | 146 | multipleStreamData.recipients.forEach((recipient) => { |
119 | 147 | errors.push({ |
120 | 148 | error: effects!.status.error ?? "Unknown error!", |
|
0 commit comments