From b112a067ab0d5eaad426e07ff4fbee282102a439 Mon Sep 17 00:00:00 2001 From: Jibz1 Date: Mon, 27 Jun 2022 06:09:22 -0400 Subject: [PATCH] Show address that publishes a package (#2704) * get tx * add show publisher address * typo and lint fix * method rename * lint fix and rename Address -> Publisher * rm link from Publisher link for Genesis * rm link from Publisher link for Genesis * rm last tx for Genesis publish package txId * lint fix --- .../src/pages/object-result/ObjectLoaded.tsx | 17 +++++++- .../src/pages/object-result/ObjectResult.tsx | 39 +++++++++++++++++-- .../pages/object-result/ObjectResultType.tsx | 1 + 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/explorer/client/src/pages/object-result/ObjectLoaded.tsx b/explorer/client/src/pages/object-result/ObjectLoaded.tsx index 79f81d4cd1a61..e526eac8d239d 100644 --- a/explorer/client/src/pages/object-result/ObjectLoaded.tsx +++ b/explorer/client/src/pages/object-result/ObjectLoaded.tsx @@ -80,6 +80,9 @@ function ObjectLoaded({ data }: { data: DataType }) { ? 'Disassembled Bytecode' : 'Properties'; + const isPublisherGenesis = + data.objType === 'Move Package' && data?.publisherAddress === 'Genesis'; + return ( <>
@@ -120,7 +123,7 @@ function ObjectLoaded({ data }: { data: DataType }) { />
- {data.data?.tx_digest && ( + {data.data?.tx_digest && !isPublisherGenesis && (
Last Transaction ID
@@ -136,6 +139,18 @@ function ObjectLoaded({ data }: { data: DataType }) {
Version
{data.version}
+ {data?.publisherAddress && ( +
+
Publisher
+
+ +
+
+ )} {data.readonly && (
Read Only?
diff --git a/explorer/client/src/pages/object-result/ObjectResult.tsx b/explorer/client/src/pages/object-result/ObjectResult.tsx index 3b0e4eeed5dc5..2173b39907200 100644 --- a/explorer/client/src/pages/object-result/ObjectResult.tsx +++ b/explorer/client/src/pages/object-result/ObjectResult.tsx @@ -1,6 +1,10 @@ // Copyright (c) 2022, Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +import { + type TransactionEffectsResponse, + getTransactionSender, +} from '@mysten/sui.js'; import React, { useEffect, useState, useContext } from 'react'; import { useLocation, useParams } from 'react-router-dom'; @@ -39,15 +43,44 @@ const Fail = ({ objID }: { objID: string | undefined }): JSX.Element => { ); }; +// Get the data for the object ID and address that publishes a Package +function getObjectDataWithPackageAddress(objID: string, network: string) { + return rpc(network) + .getObject(objID as string) + .then((objState) => { + const resp: DataType = translate(objState) as DataType; + if (resp.objType === 'Move Package' && resp.data.tx_digest) { + return rpc(network) + .getTransactionWithEffects(resp.data.tx_digest) + .then((txEff: TransactionEffectsResponse) => ({ + ...resp, + publisherAddress: getTransactionSender( + txEff.certificate + ), + })) + .catch((err) => { + console.log(err); + // TODO: Not sure if I should show Genesis as Package Publisher or ignore it + return { + ...(resp.owner === 'Immutable' + ? { publisherAddress: 'Genesis' } + : {}), + ...resp, + }; + }); + } + return resp; + }); +} + const ObjectResultAPI = ({ objID }: { objID: string }): JSX.Element => { const [showObjectState, setObjectState] = useState(DATATYPE_DEFAULT); const [network] = useContext(NetworkContext); useEffect(() => { - rpc(network) - .getObject(objID as string) + getObjectDataWithPackageAddress(objID, network) .then((objState) => { setObjectState({ - ...(translate(objState) as DataType), + ...(objState as DataType), loadState: 'loaded', }); }) diff --git a/explorer/client/src/pages/object-result/ObjectResultType.tsx b/explorer/client/src/pages/object-result/ObjectResultType.tsx index f7dd6521efef9..1fe48af2ee677 100644 --- a/explorer/client/src/pages/object-result/ObjectResultType.tsx +++ b/explorer/client/src/pages/object-result/ObjectResultType.tsx @@ -24,6 +24,7 @@ export type DataType = { name?: string; ethAddress?: string; ethTokenId?: string; + publisherAddress?: string; contract_id?: { bytes: string }; data: { contents: {