- {IS_COIN_TYPE(typeV) &&
+ {subObjList[0]._isCoin &&
subObjList.every(
(el) => el.balance !== undefined
)
? `${subObjList.reduce(
(prev, current) =>
+ // TODO: handle number overflow
prev + current.balance!,
0
)}`
@@ -369,7 +367,7 @@ function OwnedObjectView({ results }: { results: resultType }) {
case 'display':
break;
case 'Type':
- if (IS_COIN_TYPE(entryObj.Type)) {
+ if (entryObj._isCoin) {
break;
} else {
return (
@@ -386,9 +384,12 @@ function OwnedObjectView({ results }: { results: resultType }) {
default:
if (
key === 'balance' &&
- !IS_COIN_TYPE(entryObj.Type)
+ !entryObj._isCoin
)
break;
+ if (key.startsWith('_')) {
+ break;
+ }
return (
{key}
diff --git a/explorer/client/src/components/transaction-card/RecentTxCard.tsx b/explorer/client/src/components/transaction-card/RecentTxCard.tsx
index cdc398411e1e6..b8dde73fe34c5 100644
--- a/explorer/client/src/components/transaction-card/RecentTxCard.tsx
+++ b/explorer/client/src/components/transaction-card/RecentTxCard.tsx
@@ -2,11 +2,12 @@
// SPDX-License-Identifier: Apache-2.0
import {
- getSingleTransactionKind,
- getTransactionKind,
- getTransferTransaction,
getExecutionStatusType,
getTotalGasUsed,
+ getTransactions,
+ getTransactionDigest,
+ getTransactionKindName,
+ getTransferCoinTransaction,
} from '@mysten/sui.js';
import cl from 'classnames';
import { useEffect, useState } from 'react';
@@ -60,27 +61,26 @@ async function getRecentTransactions(txNum: number): Promise {
const [seq, digest] = transactions.filter(
(transactionId) =>
transactionId[1] ===
- txEff.effects.transaction_digest
+ getTransactionDigest(txEff.certificate)
)[0];
const res: CertifiedTransaction = txEff.certificate;
- const singleTransaction = getSingleTransactionKind(
- res.data
- );
- if (!singleTransaction) {
+ // TODO: handle multiple transactions
+ const txns = getTransactions(res);
+ if (txns.length > 1) {
throw new Error(
- `Transaction kind not supported yet ${res.data.kind}`
+ `Handling multiple transactions is not yet supported`
);
}
- const txKind = getTransactionKind(res.data);
- const recipient = getTransferTransaction(
- res.data
- )?.recipient;
+ const txn = txns[0];
+ const txKind = getTransactionKindName(txn);
+ const recipient =
+ getTransferCoinTransaction(txn)?.recipient;
return {
seq,
txId: digest,
- status: getExecutionStatusType(txEff.effects.status),
- txGas: getTotalGasUsed(txEff.effects.status),
+ status: getExecutionStatusType(txEff),
+ txGas: getTotalGasUsed(txEff),
kind: txKind,
From: res.data.sender,
...(recipient
@@ -165,7 +165,7 @@ function LatestTxView({
styles.txstatus
)}
>
- {tx.status === 'Success' ? '✔' : '✖'}
+ {tx.status === 'success' ? '✔' : '✖'}
{tx.txGas}
diff --git a/explorer/client/src/pages/object-result/ObjectLoaded.tsx b/explorer/client/src/pages/object-result/ObjectLoaded.tsx
index 5ca9bbf6aee61..f5a8a8cc1c074 100644
--- a/explorer/client/src/pages/object-result/ObjectLoaded.tsx
+++ b/explorer/client/src/pages/object-result/ObjectLoaded.tsx
@@ -170,7 +170,7 @@ function ObjectLoaded({ data }: { data: DataType }) {
? toHexString(data.data.tx_digest as number[])
: data.data.tx_digest,
owner: processOwner(data.owner),
- url: parseImageURL(data.data),
+ url: parseImageURL(data.data.contents),
};
//TO DO remove when have distinct name field under Description
diff --git a/explorer/client/src/pages/object-result/ObjectResultType.tsx b/explorer/client/src/pages/object-result/ObjectResultType.tsx
index 1ee63988cd46f..8fe8d87387456 100644
--- a/explorer/client/src/pages/object-result/ObjectResultType.tsx
+++ b/explorer/client/src/pages/object-result/ObjectResultType.tsx
@@ -1,18 +1,19 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
-import { getMovePackageContent, getObjectContent } from '@mysten/sui.js';
+import {
+ getMovePackageContent,
+ getObjectId,
+ getObjectVersion,
+ getObjectOwner,
+ getObjectFields,
+ getObjectPreviousTransactionDigest,
+} from '@mysten/sui.js';
import { type AddressOwner } from '../../utils/api/DefaultRpcClient';
import { parseObjectType } from '../../utils/objectUtils';
-import type {
- GetObjectInfoResponse,
- ObjectExistsInfo,
- ObjectNotExistsInfo,
- ObjectOwner,
- ObjectRef,
-} from '@mysten/sui.js';
+import type { GetObjectInfoResponse, ObjectOwner } from '@mysten/sui.js';
export type DataType = {
id: string;
@@ -45,41 +46,33 @@ export function instanceOfDataType(object: any): object is DataType {
* to make this more extensible and customizable for different Move types
*/
export function translate(o: GetObjectInfoResponse): DataType {
- const { status, details } = o;
- switch (status) {
+ switch (o.status) {
case 'Exists': {
- const {
- objectRef: { objectId, version },
- object: { owner, tx_digest },
- } = details as ObjectExistsInfo;
-
return {
- id: objectId,
- version: version.toString(),
- objType: parseObjectType(details as ObjectExistsInfo)!,
- owner: parseOwner(owner),
+ id: getObjectId(o),
+ version: getObjectVersion(o)!.toString(),
+ objType: parseObjectType(o),
+ owner: parseOwner(getObjectOwner(o)!),
data: {
- contents:
- getObjectContent(o)?.fields ??
- getMovePackageContent(o)!,
- tx_digest,
+ contents: getObjectFields(o) ?? getMovePackageContent(o)!,
+ tx_digest: getObjectPreviousTransactionDigest(o),
},
};
}
case 'NotExists': {
- const { objectId } = details as ObjectNotExistsInfo;
// TODO: implement this
- throw new Error(`Implement me: Object ${objectId} does not exist`);
+ throw new Error(
+ `Implement me: Object ${getObjectId(o)} does not exist`
+ );
}
case 'Deleted': {
- const { objectId } = details as ObjectRef;
// TODO: implement this
throw new Error(
- `Implement me: Object ${objectId} has been deleted`
+ `Implement me: Object ${getObjectId(o)} has been deleted`
);
}
default: {
- throw new Error(`Unexpected status ${status} for object ${o}`);
+ throw new Error(`Unexpected status ${o.status} for object ${o}`);
}
}
}
diff --git a/explorer/client/src/pages/transaction-result/TransactionResult.tsx b/explorer/client/src/pages/transaction-result/TransactionResult.tsx
index ade684bb7e4c5..aac5bec03e6fa 100644
--- a/explorer/client/src/pages/transaction-result/TransactionResult.tsx
+++ b/explorer/client/src/pages/transaction-result/TransactionResult.tsx
@@ -2,10 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
import {
- getSingleTransactionKind,
getExecutionStatusType,
getTotalGasUsed,
- getExecutionDetails,
+ getExecutionStatusError,
} from '@mysten/sui.js';
import cl from 'classnames';
import { useEffect, useState } from 'react';
@@ -24,7 +23,7 @@ import type {
TransactionEffectsResponse,
ExecutionStatusType,
TransactionEffects,
- RawObjectRef,
+ SuiObjectRef,
} from '@mysten/sui.js';
import styles from './TransactionResult.module.css';
@@ -35,32 +34,27 @@ type TxnState = CertifiedTransaction & {
status: ExecutionStatusType;
gasFee: number;
txError: string;
- mutated: RawObjectRef[];
- created: RawObjectRef[];
+ mutated: SuiObjectRef[];
+ created: SuiObjectRef[];
};
-// Todo update state to include Call types
+// TODO: update state to include Call types
+// TODO: clean up duplicate fields
const initState: TxnState = {
loadState: 'pending',
txId: '',
data: {
- kind: {
- Single: {
- TransferCoin: {
- recipient: '',
- object_ref: ['', 0, ''],
- },
- },
- },
+ transactions: [],
sender: '',
- gas_payment: ['', 0, ''],
- gas_budget: 0,
+ gasPayment: { digest: '', objectId: '', version: 0 },
+ gasBudget: 0,
},
- tx_signature: '',
- auth_sign_info: {
+ transactionDigest: '',
+ txSignature: '',
+ authSignInfo: {
epoch: 0,
signatures: [],
},
- status: 'Success',
+ status: 'success',
gasFee: 0,
txError: '',
mutated: [],
@@ -85,10 +79,9 @@ function fetchTransactionData(
const getCreatedOrMutatedData = (
txEffects: TransactionEffects,
contentType: 'created' | 'mutated'
-) => {
- // Get the first item in the 'created' | 'mutated' array
- return contentType in txEffects
- ? txEffects[contentType].map((itm) => itm[0])
+): SuiObjectRef[] => {
+ return contentType in txEffects && txEffects[contentType] != null
+ ? txEffects[contentType]!.map((item) => item.reference)
: [];
};
@@ -106,18 +99,12 @@ const FailedToGetTxResults = ({ id }: { id: string }) => (
const transformTransactionResponse = (
txObj: TransactionEffectsResponse,
id: string
-) => {
- const executionStatus = txObj.effects.status;
- const status = getExecutionStatusType(executionStatus);
- const details = getExecutionDetails(executionStatus);
+): TxnState => {
return {
...txObj.certificate,
- status,
- gasFee: getTotalGasUsed(executionStatus),
- txError:
- 'error' in details
- ? details.error[Object.keys(details.error)[0]].error
- : '',
+ status: getExecutionStatusType(txObj),
+ gasFee: getTotalGasUsed(txObj),
+ txError: getExecutionStatusError(txObj) ?? '',
txId: id,
loadState: 'loaded',
mutated: getCreatedOrMutatedData(txObj.effects, 'mutated'),
@@ -152,11 +139,7 @@ const TransactionResultAPI = ({ id }: { id: string }) => {
);
}
- if (
- id &&
- showTxState.loadState === 'loaded' &&
- getSingleTransactionKind(showTxState.data) !== null
- ) {
+ if (id && showTxState.loadState === 'loaded') {
return ;
}
// For Batch transactions show error
diff --git a/explorer/client/src/pages/transaction-result/TransactionResultType.tsx b/explorer/client/src/pages/transaction-result/TransactionResultType.tsx
index 1f6a1ed35a089..bc41b0a7a05fa 100644
--- a/explorer/client/src/pages/transaction-result/TransactionResultType.tsx
+++ b/explorer/client/src/pages/transaction-result/TransactionResultType.tsx
@@ -4,7 +4,7 @@
import type {
CertifiedTransaction,
ExecutionStatusType,
- RawObjectRef,
+ SuiObjectRef,
} from '@mysten/sui.js';
export type DataType = CertifiedTransaction & {
@@ -13,6 +13,6 @@ export type DataType = CertifiedTransaction & {
status: ExecutionStatusType;
gasFee: number;
txError: string;
- mutated: RawObjectRef[];
- created: RawObjectRef[];
+ mutated: SuiObjectRef[];
+ created: SuiObjectRef[];
};
diff --git a/explorer/client/src/pages/transaction-result/TransactionView.tsx b/explorer/client/src/pages/transaction-result/TransactionView.tsx
index bc0fb10c2f786..7e47d0d376202 100644
--- a/explorer/client/src/pages/transaction-result/TransactionView.tsx
+++ b/explorer/client/src/pages/transaction-result/TransactionView.tsx
@@ -4,10 +4,13 @@
import {
getMoveCallTransaction,
getPublishTransaction,
- getTransactionKind,
- getTransferTransaction,
+ getTransactionKindName,
+ getTransactions,
+ getTransactionSender,
+ getTransferCoinTransaction,
+ getMovePackageContent,
+ getObjectId,
} from '@mysten/sui.js';
-import { Buffer } from 'buffer';
import cl from 'classnames';
import Longtext from '../../components/longtext/Longtext';
@@ -15,10 +18,10 @@ import { type DataType } from './TransactionResultType';
import type {
CertifiedTransaction,
- TransactionData,
TransactionKindName,
ExecutionStatusType,
- RawObjectRef,
+ SuiTransactionKind,
+ SuiObjectRef,
} from '@mysten/sui.js';
import styles from './TransactionResult.module.css';
@@ -27,15 +30,16 @@ type TxDataProps = CertifiedTransaction & {
status: ExecutionStatusType;
gasFee: number;
txError: string;
- mutated: RawObjectRef[];
- created: RawObjectRef[];
+ mutated: SuiObjectRef[];
+ created: SuiObjectRef[];
};
// Generate an Arr of Obj with Label and Value
// TODO rewrite to use sui.js, verify tx types and dynamically generate list
function formatTxResponse(tx: TxDataProps, txId: string) {
- // Todo add batch kind
- const txKindName = getTransactionKind(tx.data);
+ // TODO: handle multiple transactions
+ const txData = getTransactions(tx)[0];
+ const txKindName = getTransactionKindName(txData);
return [
{
@@ -47,36 +51,40 @@ function formatTxResponse(tx: TxDataProps, txId: string) {
// May change later
label: 'Status',
value:
- tx.status === 'Success' ? 'Success' : `Failed - ${tx.txError}`,
+ tx.status === 'success' ? 'Success' : `Failed - ${tx.txError}`,
classAttr:
- tx.status === 'Success' ? 'status-success' : 'status-fail',
+ tx.status === 'success' ? 'status-success' : 'status-fail',
},
{
label: 'Transaction Type',
value: txKindName,
},
// txKind Transfer or Call
- ...(formatByTransactionKind(txKindName, tx.data) ?? []),
+ ...(formatByTransactionKind(
+ txKindName,
+ txData,
+ getTransactionSender(tx)
+ ) ?? []),
{
label: 'Transaction Signature',
- value: tx.tx_signature,
+ value: tx.txSignature,
},
- ...(tx.mutated.length
+ ...(tx.mutated?.length
? [
{
label: 'Mutated',
category: 'objects',
- value: tx.mutated.map((obj) => obj[0]),
+ value: tx.mutated.map((obj) => getObjectId(obj)),
list: true,
link: true,
},
]
: []),
- ...(tx.created.length
+ ...(tx.created?.length
? [
{
label: 'Created',
- value: tx.created.map((obj) => obj[0]),
+ value: tx.created.map((obj) => getObjectId(obj)),
category: 'objects',
list: true,
link: true,
@@ -85,7 +93,7 @@ function formatTxResponse(tx: TxDataProps, txId: string) {
: []),
{
label: 'Gas Payment',
- value: tx.data.gas_payment[0],
+ value: tx.data.gasPayment.objectId,
link: true,
},
{
@@ -94,11 +102,11 @@ function formatTxResponse(tx: TxDataProps, txId: string) {
},
{
label: 'Gas Budget',
- value: tx.data.gas_budget,
+ value: tx.data.gasBudget,
},
{
label: 'Validator Signatures',
- value: tx.auth_sign_info.signatures,
+ value: tx.authSignInfo.signatures,
list: true,
sublist: true,
// Todo - assumes only two itmes in list ['A', 'B']
@@ -109,21 +117,22 @@ function formatTxResponse(tx: TxDataProps, txId: string) {
function formatByTransactionKind(
kind: TransactionKindName | undefined,
- data: TransactionData
+ data: SuiTransactionKind,
+ sender: string
) {
switch (kind) {
case 'TransferCoin':
- const transfer = getTransferTransaction(data)!;
+ const transfer = getTransferCoinTransaction(data)!;
return [
{
label: 'Object',
- value: transfer.object_ref[0],
+ value: transfer.objectRef.objectId,
link: true,
category: 'objects',
},
{
label: 'Sender',
- value: data.sender,
+ value: sender,
link: true,
category: 'addresses',
className: 'Receiver',
@@ -140,14 +149,14 @@ function formatByTransactionKind(
return [
{
label: 'From',
- value: data.sender,
+ value: sender,
link: true,
category: 'addresses',
},
{
label: 'Package',
category: 'objects',
- value: moveCall.package[0],
+ value: getObjectId(moveCall.package),
link: true,
},
{
@@ -160,12 +169,7 @@ function formatByTransactionKind(
},
{
label: 'Arguments',
- // convert pure type
- value: moveCall.arguments
- .filter((itm: any) => itm['Pure'])
- .map((data: any) =>
- Buffer.from(data['Pure']).toString('base64')
- ),
+ value: JSON.stringify(moveCall.arguments),
},
];
case 'Publish':
@@ -173,14 +177,15 @@ function formatByTransactionKind(
return [
{
label: 'Modules',
- value: publish.modules,
+ // TODO: render modules correctly
+ value: Object.entries(getMovePackageContent(publish)!),
list: true,
},
- ...(data.sender
+ ...(sender
? [
{
label: 'Sender ',
- value: data.sender,
+ value: sender,
link: true,
category: 'addresses',
},
diff --git a/explorer/client/src/utils/api/searchUtil.ts b/explorer/client/src/utils/api/searchUtil.ts
index de73af55ceda2..e66574a7c4703 100644
--- a/explorer/client/src/utils/api/searchUtil.ts
+++ b/explorer/client/src/utils/api/searchUtil.ts
@@ -1,8 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
-import { isObjectNotExistsInfo, isObjectRef } from '@mysten/sui.js';
-
import { DefaultRpcClient as rpc } from './DefaultRpcClient';
export const navigateWithUnknown = async (
@@ -18,8 +16,7 @@ export const navigateWithUnknown = async (
};
});
const objInfoPromise = rpc.getObjectInfo(input).then((data) => {
- const deets = data.details;
- if (isObjectNotExistsInfo(deets) && !isObjectRef(deets)) {
+ if (data.status !== 'Exists') {
throw new Error('no object found');
}
diff --git a/explorer/client/src/utils/objectUtils.ts b/explorer/client/src/utils/objectUtils.ts
index 20ce52f33652c..0f2d9c709ab8c 100644
--- a/explorer/client/src/utils/objectUtils.ts
+++ b/explorer/client/src/utils/objectUtils.ts
@@ -1,27 +1,28 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
-import type { ObjectExistsInfo } from '@mysten/sui.js';
+import { getObjectType, getMoveObjectType } from '@mysten/sui.js';
+
+import type { GetObjectInfoResponse } from '@mysten/sui.js';
export function parseImageURL(data: any): string {
return (
- //Render Image for Preview Cards
- data?.contents?.fields?.url?.fields?.url ||
- //Render Image for Object Results
- data?.contents?.url?.fields?.url ||
+ data?.url ||
// TODO: Remove Legacy format
+ data?.display ||
data?.contents?.display ||
''
);
}
-export function parseObjectType(data: ObjectExistsInfo): string {
+export function parseObjectType(data: GetObjectInfoResponse): string {
// TODO: define better naming and typing here
- if (data.objectType === 'movePackage') {
+ const dataType = getObjectType(data);
+ if (dataType === 'package') {
return 'Move Package';
}
- if (data.objectType === 'moveObject') {
- return data.object.contents.type;
+ if (dataType === 'moveObject') {
+ return getMoveObjectType(data)!;
}
return 'unknown';
}
diff --git a/sdk/typescript/src/index.guard.ts b/sdk/typescript/src/index.guard.ts
index 77e3ae70c5e12..9c1de75360aa2 100644
--- a/sdk/typescript/src/index.guard.ts
+++ b/sdk/typescript/src/index.guard.ts
@@ -5,7 +5,7 @@
* Generated type guards for "index.ts".
* WARNING: Do not manually change this file.
*/
-import { Ed25519KeypairData, Keypair, PublicKeyInitData, PublicKeyData, TransferCoinTransaction, TxnDataSerializer, TransactionDigest, SuiAddress, ObjectOwner, ObjectRef, ObjectContentField, ObjectContentFields, ObjectContent, MovePackageContent, SuiObject, ObjectExistsInfo, ObjectNotExistsInfo, ObjectStatus, ObjectType, GetOwnedObjectRefsResponse, GetObjectInfoResponse, ObjectDigest, ObjectId, SequenceNumber, RawObjectRef, TransferCoin, RawAuthoritySignInfo, TransactionKindName, SingleTransactionKind, TransactionKind, TransactionData, EpochId, AuthorityQuorumSignInfo, CertifiedTransaction, GasCostSummary, ExecutionStatusType, ExecutionStatus, ExecutionStatusDetail, OwnedObjectRef, TransactionEffects, TransactionEffectsResponse, GatewayTxSeqNumber, GetTxnDigestsResponse, MoveModulePublish, Event, StructTag, MoveTypeTag, MoveCall, MoveCallArg, EmptySignInfo, AuthorityName, AuthoritySignature, TransactionBytes, TransactionResponse, SignedTransaction } from "./index";
+import { Ed25519KeypairData, Keypair, PublicKeyInitData, PublicKeyData, TransferCoinTransaction, TxnDataSerializer, TransactionDigest, SuiAddress, ObjectOwner, SuiObjectRef, ObjectContentFields, MovePackageContent, SuiData, SuiMoveObject, SuiMovePackage, SuiObject, ObjectStatus, ObjectType, GetOwnedObjectRefsResponse, GetObjectInfoResponse, ObjectDigest, ObjectId, SequenceNumber, TransferCoin, RawAuthoritySignInfo, TransactionKindName, SuiTransactionKind, TransactionData, EpochId, AuthorityQuorumSignInfo, CertifiedTransaction, GasCostSummary, ExecutionStatusType, ExecutionStatus, OwnedObjectRef, TransactionEffects, TransactionEffectsResponse, GatewayTxSeqNumber, GetTxnDigestsResponse, Event, MoveCall, SuiJsonValue, EmptySignInfo, AuthorityName, AuthoritySignature, TransactionBytes, SplitCoinResponse, TransactionResponse } from "./index";
import { BN } from "bn.js";
export function isEd25519KeypairData(obj: any, _argumentName?: string): obj is Ed25519KeypairData {
@@ -100,7 +100,7 @@ export function isObjectOwner(obj: any, _argumentName?: string): obj is ObjectOw
)
}
-export function isObjectRef(obj: any, _argumentName?: string): obj is ObjectRef {
+export function isSuiObjectRef(obj: any, _argumentName?: string): obj is SuiObjectRef {
return (
(obj !== null &&
typeof obj === "object" ||
@@ -111,85 +111,71 @@ export function isObjectRef(obj: any, _argumentName?: string): obj is ObjectRef
)
}
-export function isObjectContentField(obj: any, _argumentName?: string): obj is ObjectContentField {
- return (
- (isTransactionDigest(obj) as boolean ||
- isSequenceNumber(obj) as boolean ||
- obj === false ||
- obj === true ||
- Array.isArray(obj) &&
- obj.every((e: any) =>
- isSequenceNumber(e) as boolean
- ) ||
- isObjectContent(obj) as boolean ||
- Array.isArray(obj) &&
- obj.every((e: any) =>
- isObjectContent(e) as boolean
- ))
- )
-}
-
export function isObjectContentFields(obj: any, _argumentName?: string): obj is ObjectContentFields {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
Object.entries(obj)
- .every(([key, value]) => (isObjectContentField(value) as boolean &&
- isTransactionDigest(key) as boolean))
+ .every(([key, _value]) => (isTransactionDigest(key) as boolean))
)
}
-export function isObjectContent(obj: any, _argumentName?: string): obj is ObjectContent {
+export function isMovePackageContent(obj: any, _argumentName?: string): obj is MovePackageContent {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- isObjectContentFields(obj.fields) as boolean &&
- isTransactionDigest(obj.type) as boolean
+ Object.entries(obj)
+ .every(([key, value]) => (isTransactionDigest(value) as boolean &&
+ isTransactionDigest(key) as boolean))
)
}
-export function isMovePackageContent(obj: any, _argumentName?: string): obj is MovePackageContent {
+export function isSuiData(obj: any, _argumentName?: string): obj is SuiData {
return (
- (obj !== null &&
+ ((obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- Object.entries(obj)
- .every(([key, value]) => (isTransactionDigest(value) as boolean &&
- isTransactionDigest(key) as boolean))
+ isObjectType(obj.dataType) as boolean &&
+ isSuiMoveObject(obj) as boolean ||
+ (obj !== null &&
+ typeof obj === "object" ||
+ typeof obj === "function") &&
+ isObjectType(obj.dataType) as boolean &&
+ isSuiMovePackage(obj) as boolean)
)
}
-export function isSuiObject(obj: any, _argumentName?: string): obj is SuiObject {
+export function isSuiMoveObject(obj: any, _argumentName?: string): obj is SuiMoveObject {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- (isObjectContent(obj.contents) as boolean ||
- isMovePackageContent(obj.contents) as boolean) &&
- isObjectOwner(obj.owner) as boolean &&
- isTransactionDigest(obj.tx_digest) as boolean
+ isTransactionDigest(obj.type) as boolean &&
+ isObjectContentFields(obj.fields) as boolean
)
}
-export function isObjectExistsInfo(obj: any, _argumentName?: string): obj is ObjectExistsInfo {
+export function isSuiMovePackage(obj: any, _argumentName?: string): obj is SuiMovePackage {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- isObjectRef(obj.objectRef) as boolean &&
- isObjectType(obj.objectType) as boolean &&
- isSuiObject(obj.object) as boolean
+ isMovePackageContent(obj.disassembled) as boolean
)
}
-export function isObjectNotExistsInfo(obj: any, _argumentName?: string): obj is ObjectNotExistsInfo {
+export function isSuiObject(obj: any, _argumentName?: string): obj is SuiObject {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- isTransactionDigest(obj.objectId) as boolean
+ isSuiData(obj.data) as boolean &&
+ isObjectOwner(obj.owner) as boolean &&
+ isTransactionDigest(obj.previousTransaction) as boolean &&
+ isSequenceNumber(obj.storageRebate) as boolean &&
+ isSuiObjectRef(obj.reference) as boolean
)
}
@@ -204,7 +190,7 @@ export function isObjectStatus(obj: any, _argumentName?: string): obj is ObjectS
export function isObjectType(obj: any, _argumentName?: string): obj is ObjectType {
return (
(obj === "moveObject" ||
- obj === "movePackage")
+ obj === "package")
)
}
@@ -215,7 +201,7 @@ export function isGetOwnedObjectRefsResponse(obj: any, _argumentName?: string):
typeof obj === "function") &&
Array.isArray(obj.objects) &&
obj.objects.every((e: any) =>
- isObjectRef(e) as boolean
+ isSuiObjectRef(e) as boolean
)
)
}
@@ -226,9 +212,9 @@ export function isGetObjectInfoResponse(obj: any, _argumentName?: string): obj i
typeof obj === "object" ||
typeof obj === "function") &&
isObjectStatus(obj.status) as boolean &&
- (isObjectRef(obj.details) as boolean ||
- isObjectExistsInfo(obj.details) as boolean ||
- isObjectNotExistsInfo(obj.details) as boolean)
+ (isTransactionDigest(obj.details) as boolean ||
+ isSuiObjectRef(obj.details) as boolean ||
+ isSuiObject(obj.details) as boolean)
)
}
@@ -250,22 +236,13 @@ export function isSequenceNumber(obj: any, _argumentName?: string): obj is Seque
)
}
-export function isRawObjectRef(obj: any, _argumentName?: string): obj is RawObjectRef {
- return (
- Array.isArray(obj) &&
- isTransactionDigest(obj[0]) as boolean &&
- isSequenceNumber(obj[1]) as boolean &&
- isTransactionDigest(obj[2]) as boolean
- )
-}
-
export function isTransferCoin(obj: any, _argumentName?: string): obj is TransferCoin {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
isTransactionDigest(obj.recipient) as boolean &&
- isRawObjectRef(obj.object_ref) as boolean
+ isSuiObjectRef(obj.objectRef) as boolean
)
}
@@ -285,7 +262,7 @@ export function isTransactionKindName(obj: any, _argumentName?: string): obj is
)
}
-export function isSingleTransactionKind(obj: any, _argumentName?: string): obj is SingleTransactionKind {
+export function isSuiTransactionKind(obj: any, _argumentName?: string): obj is SuiTransactionKind {
return (
((obj !== null &&
typeof obj === "object" ||
@@ -294,7 +271,7 @@ export function isSingleTransactionKind(obj: any, _argumentName?: string): obj i
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- isMoveModulePublish(obj.Publish) as boolean ||
+ isSuiMovePackage(obj.Publish) as boolean ||
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
@@ -302,31 +279,18 @@ export function isSingleTransactionKind(obj: any, _argumentName?: string): obj i
)
}
-export function isTransactionKind(obj: any, _argumentName?: string): obj is TransactionKind {
- return (
- ((obj !== null &&
- typeof obj === "object" ||
- typeof obj === "function") &&
- isSingleTransactionKind(obj.Single) as boolean ||
- (obj !== null &&
- typeof obj === "object" ||
- typeof obj === "function") &&
- Array.isArray(obj.Batch) &&
- obj.Batch.every((e: any) =>
- isSingleTransactionKind(e) as boolean
- ))
- )
-}
-
export function isTransactionData(obj: any, _argumentName?: string): obj is TransactionData {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- isTransactionKind(obj.kind) as boolean &&
+ Array.isArray(obj.transactions) &&
+ obj.transactions.every((e: any) =>
+ isSuiTransactionKind(e) as boolean
+ ) &&
isTransactionDigest(obj.sender) as boolean &&
- isRawObjectRef(obj.gas_payment) as boolean &&
- isSequenceNumber(obj.gas_budget) as boolean
+ isSuiObjectRef(obj.gasPayment) as boolean &&
+ isSequenceNumber(obj.gasBudget) as boolean
)
}
@@ -354,9 +318,10 @@ export function isCertifiedTransaction(obj: any, _argumentName?: string): obj is
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
+ isTransactionDigest(obj.transactionDigest) as boolean &&
isTransactionData(obj.data) as boolean &&
- isTransactionDigest(obj.tx_signature) as boolean &&
- isAuthorityQuorumSignInfo(obj.auth_sign_info) as boolean
+ isTransactionDigest(obj.txSignature) as boolean &&
+ isAuthorityQuorumSignInfo(obj.authSignInfo) as boolean
)
}
@@ -365,46 +330,38 @@ export function isGasCostSummary(obj: any, _argumentName?: string): obj is GasCo
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- isSequenceNumber(obj.computation_cost) as boolean &&
- isSequenceNumber(obj.storage_cost) as boolean &&
- isSequenceNumber(obj.storage_rebate) as boolean
+ isSequenceNumber(obj.computationCost) as boolean &&
+ isSequenceNumber(obj.storageCost) as boolean &&
+ isSequenceNumber(obj.storageRebate) as boolean
)
}
export function isExecutionStatusType(obj: any, _argumentName?: string): obj is ExecutionStatusType {
return (
- (obj === "Success" ||
- obj === "Failure")
+ (obj === "success" ||
+ obj === "failure")
)
}
export function isExecutionStatus(obj: any, _argumentName?: string): obj is ExecutionStatus {
return (
- ((obj !== null &&
+ (obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- isExecutionStatusDetail(obj.Success) as boolean ||
- (obj !== null &&
- typeof obj === "object" ||
- typeof obj === "function") &&
- isExecutionStatusDetail(obj.Failure) as boolean)
+ isExecutionStatusType(obj.status) as boolean &&
+ isGasCostSummary(obj.gas_cost) as boolean &&
+ (typeof obj.error === "undefined" ||
+ isTransactionDigest(obj.error) as boolean)
)
}
-export function isExecutionStatusDetail(obj: any, _argumentName?: string): obj is ExecutionStatusDetail {
+export function isOwnedObjectRef(obj: any, _argumentName?: string): obj is OwnedObjectRef {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- isGasCostSummary(obj.gas_cost) as boolean
- )
-}
-
-export function isOwnedObjectRef(obj: any, _argumentName?: string): obj is OwnedObjectRef {
- return (
- Array.isArray(obj) &&
- isRawObjectRef(obj[0]) as boolean &&
- isObjectOwner(obj[1]) as boolean
+ isObjectOwner(obj.owner) as boolean &&
+ isSuiObjectRef(obj.reference) as boolean
)
}
@@ -414,40 +371,48 @@ export function isTransactionEffects(obj: any, _argumentName?: string): obj is T
typeof obj === "object" ||
typeof obj === "function") &&
isExecutionStatus(obj.status) as boolean &&
- Array.isArray(obj.shared_objects) &&
- obj.shared_objects.every((e: any) =>
- isRawObjectRef(e) as boolean
- ) &&
- isTransactionDigest(obj.transaction_digest) as boolean &&
- Array.isArray(obj.created) &&
- obj.created.every((e: any) =>
- isOwnedObjectRef(e) as boolean
- ) &&
- Array.isArray(obj.mutated) &&
- obj.mutated.every((e: any) =>
- isOwnedObjectRef(e) as boolean
- ) &&
- Array.isArray(obj.unwrapped) &&
- obj.unwrapped.every((e: any) =>
- isOwnedObjectRef(e) as boolean
- ) &&
- Array.isArray(obj.deleted) &&
- obj.deleted.every((e: any) =>
- isRawObjectRef(e) as boolean
- ) &&
- Array.isArray(obj.wrapped) &&
- obj.wrapped.every((e: any) =>
- isRawObjectRef(e) as boolean
- ) &&
- isOwnedObjectRef(obj.gas_object) as boolean &&
- Array.isArray(obj.events) &&
- obj.events.every((e: any) =>
- isEvent(e) as boolean
- ) &&
- Array.isArray(obj.dependencies) &&
- obj.dependencies.every((e: any) =>
- isTransactionDigest(e) as boolean
- )
+ (typeof obj.sharedObjects === "undefined" ||
+ Array.isArray(obj.sharedObjects) &&
+ obj.sharedObjects.every((e: any) =>
+ isSuiObjectRef(e) as boolean
+ )) &&
+ isTransactionDigest(obj.transactionDigest) as boolean &&
+ (typeof obj.created === "undefined" ||
+ Array.isArray(obj.created) &&
+ obj.created.every((e: any) =>
+ isOwnedObjectRef(e) as boolean
+ )) &&
+ (typeof obj.mutated === "undefined" ||
+ Array.isArray(obj.mutated) &&
+ obj.mutated.every((e: any) =>
+ isOwnedObjectRef(e) as boolean
+ )) &&
+ (typeof obj.unwrapped === "undefined" ||
+ Array.isArray(obj.unwrapped) &&
+ obj.unwrapped.every((e: any) =>
+ isOwnedObjectRef(e) as boolean
+ )) &&
+ (typeof obj.deleted === "undefined" ||
+ Array.isArray(obj.deleted) &&
+ obj.deleted.every((e: any) =>
+ isSuiObjectRef(e) as boolean
+ )) &&
+ (typeof obj.wrapped === "undefined" ||
+ Array.isArray(obj.wrapped) &&
+ obj.wrapped.every((e: any) =>
+ isSuiObjectRef(e) as boolean
+ )) &&
+ isOwnedObjectRef(obj.gasObject) as boolean &&
+ (typeof obj.events === "undefined" ||
+ Array.isArray(obj.events) &&
+ obj.events.every((e: any) =>
+ isEvent(e) as boolean
+ )) &&
+ (typeof obj.dependencies === "undefined" ||
+ Array.isArray(obj.dependencies) &&
+ obj.dependencies.every((e: any) =>
+ isTransactionDigest(e) as boolean
+ ))
)
}
@@ -478,58 +443,12 @@ export function isGetTxnDigestsResponse(obj: any, _argumentName?: string): obj i
)
}
-export function isMoveModulePublish(obj: any, _argumentName?: string): obj is MoveModulePublish {
- return (
- (obj !== null &&
- typeof obj === "object" ||
- typeof obj === "function")
- )
-}
-
export function isEvent(obj: any, _argumentName?: string): obj is Event {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- isStructTag(obj.type_) as boolean &&
- isTransactionDigest(obj.contents) as boolean
- )
-}
-
-export function isStructTag(obj: any, _argumentName?: string): obj is StructTag {
- return (
- (obj !== null &&
- typeof obj === "object" ||
- typeof obj === "function") &&
- isTransactionDigest(obj.address) as boolean &&
- isTransactionDigest(obj.module) as boolean &&
- isTransactionDigest(obj.name) as boolean &&
- Array.isArray(obj.type_args) &&
- obj.type_args.every((e: any) =>
- isMoveTypeTag(e) as boolean
- )
- )
-}
-
-export function isMoveTypeTag(obj: any, _argumentName?: string): obj is MoveTypeTag {
- return (
- (obj === "bool" ||
- obj === "u8" ||
- obj === "u64" ||
- obj === "u128" ||
- obj === "address" ||
- obj === "signer" ||
- (obj !== null &&
- typeof obj === "object" ||
- typeof obj === "function") &&
- Array.isArray(obj.vector) &&
- obj.vector.every((e: any) =>
- isMoveTypeTag(e) as boolean
- ) ||
- (obj !== null &&
- typeof obj === "object" ||
- typeof obj === "function") &&
- isStructTag(obj.struct) as boolean)
+ isTransactionDigest(obj.type_) as boolean
)
}
@@ -538,37 +457,35 @@ export function isMoveCall(obj: any, _argumentName?: string): obj is MoveCall {
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- isRawObjectRef(obj.package) as boolean &&
+ isSuiObjectRef(obj.package) as boolean &&
isTransactionDigest(obj.module) as boolean &&
isTransactionDigest(obj.function) as boolean &&
- Array.isArray(obj.type_arguments) &&
- obj.type_arguments.every((e: any) =>
- isMoveTypeTag(e) as boolean
- ) &&
- Array.isArray(obj.arguments) &&
- obj.arguments.every((e: any) =>
- isMoveCallArg(e) as boolean
- )
+ (typeof obj.typeArguments === "undefined" ||
+ Array.isArray(obj.typeArguments) &&
+ obj.typeArguments.every((e: any) =>
+ isTransactionDigest(e) as boolean
+ )) &&
+ (typeof obj.arguments === "undefined" ||
+ Array.isArray(obj.arguments) &&
+ obj.arguments.every((e: any) =>
+ isSuiJsonValue(e) as boolean
+ ))
)
}
-export function isMoveCallArg(obj: any, _argumentName?: string): obj is MoveCallArg {
+export function isSuiJsonValue(obj: any, _argumentName?: string): obj is SuiJsonValue {
return (
- ((obj !== null &&
- typeof obj === "object" ||
- typeof obj === "function") &&
- Array.isArray(obj.Pure) &&
- obj.Pure.every((e: any) =>
- isSequenceNumber(e) as boolean
- ) ||
- (obj !== null &&
- typeof obj === "object" ||
- typeof obj === "function") &&
- isRawObjectRef(obj.ImmOrOwnedObject) as boolean ||
- (obj !== null &&
- typeof obj === "object" ||
- typeof obj === "function") &&
- isTransactionDigest(obj.SharedObject) as boolean)
+ (isTransactionDigest(obj) as boolean ||
+ isSequenceNumber(obj) as boolean ||
+ obj === false ||
+ obj === true ||
+ Array.isArray(obj) &&
+ obj.every((e: any) =>
+ (isTransactionDigest(e) as boolean ||
+ isSequenceNumber(e) as boolean ||
+ e === false ||
+ e === true)
+ ))
)
}
@@ -595,26 +512,35 @@ export function isTransactionBytes(obj: any, _argumentName?: string): obj is Tra
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- isTransactionDigest(obj.tx_bytes) as boolean
+ isTransactionDigest(obj.txBytes) as boolean &&
+ isSuiObjectRef(obj.gas) as boolean
)
}
-export function isTransactionResponse(obj: any, _argumentName?: string): obj is TransactionResponse {
+export function isSplitCoinResponse(obj: any, _argumentName?: string): obj is SplitCoinResponse {
return (
(obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- isTransactionEffectsResponse(obj.EffectResponse) as boolean
+ isCertifiedTransaction(obj.certificate) as boolean &&
+ isSuiObject(obj.updatedCoin) as boolean &&
+ Array.isArray(obj.newCoins) &&
+ obj.newCoins.every((e: any) =>
+ isSuiObject(e) as boolean
+ ) &&
+ isSuiObject(obj.updatedGas) as boolean
)
}
-export function isSignedTransaction(obj: any, _argumentName?: string): obj is SignedTransaction {
+export function isTransactionResponse(obj: any, _argumentName?: string): obj is TransactionResponse {
return (
- (obj !== null &&
+ ((obj !== null &&
typeof obj === "object" ||
typeof obj === "function") &&
- isTransactionDigest(obj.tx_bytes) as boolean &&
- isTransactionDigest(obj.signature) as boolean &&
- isTransactionDigest(obj.pub_key) as boolean
+ isTransactionEffectsResponse(obj.EffectResponse) as boolean ||
+ (obj !== null &&
+ typeof obj === "object" ||
+ typeof obj === "function") &&
+ isSplitCoinResponse(obj.SplitCoinResponse) as boolean)
)
}
diff --git a/sdk/typescript/src/providers/json-rpc-provider.ts b/sdk/typescript/src/providers/json-rpc-provider.ts
index 47de48e87d893..4929f81c5d888 100644
--- a/sdk/typescript/src/providers/json-rpc-provider.ts
+++ b/sdk/typescript/src/providers/json-rpc-provider.ts
@@ -11,17 +11,14 @@ import {
isTransactionResponse,
} from '../index.guard';
import {
- CertifiedTransaction,
GatewayTxSeqNumber,
GetTxnDigestsResponse,
GetObjectInfoResponse,
- ObjectRef,
+ SuiObjectRef,
TransactionDigest,
TransactionEffectsResponse,
- SignedTransaction,
TransactionResponse,
} from '../types';
-import { transformGetObjectInfoResponse } from '../types/framework/transformer';
const isNumber = (val: any): val is number => typeof val === 'number';
@@ -39,7 +36,7 @@ export class JsonRpcProvider extends Provider {
}
// Objects
- async getOwnedObjectRefs(address: string): Promise {
+ async getOwnedObjectRefs(address: string): Promise {
try {
const resp = await this.client.requestWithType(
'sui_getOwnedObjects',
@@ -56,12 +53,11 @@ export class JsonRpcProvider extends Provider {
async getObjectInfo(objectId: string): Promise {
try {
- const resp = await this.client.requestWithType(
- 'sui_getObjectTypedInfo',
+ return await this.client.requestWithType(
+ 'sui_getObjectInfo',
[objectId],
isGetObjectInfoResponse
);
- return transformGetObjectInfoResponse(resp);
} catch (err) {
throw new Error(`Error fetching object info: ${err} for id ${objectId}`);
}
@@ -71,15 +67,14 @@ export class JsonRpcProvider extends Provider {
objectIds: string[]
): Promise {
const requests = objectIds.map(id => ({
- method: 'sui_getObjectTypedInfo',
+ method: 'sui_getObjectInfo',
args: [id],
}));
try {
- const responses = await this.client.batchRequestWithType(
+ return await this.client.batchRequestWithType(
requests,
isGetObjectInfoResponse
);
- return responses.map(r => transformGetObjectInfoResponse(r));
} catch (err) {
throw new Error(`Error fetching object info: ${err} for id ${objectIds}`);
}
@@ -123,35 +118,20 @@ export class JsonRpcProvider extends Provider {
}
}
- async getTransaction(
- digest: TransactionDigest
- ): Promise {
- try {
- const resp = await this.client.requestWithType(
- 'sui_getTransaction',
- [digest],
- isTransactionEffectsResponse
- );
- return resp.certificate;
- } catch (err) {
- throw new Error(`Error getting transaction: ${err} for digest ${digest}`);
- }
- }
-
async executeTransaction(
- txn: SignedTransaction
+ txnBytes: string,
+ signature: string,
+ pubkey: string
): Promise {
try {
const resp = await this.client.requestWithType(
'sui_executeTransaction',
- [txn],
+ [txnBytes, signature, pubkey],
isTransactionResponse
);
return resp;
} catch (err) {
- throw new Error(
- `Error executing transaction: ${err} for txn ${JSON.stringify(txn)}`
- );
+ throw new Error(`Error executing transaction: ${err}}`);
}
}
diff --git a/sdk/typescript/src/providers/provider.ts b/sdk/typescript/src/providers/provider.ts
index 96465c59ef7dd..9a344a6312e2f 100644
--- a/sdk/typescript/src/providers/provider.ts
+++ b/sdk/typescript/src/providers/provider.ts
@@ -3,11 +3,10 @@
import {
GetObjectInfoResponse,
- ObjectRef,
+ SuiObjectRef,
GatewayTxSeqNumber,
GetTxnDigestsResponse,
TransactionResponse,
- SignedTransaction,
} from '../types';
///////////////////////////////
@@ -17,7 +16,7 @@ export abstract class Provider {
/**
* Get all objects owned by an address
*/
- abstract getOwnedObjectRefs(address: string): Promise;
+ abstract getOwnedObjectRefs(address: string): Promise;
/**
* Get information about an object
@@ -49,7 +48,9 @@ export abstract class Provider {
abstract getTotalTransactionNumber(): Promise;
abstract executeTransaction(
- txn: SignedTransaction
+ txnBytes: string,
+ signature: string,
+ pubkey: string
): Promise;
// TODO: add more interface methods
diff --git a/sdk/typescript/src/providers/void-provider.ts b/sdk/typescript/src/providers/void-provider.ts
index f78f312dafb8d..4234e37483913 100644
--- a/sdk/typescript/src/providers/void-provider.ts
+++ b/sdk/typescript/src/providers/void-provider.ts
@@ -6,16 +6,15 @@ import {
TransactionDigest,
GetTxnDigestsResponse,
GatewayTxSeqNumber,
- ObjectRef,
+ SuiObjectRef,
GetObjectInfoResponse,
- SignedTransaction,
TransactionResponse,
} from '../types';
import { Provider } from './provider';
export class VoidProvider extends Provider {
// Objects
- async getOwnedObjectRefs(_address: string): Promise {
+ async getOwnedObjectRefs(_address: string): Promise {
throw this.newError('getOwnedObjectRefs');
}
@@ -31,7 +30,9 @@ export class VoidProvider extends Provider {
}
async executeTransaction(
- _txn: SignedTransaction
+ _txnBytes: string,
+ _signature: string,
+ _pubkey: string
): Promise {
throw this.newError('executeTransaction');
}
diff --git a/sdk/typescript/src/signers/signer-with-provider.ts b/sdk/typescript/src/signers/signer-with-provider.ts
index fb6ed38968266..1ce47ea1e6617 100644
--- a/sdk/typescript/src/signers/signer-with-provider.ts
+++ b/sdk/typescript/src/signers/signer-with-provider.ts
@@ -55,11 +55,11 @@ export abstract class SignerWithProvider implements Signer {
txBytes: Base64DataBuffer
): Promise {
const sig = await this.signData(txBytes);
- return await this.provider.executeTransaction({
- tx_bytes: txBytes.toString(),
- signature: sig.signature.toString(),
- pub_key: sig.pubKey.toString(),
- });
+ return await this.provider.executeTransaction(
+ txBytes.toString(),
+ sig.signature.toString(),
+ sig.pubKey.toString()
+ );
}
/**
diff --git a/sdk/typescript/src/signers/txn-data-serializers/rpc-txn-data-serializer.ts b/sdk/typescript/src/signers/txn-data-serializers/rpc-txn-data-serializer.ts
index eacedd4fa4e0d..8444b4c209cd9 100644
--- a/sdk/typescript/src/signers/txn-data-serializers/rpc-txn-data-serializer.ts
+++ b/sdk/typescript/src/signers/txn-data-serializers/rpc-txn-data-serializer.ts
@@ -35,7 +35,7 @@ export class RpcTxnDataSerializer implements TxnDataSerializer {
[t.signer, t.objectId, t.gasPayment, t.gasBudget, t.recipient],
isTransactionBytes
);
- return new Base64DataBuffer(resp.tx_bytes);
+ return new Base64DataBuffer(resp.txBytes);
} catch (err) {
throw new Error(`Error transferring coin: ${err}`);
}
diff --git a/sdk/typescript/src/types/common.ts b/sdk/typescript/src/types/common.ts
index 3093deed0f18c..9d638970c4d24 100644
--- a/sdk/typescript/src/types/common.ts
+++ b/sdk/typescript/src/types/common.ts
@@ -1,6 +1,7 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
+/** Base64 string representing the object digest */
export type TransactionDigest = string;
export type SuiAddress = string;
export type ObjectOwner =
diff --git a/sdk/typescript/src/types/framework.ts b/sdk/typescript/src/types/framework.ts
new file mode 100644
index 0000000000000..257af580766ec
--- /dev/null
+++ b/sdk/typescript/src/types/framework.ts
@@ -0,0 +1,24 @@
+// Copyright (c) 2022, Mysten Labs, Inc.
+// SPDX-License-Identifier: Apache-2.0
+
+import { getObjectFields, GetObjectInfoResponse } from './objects';
+
+import { getMoveObjectType } from './objects';
+
+/**
+ * Utility class for 0x2::Coin
+ * as defined in https://github.com/MystenLabs/sui/blob/ca9046fd8b1a9e8634a4b74b0e7dabdc7ea54475/sui_programmability/framework/sources/Coin.move#L4
+ */
+export class Coin {
+ static isCoin(data: GetObjectInfoResponse): boolean {
+ return getMoveObjectType(data)?.startsWith('0x2::Coin::Coin') ?? false;
+ }
+
+ static getBalance(data: GetObjectInfoResponse): string | undefined {
+ if (!Coin.isCoin(data)) {
+ return undefined;
+ }
+ const balance = getObjectFields(data)?.value;
+ return typeof balance === 'string' ? balance : balance?.toString();
+ }
+}
diff --git a/sdk/typescript/src/types/framework/transformer.ts b/sdk/typescript/src/types/framework/transformer.ts
deleted file mode 100644
index fc57bd31272c5..0000000000000
--- a/sdk/typescript/src/types/framework/transformer.ts
+++ /dev/null
@@ -1,142 +0,0 @@
-// Copyright (c) 2022, Mysten Labs, Inc.
-// SPDX-License-Identifier: Apache-2.0
-
-import { isObjectContent } from '../../index.guard';
-import {
- getObjectContent,
- GetObjectInfoResponse,
- ObjectContent,
- ObjectContentField,
- ObjectContentFields,
- ObjectExistsInfo,
-} from '../objects';
-
-/**
- * Simplifies the common Move Object Content. This will be implemented
- * in the Gateway server level after DevNet.
- */
-export function transformGetObjectInfoResponse(resp: GetObjectInfoResponse) {
- const content = getObjectContent(resp);
- if (content != null) {
- (resp.details as ObjectExistsInfo).object.contents = transformObjectContent(
- content
- );
- }
- return resp;
-}
-
-export function transformObjectContent(input: ObjectContent): ObjectContent {
- let fields: ObjectContentFields = {};
- Object.entries(input.fields).forEach(([key, value]) => {
- if (!isObjectContent(value)) {
- fields[key] = value;
- return;
- }
- const parsers: typeof MoveObjectContentTransformer[] = [
- BalanceTransformer,
- StringTransformer,
- UniqueIDTransformer,
- ];
- let isTransformed = false;
- for (let p of parsers) {
- if (p.canTransform(value)) {
- fields[key] = p.toFieldValue(value);
- isTransformed = true;
- break;
- }
- }
- if (!isTransformed) {
- fields[key] = transformObjectContent(value);
- }
- });
- return {
- fields,
- type: input.type,
- };
-}
-
-abstract class MoveObjectContentTransformer {
- static toFieldValue(_input: ObjectContent): ObjectContentField {
- throw new Error('Children classes must override');
- }
-
- static canTransform(_input: ObjectContent): boolean {
- throw new Error('Children classes must override');
- }
-}
-
-class StringTransformer extends MoveObjectContentTransformer {
- static toFieldValue(input: ObjectContent): ObjectContentField {
- const bytes = input.fields['bytes'] as number[];
- switch (input.type) {
- case '0x1::ASCII::String':
- return bytes.map(n => String.fromCharCode(n)).join('');
- case '0x2::UTF8::String':
- return stringFromUTF8Array(new Uint8Array(bytes))!;
- }
- return input;
- }
-
- static canTransform(input: ObjectContent): boolean {
- return (
- input.type === '0x2::UTF8::String' || input.type === '0x1::ASCII::String'
- );
- }
-}
-
-class UniqueIDTransformer extends MoveObjectContentTransformer {
- static toFieldValue(input: ObjectContent): ObjectContentField {
- if (UniqueIDTransformer.canTransform(input)) {
- return (input.fields['id'] as ObjectContent).fields['bytes'];
- }
- return input;
- }
-
- static canTransform(input: ObjectContent): boolean {
- return (
- input.type === '0x2::ID::UniqueID' &&
- isObjectContent(input.fields['id']) &&
- input.fields['id'].type === '0x2::ID::ID'
- );
- }
-}
-
-class BalanceTransformer extends MoveObjectContentTransformer {
- static toFieldValue(input: ObjectContent): ObjectContentField {
- if (BalanceTransformer.canTransform(input)) {
- return input.fields['value'] as number;
- }
- return input;
- }
-
- static canTransform(input: ObjectContent): boolean {
- return input.type.startsWith('0x2::Balance::Balance');
- }
-}
-
-// from https://weblog.rogueamoeba.com/2017/02/27/javascript-correctly-converting-a-byte-array-to-a-utf-8-string/
-function stringFromUTF8Array(data: Uint8Array): string | null {
- const extraByteMap = [1, 1, 1, 1, 2, 2, 3, 0];
- var count = data.length;
- var str = '';
-
- for (var index = 0; index < count; ) {
- var ch = data[index++];
- if (ch & 0x80) {
- var extra = extraByteMap[(ch >> 3) & 0x07];
- if (!(ch & 0x40) || !extra || index + extra > count) return null;
-
- ch = ch & (0x3f >> extra);
- for (; extra > 0; extra -= 1) {
- var chx = data[index++];
- if ((chx & 0xc0) != 0x80) return null;
-
- ch = (ch << 6) | (chx & 0x3f);
- }
- }
-
- str += String.fromCharCode(ch);
- }
-
- return str;
-}
diff --git a/sdk/typescript/src/types/index.ts b/sdk/typescript/src/types/index.ts
index 55ad06d694124..ad494b4424df8 100644
--- a/sdk/typescript/src/types/index.ts
+++ b/sdk/typescript/src/types/index.ts
@@ -4,3 +4,4 @@
export * from './common';
export * from './objects';
export * from './transactions';
+export * from './framework';
diff --git a/sdk/typescript/src/types/objects.ts b/sdk/typescript/src/types/objects.ts
index 0ebc4397e1e3b..e57b15e6c7e9a 100644
--- a/sdk/typescript/src/types/objects.ts
+++ b/sdk/typescript/src/types/objects.ts
@@ -4,102 +4,173 @@
import { ObjectOwner } from './common';
import { TransactionDigest } from './common';
-export type ObjectRef = {
+export type SuiObjectRef = {
+ /** Base64 string representing the object digest */
digest: TransactionDigest;
+ /** Hex code as string representing the object id */
objectId: string;
+ /** Object version */
version: number;
};
-export type ObjectContentField =
- | ObjectContent
- | string
- | boolean
- | number
- | number[]
- | ObjectContent[];
+export type ObjectContentFields = Record;
-export type ObjectContentFields = Record;
+export type MovePackageContent = Record;
-export type ObjectContent = {
- fields: ObjectContentFields;
+export type SuiData = { dataType: ObjectType } & (
+ | SuiMoveObject
+ | SuiMovePackage
+);
+
+export type SuiMoveObject = {
+ /** Move type (e.g., "0x2::Coin::Coin<0x2::SUI::SUI>") */
type: string;
+ /** Fields and values stored inside the Move object */
+ fields: ObjectContentFields;
};
-export type MovePackageContent = Record;
+export type SuiMovePackage = {
+ /** A mapping from module name to disassembled Move bytecode */
+ disassembled: MovePackageContent;
+};
export type SuiObject = {
- contents: ObjectContent | MovePackageContent;
+ /** The meat of the object */
+ data: SuiData;
+ /** The owner of the object */
owner: ObjectOwner;
- tx_digest: TransactionDigest;
-};
-
-export type ObjectExistsInfo = {
- objectRef: ObjectRef;
- objectType: ObjectType;
- object: SuiObject;
-};
-
-export type ObjectNotExistsInfo = {
- objectId: ObjectId;
+ /** The digest of the transaction that created or last mutated this object */
+ previousTransaction: TransactionDigest;
+ /**
+ * The amount of SUI we would rebate if this object gets deleted.
+ * This number is re-calculated each time the object is mutated based on
+ * the present storage gas price.
+ */
+ storageRebate: number;
+ reference: SuiObjectRef;
};
export type ObjectStatus = 'Exists' | 'NotExists' | 'Deleted';
-export type ObjectType = 'moveObject' | 'movePackage';
+export type ObjectType = 'moveObject' | 'package';
export type GetOwnedObjectRefsResponse = {
- objects: ObjectRef[];
+ objects: SuiObjectRef[];
};
export type GetObjectInfoResponse = {
status: ObjectStatus;
- details: ObjectExistsInfo | ObjectNotExistsInfo | ObjectRef;
+ details: SuiObject | ObjectId | SuiObjectRef;
};
export type ObjectDigest = string;
export type ObjectId = string;
export type SequenceNumber = number;
-// TODO: get rid of this by implementing some conversion logic from ObjectRef
-export type RawObjectRef = [ObjectId, SequenceNumber, ObjectDigest];
+/* -------------------------------------------------------------------------- */
+/* Helper functions */
+/* -------------------------------------------------------------------------- */
-/* ---------------------------- Helper functions ---------------------------- */
+/* -------------------------- GetObjectInfoResponse ------------------------- */
export function getObjectExistsResponse(
resp: GetObjectInfoResponse
-): ObjectExistsInfo | undefined {
- return resp.status !== 'Exists'
- ? undefined
- : (resp.details as ObjectExistsInfo);
+): SuiObject | undefined {
+ return resp.status !== 'Exists' ? undefined : (resp.details as SuiObject);
}
+export function getObjectDeletedResponse(
+ resp: GetObjectInfoResponse
+): SuiObjectRef | undefined {
+ return resp.status !== 'Deleted' ? undefined : (resp.details as SuiObjectRef);
+}
+
+export function getObjectNotExistsResponse(
+ resp: GetObjectInfoResponse
+): ObjectId | undefined {
+ return resp.status !== 'NotExists' ? undefined : (resp.details as ObjectId);
+}
+
+export function getObjectReference(
+ resp: GetObjectInfoResponse
+): SuiObjectRef | undefined {
+ return (
+ getObjectExistsResponse(resp)?.reference || getObjectDeletedResponse(resp)
+ );
+}
+
+/* ------------------------------ SuiObjectRef ------------------------------ */
+
+export function getObjectId(
+ data: GetObjectInfoResponse | SuiObjectRef
+): ObjectId {
+ if ('objectId' in data) {
+ return data.objectId;
+ }
+ return (
+ getObjectReference(data)?.objectId ?? getObjectNotExistsResponse(data)!
+ );
+}
+
+export function getObjectVersion(
+ data: GetObjectInfoResponse | SuiObjectRef
+): number | undefined {
+ if ('version' in data) {
+ return data.version;
+ }
+ return getObjectReference(data)?.version;
+}
+
+/* -------------------------------- SuiObject ------------------------------- */
+
export function getObjectType(
resp: GetObjectInfoResponse
-): 'moveObject' | 'movePackage' | undefined {
- return getObjectExistsResponse(resp)?.objectType;
+): ObjectType | undefined {
+ return getObjectExistsResponse(resp)?.data.dataType;
+}
+
+export function getObjectPreviousTransactionDigest(
+ resp: GetObjectInfoResponse
+): TransactionDigest | undefined {
+ return getObjectExistsResponse(resp)?.previousTransaction;
+}
+
+export function getObjectOwner(
+ resp: GetObjectInfoResponse
+): ObjectOwner | undefined {
+ return getObjectExistsResponse(resp)?.owner;
+}
+
+export function getMoveObjectType(
+ resp: GetObjectInfoResponse
+): string | undefined {
+ return getMoveObject(resp)?.type;
}
-export function getObjectContent(
+export function getObjectFields(
resp: GetObjectInfoResponse
-): ObjectContent | undefined {
- const existsInfo = getObjectExistsResponse(resp);
- if (existsInfo == null) {
+): ObjectContentFields | undefined {
+ return getMoveObject(resp)?.fields;
+}
+
+export function getMoveObject(
+ resp: GetObjectInfoResponse
+): SuiMoveObject | undefined {
+ const suiObject = getObjectExistsResponse(resp);
+ if (suiObject?.data.dataType !== 'moveObject') {
return undefined;
}
- const { object, objectType } = existsInfo;
- return objectType === 'moveObject'
- ? (object.contents as ObjectContent)
- : undefined;
+ return suiObject.data as SuiMoveObject;
}
export function getMovePackageContent(
- resp: GetObjectInfoResponse
+ data: GetObjectInfoResponse | SuiMovePackage
): MovePackageContent | undefined {
- const existsInfo = getObjectExistsResponse(resp);
- if (existsInfo == null) {
+ if ('disassembled' in data) {
+ return data.disassembled;
+ }
+ const suiObject = getObjectExistsResponse(data);
+ if (suiObject?.data.dataType !== 'package') {
return undefined;
}
- const { object, objectType } = existsInfo;
- return objectType === 'movePackage'
- ? (object.contents as MovePackageContent)
- : undefined;
+ return (suiObject.data as SuiMovePackage).disassembled;
}
diff --git a/sdk/typescript/src/types/transactions.ts b/sdk/typescript/src/types/transactions.ts
index 59b18ad894851..83d4a1cb28e1a 100644
--- a/sdk/typescript/src/types/transactions.ts
+++ b/sdk/typescript/src/types/transactions.ts
@@ -2,27 +2,24 @@
// SPDX-License-Identifier: Apache-2.0
import { ObjectOwner, SuiAddress, TransactionDigest } from './common';
-import { ObjectId, RawObjectRef } from './objects';
+import { SuiMovePackage, SuiObject, SuiObjectRef } from './objects';
export type TransferCoin = {
- recipient: string;
- object_ref: RawObjectRef;
+ recipient: SuiAddress;
+ objectRef: SuiObjectRef;
};
export type RawAuthoritySignInfo = [AuthorityName, AuthoritySignature];
export type TransactionKindName = 'TransferCoin' | 'Publish' | 'Call';
-export type SingleTransactionKind =
+export type SuiTransactionKind =
| { TransferCoin: TransferCoin }
- | { Publish: MoveModulePublish }
+ | { Publish: SuiMovePackage }
| { Call: MoveCall };
-export type TransactionKind =
- | { Single: SingleTransactionKind }
- | { Batch: SingleTransactionKind[] };
export type TransactionData = {
- kind: TransactionKind;
- sender: string;
- gas_payment: RawObjectRef;
- gas_budget: number;
+ transactions: SuiTransactionKind[];
+ sender: SuiAddress;
+ gasPayment: SuiObjectRef;
+ gasBudget: number;
};
// TODO: support u64
@@ -34,39 +31,61 @@ export type AuthorityQuorumSignInfo = {
};
export type CertifiedTransaction = {
+ transactionDigest: TransactionDigest;
data: TransactionData;
- tx_signature: string;
- auth_sign_info: AuthorityQuorumSignInfo;
+ txSignature: string;
+ authSignInfo: AuthorityQuorumSignInfo;
};
export type GasCostSummary = {
- computation_cost: number;
- storage_cost: number;
- storage_rebate: number;
+ computationCost: number;
+ storageCost: number;
+ storageRebate: number;
};
-export type ExecutionStatusType = 'Success' | 'Failure';
-export type ExecutionStatus =
- | { Success: ExecutionStatusDetail }
- | { Failure: ExecutionStatusDetail };
-
-export type ExecutionStatusDetail = { gas_cost: GasCostSummary; error?: any };
+export type ExecutionStatusType = 'success' | 'failure';
+export type ExecutionStatus = {
+ status: ExecutionStatusType;
+ gas_cost: GasCostSummary;
+ error?: string;
+};
// TODO: change the tuple to struct from the server end
-export type OwnedObjectRef = [RawObjectRef, ObjectOwner];
+export type OwnedObjectRef = {
+ owner: ObjectOwner;
+ reference: SuiObjectRef;
+};
export type TransactionEffects = {
+ /** The status of the execution */
status: ExecutionStatus;
- shared_objects: RawObjectRef[];
- transaction_digest: TransactionDigest;
- created: OwnedObjectRef[];
- mutated: OwnedObjectRef[];
- unwrapped: OwnedObjectRef[];
- deleted: RawObjectRef[];
- wrapped: RawObjectRef[];
- gas_object: OwnedObjectRef;
- events: Event[];
- dependencies: TransactionDigest[];
+ /** The object references of the shared objects used in this transaction. Empty if no shared objects were used. */
+ sharedObjects?: SuiObjectRef[];
+ /** The transaction digest */
+ transactionDigest: TransactionDigest;
+ /** ObjectRef and owner of new objects created */
+ created?: OwnedObjectRef[];
+ /** ObjectRef and owner of mutated objects, including gas object */
+ mutated?: OwnedObjectRef[];
+ /**
+ * ObjectRef and owner of objects that are unwrapped in this transaction.
+ * Unwrapped objects are objects that were wrapped into other objects in the past,
+ * and just got extracted out.
+ */
+ unwrapped?: OwnedObjectRef[];
+ /** Object Refs of objects now deleted (the old refs) */
+ deleted?: SuiObjectRef[];
+ /** Object refs of objects now wrapped in other objects */
+ wrapped?: SuiObjectRef[];
+ /**
+ * The updated gas object reference. Have a dedicated field for convenient access.
+ * It's also included in mutated.
+ */
+ gasObject: OwnedObjectRef;
+ /** The events emitted during execution. Note that only successful transactions emit events */
+ events?: Event[];
+ /** The set of transaction digests this transaction depends on */
+ dependencies?: TransactionDigest[];
};
export type TransactionEffectsResponse = {
@@ -78,133 +97,153 @@ export type GatewayTxSeqNumber = number;
export type GetTxnDigestsResponse = [GatewayTxSeqNumber, TransactionDigest][];
-export type MoveModulePublish = {
- modules: any;
-};
-
export type Event = {
- type_: StructTag;
- contents: string;
-};
-
-export type StructTag = {
- address: SuiAddress;
- module: string;
- name: string;
- type_args: MoveTypeTag[];
+ type_: string;
+ contents: any;
};
-export type MoveTypeTag =
- | 'bool'
- | 'u8'
- | 'u64'
- | 'u128'
- | 'address'
- | 'signer'
- | { vector: MoveTypeTag[] }
- | { struct: StructTag };
export type MoveCall = {
- package: RawObjectRef;
+ package: SuiObjectRef;
module: string;
function: string;
- type_arguments: MoveTypeTag[];
- arguments: MoveCallArg[];
+ typeArguments?: string[];
+ arguments?: SuiJsonValue[];
};
-export type MoveCallArg =
- // TODO: convert to Uint8Array
- | { Pure: number[] }
- | { ImmOrOwnedObject: RawObjectRef }
- | { SharedObject: ObjectId };
+export type SuiJsonValue =
+ | boolean
+ | number
+ | string
+ | Array;
export type EmptySignInfo = object;
export type AuthorityName = string;
export type AuthoritySignature = string;
export type TransactionBytes = {
- tx_bytes: string;
+ txBytes: string;
+ gas: SuiObjectRef;
+ // TODO: Add input_objects field
};
-export type TransactionResponse = {
- EffectResponse: TransactionEffectsResponse;
- // TODO: Add Publish, MergeCoin, SplitCoin Response
+export type SplitCoinResponse = {
+ certificate: CertifiedTransaction;
+ updatedCoin: SuiObject;
+ newCoins: SuiObject[];
+ updatedGas: SuiObject;
};
-export type SignedTransaction = {
- tx_bytes: string;
- signature: string;
- pub_key: string;
-};
+export type TransactionResponse =
+ | {
+ EffectResponse: TransactionEffectsResponse;
+ // TODO: Add Publish, MergeCoin Response
+ }
+ | {
+ SplitCoinResponse: SplitCoinResponse;
+ };
+
+/* -------------------------------------------------------------------------- */
+/* Helper functions */
+/* -------------------------------------------------------------------------- */
+
+/* ---------------------------------- CertifiedTransaction --------------------------------- */
+export function getTransactionDigest(
+ tx: CertifiedTransaction
+): TransactionDigest {
+ return tx.transactionDigest;
+}
+
+export function getTransactionSignature(tx: CertifiedTransaction): string {
+ return tx.txSignature;
+}
+
+export function getTransactionAuthorityQuorumSignInfo(
+ tx: CertifiedTransaction
+): AuthorityQuorumSignInfo {
+ return tx.authSignInfo;
+}
+
+export function getTransactionData(tx: CertifiedTransaction): TransactionData {
+ return tx.data;
+}
+
+/* ----------------------------- TransactionData ---------------------------- */
+
+export function getTransactionSender(tx: CertifiedTransaction): SuiAddress {
+ return tx.data.sender;
+}
-/* ---------------------------- Helper functions ---------------------------- */
+export function getTransactionGasObject(
+ tx: CertifiedTransaction
+): SuiObjectRef {
+ return tx.data.gasPayment;
+}
-export function getSingleTransactionKind(
- data: TransactionData
-): SingleTransactionKind | undefined {
- return 'Single' in data.kind ? data.kind.Single : undefined;
+export function getTransactionGasBudget(tx: CertifiedTransaction): number {
+ return tx.data.gasBudget;
}
-export function getTransferTransaction(
- data: TransactionData
+export function getTransferCoinTransaction(
+ data: SuiTransactionKind
): TransferCoin | undefined {
- const tx = getSingleTransactionKind(data);
- return tx && 'TransferCoin' in tx ? tx.TransferCoin : undefined;
+ return 'TransferCoin' in data ? data.TransferCoin : undefined;
}
export function getPublishTransaction(
- data: TransactionData
-): MoveModulePublish | undefined {
- const tx = getSingleTransactionKind(data);
- return tx && 'Publish' in tx ? tx.Publish : undefined;
+ data: SuiTransactionKind
+): SuiMovePackage | undefined {
+ return 'Publish' in data ? data.Publish : undefined;
}
export function getMoveCallTransaction(
- data: TransactionData
+ data: SuiTransactionKind
): MoveCall | undefined {
- const tx = getSingleTransactionKind(data);
- return tx && 'Call' in tx ? tx.Call : undefined;
+ return 'Call' in data ? data.Call : undefined;
+}
+
+export function getTransactions(
+ data: CertifiedTransaction
+): SuiTransactionKind[] {
+ return data.data.transactions;
}
-export function getTransactionKind(
- data: TransactionData
-): TransactionKindName | undefined {
- const tx = getSingleTransactionKind(data);
- return tx && (Object.keys(tx)[0] as TransactionKindName);
+export function getTransactionKindName(
+ data: SuiTransactionKind
+): TransactionKindName {
+ return Object.keys(data)[0] as TransactionKindName;
}
+/* ----------------------------- ExecutionStatus ---------------------------- */
+
export function getExecutionStatusType(
- data: ExecutionStatus
+ data: TransactionEffectsResponse
): ExecutionStatusType {
- return Object.keys(data)[0] as ExecutionStatusType;
-}
-
-export function getGasSummary(
- data: ExecutionStatus
-): GasCostSummary | undefined {
- const details = getExecutionDetails(data);
- return details.gas_cost;
-}
-
-export function getTotalGasUsed(data: ExecutionStatus): number {
- const gasSummary = getGasSummary(data);
- if (gasSummary) {
- return (
- gasSummary.computation_cost +
- gasSummary.storage_cost -
- gasSummary.storage_rebate
- );
- }
- return 0;
-}
-
-export function getExecutionDetails(
- data: ExecutionStatus
-): ExecutionStatusDetail {
- if ('Success' in data) {
- return data.Success;
- } else if ('Failure' in data) {
- return data.Failure;
- }
- console.error('Unrecognized ExecutionStatus:', data);
- return data[Object.keys(data)[0]];
+ return getExecutionStatus(data).status;
+}
+
+export function getExecutionStatus(
+ data: TransactionEffectsResponse
+): ExecutionStatus {
+ return data.effects.status;
+}
+
+export function getExecutionStatusError(
+ data: TransactionEffectsResponse
+): string | undefined {
+ return getExecutionStatus(data).error;
+}
+
+export function getExecutionStatusGasSummary(
+ data: TransactionEffectsResponse
+): GasCostSummary {
+ return getExecutionStatus(data).gas_cost;
+}
+
+export function getTotalGasUsed(data: TransactionEffectsResponse): number {
+ const gasSummary = getExecutionStatusGasSummary(data);
+ return (
+ gasSummary.computationCost +
+ gasSummary.storageCost -
+ gasSummary.storageRebate
+ );
}
diff --git a/sdk/typescript/test/mocks/data/objects.json b/sdk/typescript/test/mocks/data/objects.json
deleted file mode 100644
index 589d4a554c1d2..0000000000000
--- a/sdk/typescript/test/mocks/data/objects.json
+++ /dev/null
@@ -1,328 +0,0 @@
-{
- "example_nft": {
- "status": "Exists",
- "details": {
- "objectRef": {
- "objectId": "be64c8f6d5fe15799c46f245d1211f1b084e589c",
- "version": 1,
- "digest": "Y8GESuU9Wj8tsg3qLzIq8PZPSmWvNnGsB6dlZO2ERnw="
- },
- "objectType": "moveObject",
- "object": {
- "contents": {
- "fields": {
- "description": {
- "fields": {
- "bytes": [
- 65,
- 110,
- 32,
- 78,
- 70,
- 84,
- 32,
- 99,
- 114,
- 101,
- 97,
- 116,
- 101,
- 100,
- 32,
- 98,
- 121,
- 32,
- 116,
- 104,
- 101,
- 32,
- 119,
- 97,
- 108,
- 108,
- 101,
- 116,
- 32,
- 67,
- 111,
- 109,
- 109,
- 97,
- 110,
- 100,
- 32,
- 76,
- 105,
- 110,
- 101,
- 32,
- 84,
- 111,
- 111,
- 108
- ]
- },
- "type": "0x2::UTF8::String"
- },
- "id": {
- "fields": {
- "id": {
- "fields": {
- "id": {
- "fields": {
- "bytes": "be64c8f6d5fe15799c46f245d1211f1b084e589c"
- },
- "type": "0x2::ID::ID"
- }
- },
- "type": "0x2::ID::UniqueID"
- },
- "version": 1
- },
- "type": "0x2::ID::VersionedID"
- },
- "name": {
- "fields": {
- "bytes": [69, 120, 97, 109, 112, 108, 101, 32, 78, 70, 84]
- },
- "type": "0x2::UTF8::String"
- },
- "url": {
- "fields": {
- "url": {
- "fields": {
- "bytes": [
- 105,
- 112,
- 102,
- 115,
- 58,
- 47,
- 47,
- 98,
- 97,
- 102,
- 107,
- 114,
- 101,
- 105,
- 98,
- 110,
- 103,
- 113,
- 104,
- 108,
- 51,
- 103,
- 97,
- 97,
- 55,
- 100,
- 97,
- 111,
- 98,
- 52,
- 105,
- 50,
- 118,
- 99,
- 99,
- 122,
- 105,
- 97,
- 121,
- 50,
- 106,
- 106,
- 108,
- 112,
- 52,
- 51,
- 53,
- 99,
- 102,
- 54,
- 54,
- 118,
- 104,
- 111,
- 110,
- 111,
- 55,
- 110,
- 114,
- 118,
- 119,
- 119,
- 53,
- 51,
- 116,
- 121
- ]
- },
- "type": "0x1::ASCII::String"
- }
- },
- "type": "0x2::Url::Url"
- }
- },
- "type": "0x2::DevNetNFT::DevNetNFT"
- },
- "owner": {
- "AddressOwner": "ccdd6ef735e9d2081da41e6c112e9b0c45bb1f0a"
- },
- "tx_digest": "xTvGzQA/4oKdq74Ny/r+Ms8vhIynA7LfuD7lf+dtJoU="
- }
- }
- },
-
- "coin": {
- "status": "Exists",
- "details": {
- "objectRef": {
- "objectId": "dbe11ea56da16992d8e68d07427fe74a85606d5e",
- "version": 2,
- "digest": "hobnw2DdC2quOLZf7D7QiRtAJGPP3GeAJA3iPmEoEaA="
- },
- "objectType": "moveObject",
- "object": {
- "contents": {
- "fields": {
- "balance": {
- "fields": {
- "value": 50000
- },
- "type": "0x2::Balance::Balance<0x2::SUI::SUI>"
- },
- "id": {
- "fields": {
- "id": {
- "fields": {
- "id": {
- "fields": {
- "bytes": "dbe11ea56da16992d8e68d07427fe74a85606d5e"
- },
- "type": "0x2::ID::ID"
- }
- },
- "type": "0x2::ID::UniqueID"
- },
- "version": 2
- },
- "type": "0x2::ID::VersionedID"
- }
- },
- "type": "0x2::Coin::Coin<0x2::SUI::SUI>"
- },
- "owner": {
- "AddressOwner": "f16a5aedcdf9f2a9c2bd0f077279ec3d5ff0dfee"
- },
- "tx_digest": "vU/KG88bjX8VgdNtflBjNUFNZAqYv2qMCwP9S0+tQRc="
- }
- }
- },
-
- "move_package": {
- "status": "Exists",
- "details": {
- "objectRef": {
- "objectId": "8070e826b3668a048a59a095de23ec26491ca2d9",
- "version": 1,
- "digest": "mpvRbMifZveAfw0wnss0EwtUhc0XgeTvQWO5V0vG790="
- },
- "objectType": "movePackage",
- "object": {
- "contents": {
- "M1": "// Move bytecode v5\nmodule 8070e826b3668a048a59a095de23ec26491ca2d9.M1 {\nstruct Forge has store, key {\n\tid: VersionedID,\n\tswords_created: u64\n}\nstruct Sword has store, key {\n\tid: VersionedID,\n\tmagic: u64,\n\tstrength: u64\n}\n\ninit(loc0: &mut TxContext) {\nB0:\n\t0: CopyLoc[0](Arg0: &mut TxContext)\n\t1: Call[6](new_id(&mut TxContext): VersionedID)\n\t2: LdU64(0)\n\t3: Pack[0](Forge)\n\t4: StLoc[1](loc0: Forge)\n\t5: MoveLoc[1](loc0: Forge)\n\t6: MoveLoc[0](Arg0: &mut TxContext)\n\t7: FreezeRef\n\t8: Call[7](sender(&TxContext): address)\n\t9: Call[0](transfer(Forge, address))\n\t10: Ret\n}\npublic magic(): u64 {\nB0:\n\t0: MoveLoc[0](Arg0: &Sword)\n\t1: ImmBorrowField[0](Sword.magic: u64)\n\t2: ReadRef\n\t3: Ret\n}\npublic strength(): u64 {\nB0:\n\t0: MoveLoc[0](Arg0: &Sword)\n\t1: ImmBorrowField[1](Sword.strength: u64)\n\t2: ReadRef\n\t3: Ret\n}\npublic(script) sword_create(loc0: &mut Forge) {\nB0:\n\t0: MoveLoc[4](Arg4: &mut TxContext)\n\t1: Call[6](new_id(&mut TxContext): VersionedID)\n\t2: MoveLoc[1](Arg1: u64)\n\t3: MoveLoc[2](Arg2: u64)\n\t4: Pack[1](Sword)\n\t5: StLoc[5](loc0: Sword)\n\t6: MoveLoc[5](loc0: Sword)\n\t7: MoveLoc[3](Arg3: address)\n\t8: Call[1](transfer(Sword, address))\n\t9: CopyLoc[0](Arg0: &mut Forge)\n\t10: ImmBorrowField[2](Forge.swords_created: u64)\n\t11: ReadRef\n\t12: LdU64(1)\n\t13: Add\n\t14: MoveLoc[0](Arg0: &mut Forge)\n\t15: MutBorrowField[2](Forge.swords_created: u64)\n\t16: WriteRef\n\t17: Ret\n}\npublic(script) sword_transfer() {\nB0:\n\t0: MoveLoc[0](Arg0: Sword)\n\t1: MoveLoc[1](Arg1: address)\n\t2: Call[1](transfer(Sword, address))\n\t3: Ret\n}\npublic swords_created(): u64 {\nB0:\n\t0: MoveLoc[0](Arg0: &Forge)\n\t1: ImmBorrowField[2](Forge.swords_created: u64)\n\t2: ReadRef\n\t3: Ret\n}\n}"
- },
- "owner": "Immutable",
- "tx_digest": "Zy76499PkX9Rm4DEWEj5o1NSnLWqu/700Xfx+bd4qSc="
- }
- }
- },
-
- "hero": {
- "status": "Exists",
- "details": {
- "objectRef": {
- "objectId": "3cc2a1f0d3f7c3df8cf74249490eeb995cd5b268",
- "version": 1,
- "digest": "AreMRNmuTBKRmeeQfu2wcIA5aR/EkO5vUdHH7y7yoT0="
- },
- "objectType": "moveObject",
- "object": {
- "contents": {
- "fields": {
- "experience": 0,
- "game_id": {
- "fields": {
- "bytes": "1a2c7db7cbb34abfe2374e8d9879f8ec0f295111"
- },
- "type": "0x2::ID::ID"
- },
- "hp": 100,
- "id": {
- "fields": {
- "id": {
- "fields": {
- "id": {
- "fields": {
- "bytes": "3cc2a1f0d3f7c3df8cf74249490eeb995cd5b268"
- },
- "type": "0x2::ID::ID"
- }
- },
- "type": "0x2::ID::UniqueID"
- },
- "version": 1
- },
- "type": "0x2::ID::VersionedID"
- },
- "sword": {
- "fields": {
- "vec": [
- {
- "fields": {
- "game_id": {
- "fields": {
- "bytes": "1a2c7db7cbb34abfe2374e8d9879f8ec0f295111"
- },
- "type": "0x2::ID::ID"
- },
- "id": {
- "fields": {
- "id": {
- "fields": {
- "id": {
- "fields": {
- "bytes": "a3b20b97b43aefe1539c6dbeff1547eb7b171ca1"
- },
- "type": "0x2::ID::ID"
- }
- },
- "type": "0x2::ID::UniqueID"
- },
- "version": 0
- },
- "type": "0x2::ID::VersionedID"
- },
- "magic": 10,
- "strength": 1
- },
- "type": "0xba510c18a7c08c306f524b82d05f918bf91fb5c0::Hero::Sword"
- }
- ]
- },
- "type": "0x1::Option::Option<0xba510c18a7c08c306f524b82d05f918bf91fb5c0::Hero::Sword>"
- }
- },
- "type": "0xba510c18a7c08c306f524b82d05f918bf91fb5c0::Hero::Hero"
- },
- "owner": {
- "AddressOwner": "a8ac9659d254c9ad366971c7c1b751a86ea2e84f"
- },
- "tx_digest": "LLz5oCSAxbL5bnwcn2mKq8zcIE70GgS3flWAeSq6EJI="
- }
- }
- }
-}
diff --git a/sdk/typescript/test/mocks/data/transactions.json b/sdk/typescript/test/mocks/data/transactions.json
deleted file mode 100644
index 762d972e794d3..0000000000000
--- a/sdk/typescript/test/mocks/data/transactions.json
+++ /dev/null
@@ -1,785 +0,0 @@
-{
- "move_call": {
- "certificate": {
- "data": {
- "kind": {
- "Single": {
- "Call": {
- "package": [
- "0000000000000000000000000000000000000002",
- 1,
- "0YGqZ5DhiIVttKzuC3lirSE/EHi8rHT9rrcAzpf5Muw="
- ],
- "module": "DevNetNFT",
- "function": "mint",
- "type_arguments": [],
- "arguments": [
- {
- "Pure": [11, 69, 120, 97, 109, 112, 108, 101, 32, 78, 70, 84]
- },
- {
- "Pure": [
- 46,
- 65,
- 110,
- 32,
- 78,
- 70,
- 84,
- 32,
- 99,
- 114,
- 101,
- 97,
- 116,
- 101,
- 100,
- 32,
- 98,
- 121,
- 32,
- 116,
- 104,
- 101,
- 32,
- 119,
- 97,
- 108,
- 108,
- 101,
- 116,
- 32,
- 67,
- 111,
- 109,
- 109,
- 97,
- 110,
- 100,
- 32,
- 76,
- 105,
- 110,
- 101,
- 32,
- 84,
- 111,
- 111,
- 108
- ]
- },
- {
- "Pure": [
- 66,
- 105,
- 112,
- 102,
- 115,
- 58,
- 47,
- 47,
- 98,
- 97,
- 102,
- 107,
- 114,
- 101,
- 105,
- 98,
- 110,
- 103,
- 113,
- 104,
- 108,
- 51,
- 103,
- 97,
- 97,
- 55,
- 100,
- 97,
- 111,
- 98,
- 52,
- 105,
- 50,
- 118,
- 99,
- 99,
- 122,
- 105,
- 97,
- 121,
- 50,
- 106,
- 106,
- 108,
- 112,
- 52,
- 51,
- 53,
- 99,
- 102,
- 54,
- 54,
- 118,
- 104,
- 111,
- 110,
- 111,
- 55,
- 110,
- 114,
- 118,
- 119,
- 119,
- 53,
- 51,
- 116,
- 121
- ]
- }
- ]
- }
- }
- },
- "sender": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f",
- "gas_payment": [
- "30b71f3695b7cf8c6d84e68f26deb0be766eb47b",
- 2,
- "loIm5cajGOhvXbssNGLz+dnBx4DYuRsNHHs3w3GFcPE="
- ],
- "gas_budget": 1000
- },
- "tx_signature": "/w9neF7jwXS+HqU9Z9WAI7J0vWg3hdUTa1+m+c82sSKnH/4m9szA09KqdllYYGoUXphk0oLYcMns1hNAPG2jAh6+oZXjpgiFeWKuidOIY5pmcp96Y+5wRPApBqs3+tQn",
- "auth_sign_info": {
- "epoch": 0,
- "signatures": [
- [
- "pHEGIvQKVycPpyPgFrcX767MKt3KRQ93rQja35qXv7M=",
- "jnm2llDrDqsHydQZnF0Csm3iEXUuPrECv0WMl+Zq4YoRtZ+5hcHrN/fT2yVYkcLkOhLhGc4iVvrE+VylQrvZDw=="
- ],
- [
- "F3GstMjvMzE9bKm4/9NrSrOZUAHgrTV9qAAtJDZGpxo=",
- "Wk4xgB8lSuN54fZQaN0Trm1tdHInvao+OikM086CZwUy1VLucQJvVifhbJ0cJ+U2sTlWldOEIGLo0bzunojSAQ=="
- ],
- [
- "j/Mh2m268+PwnfmuJZWa4Zau8bk2TbzSCVTZywcq6DM=",
- "NSg28xAJacp4C8zhRvOqMrvsWyAvwdWF3BlF8SI/f1BsMt682YeHjgSR55kKN4mvjyPrTuFp949ZnNNRLqh1CA=="
- ]
- ]
- }
- },
- "effects": {
- "status": {
- "Success": {
- "gas_cost": {
- "computation_cost": 828,
- "storage_cost": 40,
- "storage_rebate": 15
- }
- }
- },
- "shared_objects": [],
- "transaction_digest": "sqojprqTmTjB9rEPjt37hQmkYIUY0LpK/wFVbgNdkOs=",
- "created": [
- [
- [
- "3fc09fd3014ac5484f502cc1dc6441c36179c640",
- 1,
- "M6M3sy+0GhShAsBAmmZHXjgee411oV0j7E1a7D7gKa4="
- ],
- {
- "AddressOwner": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f"
- }
- ]
- ],
- "mutated": [
- [
- [
- "30b71f3695b7cf8c6d84e68f26deb0be766eb47b",
- 3,
- "picobSw8VE3bJ3IPn275+tRepnfkdqaUXObdX0TSQ2A="
- ],
- {
- "AddressOwner": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f"
- }
- ]
- ],
- "unwrapped": [],
- "deleted": [],
- "wrapped": [],
- "gas_object": [
- [
- "30b71f3695b7cf8c6d84e68f26deb0be766eb47b",
- 3,
- "picobSw8VE3bJ3IPn275+tRepnfkdqaUXObdX0TSQ2A="
- ],
- {
- "AddressOwner": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f"
- }
- ],
- "events": [],
- "dependencies": ["eJjcPfd0gVRPY9H87weaUwspJw8HQCQzWLWs5rrlMNY="]
- }
- },
-
- "transfer": {
- "certificate": {
- "data": {
- "kind": {
- "Single": {
- "Transfer": {
- "recipient": "bd51e8848e117725f20053a21aa7460362116527",
- "object_ref": [
- "677993369f658c4990d1b6f6b9a215a7a9164d07",
- 0,
- "5yJBs+5ixHNEh4sB14ca87fkZ2vQLueoybCOhzhVozc="
- ]
- }
- }
- },
- "sender": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f",
- "gas_payment": [
- "30b71f3695b7cf8c6d84e68f26deb0be766eb47b",
- 3,
- "picobSw8VE3bJ3IPn275+tRepnfkdqaUXObdX0TSQ2A="
- ],
- "gas_budget": 1000
- },
- "tx_signature": "G4UzFLA6o27nLQTxXaXGzqdxu/CCr0fMMi6qIloJFiEuhxXWpP1DMptMpBkqdBujddJlB77Z/LOX0W8pmUGBBB6+oZXjpgiFeWKuidOIY5pmcp96Y+5wRPApBqs3+tQn",
- "auth_sign_info": {
- "epoch": 0,
- "signatures": [
- [
- "DhT2M+ekSBrlBnO++N0Ng0cgVxBIDQ0cvvwkj4pSNJU=",
- "CyjNsQbEbzHFtfPjL7n2T5qgHuLgFr6yrC8UAhiE8MixmQ1VYhVxJ/4Gnk/dciXAPfV02qo28zbwE2YzhFnxBw=="
- ],
- [
- "F3GstMjvMzE9bKm4/9NrSrOZUAHgrTV9qAAtJDZGpxo=",
- "k268P2qgLtpH38S9B1boGHWYCj5qFoJy0dhIryP2XLv37aUaKUT+qw2yjIt5D65JGICzMbu42WPUkSf0XSmdAA=="
- ],
- [
- "pHEGIvQKVycPpyPgFrcX767MKt3KRQ93rQja35qXv7M=",
- "YyWQZIU4LHrhFqY4RcKdM7Ni2cxZnCvo3JBTd7GC/0FAma5kuSReDuPjXcSzbKBzH6Dt7TRTD4FRcBGfoWgHDw=="
- ]
- ]
- }
- },
- "effects": {
- "status": {
- "Success": {
- "gas_cost": {
- "computation_cost": 41,
- "storage_cost": 30,
- "storage_rebate": 15
- }
- }
- },
- "shared_objects": [],
- "transaction_digest": "c0r7Tg+jAGjEAAYTSun9gUN/wc82dgF/suQXua1/GQQ=",
- "created": [],
- "mutated": [
- [
- [
- "30b71f3695b7cf8c6d84e68f26deb0be766eb47b",
- 4,
- "upRmSnI93KP9DSSP6Qrzh8w+PixodAch2jGKMZCqjew="
- ],
- {
- "AddressOwner": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f"
- }
- ],
- [
- [
- "677993369f658c4990d1b6f6b9a215a7a9164d07",
- 1,
- "AoqAWyJhcgyP0khZrRRNU1X7cMAAUZaFWoLmDsSsACc="
- ],
- {
- "AddressOwner": "bd51e8848e117725f20053a21aa7460362116527"
- }
- ]
- ],
- "unwrapped": [],
- "deleted": [],
- "wrapped": [],
- "gas_object": [
- [
- "30b71f3695b7cf8c6d84e68f26deb0be766eb47b",
- 4,
- "upRmSnI93KP9DSSP6Qrzh8w+PixodAch2jGKMZCqjew="
- ],
- {
- "AddressOwner": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f"
- }
- ],
- "events": [],
- "dependencies": ["sqojprqTmTjB9rEPjt37hQmkYIUY0LpK/wFVbgNdkOs="]
- }
- },
-
- "coin_split": {
- "certificate": {
- "data": {
- "kind": {
- "Single": {
- "Call": {
- "package": [
- "0000000000000000000000000000000000000002",
- 1,
- "0YGqZ5DhiIVttKzuC3lirSE/EHi8rHT9rrcAzpf5Muw="
- ],
- "module": "Coin",
- "function": "split_vec",
- "type_arguments": [
- {
- "struct": {
- "address": "0000000000000000000000000000000000000002",
- "module": "SUI",
- "name": "SUI",
- "type_args": []
- }
- }
- ],
- "arguments": [
- {
- "ImmOrOwnedObject": [
- "f962f8bec6611e573f11636c93aebcc20a2d1ddc",
- 0,
- "P0SAdxNNUHn9LS9nqMSHh6FYYMVf+Ax5la/OLjAphks="
- ]
- },
- {
- "Pure": [
- 5,
- 20,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 20,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 20,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 20,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 20,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0
- ]
- }
- ]
- }
- }
- },
- "sender": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f",
- "gas_payment": [
- "64e4fc9cc632ea8ed887f47dfa7ef852bb8c7bc5",
- 0,
- "tIUqGJ3n9el8sOQrQxZx03S6KmfyZHgqqG1TGVGncLA="
- ],
- "gas_budget": 1000
- },
- "tx_signature": "gnWSuG4sHyUvO8L87wNU7x7HqrdKjIKwi80vijgdqHxALsgN6NeAseX7vZsCK2G2rt8iyFlyx5qUc7JsAjbyDh6+oZXjpgiFeWKuidOIY5pmcp96Y+5wRPApBqs3+tQn",
- "auth_sign_info": {
- "epoch": 0,
- "signatures": [
- [
- "DhT2M+ekSBrlBnO++N0Ng0cgVxBIDQ0cvvwkj4pSNJU=",
- "KAioJJkXAwLDups/nq+FjL0KgE+g45OBziDec2DQlqM3TbhA8OIya9tognhBNlN7xaf+2cNkzZm0ZSEi3TY6BQ=="
- ],
- [
- "pHEGIvQKVycPpyPgFrcX767MKt3KRQ93rQja35qXv7M=",
- "z2mrQt1Gzvv1w9ciAFhZSNIGWlSXMXgQwJUcWUUDoLmy9Iv+Ul+j5mY6xle3OzBTABZUpEib3c2IuAWq3OypAA=="
- ],
- [
- "F3GstMjvMzE9bKm4/9NrSrOZUAHgrTV9qAAtJDZGpxo=",
- "y54xpdwXcpb9Ko1jJDO+ntVpbQbKWzw0ZynSOn3W8vWpHnT1hS7BtqKTSX8dlA2+kOYMIqJLxF5JvmHKQmLBCg=="
- ]
- ]
- }
- },
- "effects": {
- "status": {
- "Success": {
- "gas_cost": {
- "computation_cost": 531,
- "storage_cost": 105,
- "storage_rebate": 0
- }
- }
- },
- "shared_objects": [],
- "transaction_digest": "zKHVFCpBRegfR9Vp1WpsdGVPLqUDHGpagTWHEwspE3o=",
- "created": [
- [
- [
- "633ceff2c371dab019ff6cad6aa403f80b600162",
- 1,
- "gJMTTnR8saeJi1473YE4Q1ne0nrSZ+d9CAmbPvFfgQY="
- ],
- {
- "AddressOwner": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f"
- }
- ],
- [
- [
- "75365860449048ad70e424eb7271322c73e4bb04",
- 1,
- "yWeaqgmM0dN8HiwAX/HuhVL26Dciphh6mU++/d4PJKg="
- ],
- {
- "AddressOwner": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f"
- }
- ],
- [
- [
- "a0b8116a6abe498a7f507d9b02f60cf3a80a3e2d",
- 1,
- "4EsCCiGyYVxRMyzSfrIZI1I3R+Qcp5PGRdG+Tl5aUaA="
- ],
- {
- "AddressOwner": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f"
- }
- ],
- [
- [
- "e3312b49917eb957707e56300f0f82ddc312ae12",
- 1,
- "dIc/LkJscLgUTeCRhQebsI+UGPSzcMlHYkbipPzMZDU="
- ],
- {
- "AddressOwner": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f"
- }
- ],
- [
- [
- "f8c81d9a4f5d26a3458f7b5a1dfb2a0c703ef1d8",
- 1,
- "AtPxgq6YS0IQ02Me8/0Ockthh8KAMj4O8sVslD/bRR0="
- ],
- {
- "AddressOwner": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f"
- }
- ]
- ],
- "mutated": [
- [
- [
- "64e4fc9cc632ea8ed887f47dfa7ef852bb8c7bc5",
- 1,
- "POw0Wb/vakQf9MjW8R5BaZldmE+QC1GyvKzkk9UShkk="
- ],
- {
- "AddressOwner": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f"
- }
- ],
- [
- [
- "f962f8bec6611e573f11636c93aebcc20a2d1ddc",
- 1,
- "cSy0id2bEbTIW0IFipfCpwKw02DY3Dxw2Kd0MDxQwT8="
- ],
- {
- "AddressOwner": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f"
- }
- ]
- ],
- "unwrapped": [],
- "deleted": [],
- "wrapped": [],
- "gas_object": [
- [
- "64e4fc9cc632ea8ed887f47dfa7ef852bb8c7bc5",
- 1,
- "POw0Wb/vakQf9MjW8R5BaZldmE+QC1GyvKzkk9UShkk="
- ],
- {
- "AddressOwner": "6683eaf54a5cdf030e2bc35b945c9761c89e1f2f"
- }
- ],
- "events": [],
- "dependencies": []
- }
- },
-
- "fail": {
- "certificate": {
- "data": {
- "kind": {
- "Single": {
- "Call": {
- "package": [
- "0000000000000000000000000000000000000002",
- 1,
- "0YGqZ5DhiIVttKzuC3lirSE/EHi8rHT9rrcAzpf5Muw="
- ],
- "module": "DevNetNFT",
- "function": "mint",
- "type_arguments": [],
- "arguments": [
- {
- "Pure": [
- 13,
- 71,
- 114,
- 101,
- 97,
- 116,
- 101,
- 115,
- 116,
- 32,
- 67,
- 104,
- 101,
- 102
- ]
- },
- {
- "Pure": [
- 30,
- 84,
- 104,
- 101,
- 32,
- 103,
- 114,
- 101,
- 97,
- 116,
- 101,
- 115,
- 116,
- 32,
- 99,
- 104,
- 101,
- 102,
- 32,
- 105,
- 110,
- 32,
- 116,
- 104,
- 101,
- 32,
- 119,
- 111,
- 114,
- 108,
- 100
- ]
- },
- {
- "Pure": [
- 101,
- 104,
- 116,
- 116,
- 112,
- 115,
- 58,
- 47,
- 47,
- 117,
- 115,
- 101,
- 114,
- 45,
- 105,
- 109,
- 97,
- 103,
- 101,
- 115,
- 46,
- 103,
- 105,
- 116,
- 104,
- 117,
- 98,
- 117,
- 115,
- 101,
- 114,
- 99,
- 111,
- 110,
- 116,
- 101,
- 110,
- 116,
- 46,
- 99,
- 111,
- 109,
- 47,
- 55,
- 54,
- 48,
- 54,
- 55,
- 49,
- 53,
- 56,
- 47,
- 49,
- 54,
- 54,
- 49,
- 51,
- 54,
- 50,
- 56,
- 54,
- 45,
- 99,
- 54,
- 48,
- 102,
- 101,
- 55,
- 48,
- 101,
- 45,
- 98,
- 57,
- 56,
- 50,
- 45,
- 52,
- 56,
- 49,
- 51,
- 45,
- 57,
- 51,
- 50,
- 97,
- 45,
- 48,
- 52,
- 49,
- 52,
- 100,
- 48,
- 102,
- 53,
- 53,
- 99,
- 102,
- 98,
- 46,
- 112,
- 110,
- 103
- ]
- }
- ]
- }
- }
- },
- "sender": "813ec1ab1e1797c79d1e1fcbebebc27a1fd21f07",
- "gas_payment": [
- "003e1d8b91a4cb1538cdb50c3cae8e62e1960b1c",
- 0,
- "HGSxZaaBFyRVSWgyvzxXw9W7kqsWeQCVrpO1mdRH3bs="
- ],
- "gas_budget": 1000
- },
- "tx_signature": "y0xGKqG4zKKdGStb6Kej0NuG0Ex2n7o5h34h287GDAT0aADdZN38Vk4xmWVNXEFsIC7DNgpQQ7GuJg5tqsf4CdRj4Rx5FZRehqwrctiLgZDPrY/3tI5+uJLCdaXPCj6C",
- "auth_sign_info": {
- "epoch": 0,
- "signatures": [
- [
- "ImYYav2doQpD3T7XPRA5xnk9LYUU22okB/z4NRMuhjs=",
- "RzxVVfKp468Bl+CXznmb48JshKhyJ5y6vh9C5+m1DkHSp73Nma5HBSYMmz8DKVNgXtexEa+qIr+0UIrlRIKNAA=="
- ],
- [
- "J2E+G3jRyOuxrCY+9xgPF+uc/6OrVUTNNp+L4XmwMn4=",
- "vS5KV5kujZC/Rew9BjoPVm9ABMMlEwtPtkPRUsSObqmPLhir6o3UbpCglUYsQLXyKewA+1qK0KZFfhA8hBskDQ=="
- ],
- [
- "HUetNOK8VYmILFADRclTtYN+MNZknTFcYWkLp6HijSM=",
- "G+S5s07mk8aKeMnAT7aBkMOZ0OutkM2V8TD8EvHlMM9KPPKPUITjrGJr5aThczg5sRLAm7tpjMpYlSCRf0vACQ=="
- ]
- ]
- }
- },
- "effects": {
- "status": {
- "Failure": {
- "gas_cost": {
- "computation_cost": 1000,
- "storage_cost": 0,
- "storage_rebate": 0
- },
- "error": {
- "InsufficientGas": {
- "error": "Ran out of gas while deducting computation cost"
- }
- }
- }
- },
- "shared_objects": [],
- "transaction_digest": "EnpPw9jQI4/k8IIoWFtMhoZKIOeXVsBWPbbMG07QvDM=",
- "created": [],
- "mutated": [
- [
- [
- "003e1d8b91a4cb1538cdb50c3cae8e62e1960b1c",
- 1,
- "jtJSPH26Z/iwtaFEGpd4CQFR4G/fNR1yyb2BV2F3pd4="
- ],
- {
- "AddressOwner": "813ec1ab1e1797c79d1e1fcbebebc27a1fd21f07"
- }
- ]
- ],
- "unwrapped": [],
- "deleted": [],
- "wrapped": [],
- "gas_object": [
- [
- "003e1d8b91a4cb1538cdb50c3cae8e62e1960b1c",
- 1,
- "jtJSPH26Z/iwtaFEGpd4CQFR4G/fNR1yyb2BV2F3pd4="
- ],
- {
- "AddressOwner": "813ec1ab1e1797c79d1e1fcbebebc27a1fd21f07"
- }
- ],
- "events": [],
- "dependencies": []
- }
- }
-}
diff --git a/sdk/typescript/test/types/objects.test.ts b/sdk/typescript/test/types/objects.test.ts
index d4d5e67de12e3..767dab18d0fef 100644
--- a/sdk/typescript/test/types/objects.test.ts
+++ b/sdk/typescript/test/types/objects.test.ts
@@ -1,10 +1,9 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
-import mockObjectData from '../mocks/data/objects.json';
+import mockObjectData from '../../../../sui/open_rpc/samples/objects.json';
import { isGetObjectInfoResponse } from '../../src/index.guard';
-import { GetObjectInfoResponse } from '../../src';
describe('Test Objects Definition', () => {
it('Test against different object definitions', () => {
@@ -15,10 +14,7 @@ describe('Test Objects Definition', () => {
});
});
-function validate(
- key: 'coin' | 'example_nft' | 'move_package' | 'hero'
-): GetObjectInfoResponse {
+function validate(key: 'coin' | 'example_nft' | 'move_package' | 'hero') {
const data = mockObjectData[key];
expect(isGetObjectInfoResponse(data)).toBeTruthy();
- return data as GetObjectInfoResponse;
}
diff --git a/sdk/typescript/test/types/transactions.test.ts b/sdk/typescript/test/types/transactions.test.ts
index 0db6858d84cbc..18b60b7199ca2 100644
--- a/sdk/typescript/test/types/transactions.test.ts
+++ b/sdk/typescript/test/types/transactions.test.ts
@@ -1,16 +1,19 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
-import mockTransactionData from '../mocks/data/transactions.json';
+import mockTransactionData from '../../../../sui/open_rpc/samples/transactions.json';
-import { isTransactionEffectsResponse } from '../../src/index.guard';
+import { isTransactionResponse } from '../../src/index.guard';
describe('Test Transaction Definition', () => {
it('Test against different transaction definitions', () => {
const txns = mockTransactionData;
- expect(isTransactionEffectsResponse(txns['move_call'])).toBeTruthy();
- expect(isTransactionEffectsResponse(txns['transfer'])).toBeTruthy();
- expect(isTransactionEffectsResponse(txns['coin_split'])).toBeTruthy();
- expect(isTransactionEffectsResponse(txns['fail'])).toBeTruthy();
+ expect(isTransactionResponse(txns['move_call'])).toBeTruthy();
+ expect(isTransactionResponse(txns['transfer'])).toBeTruthy();
+ expect(isTransactionResponse(txns['coin_split'])).toBeTruthy();
+ // TODO: add mock data for failed transaction
+ // expect(
+ // isTransactionEffectsResponse(txns['fail'])
+ // ).toBeTruthy();
});
});
diff --git a/sdk/typescript/test/types/transformer.test.ts b/sdk/typescript/test/types/transformer.test.ts
deleted file mode 100644
index 749a8f28b822b..0000000000000
--- a/sdk/typescript/test/types/transformer.test.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (c) 2022, Mysten Labs, Inc.
-// SPDX-License-Identifier: Apache-2.0
-
-import mockObjectData from '../mocks/data/objects.json';
-import { transformObjectContent } from '../../src/types/framework/transformer';
-
-import {
- getObjectContent,
- GetObjectInfoResponse,
- ObjectContent,
-} from '../../src';
-import { isGetObjectInfoResponse } from '../../src/index.guard';
-
-describe('Test simplify common Move structs', () => {
- it('Test with Coin', () => {
- const coin = getContent('coin');
- const expected = {
- ...coin,
- fields: {
- ...coin.fields,
- balance: 50000,
- },
- };
- replaceField(expected, 'id', '07db46736b11cc9e46ea2bbcaf4b71bea706ea4e');
- expect(transformObjectContent(coin)).toEqual(expected);
- });
-
- it('Test with Example NFT', () => {
- const example_nft = getContent('example_nft');
- const expected = {
- ...example_nft,
- fields: {
- ...example_nft.fields,
- description: 'An NFT created by the wallet Command Line Tool',
- name: 'Example NFT',
- },
- } as ObjectContent;
- replaceField(expected, 'id', 'be64c8f6d5fe15799c46f245d1211f1b084e589c');
- replaceField(
- expected,
- 'url',
- 'ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty'
- );
- expect(transformObjectContent(example_nft)).toEqual(expected);
- });
-});
-
-function replaceField(data: ObjectContent, key: string, id: string) {
- (data.fields[key] as ObjectContent)['fields'][key] = id;
-}
-
-function getContent(key: 'coin' | 'example_nft'): ObjectContent {
- return getObjectContent(validate(mockObjectData[key]))!;
-}
-
-function validate(data: any): GetObjectInfoResponse {
- expect(isGetObjectInfoResponse(data)).toBeTruthy();
- return data;
-}
diff --git a/sui/open_rpc/samples/objects.json b/sui/open_rpc/samples/objects.json
new file mode 100644
index 0000000000000..e3448106f522d
--- /dev/null
+++ b/sui/open_rpc/samples/objects.json
@@ -0,0 +1,115 @@
+{
+ "example_nft": {
+ "status": "Exists",
+ "details": {
+ "data": {
+ "dataType": "moveObject",
+ "type": "0x2::DevNetNFT::DevNetNFT",
+ "fields": {
+ "description": "An NFT created by the wallet Command Line Tool",
+ "id": {
+ "id": "0x69cb378ec715bfadcf765fbd06fe31ee28f76426",
+ "version": 1
+ },
+ "name": "Example NFT",
+ "url": "ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty"
+ }
+ },
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "previousTransaction": "9kJ9ImsEyufaaqzdwPrAQ8b+L9fu9mjTSyLeyGe55Vk=",
+ "storageRebate": 25,
+ "reference": {
+ "objectId": "0x69cb378ec715bfadcf765fbd06fe31ee28f76426",
+ "version": 1,
+ "digest": "qFEepmg29Sk8HzFm/4XcrcvDOyV9icQhhRd72TZ25H8="
+ }
+ }
+ },
+ "coin": {
+ "status": "Exists",
+ "details": {
+ "data": {
+ "dataType": "moveObject",
+ "type": "0x2::Coin::Coin<0x2::SUI::SUI>",
+ "fields": {
+ "balance": 100000,
+ "id": {
+ "id": "0x0c202409b97da9d63179decdc547131123f70444",
+ "version": 0
+ }
+ }
+ },
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "previousTransaction": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
+ "storageRebate": 0,
+ "reference": {
+ "objectId": "0x0c202409b97da9d63179decdc547131123f70444",
+ "version": 0,
+ "digest": "RzCxIKgTPpbWe/wIIP4vLI/evYkGyZhqboeSdW80isw="
+ }
+ }
+ },
+ "move_package": {
+ "status": "Exists",
+ "details": {
+ "data": {
+ "dataType": "package",
+ "disassembled": {
+ "M1": "// Move bytecode v5\nmodule 621cdb89add3d66ee2e3f41ed1dae2127ede7e4e.M1 {\nstruct Forge has store, key {\n\tid: VersionedID,\n\tswords_created: u64\n}\nstruct Sword has store, key {\n\tid: VersionedID,\n\tmagic: u64,\n\tstrength: u64\n}\n\ninit(loc0: &mut TxContext) {\nB0:\n\t0: CopyLoc[0](Arg0: &mut TxContext)\n\t1: Call[6](new_id(&mut TxContext): VersionedID)\n\t2: LdU64(0)\n\t3: Pack[0](Forge)\n\t4: StLoc[1](loc0: Forge)\n\t5: MoveLoc[1](loc0: Forge)\n\t6: MoveLoc[0](Arg0: &mut TxContext)\n\t7: FreezeRef\n\t8: Call[7](sender(&TxContext): address)\n\t9: Call[0](transfer(Forge, address))\n\t10: Ret\n}\npublic magic(): u64 {\nB0:\n\t0: MoveLoc[0](Arg0: &Sword)\n\t1: ImmBorrowField[0](Sword.magic: u64)\n\t2: ReadRef\n\t3: Ret\n}\npublic strength(): u64 {\nB0:\n\t0: MoveLoc[0](Arg0: &Sword)\n\t1: ImmBorrowField[1](Sword.strength: u64)\n\t2: ReadRef\n\t3: Ret\n}\npublic(script) sword_create(loc0: &mut Forge) {\nB0:\n\t0: MoveLoc[4](Arg4: &mut TxContext)\n\t1: Call[6](new_id(&mut TxContext): VersionedID)\n\t2: MoveLoc[1](Arg1: u64)\n\t3: MoveLoc[2](Arg2: u64)\n\t4: Pack[1](Sword)\n\t5: StLoc[5](loc0: Sword)\n\t6: MoveLoc[5](loc0: Sword)\n\t7: MoveLoc[3](Arg3: address)\n\t8: Call[1](transfer(Sword, address))\n\t9: CopyLoc[0](Arg0: &mut Forge)\n\t10: ImmBorrowField[2](Forge.swords_created: u64)\n\t11: ReadRef\n\t12: LdU64(1)\n\t13: Add\n\t14: MoveLoc[0](Arg0: &mut Forge)\n\t15: MutBorrowField[2](Forge.swords_created: u64)\n\t16: WriteRef\n\t17: Ret\n}\npublic(script) sword_transfer() {\nB0:\n\t0: MoveLoc[0](Arg0: Sword)\n\t1: MoveLoc[1](Arg1: address)\n\t2: Call[1](transfer(Sword, address))\n\t3: Ret\n}\npublic swords_created(): u64 {\nB0:\n\t0: MoveLoc[0](Arg0: &Forge)\n\t1: ImmBorrowField[2](Forge.swords_created: u64)\n\t2: ReadRef\n\t3: Ret\n}\n}"
+ }
+ },
+ "owner": "Immutable",
+ "previousTransaction": "l9z1kXcM0PFDMJ/Fyg9+W7WRBFtuswnLgNmLFOQGyRQ=",
+ "storageRebate": 0,
+ "reference": {
+ "objectId": "0x621cdb89add3d66ee2e3f41ed1dae2127ede7e4e",
+ "version": 1,
+ "digest": "ZnWHKtww5D6jq/dbTUjcAyuCUqd38VPfcSGNPv0ttB8="
+ }
+ }
+ },
+ "hero": {
+ "status": "Exists",
+ "details": {
+ "data": {
+ "dataType": "moveObject",
+ "type": "0x2839e7a4f2622cc3b3af4728295418455dca24c0::Hero::Hero",
+ "fields": {
+ "experience": 0,
+ "game_id": "0x2be060a0949d060b0e4dffb4e2d55433607f69b2",
+ "hp": 100,
+ "id": {
+ "id": "0x9da74a0a4ab5229170deacf33530e39663638bb2",
+ "version": 1
+ },
+ "sword": {
+ "type": "0x2839e7a4f2622cc3b3af4728295418455dca24c0::Hero::Sword",
+ "fields": {
+ "game_id": "0x2be060a0949d060b0e4dffb4e2d55433607f69b2",
+ "id": {
+ "id": "0x19d2f72b9058f1e2b7a5ff2624aed7afcc07c2e4",
+ "version": 0
+ },
+ "magic": 10,
+ "strength": 1
+ }
+ }
+ }
+ },
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "previousTransaction": "hka0OV95yi77Y5aeoOA58selKIazvhmv5EXYXM31Quk=",
+ "storageRebate": 22,
+ "reference": {
+ "objectId": "0x9da74a0a4ab5229170deacf33530e39663638bb2",
+ "version": 1,
+ "digest": "2B9baIJN4s9qA7Z5t4NLoYtA1eBu20IDz556K4p+6TU="
+ }
+ }
+ }
+}
diff --git a/sui/open_rpc/samples/transactions.json b/sui/open_rpc/samples/transactions.json
new file mode 100644
index 0000000000000..e4ad72f086c5a
--- /dev/null
+++ b/sui/open_rpc/samples/transactions.json
@@ -0,0 +1,414 @@
+{
+ "move_call": {
+ "EffectResponse": {
+ "certificate": {
+ "transactionDigest": "9kJ9ImsEyufaaqzdwPrAQ8b+L9fu9mjTSyLeyGe55Vk=",
+ "data": {
+ "transactions": [
+ {
+ "Call": {
+ "package": {
+ "objectId": "0x0000000000000000000000000000000000000002",
+ "version": 1,
+ "digest": "8xrIk23UnAReKXZYzKY2PDLsALkXcA5a3xrPldgDlwY="
+ },
+ "module": "DevNetNFT",
+ "function": "mint",
+ "arguments": [
+ "Example NFT",
+ "An NFT created by the wallet Command Line Tool",
+ "ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty"
+ ]
+ }
+ }
+ ],
+ "sender": "0x675ced84037e1ab83177b082d89981b9ca720545",
+ "gasPayment": {
+ "objectId": "0x0c202409b97da9d63179decdc547131123f70444",
+ "version": 0,
+ "digest": "RzCxIKgTPpbWe/wIIP4vLI/evYkGyZhqboeSdW80isw="
+ },
+ "gasBudget": 10000
+ },
+ "txSignature": "+p5BlJ+XH726S2ckmf0XLOkh0Y5gXjJguKb3oSBkMz2Vr4yAoOuS1xdIt7seKz3FT37bCxl29xtWg/b5CMUaAxnk1OQq71z2mLS+PnZRwcxZhkGecGWOO9MMlGsOBC/0",
+ "authSignInfo": {
+ "epoch": 0,
+ "signatures": [
+ [
+ "nIy0Y/xPCSLOr0ADtuS1aPcAl7GmC8+wLgRQyQVB+IQ=",
+ "azgwjBcleDLi7QaXPwoTSeKzVPMrFUe0pky2q31KZXipQ10uk0+3KQkxbYedAghEHjdZE86OA9xfo0n3lz9KAQ=="
+ ],
+ [
+ "XtjdmvKdBoCanT8G0YkfB+0k3vsAds/IUf5XDQw0Cck=",
+ "h4pvEB2N0QguVj3K8KgwnK6CpyHcgbB/TTUlRPdKX11xR6TvcViu+sZ8sahEIsJO0vMvPExwqKpwA0FnF/cLCw=="
+ ],
+ [
+ "ePf1xSQ3krbIge1TwpbLslzZdJ6f9Mdb8v4gMX4Jt3Y=",
+ "eu9e1AnbBAyz68mjE8ReRTHFoYpi8MZDk6s/h7ZgvH9a83p7QhZqZSG5xmW27XoiaKChHNaOkgyiHYHh3nP1AA=="
+ ]
+ ]
+ }
+ },
+ "effects": {
+ "status": {
+ "status": "success",
+ "gas_cost": {
+ "computationCost": 719,
+ "storageCost": 40,
+ "storageRebate": 0
+ }
+ },
+ "transactionDigest": "9kJ9ImsEyufaaqzdwPrAQ8b+L9fu9mjTSyLeyGe55Vk=",
+ "created": [
+ {
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "reference": {
+ "objectId": "0x69cb378ec715bfadcf765fbd06fe31ee28f76426",
+ "version": 1,
+ "digest": "qFEepmg29Sk8HzFm/4XcrcvDOyV9icQhhRd72TZ25H8="
+ }
+ }
+ ],
+ "mutated": [
+ {
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "reference": {
+ "objectId": "0x0c202409b97da9d63179decdc547131123f70444",
+ "version": 1,
+ "digest": "hupcArDLo888jZnqCEEah+1LX5Sl0y428vQIuBZyF44="
+ }
+ }
+ ],
+ "gasObject": {
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "reference": {
+ "objectId": "0x0c202409b97da9d63179decdc547131123f70444",
+ "version": 1,
+ "digest": "hupcArDLo888jZnqCEEah+1LX5Sl0y428vQIuBZyF44="
+ }
+ }
+ }
+ }
+ },
+ "transfer": {
+ "EffectResponse": {
+ "certificate": {
+ "transactionDigest": "32f851bRK1wfG1WxHTw6AP0ZTY8f4r6NboyiZRPqNJw=",
+ "data": {
+ "transactions": [
+ {
+ "TransferCoin": {
+ "recipient": "0x675ced84037e1ab83177b082d89981b9ca720545",
+ "objectRef": {
+ "objectId": "0x0c202409b97da9d63179decdc547131123f70444",
+ "version": 4,
+ "digest": "sUHN3UqZbHOLCPrsQ1j/tiajDzSjLHs10kD8b/URNQE="
+ }
+ }
+ }
+ ],
+ "sender": "0x675ced84037e1ab83177b082d89981b9ca720545",
+ "gasPayment": {
+ "objectId": "0x4a43449008db7c8d408ef3542fa4b850e3cd6035",
+ "version": 1,
+ "digest": "P/wvQruDhH2XYZfPOwCVvyySu7oow0BMMGTOZfN3caI="
+ },
+ "gasBudget": 1000
+ },
+ "txSignature": "jBm30k7aQ+nWLrcL425vLZqbgpFsOpxmLSYJiEx+vnd9k1R2ceXVW47fUhiSUXcALyfXdsain2OnPSuGXkiJCRnk1OQq71z2mLS+PnZRwcxZhkGecGWOO9MMlGsOBC/0",
+ "authSignInfo": {
+ "epoch": 0,
+ "signatures": [
+ [
+ "3dG2xdD+TKr+G0BRj6fs+/aUpJxDomVkM3FHRoZzCJY=",
+ "rGHYLi+RPzztfrRGVx4K8g1vZ5DULBSvOCNDm65DI825TjiEcRAX4NJ4DiPnAzWVu6Nk57bsSwiaUL5nMVjxAw=="
+ ],
+ [
+ "ePf1xSQ3krbIge1TwpbLslzZdJ6f9Mdb8v4gMX4Jt3Y=",
+ "jfvebij5YOfVbwO6dgEtc1wEdkAijdHqs/xhacBG2oXscSONy36ijoJ1bvm0zb0s7VDOqAxIp5HerJD4dcNiCw=="
+ ],
+ [
+ "XtjdmvKdBoCanT8G0YkfB+0k3vsAds/IUf5XDQw0Cck=",
+ "UczsUJFY3e/ehR2cUdbGArAGLTmuRuDqMUgtohlqmnqXnuzHrRa+QbuILGkrROLAGeudoo5FaIcNr+5O/41/Ag=="
+ ]
+ ]
+ }
+ },
+ "effects": {
+ "status": {
+ "status": "success",
+ "gas_cost": {
+ "computationCost": 41,
+ "storageCost": 30,
+ "storageRebate": 30
+ }
+ },
+ "transactionDigest": "32f851bRK1wfG1WxHTw6AP0ZTY8f4r6NboyiZRPqNJw=",
+ "mutated": [
+ {
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "reference": {
+ "objectId": "0x0c202409b97da9d63179decdc547131123f70444",
+ "version": 5,
+ "digest": "bBp66hor3YsQBOJxkNUp335pjrz6IGfNlj0kxV/GLzI="
+ }
+ },
+ {
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "reference": {
+ "objectId": "0x4a43449008db7c8d408ef3542fa4b850e3cd6035",
+ "version": 2,
+ "digest": "YnkRFunVsV3ihcoFRbb1tnyqHiKIihjTcHLfHBGCpy4="
+ }
+ }
+ ],
+ "gasObject": {
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "reference": {
+ "objectId": "0x4a43449008db7c8d408ef3542fa4b850e3cd6035",
+ "version": 2,
+ "digest": "YnkRFunVsV3ihcoFRbb1tnyqHiKIihjTcHLfHBGCpy4="
+ }
+ },
+ "dependencies": [
+ "hka0OV95yi77Y5aeoOA58selKIazvhmv5EXYXM31Quk="
+ ]
+ }
+ }
+ },
+ "coin_split": {
+ "SplitCoinResponse": {
+ "certificate": {
+ "transactionDigest": "UB3QDWeeW//B6Uj0AfiYw3ROPXhfNBjnZhD7+YEGuCo=",
+ "data": {
+ "transactions": [
+ {
+ "Call": {
+ "package": {
+ "objectId": "0x0000000000000000000000000000000000000002",
+ "version": 1,
+ "digest": "8xrIk23UnAReKXZYzKY2PDLsALkXcA5a3xrPldgDlwY="
+ },
+ "module": "Coin",
+ "function": "split_vec",
+ "typeArguments": [
+ "0x2::SUI::SUI"
+ ],
+ "arguments": [
+ "0xc202409b97da9d63179decdc547131123f70444",
+ [
+ 20,
+ 20,
+ 20,
+ 20,
+ 20
+ ]
+ ]
+ }
+ }
+ ],
+ "sender": "0x675ced84037e1ab83177b082d89981b9ca720545",
+ "gasPayment": {
+ "objectId": "0x4a43449008db7c8d408ef3542fa4b850e3cd6035",
+ "version": 2,
+ "digest": "YnkRFunVsV3ihcoFRbb1tnyqHiKIihjTcHLfHBGCpy4="
+ },
+ "gasBudget": 1000
+ },
+ "txSignature": "9jNsbZuMLbz9wJzg6OQg73PP47TRA3HMnFUlxuQ1jIpzNmtcY9baktGsfBsgK9ZbmPayJpqszwM5wRxyzM6xCxnk1OQq71z2mLS+PnZRwcxZhkGecGWOO9MMlGsOBC/0",
+ "authSignInfo": {
+ "epoch": 0,
+ "signatures": [
+ [
+ "XtjdmvKdBoCanT8G0YkfB+0k3vsAds/IUf5XDQw0Cck=",
+ "01LQFz442Hn4OU0PDBsEOx3Rx11KscN2kSIYAnKvan6cdauCv/twwVDYXqG5YP9jFzBFrBxAC/DKUVpyw6viBg=="
+ ],
+ [
+ "ePf1xSQ3krbIge1TwpbLslzZdJ6f9Mdb8v4gMX4Jt3Y=",
+ "PjOcju6dhuye4sJDh5ns44dK6FmjNwWjW5QASpYUVVy+vTgOLllmTHYDUfti1ddlu280POVfz7doTorXhSweAw=="
+ ],
+ [
+ "3dG2xdD+TKr+G0BRj6fs+/aUpJxDomVkM3FHRoZzCJY=",
+ "NAnwp7EwrY6IUdyKb4yBSBHrEyE8XihyZvBMhtudgMahuV9JfGvoPRcR8zrvBq5W24WN30PamCMNPwrM2lPzAw=="
+ ]
+ ]
+ }
+ },
+ "updatedCoin": {
+ "data": {
+ "dataType": "moveObject",
+ "type": "0x2::Coin::Coin<0x2::SUI::SUI>",
+ "fields": {
+ "balance": 95649,
+ "id": {
+ "id": "0x0c202409b97da9d63179decdc547131123f70444",
+ "version": 6
+ }
+ }
+ },
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "previousTransaction": "UB3QDWeeW//B6Uj0AfiYw3ROPXhfNBjnZhD7+YEGuCo=",
+ "storageRebate": 15,
+ "reference": {
+ "objectId": "0x0c202409b97da9d63179decdc547131123f70444",
+ "version": 6,
+ "digest": "Oi03KYMwLk1CbxRTrj5EAcUkckW2Z9oRMeA+TEw79HQ="
+ }
+ },
+ "newCoins": [
+ {
+ "data": {
+ "dataType": "moveObject",
+ "type": "0x2::Coin::Coin<0x2::SUI::SUI>",
+ "fields": {
+ "balance": 20,
+ "id": {
+ "id": "0x0fa0e13483c37d42bd33925a154dd5bbf781a7b0",
+ "version": 1
+ }
+ }
+ },
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "previousTransaction": "UB3QDWeeW//B6Uj0AfiYw3ROPXhfNBjnZhD7+YEGuCo=",
+ "storageRebate": 15,
+ "reference": {
+ "objectId": "0x0fa0e13483c37d42bd33925a154dd5bbf781a7b0",
+ "version": 1,
+ "digest": "INlLPT+PgAueYjWspDWBnjlb9gisct74YzkmtHKrJik="
+ }
+ },
+ {
+ "data": {
+ "dataType": "moveObject",
+ "type": "0x2::Coin::Coin<0x2::SUI::SUI>",
+ "fields": {
+ "balance": 20,
+ "id": {
+ "id": "0x294e8b52f9189879f5688d917fb973a5854e1533",
+ "version": 1
+ }
+ }
+ },
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "previousTransaction": "UB3QDWeeW//B6Uj0AfiYw3ROPXhfNBjnZhD7+YEGuCo=",
+ "storageRebate": 15,
+ "reference": {
+ "objectId": "0x294e8b52f9189879f5688d917fb973a5854e1533",
+ "version": 1,
+ "digest": "l92xxANQ5L2kHEB/t/GwgHiovdUO5gocAwqT3plBoxU="
+ }
+ },
+ {
+ "data": {
+ "dataType": "moveObject",
+ "type": "0x2::Coin::Coin<0x2::SUI::SUI>",
+ "fields": {
+ "balance": 20,
+ "id": {
+ "id": "0x355b296c205554a48bde0e56d53a47300ca6acff",
+ "version": 1
+ }
+ }
+ },
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "previousTransaction": "UB3QDWeeW//B6Uj0AfiYw3ROPXhfNBjnZhD7+YEGuCo=",
+ "storageRebate": 15,
+ "reference": {
+ "objectId": "0x355b296c205554a48bde0e56d53a47300ca6acff",
+ "version": 1,
+ "digest": "9BD/QV8o63C7lDLV3QBTY0kSVaq5udZBajvh4mmIR2E="
+ }
+ },
+ {
+ "data": {
+ "dataType": "moveObject",
+ "type": "0x2::Coin::Coin<0x2::SUI::SUI>",
+ "fields": {
+ "balance": 20,
+ "id": {
+ "id": "0x3ba489eeaea947d17d0c9dedce2166c2a64addf0",
+ "version": 1
+ }
+ }
+ },
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "previousTransaction": "UB3QDWeeW//B6Uj0AfiYw3ROPXhfNBjnZhD7+YEGuCo=",
+ "storageRebate": 15,
+ "reference": {
+ "objectId": "0x3ba489eeaea947d17d0c9dedce2166c2a64addf0",
+ "version": 1,
+ "digest": "2YNBSmQIMikFeaXBiDph3wLtCQfyZKWiWDCHRLboPDM="
+ }
+ },
+ {
+ "data": {
+ "dataType": "moveObject",
+ "type": "0x2::Coin::Coin<0x2::SUI::SUI>",
+ "fields": {
+ "balance": 20,
+ "id": {
+ "id": "0xc802ca70359531667762fc1603a3d3c4b550a1d2",
+ "version": 1
+ }
+ }
+ },
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "previousTransaction": "UB3QDWeeW//B6Uj0AfiYw3ROPXhfNBjnZhD7+YEGuCo=",
+ "storageRebate": 15,
+ "reference": {
+ "objectId": "0xc802ca70359531667762fc1603a3d3c4b550a1d2",
+ "version": 1,
+ "digest": "jfnlfFCQtoggswf5q/3OYs20JsVFCfNFPC6Y557bd0I="
+ }
+ }
+ ],
+ "updatedGas": {
+ "data": {
+ "dataType": "moveObject",
+ "type": "0x2::Coin::Coin<0x2::SUI::SUI>",
+ "fields": {
+ "balance": 98958,
+ "id": {
+ "id": "0x4a43449008db7c8d408ef3542fa4b850e3cd6035",
+ "version": 3
+ }
+ }
+ },
+ "owner": {
+ "AddressOwner": "0x675ced84037e1ab83177b082d89981b9ca720545"
+ },
+ "previousTransaction": "UB3QDWeeW//B6Uj0AfiYw3ROPXhfNBjnZhD7+YEGuCo=",
+ "storageRebate": 15,
+ "reference": {
+ "objectId": "0x4a43449008db7c8d408ef3542fa4b850e3cd6035",
+ "version": 3,
+ "digest": "Ma73kod8I+f/3691m8rGwZIpp1dOU0ACDN0eWL9WUXo="
+ }
+ }
+ }
+ }
+}
diff --git a/sui/src/generate_json_rpc_spec.rs b/sui/src/generate_json_rpc_spec.rs
index 45a0f2299e9b9..d48fc7af1f6a1 100644
--- a/sui/src/generate_json_rpc_spec.rs
+++ b/sui/src/generate_json_rpc_spec.rs
@@ -1,14 +1,28 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
+extern crate core;
+
use std::fs::File;
use std::io::Write;
use clap::ArgEnum;
use clap::Parser;
use pretty_assertions::assert_str_eq;
+use serde::Serialize;
+use serde_json::json;
use sui::api::RpcGatewayOpenRpc;
+use sui::config::SUI_WALLET_CONFIG;
+use sui::wallet_commands::{WalletCommandResult, WalletCommands, WalletContext};
+use sui::wallet_commands::{EXAMPLE_NFT_DESCRIPTION, EXAMPLE_NFT_NAME, EXAMPLE_NFT_URL};
+use sui_core::gateway_types::{
+ GetObjectInfoResponse, SuiObjectRef, TransactionEffectsResponse, TransactionResponse,
+};
+use sui_core::sui_json::SuiJsonValue;
+use sui_types::base_types::{ObjectID, SuiAddress};
+use sui_types::SUI_FRAMEWORK_ADDRESS;
+use test_utils::network::start_test_network;
#[derive(Debug, Parser, Clone, Copy, ArgEnum)]
enum Action {
@@ -28,19 +42,32 @@ struct Options {
}
const FILE_PATH: &str = "sui/open_rpc/spec/openrpc.json";
+const OBJECT_SAMPLE_FILE_PATH: &str = "sui/open_rpc/samples/objects.json";
+const TRANSACTION_SAMPLE_FILE_PATH: &str = "sui/open_rpc/samples/transactions.json";
-fn main() {
+#[tokio::main]
+async fn main() {
let options = Options::parse();
let open_rpc = RpcGatewayOpenRpc::open_rpc();
match options.action {
Action::Print => {
let content = serde_json::to_string_pretty(&open_rpc).unwrap();
println!("{content}");
+ let (objects, txs) = create_response_sample().await.unwrap();
+ println!("{}", serde_json::to_string_pretty(&objects).unwrap());
+ println!("{}", serde_json::to_string_pretty(&txs).unwrap());
}
Action::Record => {
let content = serde_json::to_string_pretty(&open_rpc).unwrap();
let mut f = File::create(FILE_PATH).unwrap();
writeln!(f, "{content}").unwrap();
+ let (objects, txs) = create_response_sample().await.unwrap();
+ let content = serde_json::to_string_pretty(&objects).unwrap();
+ let mut f = File::create(OBJECT_SAMPLE_FILE_PATH).unwrap();
+ writeln!(f, "{content}").unwrap();
+ let content = serde_json::to_string_pretty(&txs).unwrap();
+ let mut f = File::create(TRANSACTION_SAMPLE_FILE_PATH).unwrap();
+ writeln!(f, "{content}").unwrap();
}
Action::Test => {
let reference = std::fs::read_to_string(FILE_PATH).unwrap();
@@ -49,3 +76,215 @@ fn main() {
}
}
}
+
+async fn create_response_sample(
+) -> Result<(ObjectResponseSample, TransactionResponseSample), anyhow::Error> {
+ let working_dir = tempfile::tempdir()?;
+ let working_dir = working_dir.path();
+ let network = start_test_network(working_dir, None).await?;
+ let config = working_dir.join(SUI_WALLET_CONFIG);
+
+ let mut context = WalletContext::new(&config)?;
+ let address = context.config.accounts.first().cloned().unwrap();
+
+ context.gateway.sync_account_state(address).await?;
+
+ // Create coin response
+ let coins = context.gateway.get_owned_objects(address).await?;
+ let coin = context
+ .gateway
+ .get_object_info(coins.first().unwrap().object_id)
+ .await?;
+
+ let (example_nft_tx, example_nft) = get_nft_response(&mut context).await?;
+ let move_package = create_package_object_response(&mut context).await?;
+ let hero = create_hero_response(&mut context, &coins).await?;
+ let transfer = create_transfer_response(&mut context, address, &coins).await?;
+ let coin_split = create_coin_split_response(&mut context, coins).await?;
+
+ let objects = ObjectResponseSample {
+ example_nft,
+ coin,
+ move_package,
+ hero,
+ };
+
+ let txs = TransactionResponseSample {
+ move_call: example_nft_tx,
+ transfer,
+ coin_split,
+ };
+
+ network.kill().await?;
+
+ Ok((objects, txs))
+}
+
+async fn create_package_object_response(
+ context: &mut WalletContext,
+) -> Result {
+ let result = WalletCommands::Publish {
+ path: "sui_programmability/tutorial".to_string(),
+ gas: None,
+ gas_budget: 10000,
+ }
+ .execute(context)
+ .await?;
+ if let WalletCommandResult::Publish(response) = result {
+ Ok(context
+ .gateway
+ .get_object_info(response.package.object_id)
+ .await?)
+ } else {
+ panic!()
+ }
+}
+
+async fn create_transfer_response(
+ context: &mut WalletContext,
+ address: SuiAddress,
+ coins: &[SuiObjectRef],
+) -> Result {
+ let response = WalletCommands::Transfer {
+ to: address,
+ coin_object_id: coins.first().unwrap().object_id,
+ gas: None,
+ gas_budget: 1000,
+ }
+ .execute(context)
+ .await?;
+ if let WalletCommandResult::Transfer(_, certificate, effects) = response {
+ Ok(TransactionResponse::EffectResponse(
+ TransactionEffectsResponse {
+ certificate,
+ effects,
+ },
+ ))
+ } else {
+ panic!()
+ }
+}
+
+async fn create_hero_response(
+ context: &mut WalletContext,
+ coins: &[SuiObjectRef],
+) -> Result {
+ // Create hero response
+ let result = WalletCommands::Publish {
+ path: "sui_programmability/examples/games".to_string(),
+ gas: None,
+ gas_budget: 10000,
+ }
+ .execute(context)
+ .await?;
+ if let WalletCommandResult::Publish(response) = result {
+ let package_id = response.package.object_id;
+ let game_info = response
+ .created_objects
+ .iter()
+ .find(|o| o.data.type_().unwrap().ends_with("GameInfo"))
+ .unwrap();
+
+ let game_info = SuiJsonValue::new(json!(game_info.reference.object_id.to_hex_literal()))?;
+ let coin = SuiJsonValue::new(json!(coins.first().unwrap().object_id.to_hex_literal()))?;
+ let result = WalletCommands::Call {
+ package: package_id,
+ module: "Hero".to_string(),
+ function: "acquire_hero".to_string(),
+ type_args: vec![],
+ args: vec![game_info, coin],
+ gas: None,
+ gas_budget: 10000,
+ }
+ .execute(context)
+ .await?;
+
+ if let WalletCommandResult::Call(_, effect) = result {
+ let hero = effect.created.first().unwrap();
+ Ok(context
+ .gateway
+ .get_object_info(hero.reference.object_id)
+ .await?)
+ } else {
+ panic!()
+ }
+ } else {
+ panic!()
+ }
+}
+
+async fn create_coin_split_response(
+ context: &mut WalletContext,
+ coins: Vec,
+) -> Result {
+ // create coin_split response
+ let result = WalletCommands::SplitCoin {
+ coin_id: coins.first().unwrap().object_id,
+ amounts: vec![20, 20, 20, 20, 20],
+ gas: None,
+ gas_budget: 1000,
+ }
+ .execute(context)
+ .await?;
+
+ if let WalletCommandResult::SplitCoin(resp) = result {
+ Ok(TransactionResponse::SplitCoinResponse(resp))
+ } else {
+ panic!()
+ }
+}
+
+async fn get_nft_response(
+ context: &mut WalletContext,
+) -> Result<(TransactionResponse, GetObjectInfoResponse), anyhow::Error> {
+ // Create example-nft response
+ let args_json = json!([EXAMPLE_NFT_NAME, EXAMPLE_NFT_DESCRIPTION, EXAMPLE_NFT_URL]);
+ let args = args_json
+ .as_array()
+ .unwrap()
+ .iter()
+ .cloned()
+ .map(SuiJsonValue::new)
+ .collect::>()?;
+
+ let result = WalletCommands::Call {
+ package: ObjectID::from(SUI_FRAMEWORK_ADDRESS),
+ module: "DevNetNFT".to_string(),
+ function: "mint".to_string(),
+ type_args: vec![],
+ args,
+ gas: None,
+ gas_budget: 10000,
+ }
+ .execute(context)
+ .await?;
+
+ if let WalletCommandResult::Call(certificate, effects) = result {
+ let object = context
+ .gateway
+ .get_object_info(effects.created.first().unwrap().reference.object_id)
+ .await?;
+ let tx = TransactionResponse::EffectResponse(TransactionEffectsResponse {
+ certificate,
+ effects,
+ });
+ Ok((tx, object))
+ } else {
+ panic!()
+ }
+}
+
+#[derive(Serialize)]
+struct ObjectResponseSample {
+ pub example_nft: GetObjectInfoResponse,
+ pub coin: GetObjectInfoResponse,
+ pub move_package: GetObjectInfoResponse,
+ pub hero: GetObjectInfoResponse,
+}
+
+#[derive(Serialize)]
+struct TransactionResponseSample {
+ pub move_call: TransactionResponse,
+ pub transfer: TransactionResponse,
+ pub coin_split: TransactionResponse,
+}
diff --git a/sui/src/wallet_commands.rs b/sui/src/wallet_commands.rs
index a439e6d448196..0c60958567a9b 100644
--- a/sui/src/wallet_commands.rs
+++ b/sui/src/wallet_commands.rs
@@ -38,9 +38,10 @@ use crate::{
keystore::Keystore,
};
-const EXAMPLE_NFT_NAME: &str = "Example NFT";
-const EXAMPLE_NFT_DESCRIPTION: &str = "An NFT created by the wallet Command Line Tool";
-const EXAMPLE_NFT_URL: &str = "ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty";
+pub const EXAMPLE_NFT_NAME: &str = "Example NFT";
+pub const EXAMPLE_NFT_DESCRIPTION: &str = "An NFT created by the wallet Command Line Tool";
+pub const EXAMPLE_NFT_URL: &str =
+ "ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty";
#[derive(Parser)]
#[clap(name = "", rename_all = "kebab-case", no_binary_name = true)]