Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[ts-sdk] tx block rename #9941

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getPureSerializationType,
getExecutionStatusType,
getExecutionStatusError,
Transaction,
TransactionBlock,
} from '@mysten/sui.js';
import { useWalletKit, ConnectButton } from '@mysten/wallet-kit';
import { useMutation } from '@tanstack/react-query';
Expand Down Expand Up @@ -71,7 +71,7 @@ export function ModuleFunction({

const execute = useMutation({
mutationFn: async ({ params, types }: TypeOf<typeof argsSchema>) => {
const tx = new Transaction();
const tx = new TransactionBlock();
tx.moveCall({
target: `${packageId}::${moduleName}::${functionName}`,
typeArguments: types ?? [],
Expand All @@ -86,7 +86,7 @@ export function ModuleFunction({
) ?? [],
});
const result = await signAndExecuteTransaction({
transaction: tx,
transactionBlock: tx,
options: {
showEffects: true,
showEvents: true,
Expand Down
6 changes: 3 additions & 3 deletions apps/explorer/tests/utils/localnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
RawSigner,
type Keypair,
localnetConnection,
Transaction,
TransactionBlock,
} from '@mysten/sui.js';

const addressToKeypair = new Map<string, Keypair>();
Expand All @@ -28,15 +28,15 @@ export async function split_coin(address: string) {
const coins = await provider.getCoins({ owner: address });
const coin_id = coins.data[0].coinObjectId;

const tx = new Transaction();
const tx = new TransactionBlock();
tx.moveCall({
target: '0x2::pay::split',
typeArguments: ['0x2::sui::SUI'],
arguments: [tx.object(coin_id), tx.pure(10)],
});

const result = await signer.signAndExecuteTransaction({
transaction: tx,
transactionBlock: tx,
options: {
showInput: true,
showEffects: true,
Expand Down
10 changes: 5 additions & 5 deletions apps/wallet/src/dapp-interface/WalletStandardInterface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { type SuiAddress, toB64, Transaction } from '@mysten/sui.js';
import { type SuiAddress, toB64, TransactionBlock } from '@mysten/sui.js';
import {
SUI_CHAINS,
ReadonlyWalletAccount,
Expand Down Expand Up @@ -225,7 +225,7 @@ export class SuiWallet implements Wallet {
};

#signTransaction: SuiSignTransactionMethod = async (input) => {
if (!Transaction.is(input.transaction)) {
if (!TransactionBlock.is(input.transactionBlock)) {
throw new Error(
'Unexpect transaction format found. Ensure that you are using the `Transaction` class.'
);
Expand All @@ -242,7 +242,7 @@ export class SuiWallet implements Wallet {
input.account?.address ||
this.#accounts[0]?.address ||
'',
transaction: input.transaction.serialize(),
transaction: input.transactionBlock.serialize(),
},
}),
(response) => response.result
Expand All @@ -252,7 +252,7 @@ export class SuiWallet implements Wallet {
#signAndExecuteTransaction: SuiSignAndExecuteTransactionMethod = async (
input
) => {
if (!Transaction.is(input.transaction)) {
if (!TransactionBlock.is(input.transactionBlock)) {
throw new Error(
'Unexpect transaction format found. Ensure that you are using the `Transaction` class.'
);
Expand All @@ -263,7 +263,7 @@ export class SuiWallet implements Wallet {
type: 'execute-transaction-request',
transaction: {
type: 'transaction',
data: input.transaction.serialize(),
data: input.transactionBlock.serialize(),
options: input.options,
// account might be undefined if previous version of adapters is used
// in that case use the first account address
Expand Down
14 changes: 9 additions & 5 deletions apps/wallet/src/ui/app/hooks/useTransactionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
// SPDX-License-Identifier: Apache-2.0

import { useFormatCoin, useRpcClient } from '@mysten/core';
import { type SuiAddress, SUI_TYPE_ARG, Transaction } from '@mysten/sui.js';
import {
type SuiAddress,
SUI_TYPE_ARG,
TransactionBlock,
} from '@mysten/sui.js';
import { useQuery } from '@tanstack/react-query';
import { useMemo } from 'react';

export function useTransactionData(
sender?: SuiAddress | null,
transaction?: Transaction | null
transaction?: TransactionBlock | null
) {
const rpc = useRpcClient();
const clonedTransaction = useMemo(() => {
if (!transaction) return;

const tx = new Transaction(transaction);
const tx = new TransactionBlock(transaction);
if (sender) {
tx.setSenderIfNotSet(sender);
}
Expand All @@ -26,7 +30,7 @@ export function useTransactionData(
async () => {
// Build the transaction to bytes, which will ensure that the transaction data is fully populated:
await clonedTransaction!.build({ provider: rpc });
return clonedTransaction!.transactionData;
return clonedTransaction!.blockData;
},
{
enabled: !!clonedTransaction,
Expand All @@ -36,7 +40,7 @@ export function useTransactionData(

export function useTransactionGasBudget(
sender?: SuiAddress | null,
transaction?: Transaction | null
transaction?: TransactionBlock | null
) {
const { data, ...rest } = useTransactionData(sender, transaction);

Expand Down
8 changes: 4 additions & 4 deletions apps/wallet/src/ui/app/hooks/useTransactionDryRun.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { type SuiAddress, type Transaction } from '@mysten/sui.js';
import { type SuiAddress, type TransactionBlock } from '@mysten/sui.js';
import { useQuery } from '@tanstack/react-query';

import { useSigner } from '_hooks';

export function useTransactionDryRun(
sender: SuiAddress | undefined,
transaction: Transaction
transactionBlock: TransactionBlock
) {
const signer = useSigner(sender);
const response = useQuery({
queryKey: ['dryRunTransaction', transaction.serialize()],
queryKey: ['dryRunTransaction', transactionBlock.serialize()],
queryFn: () => {
return signer.dryRunTransaction({ transaction });
return signer.dryRunTransaction({ transactionBlock });
},
});
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {
formatAddress,
type SuiAddress,
type Transaction,
type TransactionBlock,
} from '@mysten/sui.js';

import { DescriptionItem, DescriptionList } from './DescriptionList';
Expand All @@ -14,7 +14,7 @@ import { GAS_SYMBOL } from '_src/ui/app/redux/slices/sui-objects/Coin';

interface Props {
sender?: SuiAddress;
transaction: Transaction;
transaction: TransactionBlock;
}

export function GasFees({ sender, transaction }: Props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

import { ChevronDown12, ChevronRight12 } from '@mysten/icons';
import {
type CommandArgument,
type TransactionArgument,
formatAddress,
type TransactionCommand,
type TransactionType,
normalizeSuiAddress,
} from '@mysten/sui.js';
import { useState } from 'react';

import { Text } from '_src/ui/app/shared/text';

function convertCommandArgumentToString(
arg: string | string[] | CommandArgument | CommandArgument[]
arg: string | string[] | TransactionArgument | TransactionArgument[]
): string {
if (typeof arg === 'string') return arg;

Expand All @@ -37,7 +37,7 @@ function convertCommandArgumentToString(
}
}

function convertCommandToString({ kind, ...command }: TransactionCommand) {
function convertCommandToString({ kind, ...command }: TransactionType) {
const commandArguments = Object.entries(command);

return commandArguments
Expand All @@ -57,7 +57,7 @@ function convertCommandToString({ kind, ...command }: TransactionCommand) {
}

interface CommandProps {
command: TransactionCommand;
command: TransactionType;
}

export function Command({ command }: CommandProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
formatAddress,
is,
toB64,
type TransactionInput,
type TransactionBlockInput,
} from '@mysten/sui.js';

import ExplorerLink from '_src/ui/app/components/explorer-link';
import { ExplorerLinkType } from '_src/ui/app/components/explorer-link/ExplorerLinkType';
import { Text } from '_src/ui/app/shared/text';

interface InputProps {
input: TransactionInput;
input: TransactionBlockInput;
}

export function Input({ input }: InputProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { Tab as HeadlessTab, type TabProps } from '@headlessui/react';
import { type SuiAddress, type Transaction } from '@mysten/sui.js';
import { type SuiAddress, type TransactionBlock } from '@mysten/sui.js';

import { SummaryCard } from '../SummaryCard';
import { Command } from './Command';
Expand All @@ -12,7 +12,7 @@ import { useTransactionData } from '_src/ui/app/hooks';

interface Props {
sender?: SuiAddress;
transaction: Transaction;
transaction: TransactionBlock;
}

const Tab = (props: TabProps<'div'>) => (
Expand All @@ -26,7 +26,7 @@ export function TransactionDetails({ sender, transaction }: Props) {
const { data: transactionData } = useTransactionData(sender, transaction);

if (
transactionData?.commands.length === 0 &&
transactionData?.transactions.length === 0 &&
transactionData.inputs.length === 0
) {
return null;
Expand All @@ -38,17 +38,18 @@ export function TransactionDetails({ sender, transaction }: Props) {
<div>
<HeadlessTab.Group>
<HeadlessTab.List className="flex gap-6 border-0 border-b border-solid border-gray-45 mb-6">
{!!transactionData.commands.length && (
<Tab>Commands</Tab>
{!!transactionData.transactions.length && (
<Tab>Transactions</Tab>
)}
{!!transactionData.inputs.length && (
<Tab>Inputs</Tab>
)}
</HeadlessTab.List>
<HeadlessTab.Panels>
{!!transactionData.commands.length && (
{!!transactionData.transactions.length && (
<HeadlessTab.Panel className="flex flex-col gap-6">
{transactionData.commands.map(
{/* TODO: Rename components: */}
{transactionData.transactions.map(
(command, index) => (
<Command
key={index}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

// import { Transaction } from '@mysten/sui.js';
import { Transaction } from '@mysten/sui.js';
import { TransactionBlock } from '@mysten/sui.js';
import { useCallback, useMemo } from 'react';

import { GasFees } from './GasFees';
Expand All @@ -24,7 +24,7 @@ export function TransactionRequest({ txRequest }: TransactionRequestProps) {
const signer = useSigner(addressForTransaction);
const dispatch = useAppDispatch();
const transaction = useMemo(() => {
const tx = Transaction.from(txRequest.tx.data);
const tx = TransactionBlock.from(txRequest.tx.data);
if (addressForTransaction) {
tx.setSenderIfNotSet(addressForTransaction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { ArrowRight16 } from '@mysten/icons';
import { getTransactionDigest, Transaction } from '@mysten/sui.js';
import { getTransactionDigest, TransactionBlock } from '@mysten/sui.js';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { Form, Field, Formik } from 'formik';
import { toast } from 'react-hot-toast';
Expand Down Expand Up @@ -34,11 +34,11 @@ export function TransferNFTForm({ objectId }: { objectId: string }) {
if (!to || !signer) {
throw new Error('Missing data');
}
const tx = new Transaction();
const tx = new TransactionBlock();
tx.transferObjects([tx.object(objectId)], tx.pure(to));

return signer.signAndExecuteTransaction({
transaction: tx,
transactionBlock: tx,
options: {
showInput: true,
showEffects: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { useCoinDecimals } from '@mysten/core';
import { type Transaction } from '@mysten/sui.js';
import { type TransactionBlock } from '@mysten/sui.js';

import { Text } from '_app/shared/text';
import { TxnAddress } from '_components/receipt-card/TxnAddress';
Expand All @@ -17,7 +17,7 @@ export type PreviewTransferProps = {
to: string;
amount: string;
approximation?: boolean;
transaction: Transaction | null;
transaction: TransactionBlock | null;
};

export function PreviewTransfer({
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet/src/ui/app/pages/home/transfer-coin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function TransferCoinPage() {
});

return signer.signAndExecuteTransaction({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also rename this to signAndExecuteTransactionBlock?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah happening in this follow-up: #9946

transaction,
transactionBlock: transaction,
options: {
showInput: true,
showEffects: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { type CoinStruct, SUI_TYPE_ARG, Transaction } from '@mysten/sui.js';
import {
type CoinStruct,
SUI_TYPE_ARG,
TransactionBlock,
} from '@mysten/sui.js';

import { parseAmount } from '_src/ui/app/helpers';

Expand All @@ -22,7 +26,7 @@ export function createTokenTransferTransaction({
coinDecimals,
isPayAllSui,
}: Options) {
const tx = new Transaction();
const tx = new TransactionBlock();

if (isPayAllSui && coinType === SUI_TYPE_ARG) {
tx.transferObjects([tx.gas], tx.pure(to));
Expand Down
Loading