Skip to content

Commit

Permalink
Show address that publishes a package (MystenLabs#2704)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Jibz1 authored Jun 27, 2022
1 parent 07299b3 commit b112a06
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
17 changes: 16 additions & 1 deletion explorer/client/src/pages/object-result/ObjectLoaded.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ function ObjectLoaded({ data }: { data: DataType }) {
? 'Disassembled Bytecode'
: 'Properties';

const isPublisherGenesis =
data.objType === 'Move Package' && data?.publisherAddress === 'Genesis';

return (
<>
<div className={styles.resultbox}>
Expand Down Expand Up @@ -120,7 +123,7 @@ function ObjectLoaded({ data }: { data: DataType }) {
/>
</div>
</div>
{data.data?.tx_digest && (
{data.data?.tx_digest && !isPublisherGenesis && (
<div>
<div>Last Transaction ID</div>
<div id="lasttxID">
Expand All @@ -136,6 +139,18 @@ function ObjectLoaded({ data }: { data: DataType }) {
<div>Version</div>
<div>{data.version}</div>
</div>
{data?.publisherAddress && (
<div>
<div>Publisher</div>
<div id="lasttxID">
<Longtext
text={data.publisherAddress}
category="addresses"
isLink={!isPublisherGenesis}
/>
</div>
</div>
)}
{data.readonly && (
<div>
<div>Read Only?</div>
Expand Down
39 changes: 36 additions & 3 deletions explorer/client/src/pages/object-result/ObjectResult.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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',
});
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type DataType = {
name?: string;
ethAddress?: string;
ethTokenId?: string;
publisherAddress?: string;
contract_id?: { bytes: string };
data: {
contents: {
Expand Down

0 comments on commit b112a06

Please sign in to comment.