Skip to content

Commit

Permalink
refactor: reorganize files and folders for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
jjleng authored and banool committed Sep 15, 2022
1 parent 14f1dd4 commit cde1bb9
Show file tree
Hide file tree
Showing 35 changed files with 62 additions and 70 deletions.
7 changes: 1 addition & 6 deletions ecosystem/typescript/sdk/jest.config.js
Expand Up @@ -5,12 +5,7 @@ module.exports = {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
testEnvironment: "node",
coveragePathIgnorePatterns: [
"generated/*",
"transaction_builder/aptos_types/*",
"utils/memoize-decorator.ts",
"utils/hd-key.ts",
],
coveragePathIgnorePatterns: ["generated/*", "./aptos_types/*", "utils/memoize-decorator.ts", "utils/hd-key.ts"],
testPathIgnorePatterns: ["dist/*"],
collectCoverage: true,
setupFiles: ["dotenv/config"],
Expand Down
18 changes: 7 additions & 11 deletions ecosystem/typescript/sdk/src/aptos_client.test.ts
Expand Up @@ -5,15 +5,11 @@ import { AptosClient } from "./aptos_client";
import * as Gen from "./generated/index";
import { FaucetClient } from "./faucet_client";
import { AptosAccount } from "./aptos_account";
import {
TxnBuilderTypes,
TransactionBuilderMultiEd25519,
BCS,
TransactionBuilderRemoteABI,
} from "./transaction_builder";
import { TxnBuilderTypes, TransactionBuilderMultiEd25519, TransactionBuilderRemoteABI } from "./transaction_builder";
import { TokenClient } from "./token_client";
import { HexString } from "./hex_string";
import { FAUCET_URL, NODE_URL } from "./utils/test_helper.test";
import { bcsSerializeUint64, bcsToBytes } from "./bcs";

const account = "0x1::account::Account";

Expand Down Expand Up @@ -99,7 +95,7 @@ test(
"0x1::coin",
"transfer",
[token],
[BCS.bcsToBytes(TxnBuilderTypes.AccountAddress.fromHex(account2.address())), BCS.bcsSerializeUint64(717)],
[bcsToBytes(TxnBuilderTypes.AccountAddress.fromHex(account2.address())), bcsSerializeUint64(717)],
),
);

Expand Down Expand Up @@ -194,7 +190,7 @@ test(
"0x1::coin",
"transfer",
[token],
[BCS.bcsToBytes(TxnBuilderTypes.AccountAddress.fromHex(account4.address())), BCS.bcsSerializeUint64(123)],
[bcsToBytes(TxnBuilderTypes.AccountAddress.fromHex(account4.address())), bcsSerializeUint64(123)],
),
);

Expand Down Expand Up @@ -310,7 +306,7 @@ test(
"0x1::coin",
"transfer",
[token],
[BCS.bcsToBytes(TxnBuilderTypes.AccountAddress.fromHex(account2.address())), BCS.bcsSerializeUint64(1000)],
[bcsToBytes(TxnBuilderTypes.AccountAddress.fromHex(account2.address())), bcsSerializeUint64(1000)],
),
);

Expand Down Expand Up @@ -475,8 +471,8 @@ test(
const origAddress = TxnBuilderTypes.AccountAddress.fromHex(origAddressHex);
const aliceAddress = TxnBuilderTypes.AccountAddress.fromHex(alice.address());

expect(HexString.fromUint8Array(BCS.bcsToBytes(origAddress)).hex()).toBe(
HexString.fromUint8Array(BCS.bcsToBytes(aliceAddress)).hex(),
expect(HexString.fromUint8Array(bcsToBytes(origAddress)).hex()).toBe(
HexString.fromUint8Array(bcsToBytes(aliceAddress)).hex(),
);
},
30 * 1000,
Expand Down
52 changes: 26 additions & 26 deletions ecosystem/typescript/sdk/src/aptos_client.ts
Expand Up @@ -8,10 +8,10 @@ import * as Gen from "./generated/index";
import {
TxnBuilderTypes,
TransactionBuilderEd25519,
BCS,
TransactionBuilderRemoteABI,
RemoteABIBuilderConfig,
} from "./transaction_builder";
import { bcsSerializeBytes, bcsSerializeU8, bcsToBytes, Bytes, Seq, Serializer, serializeVector, Uint64 } from "./bcs";

/**
* Provides methods for retrieving data from Aptos node.
Expand Down Expand Up @@ -581,7 +581,7 @@ export class AptosClient {
async generateRawTransaction(
accountFrom: HexString,
payload: TxnBuilderTypes.TransactionPayload,
extraArgs?: { maxGasAmount?: BCS.Uint64; gasUnitPrice?: BCS.Uint64; expireTimestamp?: BCS.Uint64 },
extraArgs?: { maxGasAmount?: Uint64; gasUnitPrice?: Uint64; expireTimestamp?: Uint64 },
): Promise<TxnBuilderTypes.RawTransaction> {
const { maxGasAmount, gasUnitPrice, expireTimestamp } = {
maxGasAmount: BigInt(2000),
Expand Down Expand Up @@ -618,9 +618,9 @@ export class AptosClient {
sender: AptosAccount,
payload: TxnBuilderTypes.TransactionPayload,
extraArgs?: {
maxGasAmount?: BCS.Uint64;
gasUnitPrice?: BCS.Uint64;
expireTimestamp?: BCS.Uint64;
maxGasAmount?: Uint64;
gasUnitPrice?: Uint64;
expireTimestamp?: Uint64;
},
): Promise<string> {
// :!:>generateSignSubmitTransactionInner
Expand All @@ -642,23 +642,23 @@ export class AptosClient {
*/
async publishPackage(
sender: AptosAccount,
packageMetadata: BCS.Bytes,
modules: BCS.Seq<TxnBuilderTypes.Module>,
packageMetadata: Bytes,
modules: Seq<TxnBuilderTypes.Module>,
extraArgs?: {
maxGasAmount?: BCS.Uint64;
gasUnitPrice?: BCS.Uint64;
expireTimestamp?: BCS.Uint64;
maxGasAmount?: Uint64;
gasUnitPrice?: Uint64;
expireTimestamp?: Uint64;
},
): Promise<string> {
const codeSerializer = new BCS.Serializer();
BCS.serializeVector(modules, codeSerializer);
const codeSerializer = new Serializer();
serializeVector(modules, codeSerializer);

const payload = new TxnBuilderTypes.TransactionPayloadEntryFunction(
TxnBuilderTypes.EntryFunction.natural(
"0x1::code",
"publish_package_txn",
[],
[BCS.bcsSerializeBytes(packageMetadata), codeSerializer.getBytes()],
[bcsSerializeBytes(packageMetadata), codeSerializer.getBytes()],
),
);

Expand All @@ -675,9 +675,9 @@ export class AptosClient {
sender: AptosAccount,
payload: TxnBuilderTypes.TransactionPayload,
extraArgs?: {
maxGasAmount?: BCS.Uint64;
gasUnitPrice?: BCS.Uint64;
expireTimestamp?: BCS.Uint64;
maxGasAmount?: Uint64;
gasUnitPrice?: Uint64;
expireTimestamp?: Uint64;
checkSuccess?: boolean;
timeoutSecs?: number;
},
Expand All @@ -699,9 +699,9 @@ export class AptosClient {
forAccount: AptosAccount,
toPrivateKeyBytes: Uint8Array,
extraArgs?: {
maxGasAmount?: BCS.Uint64;
gasUnitPrice?: BCS.Uint64;
expireTimestamp?: BCS.Uint64;
maxGasAmount?: Uint64;
gasUnitPrice?: Uint64;
expireTimestamp?: Uint64;
},
): Promise<Gen.PendingTransaction> {
const { sequence_number: sequenceNumber, authentication_key: authKey } = await this.getAccount(
Expand All @@ -720,7 +720,7 @@ export class AptosClient {
helperAccount.pubKey().toUint8Array(),
);

const challengeHex = HexString.fromUint8Array(BCS.bcsToBytes(challenge));
const challengeHex = HexString.fromUint8Array(bcsToBytes(challenge));

const proofSignedByCurrentPrivateKey = forAccount.signHexString(challengeHex);

Expand All @@ -732,12 +732,12 @@ export class AptosClient {
"rotate_authentication_key",
[],
[
BCS.bcsSerializeU8(0), // ed25519 scheme
BCS.bcsSerializeBytes(forAccount.pubKey().toUint8Array()),
BCS.bcsSerializeU8(0), // ed25519 scheme
BCS.bcsSerializeBytes(helperAccount.pubKey().toUint8Array()),
BCS.bcsSerializeBytes(proofSignedByCurrentPrivateKey.toUint8Array()),
BCS.bcsSerializeBytes(proofSignedByNewPrivateKey.toUint8Array()),
bcsSerializeU8(0), // ed25519 scheme
bcsSerializeBytes(forAccount.pubKey().toUint8Array()),
bcsSerializeU8(0), // ed25519 scheme
bcsSerializeBytes(helperAccount.pubKey().toUint8Array()),
bcsSerializeBytes(proofSignedByCurrentPrivateKey.toUint8Array()),
bcsSerializeBytes(proofSignedByNewPrivateKey.toUint8Array()),
],
),
);
Expand Down
@@ -1,7 +1,7 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

import { HexString } from "../../hex_string";
import { HexString } from "../hex_string";
import { Deserializer } from "../bcs";
import { ScriptABI, EntryFunctionABI, TransactionScriptABI } from "./abi";
import { TypeTagAddress, TypeTagU64 } from "./type_tag";
Expand Down
@@ -1,7 +1,7 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

import { HexString, MaybeHexString } from "../../hex_string";
import { HexString, MaybeHexString } from "../hex_string";
import { Serializer, Deserializer, Bytes } from "../bcs";

export class AccountAddress {
Expand Down
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import sha3 from "js-sha3";
import { HexString } from "../../hex_string";
import { HexString } from "../hex_string";
import { Bytes } from "../bcs";
import { MultiEd25519PublicKey } from "./multi_ed25519";

Expand Down
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable max-len */
import { HexString } from "../../hex_string";
import { HexString } from "../hex_string";
import { bcsToBytes, Deserializer } from "../bcs";
import { Ed25519PublicKey, Ed25519Signature } from "./ed25519";
import { MultiEd25519PublicKey, MultiEd25519Signature } from "./multi_ed25519";
Expand Down
Expand Up @@ -6,7 +6,7 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable max-classes-per-file */
import sha3 from "js-sha3";
import { HexString } from "../../hex_string";
import { HexString } from "../hex_string";
import {
Deserializer,
Serializer,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions ecosystem/typescript/sdk/src/coin_client.ts
Expand Up @@ -4,8 +4,9 @@
import { AptosAccount } from "./aptos_account";
import { AptosClient } from "./aptos_client";
import { HexString } from "./hex_string";
import { BCS, TransactionBuilderABI } from "./transaction_builder";
import { TransactionBuilderABI } from "./transaction_builder";
import { COIN_ABIS } from "./abis";
import { Uint64 } from "./bcs";

export const APTOS_COIN = "0x1::aptos_coin::AptosCoin";

Expand Down Expand Up @@ -46,9 +47,9 @@ export class CoinClient {
extraArgs?: {
// The coin type to use, defaults to 0x1::aptos_coin::AptosCoin
coinType?: string;
maxGasAmount?: BCS.Uint64;
gasUnitPrice?: BCS.Uint64;
expireTimestamp?: BCS.Uint64;
maxGasAmount?: Uint64;
gasUnitPrice?: Uint64;
expireTimestamp?: Uint64;
},
): Promise<string> {
const coinTypeToTransfer = extraArgs?.coinType ?? APTOS_COIN;
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/typescript/sdk/src/index.ts
@@ -1,9 +1,9 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

// All parts of our package are accessible as imports, but we re-export our higher level API here for convenience
export * from "./aptos_account";
export * from "./aptos_client";
export * as BCS from "./bcs";
export * from "./coin_client";
export * from "./faucet_client";
export * from "./hex_string";
Expand Down
11 changes: 6 additions & 5 deletions ecosystem/typescript/sdk/src/token_client.ts
Expand Up @@ -6,9 +6,10 @@ import { AptosClient } from "./aptos_client";
import * as TokenTypes from "./token_types";
import * as Gen from "./generated/index";
import { HexString, MaybeHexString } from "./hex_string";
import { BCS, TransactionBuilder, TransactionBuilderABI, TxnBuilderTypes } from "./transaction_builder";
import { MAX_U64_BIG_INT } from "./transaction_builder/bcs/consts";
import { TransactionBuilder, TransactionBuilderABI, TxnBuilderTypes } from "./transaction_builder";
import { MAX_U64_BIG_INT } from "./bcs/consts";
import { TOKEN_ABIS } from "./abis";
import { AnyNumber, bcsToBytes } from "./bcs";

/**
* Class for creating, minting and managing minting NFT collections and tokens
Expand Down Expand Up @@ -44,7 +45,7 @@ export class TokenClient {
name: string,
description: string,
uri: string,
maxAmount: BCS.AnyNumber = MAX_U64_BIG_INT,
maxAmount: AnyNumber = MAX_U64_BIG_INT,
): Promise<string> {
// <:!:createCollection
const payload = this.transactionBuilder.buildTransactionPayload(
Expand Down Expand Up @@ -82,7 +83,7 @@ export class TokenClient {
description: string,
supply: number,
uri: string,
max: BCS.AnyNumber = MAX_U64_BIG_INT,
max: AnyNumber = MAX_U64_BIG_INT,
royalty_payee_address: MaybeHexString = account.address(),
royalty_points_denominator: number = 0,
royalty_points_numerator: number = 0,
Expand Down Expand Up @@ -257,7 +258,7 @@ export class TokenClient {
[receiverAuthenticator], // Secondary signer authenticators
);

const bcsTxn = BCS.bcsToBytes(new TxnBuilderTypes.SignedTransaction(rawTxn, multiAgentAuthenticator));
const bcsTxn = bcsToBytes(new TxnBuilderTypes.SignedTransaction(rawTxn, multiAgentAuthenticator));

const transactionRes = await this.aptosClient.submitSignedBCSTransaction(bcsTxn);

Expand Down
6 changes: 3 additions & 3 deletions ecosystem/typescript/sdk/src/transaction_builder/builder.ts
Expand Up @@ -23,9 +23,9 @@ import {
TransactionPayloadEntryFunction,
TransactionPayloadScript,
ModuleId,
} from "./aptos_types";
import { bcsToBytes, Bytes, Deserializer, Serializer, Uint64, Uint8 } from "./bcs";
import { ArgumentABI, EntryFunctionABI, ScriptABI, TransactionScriptABI, TypeArgumentABI } from "./aptos_types/abi";
} from "../aptos_types";
import { bcsToBytes, Bytes, Deserializer, Serializer, Uint64, Uint8 } from "../bcs";
import { ArgumentABI, EntryFunctionABI, ScriptABI, TransactionScriptABI, TypeArgumentABI } from "../aptos_types/abi";
import { HexString, MaybeHexString } from "../hex_string";
import { argToTransactionArgument, TypeTagParser, serializeArg } from "./builder_utils";
import * as Gen from "../generated/index";
Expand Down
Expand Up @@ -19,8 +19,8 @@ import {
TypeTagU64,
TypeTagU8,
TypeTagVector,
} from "./aptos_types";
import { Serializer } from "./bcs";
} from "../aptos_types";
import { Serializer } from "../bcs";
import {
argToTransactionArgument,
TypeTagParser,
Expand Down
Expand Up @@ -21,8 +21,8 @@ import {
TransactionArgumentAddress,
TransactionArgumentU8,
TransactionArgumentU8Vector,
} from "./aptos_types";
import { Serializer } from "./bcs";
} from "../aptos_types";
import { Serializer } from "../bcs";

function assertType(val: any, types: string[] | string, message?: string) {
if (!types?.includes(typeof val)) {
Expand Down
3 changes: 1 addition & 2 deletions ecosystem/typescript/sdk/src/transaction_builder/index.ts
Expand Up @@ -2,5 +2,4 @@
// SPDX-License-Identifier: Apache-2.0

export * from "./builder";
export * as BCS from "./bcs";
export * as TxnBuilderTypes from "./aptos_types";
export * as TxnBuilderTypes from "../aptos_types";
Expand Up @@ -4,7 +4,7 @@
/* eslint-disable max-len */
import nacl from "tweetnacl";
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
import { bcsSerializeUint64, bcsToBytes, Bytes } from "./bcs";
import { bcsSerializeUint64, bcsToBytes, Bytes } from "../bcs";
import { HexString } from "../hex_string";

import { TransactionBuilderEd25519, TransactionBuilder } from "./index";
Expand All @@ -22,7 +22,7 @@ import {
TransactionPayloadScript,
TransactionPayloadEntryFunction,
TypeTagStruct,
} from "./aptos_types";
} from "../aptos_types";

const ADDRESS_1 = "0x1222";
const ADDRESS_2 = "0xdd";
Expand Down
Expand Up @@ -39,7 +39,7 @@ import {
TransactionArgumentAddress,
TransactionArgumentU8Vector,
TransactionArgumentU128,
} from "./aptos_types";
} from "../aptos_types";
import { HexString } from "../hex_string";
import { TransactionBuilderEd25519 } from "./builder";

Expand Down

0 comments on commit cde1bb9

Please sign in to comment.