Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix call to ots_getCode() for ZQ1 so that contracts are displayed properly again #51

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const Home: FC = () => {
>
<div>Latest block: {commify(latestBlock.number)}</div>
<Timestamp value={latestBlock.timestamp} />
<div>Ziliqa Otterscan Version: {config?.version}</div>
<div>Zilliqa Otterscan Version: {config?.version}pl1</div>
</NavLink>
)}
{finalizedSlotNumber !== undefined && (
Expand Down
23 changes: 12 additions & 11 deletions src/search/TransactionResultHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import StandardTHead from "../components/StandardTHead";
import { FeeDisplay } from "./useFeeToggler";

export type ResultHeaderProps = {
Expand All @@ -10,15 +11,15 @@ const TransactionResultHeader: React.FC<ResultHeaderProps> = ({
feeDisplay,
feeDisplayToggler,
}) => (
<div className="grid grid-cols-12 gap-x-1 border-b border-t border-gray-200 bg-gray-100 px-2 py-2 text-sm font-bold text-gray-500">
<div className="col-span-2">Txn Hash</div>
<div>Method</div>
<div>Block</div>
<div>Age</div>
<div className="col-span-2 ml-1">From</div>
<div className="col-span-2 ml-1">To</div>
<div className="col-span-2">Value</div>
<div>
<StandardTHead>
<th>Txn Hash</th>
<th>Method</th>
<th className="w-28">Block</th>
<th className="w-36">Age</th>
<th>From</th>
<th>To</th>
<th className="min-w-52">Value</th>
<th>
<button
className="text-link-blue hover:text-link-blue-hover"
onClick={feeDisplayToggler}
Expand All @@ -27,8 +28,8 @@ const TransactionResultHeader: React.FC<ResultHeaderProps> = ({
{feeDisplay === FeeDisplay.TX_FEE_USD && "Txn Fee (USD)"}
{feeDisplay === FeeDisplay.GAS_PRICE && "Gas Price"}
</button>
</div>
</div>
</th>
</StandardTHead>
);

export default React.memo(TransactionResultHeader);
23 changes: 16 additions & 7 deletions src/useErigonHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
TokenTransfer,
TransactionData,
} from "./types";
import { useQuirks } from "./useQuirks";
import { formatter } from "./utils/formatter";

const TRANSFER_TOPIC =
Expand Down Expand Up @@ -420,13 +421,15 @@ export const useInternalOperations = (
}

const _t: InternalOperation[] = [];
for (const t of data) {
_t.push({
type: t.type,
from: formatter.address(getAddress(t.from)),
to: formatter.address(getAddress(t.to)),
value: formatter.bigInt(t.value),
});
if (data) {
for (const t of data) {
_t.push({
type: t.type,
from: formatter.address(getAddress(t.from)),
to: formatter.address(getAddress(t.to)),
value: formatter.bigInt(t.value),
});
}
}
return _t;
}, [provider, data]);
Expand Down Expand Up @@ -782,6 +785,12 @@ export const useHasCode = (
blockTag: BlockTag = "latest",
): boolean | undefined => {
const fetcher = providerFetcher(provider);
const quirks = useQuirks(provider);
if (quirks?.isZilliqa1) {
// Zilliqa 1 requires that the tag be numeric, but ignores it, so we can
// use 0 and save ourselves a fetch.
blockTag = 0;
}
const { data, error } = useSWRImmutable(
["ots_hasCode", address, blockTag],
fetcher,
Expand Down
31 changes: 31 additions & 0 deletions src/useQuirks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { JsonRpcApiProvider } from "ethers";
import { Fetcher } from "swr";
import useSWRImmutable from "swr/immutable";

export type Quirks = {
// Zilliqa 1 has so many odd quirks that we just have to declare it ..
isZilliqa1: boolean;
};

type ZilliqaVersion = {
Commit: string;
Version: string;
};

export const quirksFetcher =
(provider: JsonRpcApiProvider | undefined): Fetcher<any, Quirks> =>
async (key) => {
const version = await provider?.send("GetVersion", []);
const isZilliqa1 = version?.Version.match(/^v9.[0-9]+/);
return {
isZilliqa1: !!isZilliqa1,
};
};

export const useQuirks = (provider: JsonRpcApiProvider | undefined): Quirks => {
const { data: quirks } = useSWRImmutable(
"getVersion",
quirksFetcher(provider),
);
return quirks;
};