Push down flashbots checking logic
This commit is contained in:
parent
c365bde784
commit
21a549b3e1
|
@ -11,6 +11,7 @@ export enum Direction {
|
|||
}
|
||||
|
||||
export enum Flags {
|
||||
// Means the transaction internal sends ETH to the miner, e.g. flashbots
|
||||
MINER,
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import TransactionItemFiatFee from "./TransactionItemFiatFee";
|
|||
import { ProcessedTransaction } from "../types";
|
||||
import { FeeDisplay } from "./useFeeToggler";
|
||||
import { RuntimeContext } from "../useRuntime";
|
||||
import { useHasCode } from "../useErigonHooks";
|
||||
import { useHasCode, useSendsToMiner } from "../useErigonHooks";
|
||||
import { formatValue } from "../components/formatter";
|
||||
|
||||
type TransactionItemProps = {
|
||||
|
@ -36,6 +36,7 @@ const TransactionItem: React.FC<TransactionItemProps> = ({
|
|||
tx.to ?? undefined,
|
||||
tx.blockNumber - 1
|
||||
);
|
||||
const [sendsToMiner] = useSendsToMiner(provider, tx.hash, tx.miner);
|
||||
|
||||
let direction: Direction | undefined;
|
||||
if (selectedAddress) {
|
||||
|
@ -53,7 +54,7 @@ const TransactionItem: React.FC<TransactionItemProps> = ({
|
|||
}
|
||||
}
|
||||
|
||||
const flash = tx.gasPrice.isZero() && tx.internalMinerInteraction;
|
||||
const flash = tx.gasPrice.isZero() && sendsToMiner;
|
||||
|
||||
return (
|
||||
<div
|
||||
|
@ -91,7 +92,7 @@ const TransactionItem: React.FC<TransactionItemProps> = ({
|
|||
<span>
|
||||
<TransactionDirection
|
||||
direction={direction}
|
||||
flags={tx.internalMinerInteraction ? Flags.MINER : undefined}
|
||||
flags={sendsToMiner ? Flags.MINER : undefined}
|
||||
/>
|
||||
</span>
|
||||
</span>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useContext, useMemo, useState } from "react";
|
||||
import React, { useContext, useState } from "react";
|
||||
import { Tab } from "@headlessui/react";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faCheckCircle } from "@fortawesome/free-solid-svg-icons/faCheckCircle";
|
||||
|
@ -43,7 +43,7 @@ import {
|
|||
useTransactionDescription as useSourcifyTransactionDescription,
|
||||
} from "../sourcify/useSourcify";
|
||||
import { RuntimeContext } from "../useRuntime";
|
||||
import { useInternalOperations, useTransactionError } from "../useErigonHooks";
|
||||
import { useSendsToMiner, useTransactionError } from "../useErigonHooks";
|
||||
import { useChainInfo } from "../useChainInfo";
|
||||
import { useETHUSDOracle } from "../usePriceOracle";
|
||||
|
||||
|
@ -67,19 +67,11 @@ const Details: React.FC<DetailsProps> = ({ txData }) => {
|
|||
txData.value
|
||||
);
|
||||
|
||||
const internalOps = useInternalOperations(provider, txData);
|
||||
const sendsEthToMiner = useMemo(() => {
|
||||
if (!txData || !internalOps) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const t of internalOps) {
|
||||
if (t.to === txData.confirmedData?.miner) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}, [txData, internalOps]);
|
||||
const [sendsEthToMiner, internalOps] = useSendsToMiner(
|
||||
provider,
|
||||
txData.confirmedData ? txData.transactionHash : undefined,
|
||||
txData.confirmedData?.miner
|
||||
);
|
||||
|
||||
const metadata = useSourcifyMetadata(txData?.to, provider?.network.chainId);
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ export type ProcessedTransaction = {
|
|||
from?: string;
|
||||
to: string | null;
|
||||
createdContractAddress?: string;
|
||||
internalMinerInteraction?: boolean;
|
||||
value: BigNumber;
|
||||
fee: BigNumber;
|
||||
gasPrice: BigNumber;
|
||||
|
|
|
@ -140,27 +140,6 @@ export const useBlockTransactions = (
|
|||
.reverse();
|
||||
setTxs(rawTxs);
|
||||
setTotalTxs(result.fullblock.transactionCount);
|
||||
|
||||
const checkTouchMinerAddr = await Promise.all(
|
||||
rawTxs.map(async (res) => {
|
||||
const ops = await getInternalOperations(provider, res.hash);
|
||||
return (
|
||||
ops.findIndex(
|
||||
(op) =>
|
||||
op.type === OperationType.TRANSFER &&
|
||||
res.miner !== undefined &&
|
||||
res.miner === getAddress(op.to)
|
||||
) !== -1
|
||||
);
|
||||
})
|
||||
);
|
||||
const processedTxs = rawTxs.map(
|
||||
(r, i): ProcessedTransaction => ({
|
||||
...r,
|
||||
internalMinerInteraction: checkTouchMinerAddr[i],
|
||||
})
|
||||
);
|
||||
setTxs(processedTxs);
|
||||
};
|
||||
readBlock();
|
||||
}, [provider, blockNumber, pageNumber, pageSize]);
|
||||
|
@ -308,34 +287,13 @@ export const useTxData = (
|
|||
return txData;
|
||||
};
|
||||
|
||||
// TODO: convert caller to hooks and remove this function
|
||||
const getInternalOperations = async (
|
||||
provider: JsonRpcProvider,
|
||||
txHash: string
|
||||
) => {
|
||||
const rawTransfers = await provider.send("ots_getInternalOperations", [
|
||||
txHash,
|
||||
]);
|
||||
|
||||
const _transfers: InternalOperation[] = [];
|
||||
for (const t of rawTransfers) {
|
||||
_transfers.push({
|
||||
type: t.type,
|
||||
from: getAddress(t.from),
|
||||
to: getAddress(t.to),
|
||||
value: t.value,
|
||||
});
|
||||
}
|
||||
return _transfers;
|
||||
};
|
||||
|
||||
export const useInternalOperations = (
|
||||
provider: JsonRpcProvider | undefined,
|
||||
txData: TransactionData | undefined | null
|
||||
txHash: string | undefined
|
||||
): InternalOperation[] | undefined => {
|
||||
const { data, error } = useSWRImmutable(
|
||||
provider !== undefined && txData?.confirmedData
|
||||
? ["ots_getInternalOperations", txData.transactionHash]
|
||||
provider !== undefined && txHash !== undefined
|
||||
? ["ots_getInternalOperations", txHash]
|
||||
: null,
|
||||
providerFetcher(provider)
|
||||
);
|
||||
|
@ -359,6 +317,26 @@ export const useInternalOperations = (
|
|||
return _transfers;
|
||||
};
|
||||
|
||||
export const useSendsToMiner = (
|
||||
provider: JsonRpcProvider | undefined,
|
||||
txHash: string | undefined,
|
||||
miner: string | undefined
|
||||
): [boolean, InternalOperation[]] | [undefined, undefined] => {
|
||||
const ops = useInternalOperations(provider, txHash);
|
||||
if (ops === undefined) {
|
||||
return [undefined, undefined];
|
||||
}
|
||||
|
||||
const send =
|
||||
ops.findIndex(
|
||||
(op) =>
|
||||
op.type === OperationType.TRANSFER &&
|
||||
miner !== undefined &&
|
||||
miner === getAddress(op.to)
|
||||
) !== -1;
|
||||
return [send, ops];
|
||||
};
|
||||
|
||||
export type TraceEntry = {
|
||||
type: string;
|
||||
depth: number;
|
||||
|
|
Loading…
Reference in New Issue