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

Add license header, remove unused file, remove duplicate code, fix casing #7

Merged
merged 5 commits into from
Oct 11, 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
5 changes: 2 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
Copyright © Aptos Foundation
SPDX-License-Identifier: Apache-2.0

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -195,6 +192,8 @@ SPDX-License-Identifier: Apache-2.0

http://www.apache.org/licenses/LICENSE-2.0

Copyright 2023 Aptos Foundation

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
3 changes: 3 additions & 0 deletions src/api/account.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { AptosConfig } from "./aptos_config";
import {
AccountData,
Expand Down
3 changes: 3 additions & 0 deletions src/api/aptos.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Account } from "./account";
import { AptosConfig } from "./aptos_config";
import { General } from "./general";
Expand Down
14 changes: 7 additions & 7 deletions src/api/aptos_config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { AptosSettings, ClientConfig } from "../types";
import { NetworkToNodeAPI, NetworkToFaucetAPI, NetworkToIndexerAPI, Network } from "../utils/api-endpoints";
import { NetworkToNodeAPI, NetworkToFaucetAPI, NetworkToIndexerAPI, Network } from "../utils/apiEndpoints";
import { AptosApiType, DEFAULT_NETWORK } from "../utils/const";

/**
Expand Down Expand Up @@ -50,18 +53,15 @@ export class AptosConfig {
switch (apiType) {
case AptosApiType.FULLNODE:
if (this.fullnode !== undefined) return this.fullnode;
if (this.network === Network.CUSTOM && this.fullnode === undefined)
throw new Error("Please provide a custom full node url");
if (this.network === Network.CUSTOM) throw new Error("Please provide a custom full node url");
return NetworkToNodeAPI[this.network];
case AptosApiType.FAUCET:
if (this.faucet !== undefined) return this.faucet;
if (this.network === Network.CUSTOM && this.faucet === undefined)
throw new Error("Please provide a custom faucet url");
if (this.network === Network.CUSTOM) throw new Error("Please provide a custom faucet url");
return NetworkToFaucetAPI[this.network];
case AptosApiType.INDEXER:
if (this.indexer !== undefined) return this.indexer;
if (this.network === Network.CUSTOM && this.indexer === undefined)
throw new Error("Please provide a custom indexer url");
if (this.network === Network.CUSTOM) throw new Error("Please provide a custom indexer url");
return NetworkToIndexerAPI[this.network];
default:
throw Error(`apiType ${apiType} is not supported`);
Expand Down
3 changes: 3 additions & 0 deletions src/api/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { fundAccount } from "../internal/faucet";
import { HexInput } from "../types";
import { AptosConfig } from "./aptos_config";
Expand Down
3 changes: 3 additions & 0 deletions src/api/general.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import {
getBlockByHeight,
getBlockByVersion,
Expand Down
3 changes: 3 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

export * from "./aptos";
export * from "./aptos_config";
3 changes: 3 additions & 0 deletions src/api/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import {
getGasPriceEstimation,
getTransactionByHash,
Expand Down
3 changes: 3 additions & 0 deletions src/api/transaction_submission.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { AptosConfig } from "./aptos_config";
import { Account } from "../core/account";
import { AccountAuthenticator } from "../transactions/authenticator/account";
Expand Down
3 changes: 3 additions & 0 deletions src/client/core.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import aptosClient from "@aptos-labs/aptos-client";
import { AptosApiError, AptosResponse, MimeType } from "./types";
import { VERSION } from "../version";
Expand Down
3 changes: 3 additions & 0 deletions src/client/get.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { AptosResponse, MimeType } from "./types";
import { aptosRequest } from "./core";
import { AnyNumber, ClientConfig } from "../types";
Expand Down
3 changes: 3 additions & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

export * from "./core";
export * from "./get";
export * from "./post";
Expand Down
3 changes: 3 additions & 0 deletions src/client/post.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { AptosConfig } from "../api/aptos_config";
import { AnyNumber, ClientConfig } from "../types";
import { aptosRequest } from "./core";
Expand Down
3 changes: 3 additions & 0 deletions src/client/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { AptosRequest } from "../types";

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AccountAddress } from "./account_address";
import { Hex } from "./hex";
import { HexInput, SigningScheme } from "../types";
import { PrivateKey, PublicKey, Signature } from "../crypto/asymmetric_crypto";
import { derivePath } from "../utils/hd-key";
import { derivePath } from "../utils/hdKey";
import { AuthenticationKey } from "../crypto/authentication_key";
import { Ed25519PrivateKey, Ed25519PublicKey } from "../crypto/ed25519";
import { Secp256k1PrivateKey, Secp256k1PublicKey } from "../crypto/secp256k1";
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

export * from "./api";
export * from "./client";
export * from "./utils/api-endpoints";
export * from "./utils/apiEndpoints";
export * from "./bcs";
3 changes: 3 additions & 0 deletions src/internal/account.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

/**
* This file contains the underlying implementations for exposed API surface in
* the {@link api/account}. By moving the methods out into a separate file,
Expand Down
3 changes: 3 additions & 0 deletions src/internal/faucet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

/**
* This file contains the underlying implementations for exposed API surface in
* the {@link api/faucet}. By moving the methods out into a separate file,
Expand Down
3 changes: 3 additions & 0 deletions src/internal/general.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

/**
* This file contains the underlying implementations for exposed API surface in
* the {@link api/general}. By moving the methods out into a separate file,
Expand Down
3 changes: 3 additions & 0 deletions src/internal/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

/**
* This file contains the underlying implementations for exposed API surface in
* the {@link api/transaction}. By moving the methods out into a separate file,
Expand Down
28 changes: 0 additions & 28 deletions src/transaction_builder/README.md

This file was deleted.

3 changes: 3 additions & 0 deletions src/transactions/authenticator/account.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable @typescript-eslint/naming-convention */

import { Serializer, Deserializer, Serializable } from "../../bcs";
Expand Down
3 changes: 3 additions & 0 deletions src/transactions/authenticator/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable @typescript-eslint/naming-convention */

import { Deserializer, Serializer } from "../../bcs";
Expand Down
3 changes: 3 additions & 0 deletions src/transactions/instances/chainId.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Serializer, Deserializer } from "../../bcs";

/**
Expand Down
3 changes: 3 additions & 0 deletions src/transactions/instances/identifier.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Serializer, Deserializer, Serializable } from "../../bcs";

/**
Expand Down
3 changes: 3 additions & 0 deletions src/transactions/instances/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

export * from "./chainId";
export * from "./rawTransaction";
export * from "./scriptTransactionArguments";
Expand Down
3 changes: 3 additions & 0 deletions src/transactions/instances/moduleId.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Serializer, Deserializer } from "../../bcs";
import { AccountAddress } from "../../core";
import { Identifier } from "./identifier";
Expand Down
3 changes: 3 additions & 0 deletions src/transactions/instances/rawTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable @typescript-eslint/naming-convention */

import { Deserializer, Serializer, Serializable } from "../../bcs";
Expand Down
3 changes: 3 additions & 0 deletions src/transactions/instances/scriptTransactionArguments.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Serializer, Deserializer, Serializable } from "../../bcs";
import { AccountAddress } from "../../core";
import { ScriptTransactionArgumentVariants } from "../../types";
Expand Down
3 changes: 3 additions & 0 deletions src/transactions/instances/signedTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable @typescript-eslint/naming-convention */

import { Serializer, Deserializer, Serializable } from "../../bcs";
Expand Down
3 changes: 3 additions & 0 deletions src/transactions/instances/transactionPayload.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable @typescript-eslint/naming-convention */

import { Serializer, Deserializer, Serializable } from "../../bcs";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

/**
* This file handles the transaction creation lifecycle.
* It holds different operations to generate a transaction payload, a raw transaciotn,
Expand All @@ -15,7 +18,7 @@ import { getInfo } from "../../internal/account";
import { getLedgerInfo } from "../../internal/general";
import { getGasPriceEstimation } from "../../internal/transaction";
import { HexInput, SigningScheme } from "../../types";
import { NetworkToChainId } from "../../utils/api-endpoints";
import { NetworkToChainId } from "../../utils/apiEndpoints";
import { DEFAULT_MAX_GAS_AMOUNT, DEFAULT_TXN_EXP_SEC_FROM_NOW } from "../../utils/const";
import {
AccountAuthenticator,
Expand Down
3 changes: 3 additions & 0 deletions src/transactions/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { AptosConfig } from "../api/aptos_config";
import { Serializable } from "../bcs";
import { AccountAddress } from "../core";
Expand Down
5 changes: 4 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Network } from "../utils/api-endpoints";
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Network } from "../utils/apiEndpoints";

export * from "./indexer";

Expand Down
3 changes: 3 additions & 0 deletions src/types/indexer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

/**
* GENERATED QUERY TYPES FROM GRAPHQL SCHEMA
*
Expand Down
3 changes: 3 additions & 0 deletions src/utils/api-endpoints.ts → src/utils/apiEndpoints.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

export const NetworkToIndexerAPI: Record<string, string> = {
mainnet: "https://indexer.mainnet.aptoslabs.com/v1/graphql",
testnet: "https://indexer-testnet.staging.gcp.aptosdev.com/v1/graphql",
Expand Down
5 changes: 4 additions & 1 deletion src/utils/const.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Network } from "./api-endpoints";
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Network } from "./apiEndpoints";

export const DEFAULT_NETWORK = Network.DEVNET;
export const DEFAULT_TXN_TIMEOUT_SEC = 20;
Expand Down
3 changes: 3 additions & 0 deletions src/utils/hd-key.ts → src/utils/hdKey.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import nacl from "tweetnacl";
import { hmac } from "@noble/hashes/hmac";
import { sha512 } from "@noble/hashes/sha512";
Expand Down
3 changes: 3 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

export async function sleep(timeMs: number): Promise<null> {
return new Promise((resolve) => {
setTimeout(resolve, timeMs);
Expand Down
3 changes: 3 additions & 0 deletions src/utils/memoize.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

/**
* The global cache Map
*/
Expand Down
3 changes: 3 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

// hardcoded for now, we would want to have it injected dynamically
export const VERSION = "2.0.0";
5 changes: 4 additions & 1 deletion tests/e2e/api/account.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Aptos, AptosConfig } from "../../../src";
import { Network } from "../../../src/utils/api-endpoints";
import { Network } from "../../../src/utils/apiEndpoints";

// TODO
// add account getTransactions tests once sdk v2 supports faucet (which needs transaction operation support)
Expand Down
5 changes: 4 additions & 1 deletion tests/e2e/api/general.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { AptosConfig, Aptos } from "../../../src";
import { GraphqlQuery, ViewRequest } from "../../../src/types";
import { Network } from "../../../src/utils/api-endpoints";
import { Network } from "../../../src/utils/apiEndpoints";

describe("general api", () => {
test("it fetches ledger info", async () => {
Expand Down
5 changes: 4 additions & 1 deletion tests/e2e/api/transaction.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { AptosConfig, Aptos } from "../../../src";
import { Network } from "../../../src/utils/api-endpoints";
import { Network } from "../../../src/utils/apiEndpoints";

describe("transaction api", () => {
test("it queries for the network estimated gas price", async () => {
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/api/transaction_submission.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { AptosConfig, Network, Aptos, Deserializer } from "../../../src";
import { U64 } from "../../../src/bcs/serializable/move-primitives";
import { MoveObject } from "../../../src/bcs/serializable/move-structs";
Expand Down
Loading