Skip to content

Commit

Permalink
extend fix to attest flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Scatularo committed Nov 27, 2024
1 parent b1cb2ea commit 452a06a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 35 deletions.
7 changes: 5 additions & 2 deletions src/hooks/useHandleAttest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ import { signSendAndConfirm } from "../utils/solana";
import { postWithFees, waitForTerraExecution } from "../utils/terra";
import { postWithFeesXpla, waitForXplaExecution } from "../utils/xpla";
import { useInjectiveContext } from "../contexts/InjectiveWalletContext";
import { broadcastInjectiveTx } from "../utils/injective";
import {
addInjectiveRawLogsToTx,
broadcastInjectiveTx,
} from "../utils/injective";
import { AlgorandWallet } from "@xlabs-libs/wallet-aggregator-algorand";
import { SolanaWallet } from "@xlabs-libs/wallet-aggregator-solana";
import { AptosWallet } from "@xlabs-libs/wallet-aggregator-aptos";
Expand Down Expand Up @@ -544,7 +547,7 @@ async function injective(
enqueueSnackbar(null, {
content: <Alert severity="success">Transaction confirmed</Alert>,
});
const sequence = parseSequenceFromLogInjective(tx);
const sequence = parseSequenceFromLogInjective(addInjectiveRawLogsToTx(tx));
if (!sequence) {
throw new Error("Sequence not found");
}
Expand Down
37 changes: 4 additions & 33 deletions src/hooks/useHandleTransfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ import { signSendAndConfirm } from "../utils/solana";
import { postWithFees, waitForTerraExecution } from "../utils/terra";
import useTransferTargetAddressHex from "./useTransferTargetAddress";
import { postWithFeesXpla, waitForXplaExecution } from "../utils/xpla";
import { broadcastInjectiveTx } from "../utils/injective";
import {
addInjectiveRawLogsToTx,
broadcastInjectiveTx,
} from "../utils/injective";
import { useInjectiveContext } from "../contexts/InjectiveWalletContext";
import { AlgorandWallet } from "@xlabs-libs/wallet-aggregator-algorand";
import { SolanaWallet } from "@xlabs-libs/wallet-aggregator-solana";
Expand Down Expand Up @@ -149,7 +152,6 @@ import { useSeiWallet } from "../contexts/SeiWalletContext";
import { SeiWallet } from "@xlabs-libs/wallet-aggregator-sei";
import { SuiTransactionBlockResponse } from "@mysten/sui.js";
import { telemetry, TelemetryTxEvent } from "../utils/telemetry";
import { TxResponse } from "@injectivelabs/sdk-ts";

type AdditionalPayloadOverride = {
receivingContract: Uint8Array;
Expand Down Expand Up @@ -805,37 +807,6 @@ async function terra(
}
}

/**
* if raw tx logs are not present, add them to the tx object
* @param tx
* @returns tx with raw logs
*
* Note: applied the fix here, since wormhole sdk has been deprecated
*/
function addInjectiveRawLogsToTx(tx: TxResponse): TxResponse {
if (!!tx.rawLog || tx.rawLog.length === 0) {
const decoder = new TextDecoder();
const events = tx.events || [];
const rawLogs = events.map((event) => ({
type: event.type,
attributes: event.attributes.map(
(attr: { key: Uint8Array; value: Uint8Array }) => ({
key:
attr.key instanceof Uint8Array
? decoder.decode(attr.key)
: attr.key,
value:
attr.value instanceof Uint8Array
? decoder.decode(attr.value)
: attr.value,
})
),
}));
tx.rawLog = JSON.stringify([{ events: rawLogs }]);
}
return tx;
}

async function injective(
dispatch: any,
enqueueSnackbar: any,
Expand Down
32 changes: 32 additions & 0 deletions src/utils/injective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ChainGrpcWasmApi,
Msgs,
TxGrpcClient,
TxResponse,
} from "@injectivelabs/sdk-ts";
import { InjectiveWallet } from "@xlabs-libs/wallet-aggregator-injective";
import { getInjectiveNetworkInfo } from "./consts";
Expand Down Expand Up @@ -60,3 +61,34 @@ export const broadcastInjectiveTx = async (
}
return tx;
};

/**
* if raw tx logs are not present, add them to the tx object
* @param tx
* @returns tx with raw logs
*
* Note: applied the fix here, since wormhole sdk has been deprecated
*/
export function addInjectiveRawLogsToTx(tx: TxResponse): TxResponse {
if (!!tx.rawLog || tx.rawLog.length === 0) {
const decoder = new TextDecoder();
const events = tx.events || [];
const rawLogs = events.map((event) => ({
type: event.type,
attributes: event.attributes.map(
(attr: { key: Uint8Array; value: Uint8Array }) => ({
key:
attr.key instanceof Uint8Array
? decoder.decode(attr.key)
: attr.key,
value:
attr.value instanceof Uint8Array
? decoder.decode(attr.value)
: attr.value,
})
),
}));
tx.rawLog = JSON.stringify([{ events: rawLogs }]);
}
return tx;
}

0 comments on commit 452a06a

Please sign in to comment.