Skip to content

Commit

Permalink
Merge branch 'main' into add-auto-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario authored Oct 10, 2023
2 parents bf9bb5c + fb2f508 commit 98d1a0c
Show file tree
Hide file tree
Showing 35 changed files with 861 additions and 330 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file adds LF and newline support at the end of files
# for many editors automatically including Github
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
23 changes: 23 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Ensure that text files that any contributor introduces to the repository
# have their line endings normalized to LF
* text=auto eol=lf

# All known text filetypes
*.cfg text eol=lf
*.Dockerfile text eol=lf
*.hcl text eol=lf
*.json text eol=lf
*.md text eol=lf
*.move text eol=lf
*.py text eol=lf
*.sh text eol=lf
*.tf text eol=lf
*.toml text eol=lf
*.txt text eol=lf
*.yaml text eol=lf
*.ts text eol=lf
*.js text eol=lf

# Ensure that powerscript files are not auto-converted
*.ps1 binary

4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"trailingComma": "all",
"printWidth": 120
}
7 changes: 7 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# **Please** keep this file ordered alphabetically by directory paths.

# Owners for the `.github` directory and all its subdirectories.
/.github/ @aptos-labs/developer-platform @aptos-labs/security

# Auto-reviewers for all code
* @aptos-labs/developer-platform
120 changes: 120 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
id: contributing
title: Contributing to the Aptos TypeScript SDK
---

# Contributing

Our goal is to make contributing to Aptos TypeScript SDK easy and transparent. See [Aptos Community](https://aptos.dev/community)
for full details. This page describes [our development process](#our-development-process).

## Aptos SDK

To contribute to the Aptos SDK implementation, first fork the [aptos-ts-sdk](https://github.com/aptos-labs/aptos-ts-sdk)
repository. For more information on how to fork see the [Github documentation](https://docs.github.com/en/get-started/quickstart/fork-a-repo).

## Our Development Process
### Documentation

Aptos's developer website is also open source (the code can be found in this
[repository](https://github.com/aptos-labs/aptos-core/tree/main/developers-docs-site/). It is built using
[Docusaurus](https://docusaurus.io/):

If you know Markdown, you can already contribute!

## Developer Workflow

Changes to the project are proposed through pull requests. The general pull request workflow is as follows:

* If you have added code that should be tested, add unit tests.
* If you have changed APIs, update the documentation. Make sure the documentation builds.
* Ensure all formatting applies with `pnpm fmt`.
* Ensure all tests and lints pass on each and every commit that is part of your pull request using `pnpm test && pnpm lint`.
* Submit your pull request.

## Authoring Clean Commits

### Logically Separate Commits

Commits should be [atomic](https://en.wikipedia.org/wiki/Atomic_commit#Atomic_commit_convention) and broken down into
logically separate changes. Diffs should also be made easy for reviewers to read and review so formatting fixes or code
moves should not be included in commits with actual code changes.

### Meaningful Commit Messages

Commit messages are important and incredibly helpful for others when they dig through the commit history in order to
understand why a particular change was made and what problem it was intending to solve. For this reason commit messages
should be well written and conform with the following format:

All commit messages should begin with a single short (50 character max) line summarizing the change and should skip the
full stop. This is the title of the commit. It is also preferred that this summary be prefixed with "[area]" where the
area is an identifier for the general area of the code being modified, e.g.

```
* [ci] enforce whitelist of nightly features
* [language] removing VerificationPass trait
```


Following the commit title (unless it alone is self-explanatory), there should be a single blank line followed by the
commit body which includes more detailed, explanatory text as separate paragraph(s). It is recommended that the commit
body be wrapped at 72 characters so that Git has plenty of room to indent the text while still keeping everything under
80 characters overall.

The commit body should provide a meaningful commit message, which:
* Explains the problem the change tries to solve, i.e. what is wrong with the current code without the change.
* Justifies the way the change solves the problem, i.e. why the result with the change is better.
* Alternative solutions considered but discarded, if any.

### References in Commit Messages

If you want to reference a previous commit in the history of the project, use the format "abbreviated sha1 (subject,
date)", with the subject enclosed in a pair of double-quotes, like this:

```bash
Commit 895b53510 ("[consensus] remove slice_patterns feature", 2019-07-18) noticed that ...
```

This invocation of `git show` can be used to obtain this format:

```bash
git show -s --date=short --pretty='format:%h ("%s", %ad)' <commit>
```

If a commit references an issue please add a reference to the body of your commit message, e.g. `issue #1234` or `
fixes #456`. Using keywords like `fixes`, `resolves`, or `closes` will cause the corresponding issue to be closed when
the pull request is merged.

Avoid adding any `@` mentions to commit messages, instead add them to the PR cover letter.

## Responding to Reviewer Feedback

During the review process a reviewer may ask you to make changes to your pull request. If a particular commit needs to
be changed, that commit should be amended directly. Changes in response to a review *should not* be made in separate
commits on top of your PR unless it logically makes sense to have separate, distinct commits for those changes. This
helps keep the commit history clean.

If your pull request is out-of-date and needs to be updated because `main` has advanced, you should rebase your branch
on top of the latest main by doing the following:

```bash
git fetch upstream
git checkout branch
git rebase -i upstream/main
```

You *should not* update your branch by merging the latest main into your branch. Merge commits included in PRs tend to
make it more difficult for the reviewer to understand the change being made, especially if the merge wasn't clean and
needed conflicts to be resolved. As such, PRs with merge commits will be rejected.

## Bisect-able History

It is important that the project history is bisect-able so that when regressions are identified we can easily use
`git bisect` to be able to pin-point the exact commit which introduced the regression. This requires that every commit
is able to be built and passes all lints and tests. So if your pull request includes multiple commits be sure that each
and every commit is able to be built and passes all checks performed by CI.

## Issues

The Aptos SDK uses [GitHub issues](https://github.com/aptos-labs/aptos-ts-sdk/issues) to track bugs. Please include
necessary information and instructions to reproduce your issue.
5 changes: 3 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
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 @@ -186,8 +189,6 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
64 changes: 15 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# SDK for Aptos Node API
# Typescript SDK for Aptos

[![Discord][discord-image]][discord-url]
[![NPM Package Version][npm-image-version]][npm-url]
[![NPM Package Downloads][npm-image-downloads]][npm-url]

The Aptos TypeScript SDK provides a convenient way to interact with the Aptos blockchain using TypeScript. It offers a set of utility functions, classes, and types to simplify the integration process and enhance developer productivity.
The Aptos TypeScript SDK provides a convenient way to interact with the Aptos blockchain using TypeScript. It offers a
set of utility functions, classes, and types to simplify the integration process and enhance developer productivity.

This repository supports version >= 2.0.0 of the [Aptos SDK npm package](https://www.npmjs.com/package/aptos).

## Installation

##### For use in Node.js or a web application

```ts
pnpm install aptos
Install with your favorite package manager such as npm, yarn, or pnpm:
```bash
npm install aptos
```

You can also use your preferred npm client, such as yarn or npm.

##### For use in a browser

```ts
You can add the SDK to your web application using a script tag:
```html
<script src="https://unpkg.com/aptos@latest/dist/index.global.js" />
```
Expand All @@ -27,58 +30,21 @@ Then, the SDK can be accessed through `window.aptosSDK`.
## Documentation and examples
- [The Aptos documentation site](https://aptos.dev/sdks/ts-sdk/index) provides step-by-step instructions, code snippets, and best practices to use this library.
- You can view the generated [Type Doc](https://aptos-labs.github.io/ts-sdk-doc/) for the latest release of the SDK.
- For in-depth examples, check out the [examples](./examples) folder with ready-made `package.json` files to get you going quickly!
### Development environment setup

Setup an `.env` file to configure the URLs.
From the [root](https://github.com/aptos-labs/aptos-core/tree/main/ecosystem/typescript/sdk) of this package, run:

```ts
rm .env
echo 'APTOS_NODE_URL="http://localhost:8080/v1"' >> .env
echo 'APTOS_FAUCET_URL="http://localhost:8081"' >> .env
```

### Testing
To run the full SDK tests, From the [root](https://github.com/aptos-labs/aptos-core/tree/main/ecosystem/typescript/sdk) of this package, run:
To run the SDK tests, simply run from the root of this repository:
```ts
```bash
pnpm test
```
> If you see strange behavior regarding HTTP clients, try running the tests with `--detectOpenHandles`.
To test a single file in the SDK, From the [root](https://github.com/aptos-labs/aptos-core/tree/main/ecosystem/typescript/sdk) of this package, run:

```ts
npx jest -- <path/to/file.test.ts>
```

To use the local build in a local project:

```ts
// run from the root of this package
pnpm build
// run on your local project
pnpm add PATH_TO_LOCAL_SDK_PACKAGE
```

### Working with local node

To develop in a local environment, you need to use the SDK from the [main](https://github.com/aptos-labs/aptos-core/tree/main/ecosystem/typescript/sdk) branch.

Run a local node (run from the root of the [repo](https://github.com/aptos-labs/aptos-core/)):

```ts
cargo run -p aptos -- node run-local-testnet --force-restart --assume-yes
```

## Contributing
If you found a bug or would like to request a feature, please file an [issue](https://github.com/aptos-labs/aptos-core/issues/new/choose). If, based on the discussion on an issue you would like to offer a code change, please make a [pull request](./CONTRIBUTING.md). If neither of these describes what you would like to contribute, checkout out the [contributing guide](./CONTRIBUTING.md).
If you found a bug or would like to request a feature, please file an [issue](https://github.com/aptos-labs/aptos-ts-sdk/issues/new/choose).
If, based on the discussion on an issue you would like to offer a code change, please make a [pull request](./CONTRIBUTING.md).
If neither of these describes what you would like to contribute, checkout out the [contributing guide](./CONTRIBUTING.md).
[npm-image-version]: https://img.shields.io/npm/v/aptos.svg
[npm-image-downloads]: https://img.shields.io/npm/dm/aptos.svg
Expand Down
40 changes: 32 additions & 8 deletions src/api/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ export class Account {
accountAddress: HexInput;
options?: PaginationArgs;
}): Promise<TransactionResponse[]> {
const transactions = await getTransactions({ aptosConfig: this.config, ...args });
const transactions = await getTransactions({
aptosConfig: this.config,
...args,
});
return transactions;
}

Expand Down Expand Up @@ -177,7 +180,10 @@ export class Account {
* @returns An object { count : number }
*/
async getAccountTokensCount(args: { accountAddress: HexInput }): Promise<GetAccountTokensCountQueryResponse> {
const count = await getAccountTokensCount({ aptosConfig: this.config, ...args });
const count = await getAccountTokensCount({
aptosConfig: this.config,
...args,
});
return count;
}

Expand All @@ -198,7 +204,10 @@ export class Account {
orderBy?: OrderBy<GetAccountOwnedTokensQueryResponse[0]>;
};
}): Promise<GetAccountOwnedTokensQueryResponse> {
const tokens = await getAccountOwnedTokens({ aptosConfig: this.config, ...args });
const tokens = await getAccountOwnedTokens({
aptosConfig: this.config,
...args,
});
return tokens;
}

Expand All @@ -221,7 +230,10 @@ export class Account {
orderBy?: OrderBy<GetAccountOwnedTokensFromCollectionResponse[0]>;
};
}): Promise<GetAccountOwnedTokensFromCollectionResponse> {
const tokens = await getAccountOwnedTokensFromCollectionAddress({ aptosConfig: this.config, ...args });
const tokens = await getAccountOwnedTokensFromCollectionAddress({
aptosConfig: this.config,
...args,
});
return tokens;
}

Expand All @@ -242,7 +254,10 @@ export class Account {
orderBy?: OrderBy<GetAccountCollectionsWithOwnedTokenResponse[0]>;
};
}): Promise<GetAccountCollectionsWithOwnedTokenResponse> {
const collections = await getAccountCollectionsWithOwnedTokens({ aptosConfig: this.config, ...args });
const collections = await getAccountCollectionsWithOwnedTokens({
aptosConfig: this.config,
...args,
});
return collections;
}

Expand All @@ -253,7 +268,10 @@ export class Account {
* @returns An object { count : number }
*/
async getAccountTransactionsCount(args: { accountAddress: HexInput }): Promise<GetAccountTransactionsCountResponse> {
const count = getAccountTransactionsCount({ aptosConfig: this.config, ...args });
const count = getAccountTransactionsCount({
aptosConfig: this.config,
...args,
});
return count;
}

Expand All @@ -270,7 +288,10 @@ export class Account {
orderBy?: OrderBy<GetAccountCoinsDataResponse[0]>;
};
}): Promise<GetAccountCoinsDataResponse> {
const data = await getAccountCoinsData({ aptosConfig: this.config, ...args });
const data = await getAccountCoinsData({
aptosConfig: this.config,
...args,
});
return data;
}

Expand Down Expand Up @@ -298,7 +319,10 @@ export class Account {
orderBy?: OrderBy<GetAccountOwnedObjectsResponse[0]>;
};
}): Promise<GetAccountOwnedObjectsResponse> {
const objects = getAccountOwnedObjects({ aptosConfig: this.config, ...args });
const objects = getAccountOwnedObjects({
aptosConfig: this.config,
...args,
});
return objects;
}
}
Loading

0 comments on commit 98d1a0c

Please sign in to comment.