Skip to content

Commit

Permalink
Run prettier and fix typos (#5)
Browse files Browse the repository at this point in the history
prettier and fix typos
  • Loading branch information
0xmaayan authored Oct 10, 2023
1 parent 5ed3793 commit 1819e03
Show file tree
Hide file tree
Showing 29 changed files with 679 additions and 274 deletions.
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
}
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;
}
}
38 changes: 19 additions & 19 deletions src/api/faucet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import { AptosConfig } from "./aptos_config";
* A class to query all `Faucet` related queries on Aptos.
*/
export class Faucet {
readonly config: AptosConfig;

constructor(config: AptosConfig) {
this.config = config;
}
readonly config: AptosConfig;

/**
* This creates an account if it does not exist and mints the specified amount of
* coins into that account
*
* @param address Hex-encoded 16 bytes Aptos account address wich mints tokens
* @param amount Amount of tokens to mint
* @param timeoutSecs Timeout in seconds. Defaults to 20 seconds.
* @returns Hashes of submitted transactions
*/
async fundAccount(args: { accountAddress: HexInput, amount: number, timeoutSecs?: number }): Promise<Array<string>> {
const txnStrings = await fundAccount({ aptosConfig: this.config, ...args });
return txnStrings;
}
}
constructor(config: AptosConfig) {
this.config = config;
}

/**
* This creates an account if it does not exist and mints the specified amount of
* coins into that account
*
* @param address Hex-encoded 16 bytes Aptos account address wich mints tokens
* @param amount Amount of tokens to mint
* @param timeoutSecs Timeout in seconds. Defaults to 20 seconds.
* @returns Hashes of submitted transactions
*/
async fundAccount(args: { accountAddress: HexInput; amount: number; timeoutSecs?: number }): Promise<Array<string>> {
const txnStrings = await fundAccount({ aptosConfig: this.config, ...args });
return txnStrings;
}
}
10 changes: 8 additions & 2 deletions src/api/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ export class General {
* @returns Block
*/
async getBlockByVersion(args: { blockVersion: number; options?: { withTransactions?: boolean } }): Promise<Block> {
const block = await getBlockByVersion({ aptosConfig: this.config, ...args });
const block = await getBlockByVersion({
aptosConfig: this.config,
...args,
});
return block;
}

Expand Down Expand Up @@ -139,7 +142,10 @@ export class General {
* @return The provided T type
*/
async queryIndexer<T>(args: { query: GraphqlQuery }): Promise<T> {
const response = await queryIndexer<T>({ aptosConfig: this.config, ...args });
const response = await queryIndexer<T>({
aptosConfig: this.config,
...args,
});
return response;
}
}
37 changes: 27 additions & 10 deletions src/api/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export class Transaction {
* @returns Array of on-chain transactions
*/
async getTransactions(args: { options?: PaginationArgs }): Promise<TransactionResponse[]> {
const transactions = await getTransactions({ aptosConfig: this.config, ...args });
const transactions = await getTransactions({
aptosConfig: this.config,
...args,
});
return transactions;
}

Expand All @@ -35,7 +38,10 @@ export class Transaction {
* function cannot be used to query pending transactions.
*/
async getTransactionByVersion(args: { txnVersion: AnyNumber }): Promise<TransactionResponse> {
const transaction = await getTransactionByVersion({ aptosConfig: this.config, ...args });
const transaction = await getTransactionByVersion({
aptosConfig: this.config,
...args,
});
return transaction;
}

Expand All @@ -44,7 +50,10 @@ export class Transaction {
* @returns Transaction from mempool (pending) or on-chain (committed) transaction
*/
async getTransactionByHash(args: { txnHash: HexInput }): Promise<TransactionResponse> {
const transaction = await getTransactionByHash({ aptosConfig: this.config, ...args });
const transaction = await getTransactionByHash({
aptosConfig: this.config,
...args,
});
return transaction;
}

Expand All @@ -61,13 +70,16 @@ export class Transaction {
* @returns `true` if transaction is in pending state and `false` otherwise
*/
async isPendingTransaction(args: { txnHash: HexInput }): Promise<boolean> {
const isPending = await isTransactionPending({ aptosConfig: this.config, ...args });
const isPending = await isTransactionPending({
aptosConfig: this.config,
...args,
});
return isPending;
}

/**
* Waits for a transaction to move past the pending state.
*
*
* There are 4 cases.
* 1. Transaction is successfully processed and committed to the chain.
* - The function will resolve with the transaction response from the API.
Expand All @@ -79,19 +91,22 @@ export class Transaction {
* If `checkSuccess` is false, the function will resolve with the transaction response where the `success` field is false.
* 4. Transaction does not move past the pending state within `extraArgs.timeoutSecs` seconds.
* - The function will throw a WaitForTransactionError
*
*
*
*
* @param txnHash The hash of a transaction previously submitted to the blockchain.
* @param extraArgs.timeoutSecs Timeout in seconds. Defaults to 20 seconds.
* @param extraArgs.checkSuccess A boolean which controls whether the function will error if the transaction failed.
* @param extraArgs.checkSuccess A boolean which controls whether the function will error if the transaction failed.
* Defaults to true. See case 3 above.
* @returns The transaction on-chain. See above for more details.
*/
async waitForTransaction(args: {
txnHash: HexInput;
extraArgs?: { timeoutSecs?: number; checkSuccess?: boolean };
}): Promise<TransactionResponse> {
const transaction = await waitForTransaction({ aptosConfig: this.config, ...args });
const transaction = await waitForTransaction({
aptosConfig: this.config,
...args,
});
return transaction;
}

Expand All @@ -111,7 +126,9 @@ export class Transaction {
* ```
*/
async getGasPriceEstimation(): Promise<GasEstimation> {
const gasEstimation = await getGasPriceEstimation({ aptosConfig: this.config });
const gasEstimation = await getGasPriceEstimation({
aptosConfig: this.config,
});
return gasEstimation;
}
}
8 changes: 5 additions & 3 deletions src/api/transaction_submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class TransactionSubmission {
* @param args.options optional. GenerateTransactionOptions type
*
* @example
* For a singale signer entry function
* For a single signer entry function
* move function name, move function type arguments, move function arguments
* `
* data: {
Expand All @@ -61,7 +61,7 @@ export class TransactionSubmission {
* `
*
* @example
* For a singale signer script function
* For a single signer script function
* module bytecode, move function type arguments, move function arguments
* ```
* data: {
Expand Down Expand Up @@ -125,7 +125,9 @@ export class TransactionSubmission {
* @param options optional. A config to simulate the transaction with
*/
async simulateTransaction(args: SimulateTransactionData): Promise<Array<UserTransactionResponse>> {
const signedTransaction = generateSignedTransactionForSimulation({ ...args });
const signedTransaction = generateSignedTransactionForSimulation({
...args,
});
const { data } = await postAptosFullNode<Uint8Array, Array<UserTransactionResponse>>({
aptosConfig: this.config,
body: signedTransaction,
Expand Down
9 changes: 8 additions & 1 deletion src/client/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ async function request<Req, Res>(
* make a call using the @aptos-labs/aptos-client package
* {@link https://www.npmjs.com/package/@aptos-labs/aptos-client}
*/
const response = await aptosClient<Res>({ url, method, body, params, headers, overrides });
const response = await aptosClient<Res>({
url,
method,
body,
params,
headers,
overrides,
});
return response;
}

Expand Down
6 changes: 5 additions & 1 deletion src/core/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ export class Account {
throw new Error(`Can not generate new Private Key, unsupported signing scheme ${scheme}`);
}

const address = new AccountAddress({ data: Account.authKey({ publicKey: privateKey.publicKey() }).toUint8Array() });
const address = new AccountAddress({
data: Account.authKey({
publicKey: privateKey.publicKey(),
}).toUint8Array(),
});
return new Account({ privateKey, address });
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/account_address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export class AccountAddress extends Serializable {
} else if (args.input.length !== 3) {
// 0x + one hex char is the only valid SHORT form for special addresses.
throw new ParsingError(
// eslint-disable-next-line max-len
// eslint-disable-next-line max-len
`The given hex string ${args.input} is a special address not in LONG form, it must be 0x0 to 0xf without padding zeroes.`,
AddressInvalidReason.INVALID_PADDING_ZEROES,
);
Expand Down
8 changes: 6 additions & 2 deletions src/crypto/ed25519.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export class Ed25519PublicKey extends PublicKey {
verifySignature(args: { message: HexInput; signature: Ed25519Signature }): boolean {
const { message, signature } = args;
const rawMessage = Hex.fromHexInput({ hexInput: message }).toUint8Array();
const rawSignature = Hex.fromHexInput({ hexInput: signature.toUint8Array() }).toUint8Array();
const rawSignature = Hex.fromHexInput({
hexInput: signature.toUint8Array(),
}).toUint8Array();
return nacl.sign.detached.verify(rawMessage, rawSignature, this.key.toUint8Array());
}

Expand Down Expand Up @@ -157,7 +159,9 @@ export class Ed25519PrivateKey extends PrivateKey {
*/
static generate(): Ed25519PrivateKey {
const keyPair = nacl.sign.keyPair();
return new Ed25519PrivateKey({ hexInput: keyPair.secretKey.slice(0, Ed25519PrivateKey.LENGTH) });
return new Ed25519PrivateKey({
hexInput: keyPair.secretKey.slice(0, Ed25519PrivateKey.LENGTH),
});
}

/**
Expand Down
12 changes: 10 additions & 2 deletions src/crypto/multi_ed25519.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ export class MultiEd25519PublicKey extends PublicKey {

for (let i = 0; i < bytes.length - 1; i += Ed25519PublicKey.LENGTH) {
const begin = i;
keys.push(new Ed25519PublicKey({ hexInput: bytes.subarray(begin, begin + Ed25519PublicKey.LENGTH) }));
keys.push(
new Ed25519PublicKey({
hexInput: bytes.subarray(begin, begin + Ed25519PublicKey.LENGTH),
}),
);
}
return new MultiEd25519PublicKey({ publicKeys: keys, threshold });
}
Expand Down Expand Up @@ -244,7 +248,11 @@ export class MultiEd25519Signature extends Signature {

for (let i = 0; i < bytes.length - bitmap.length; i += Ed25519Signature.LENGTH) {
const begin = i;
signatures.push(new Ed25519Signature({ hexInput: bytes.subarray(begin, begin + Ed25519Signature.LENGTH) }));
signatures.push(
new Ed25519Signature({
hexInput: bytes.subarray(begin, begin + Ed25519Signature.LENGTH),
}),
);
}
return new MultiEd25519Signature({ signatures, bitmap });
}
Expand Down
Loading

0 comments on commit 1819e03

Please sign in to comment.