Skip to content

Commit

Permalink
Explorer: render transferSui (MystenLabs#3237)
Browse files Browse the repository at this point in the history
  • Loading branch information
666lcz authored Jul 16, 2022
1 parent 1405d40 commit 5ebf7ab
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getTransferObjectTransaction,
getMovePackageContent,
getObjectId,
getTransferSuiTransaction,
} from '@mysten/sui.js';
import cl from 'classnames';

Expand Down Expand Up @@ -193,7 +194,9 @@ function TransactionView({ txdata }: { txdata: DataType }) {
const txdetails = getTransactions(txdata)[0];
const txKindName = getTransactionKindName(txdetails);
const sender = getTransactionSender(txdata);
const recipient = getTransferObjectTransaction(txdetails);
const recipient =
getTransferObjectTransaction(txdetails) ||
getTransferSuiTransaction(txdetails);
const txKindData = formatByTransactionKind(txKindName, txdetails, sender);
const TabName = `${txKindName} Details`;

Expand Down Expand Up @@ -271,7 +274,7 @@ function TransactionView({ txdata }: { txdata: DataType }) {
value: txKindData.module.value,
},
{
label: 'Funtion',
label: 'Function',
monotypeClass: true,
value: txKindData.function.value,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ function TxAddressHeader({ data }: { data: TxResultState }) {
Publish: PublishTypeIcon,
TransferObject: TransferObjectTypeIcon,
Call: CallTypeIcon,
// TODO: use a different icon
ChangeEpoch: CallTypeIcon,
TransferSui: TransferObjectTypeIcon,
};
const TxKindName = data.txKindName;
const Icon = TxTransferTypeIcon[TxKindName];
Expand Down
4 changes: 3 additions & 1 deletion explorer/client/src/utils/api/DefaultRpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getTransactionDigest,
getTransactionKindName,
getTransferObjectTransaction,
getTransferSuiTransaction,
JsonRpcProvider,
} from '@mysten/sui.js';

Expand Down Expand Up @@ -53,7 +54,8 @@ export const getDataOnTxDigests = (
const txn = txns[0];
const txKind = getTransactionKindName(txn);
const recipient =
getTransferObjectTransaction(txn)?.recipient;
getTransferObjectTransaction(txn)?.recipient ||
getTransferSuiTransaction(txn)?.recipient;

return {
seq,
Expand Down
15 changes: 15 additions & 0 deletions explorer/client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7839,6 +7839,21 @@ pretty-format@^28.1.0:
ansi-styles "^5.0.0"
react-is "^18.0.0"

prism-react-renderer@^1.3.5:
version "1.3.5"
resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-1.3.5.tgz#786bb69aa6f73c32ba1ee813fbe17a0115435085"
integrity sha512-IJ+MSwBWKG+SM3b2SUfdrhC+gu01QkV2KmRQgREThBfSQRoufqRfxfHUxpG1WcaFjP+kojcFyO9Qqtpgt3qLCg==

prism-themes@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/prism-themes/-/prism-themes-1.9.0.tgz#19c034f3205f1e28d75d89728e54ccd745f7e3dd"
integrity sha512-tX2AYsehKDw1EORwBps+WhBFKc2kxfoFpQAjxBndbZKr4fRmMkv47XN0BghC/K1qwodB1otbe4oF23vUTFDokw==

prismjs@^1.28.0:
version "1.28.0"
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.28.0.tgz#0d8f561fa0f7cf6ebca901747828b149147044b6"
integrity sha512-8aaXdYvl1F7iC7Xm1spqSaY/OJBpYW3v+KJ+F17iYxvdc8sfjW194COK5wVhMZX45tGteiBQgdvD/nhxcRwylw==

process-nextick-args@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
Expand Down
38 changes: 35 additions & 3 deletions sdk/typescript/src/index.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Generated type guards for "index.ts".
* WARNING: Do not manually change this file.
*/
import { Ed25519KeypairData, Keypair, PublicKeyInitData, PublicKeyData, TransferObjectTransaction, MergeCoinTransaction, SplitCoinTransaction, MoveCallTransaction, PublishTransaction, TxnDataSerializer, SignaturePubkeyPair, Signer, TransactionDigest, SuiAddress, ObjectOwner, SuiObjectRef, SuiObjectInfo, ObjectContentFields, MovePackageContent, SuiData, SuiMoveObject, SuiMovePackage, SuiObject, ObjectStatus, ObjectType, GetOwnedObjectsResponse, GetObjectDataResponse, ObjectDigest, ObjectId, SequenceNumber, TransferObject, TransactionKindName, SuiTransactionKind, TransactionData, EpochId, AuthorityQuorumSignInfo, CertifiedTransaction, GasCostSummary, ExecutionStatusType, ExecutionStatus, OwnedObjectRef, TransactionEffects, TransactionEffectsResponse, GatewayTxSeqNumber, GetTxnDigestsResponse, MoveCall, SuiJsonValue, EmptySignInfo, AuthorityName, AuthoritySignature, TransactionBytes, MergeCoinResponse, SplitCoinResponse, PublishResponse, SuiPackage, TransactionResponse } from "./index";
import { Ed25519KeypairData, Keypair, PublicKeyInitData, PublicKeyData, TransferObjectTransaction, MergeCoinTransaction, SplitCoinTransaction, MoveCallTransaction, PublishTransaction, TxnDataSerializer, SignaturePubkeyPair, Signer, TransactionDigest, SuiAddress, ObjectOwner, SuiObjectRef, SuiObjectInfo, ObjectContentFields, MovePackageContent, SuiData, SuiMoveObject, SuiMovePackage, SuiObject, ObjectStatus, ObjectType, GetOwnedObjectsResponse, GetObjectDataResponse, ObjectDigest, ObjectId, SequenceNumber, TransferObject, SuiTransferSui, SuiChangeEpoch, TransactionKindName, SuiTransactionKind, TransactionData, EpochId, AuthorityQuorumSignInfo, CertifiedTransaction, GasCostSummary, ExecutionStatusType, ExecutionStatus, OwnedObjectRef, TransactionEffects, TransactionEffectsResponse, GatewayTxSeqNumber, GetTxnDigestsResponse, MoveCall, SuiJsonValue, EmptySignInfo, AuthorityName, AuthoritySignature, TransactionBytes, MergeCoinResponse, SplitCoinResponse, PublishResponse, SuiPackage, TransactionResponse } from "./index";
import { BN } from "bn.js";
import { Base64DataBuffer } from "./serialization/base64";
import { PublicKey } from "./cryptography/publickey";
Expand Down Expand Up @@ -352,11 +352,35 @@ export function isTransferObject(obj: any, _argumentName?: string): obj is Trans
)
}

export function isSuiTransferSui(obj: any, _argumentName?: string): obj is SuiTransferSui {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.recipient) as boolean &&
(obj.amount === null ||
isSequenceNumber(obj.amount) as boolean)
)
}

export function isSuiChangeEpoch(obj: any, _argumentName?: string): obj is SuiChangeEpoch {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isSequenceNumber(obj.epoch) as boolean &&
isSequenceNumber(obj.storage_charge) as boolean &&
isSequenceNumber(obj.computation_charge) as boolean
)
}

export function isTransactionKindName(obj: any, _argumentName?: string): obj is TransactionKindName {
return (
(obj === "TransferObject" ||
obj === "Publish" ||
obj === "Call")
obj === "Call" ||
obj === "TransferSui" ||
obj === "ChangeEpoch")
)
}

Expand All @@ -373,7 +397,15 @@ export function isSuiTransactionKind(obj: any, _argumentName?: string): obj is S
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isMoveCall(obj.Call) as boolean)
isMoveCall(obj.Call) as boolean ||
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isSuiTransferSui(obj.TransferSui) as boolean ||
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isSuiChangeEpoch(obj.ChangeEpoch) as boolean)
)
}

Expand Down
38 changes: 34 additions & 4 deletions sdk/typescript/src/types/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,29 @@ export type TransferObject = {
objectRef: SuiObjectRef;
};

export type TransactionKindName = 'TransferObject' | 'Publish' | 'Call';
export type SuiTransferSui = {
recipient: SuiAddress;
amount: number | null;
};

export type SuiChangeEpoch = {
epoch: EpochId;
storage_charge: number;
computation_charge: number;
};

export type TransactionKindName =
| 'TransferObject'
| 'Publish'
| 'Call'
| 'TransferSui'
| 'ChangeEpoch';
export type SuiTransactionKind =
| { TransferObject: TransferObject }
| { Publish: SuiMovePackage }
| { Call: MoveCall };
| { Call: MoveCall }
| { TransferSui: SuiTransferSui }
| { ChangeEpoch: SuiChangeEpoch };
export type TransactionData = {
transactions: SuiTransactionKind[];
sender: SuiAddress;
Expand Down Expand Up @@ -140,13 +158,13 @@ export type PublishResponse = {
createdObjects: SuiObject[];
package: SuiPackage;
updatedGas: SuiObject;
}
};

export type SuiPackage = {
digest: string;
objectId: string;
version: number;
}
};

export type TransactionResponse =
| {
Expand Down Expand Up @@ -221,6 +239,18 @@ export function getMoveCallTransaction(
return 'Call' in data ? data.Call : undefined;
}

export function getTransferSuiTransaction(
data: SuiTransactionKind
): SuiTransferSui | undefined {
return 'TransferSui' in data ? data.TransferSui : undefined;
}

export function getChangeEpochTransaction(
data: SuiTransactionKind
): SuiChangeEpoch | undefined {
return 'ChangeEpoch' in data ? data.ChangeEpoch : undefined;
}

export function getTransactions(
data: CertifiedTransaction
): SuiTransactionKind[] {
Expand Down

0 comments on commit 5ebf7ab

Please sign in to comment.