Skip to content

Commit

Permalink
Make type_arguments optional and publically rename to typeArguments (#71
Browse files Browse the repository at this point in the history
)

* Make type_arguments optional and publically rename to typeArguments

* Update index.ts

* Update fixed-bytes.ts
  • Loading branch information
heliuchuan authored Oct 16, 2023
1 parent 237e513 commit 2613082
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 78 deletions.
1 change: 0 additions & 1 deletion examples/javascript/simple_sponsored_transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const TRANSFER_AMOUNT = 10;
feePayerAddress: sponsorAddress,
data: {
function: "0x1::aptos_account::transfer",
type_arguments: [],
arguments: [bob.accountAddress, new aptos.U64(TRANSFER_AMOUNT)],
},
});
Expand Down
1 change: 0 additions & 1 deletion examples/typescript/simple_sponsored_transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const example = async () => {
feePayerAddress: sponsorAddress,
data: {
function: "0x1::aptos_account::transfer",
type_arguments: [],
arguments: [bob.accountAddress, new U64(TRANSFER_AMOUNT)],
},
});
Expand Down
4 changes: 2 additions & 2 deletions src/api/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
LedgerVersion,
MoveValue,
TableItemRequest,
ViewRequest,
ViewRequestData,
} from "../types";
import { AptosConfig } from "./aptos_config";

Expand Down Expand Up @@ -127,7 +127,7 @@ export class General {
*
* @returns an array of Move values
*/
async view(args: { payload: ViewRequest; options?: LedgerVersion }): Promise<Array<MoveValue>> {
async view(args: { payload: ViewRequestData; options?: LedgerVersion }): Promise<Array<MoveValue>> {
const data = await view({ aptosConfig: this.config, ...args });
return data;
}
Expand Down
1 change: 0 additions & 1 deletion src/bcs/serializable/fixed-bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { TransactionArgument } from "../../transactions/instances/transactionArg
* const fixedBytes = new FixedBytes(yourCustomSerializedBytes);
* const payload = generateTransactionPayload({
* function: "0xbeefcafe::your_module::your_function_that_requires_custom_serialization",
* type_arguments: [],
* arguments: [yourCustomBytes],
* });
*
Expand Down
2 changes: 1 addition & 1 deletion src/internal/coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function transferCoinTransaction(args: {
sender: sender.accountAddress.toString(),
data: {
function: "0x1::aptos_account::transfer_coins",
type_arguments: [new TypeTagStruct(StructTag.fromString(coinStructType))],
typeArguments: [new TypeTagStruct(StructTag.fromString(coinStructType))],
arguments: [AccountAddress.fromHexInput(recipient), new U64(amount)],
},
options,
Expand Down
9 changes: 7 additions & 2 deletions src/internal/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
MoveValue,
TableItemRequest,
ViewRequest,
ViewRequestData,
} from "../types";
import { GetChainTopUserTransactionsQuery, GetProcessorStatusQuery } from "../types/generated/operations";
import { GetChainTopUserTransactions, GetProcessorStatus } from "../types/generated/queries";
Expand Down Expand Up @@ -83,7 +84,7 @@ export async function getTableItem(args: {

export async function view(args: {
aptosConfig: AptosConfig;
payload: ViewRequest;
payload: ViewRequestData;
options?: LedgerVersion;
}): Promise<MoveValue[]> {
const { aptosConfig, payload, options } = args;
Expand All @@ -92,7 +93,11 @@ export async function view(args: {
originMethod: "view",
path: "view",
params: { ledger_version: options?.ledgerVersion },
body: payload,
body: {
function: payload.function,
type_arguments: payload.typeArguments ?? [],
arguments: payload.arguments ?? [],
},
});
return data;
}
Expand Down
6 changes: 3 additions & 3 deletions src/transactions/transaction_builder/transaction_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function generateTransactionPayload(args: GenerateTransactionPayloadData)
// generate script payload
if ("bytecode" in args) {
const scriptPayload = new TransactionPayloadScript(
new Script(hexToBytes(args.bytecode), args.type_arguments, args.arguments),
new Script(hexToBytes(args.bytecode), args.typeArguments ?? [], args.arguments),
);
return scriptPayload;
}
Expand All @@ -106,7 +106,7 @@ export function generateTransactionPayload(args: GenerateTransactionPayloadData)
EntryFunction.build(
`${funcNameParts[0]}::${funcNameParts[1]}`,
funcNameParts[2],
args.type_arguments,
args.typeArguments ?? [],
args.arguments,
),
),
Expand All @@ -121,7 +121,7 @@ export function generateTransactionPayload(args: GenerateTransactionPayloadData)
EntryFunction.build(
`${funcNameParts[0]}::${funcNameParts[1]}`,
funcNameParts[2],
args.type_arguments,
args.typeArguments ?? [],
args.arguments,
),
);
Expand Down
4 changes: 2 additions & 2 deletions src/transactions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export type GenerateTransactionPayloadData = EntryFunctionData | ScriptData | Mu
*/
export type EntryFunctionData = {
function: MoveStructType;
type_arguments: Array<TypeTag>;
typeArguments?: Array<TypeTag>;
arguments: Array<EntryFunctionArgumentTypes>;
};

Expand All @@ -100,7 +100,7 @@ export type MultiSigData = {
*/
export type ScriptData = {
bytecode: string;
type_arguments: Array<TypeTag>;
typeArguments?: Array<TypeTag>;
arguments: Array<ScriptFunctionArgumentTypes>;
};

Expand Down
9 changes: 9 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,15 @@ export type Block = {
transactions?: Array<TransactionResponse>;
};

/**
* The data needed to generate a View Request payload
*/
export type ViewRequestData = {
function: MoveStructType;
typeArguments?: Array<MoveResourceType>;
arguments?: Array<MoveValue>;
};

// REQUEST TYPES

/**
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/api/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ describe("account api", () => {
sender: senderAccount.accountAddress.toString(),
data: {
function: "0x1::aptos_account::transfer",
type_arguments: [],
arguments: [bob.accountAddress, new U64(10)],
},
});
Expand Down
6 changes: 2 additions & 4 deletions tests/e2e/api/general.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { AptosConfig, Aptos, Network, GraphqlQuery, ViewRequest } from "../../../src";
import { AptosConfig, Aptos, Network, GraphqlQuery, ViewRequestData } from "../../../src";

describe("general api", () => {
test("it fetches ledger info", async () => {
Expand Down Expand Up @@ -38,10 +38,8 @@ describe("general api", () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);

const payload: ViewRequest = {
const payload: ViewRequestData = {
function: "0x1::chain_id::get",
type_arguments: [],
arguments: [],
};

const chainId = await aptos.view({ payload });
Expand Down
2 changes: 0 additions & 2 deletions tests/e2e/api/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe("transaction api", () => {
sender: senderAccount.accountAddress.toString(),
data: {
function: "0x1::aptos_account::transfer",
type_arguments: [],
arguments: [bob.accountAddress, new U64(10)],
},
});
Expand All @@ -50,7 +49,6 @@ describe("transaction api", () => {
sender: senderAccount.accountAddress.toString(),
data: {
function: "0x1::aptos_account::transfer",
type_arguments: [],
arguments: [bob.accountAddress, new U64(10)],
},
});
Expand Down
9 changes: 0 additions & 9 deletions tests/e2e/transaction/generate_transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe("generate transaction", () => {
sender: senderAccount.accountAddress.toString(),
data: {
bytecode: singleSignerScriptBytecode,
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand All @@ -43,7 +42,6 @@ describe("generate transaction", () => {
data: {
multisigAddress: secondarySignerAccount.accountAddress,
function: "0x0000000000000000000000000000000000000000000000000000000000000123::module::name",
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand All @@ -61,7 +59,6 @@ describe("generate transaction", () => {
sender: senderAccount.accountAddress.toString(),
data: {
function: "0x0000000000000000000000000000000000000000000000000000000000000123::module::name",
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand All @@ -82,7 +79,6 @@ describe("generate transaction", () => {
secondarySignerAddresses: [secondarySignerAccount.accountAddress.toString()],
data: {
bytecode: singleSignerScriptBytecode,
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand All @@ -101,7 +97,6 @@ describe("generate transaction", () => {
secondarySignerAddresses: [secondarySignerAccount.accountAddress.toString()],
data: {
function: "0x0000000000000000000000000000000000000000000000000000000000000123::module::name",
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand All @@ -122,7 +117,6 @@ describe("generate transaction", () => {
feePayerAddress: feePayerAccount.accountAddress.toString(),
data: {
bytecode: singleSignerScriptBytecode,
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand All @@ -142,7 +136,6 @@ describe("generate transaction", () => {
data: {
multisigAddress: secondarySignerAccount.accountAddress,
function: "0x0000000000000000000000000000000000000000000000000000000000000123::module::name",
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand All @@ -161,7 +154,6 @@ describe("generate transaction", () => {
feePayerAddress: feePayerAccount.accountAddress.toString(),
data: {
function: "0x0000000000000000000000000000000000000000000000000000000000000123::module::name",
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand All @@ -181,7 +173,6 @@ describe("generate transaction", () => {
feePayerAddress: feePayerAccount.accountAddress.toString(),
data: {
function: "0x0000000000000000000000000000000000000000000000000000000000000123::module::name",
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/transaction/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export async function publishModule(
sender: senderAccount.accountAddress.toString(),
data: {
function: "0x1::code::publish_package_txn",
type_arguments: [],
arguments: [MoveVector.U8(metadataBytes), new MoveVector([MoveVector.U8(codeBytes)])],
},
});
Expand Down Expand Up @@ -61,7 +60,7 @@ export async function rawTransactionHelper(
sender: senderAccount.accountAddress.toString(),
data: {
function: `0x${senderAccount.accountAddress.toStringWithoutPrefix()}::tx_args_module::${functionName}`,
type_arguments: typeArgs,
typeArguments: typeArgs,
arguments: args,
},
});
Expand Down
6 changes: 0 additions & 6 deletions tests/e2e/transaction/sign_transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe("sign transaction", () => {
sender: senderAccount.accountAddress.toString(),
data: {
bytecode: singleSignerScriptBytecode,
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand All @@ -51,7 +50,6 @@ describe("sign transaction", () => {
sender: senderAccount.accountAddress.toString(),
data: {
function: `0x${senderAccount.accountAddress.toStringWithoutPrefix()}::transfer::transfer`,
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand All @@ -70,7 +68,6 @@ describe("sign transaction", () => {
data: {
multisigAddress: secondarySignerAccount.accountAddress,
function: `0x${senderAccount.accountAddress.toStringWithoutPrefix()}::transfer::transfer`,
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand All @@ -91,7 +88,6 @@ describe("sign transaction", () => {
sender: senderSecp256k1Account.accountAddress.toString(),
data: {
bytecode: singleSignerScriptBytecode,
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand All @@ -109,7 +105,6 @@ describe("sign transaction", () => {
sender: senderSecp256k1Account.accountAddress.toString(),
data: {
function: `0x${senderAccount.accountAddress.toStringWithoutPrefix()}::transfer::transfer`,
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand All @@ -128,7 +123,6 @@ describe("sign transaction", () => {
data: {
multisigAddress: secondarySignerAccount.accountAddress,
function: `0x${senderAccount.accountAddress.toStringWithoutPrefix()}::transfer::transfer`,
type_arguments: [],
arguments: [new U64(1), recieverAccounts[0].accountAddress],
},
});
Expand Down
Loading

0 comments on commit 2613082

Please sign in to comment.