Use new custom API to server-side check if address has code/is contract
This commit is contained in:
parent
c3dfcfeee3
commit
2e04c726d7
|
@ -12,7 +12,7 @@ import {
|
|||
useDedupedAddresses,
|
||||
useMultipleMetadata,
|
||||
} from "../sourcify/useSourcify";
|
||||
import { useAddressCodes } from "../useErigonHooks";
|
||||
import { useAddressesWithCode } from "../useErigonHooks";
|
||||
import { useMultipleETHUSDOracle } from "../usePriceOracle";
|
||||
import { RuntimeContext } from "../useRuntime";
|
||||
import { pageCollector, useResolvedAddresses } from "../useResolvedAddresses";
|
||||
|
@ -125,7 +125,7 @@ const AddressTransactionResults: React.FC<AddressTransactionResultsProps> = ({
|
|||
}, [address, page]);
|
||||
const { sourcifySource } = useAppConfigContext();
|
||||
const deduped = useDedupedAddresses(addresses);
|
||||
const checked = useAddressCodes(provider, deduped);
|
||||
const checked = useAddressesWithCode(provider, deduped);
|
||||
const metadatas = useMultipleMetadata(
|
||||
undefined,
|
||||
checked,
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
useDedupedAddresses,
|
||||
useMultipleMetadata,
|
||||
} from "../sourcify/useSourcify";
|
||||
import { useAddressCodes } from "../useErigonHooks";
|
||||
import { useAddressesWithCode } from "../useErigonHooks";
|
||||
|
||||
type BlockTransactionResultsProps = {
|
||||
blockTag: BlockTag;
|
||||
|
@ -49,7 +49,7 @@ const BlockTransactionResults: React.FC<BlockTransactionResultsProps> = ({
|
|||
}, [page]);
|
||||
const { sourcifySource } = useAppConfigContext();
|
||||
const deduped = useDedupedAddresses(addresses);
|
||||
const checked = useAddressCodes(provider, deduped);
|
||||
const checked = useAddressesWithCode(provider, deduped);
|
||||
const metadatas = useMultipleMetadata(
|
||||
undefined,
|
||||
checked,
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
export const MIN_API_LEVEL = 3;
|
||||
export const MIN_API_LEVEL = 4;
|
||||
|
||||
export const PAGE_SIZE = 25;
|
||||
|
|
|
@ -43,7 +43,7 @@ import {
|
|||
useMultipleMetadata,
|
||||
UserDoc,
|
||||
} from "../sourcify/useSourcify";
|
||||
import { useAddressCodes } from "../useErigonHooks";
|
||||
import { useAddressesWithCode } from "../useErigonHooks";
|
||||
import { ResolvedAddresses } from "../api/address-resolver";
|
||||
import { RuntimeContext } from "../useRuntime";
|
||||
import { useAppConfigContext } from "../useAppConfig";
|
||||
|
@ -103,7 +103,7 @@ const Details: React.FC<DetailsProps> = ({
|
|||
}, [txData]);
|
||||
const { sourcifySource } = useAppConfigContext();
|
||||
const deduped = useDedupedAddresses(addresses);
|
||||
const checked = useAddressCodes(provider, deduped);
|
||||
const checked = useAddressesWithCode(provider, deduped);
|
||||
const metadatas = useMultipleMetadata(
|
||||
undefined,
|
||||
checked,
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
useDedupedAddresses,
|
||||
useMultipleMetadata,
|
||||
} from "../sourcify/useSourcify";
|
||||
import { useAddressCodes } from "../useErigonHooks";
|
||||
import { useAddressesWithCode } from "../useErigonHooks";
|
||||
import { ResolvedAddresses } from "../api/address-resolver";
|
||||
import { RuntimeContext } from "../useRuntime";
|
||||
|
||||
|
@ -37,7 +37,7 @@ const Logs: React.FC<LogsProps> = ({ txData, metadata, resolvedAddresses }) => {
|
|||
const { provider } = useContext(RuntimeContext);
|
||||
const { sourcifySource } = useAppConfigContext();
|
||||
const deduped = useDedupedAddresses(logAddresses);
|
||||
const checked = useAddressCodes(provider, deduped);
|
||||
const checked = useAddressesWithCode(provider, deduped);
|
||||
const metadatas = useMultipleMetadata(
|
||||
baseMetadatas,
|
||||
checked,
|
||||
|
|
|
@ -442,41 +442,38 @@ export const useUniqueSignatures = (traces: TraceGroup[] | undefined) => {
|
|||
return uniqueSignatures;
|
||||
};
|
||||
|
||||
const checkCode = async (
|
||||
const hasCode = async (
|
||||
provider: JsonRpcProvider,
|
||||
address: ChecksummedAddress
|
||||
): Promise<boolean> => {
|
||||
const code = await provider.getCode(address);
|
||||
if (code !== "0x") {
|
||||
console.log(`Has code: ${address}`);
|
||||
}
|
||||
return code === "0x";
|
||||
const result = await provider.send("ots_hasCode", [address, "latest"]);
|
||||
return result as boolean;
|
||||
};
|
||||
|
||||
export const useAddressCodes = (
|
||||
export const useAddressesWithCode = (
|
||||
provider: JsonRpcProvider | undefined,
|
||||
addresses: ChecksummedAddress[]
|
||||
): ChecksummedAddress[] | undefined => {
|
||||
const [hasCode, setCode] = useState<ChecksummedAddress[] | undefined>();
|
||||
const [results, setResults] = useState<ChecksummedAddress[] | undefined>();
|
||||
|
||||
useEffect(() => {
|
||||
if (provider === undefined) {
|
||||
setCode(undefined);
|
||||
setResults(undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
const readCodes = async () => {
|
||||
const checkers: Promise<boolean>[] = [];
|
||||
for (const a of addresses) {
|
||||
checkers.push(checkCode(provider, a));
|
||||
checkers.push(hasCode(provider, a));
|
||||
}
|
||||
|
||||
const result = await Promise.all(checkers);
|
||||
const filtered = addresses.filter((_, i) => result[i]);
|
||||
setCode(filtered);
|
||||
setResults(filtered);
|
||||
};
|
||||
readCodes();
|
||||
}, [provider, addresses]);
|
||||
|
||||
return hasCode;
|
||||
return results;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue