Skip to content

Commit

Permalink
Combine collection and token under the digitalAsset namespace (#94)
Browse files Browse the repository at this point in the history
* Combine collection and token under the digitalAsset namespace

* uodate

* address comments

* fmt

* delet doc
  • Loading branch information
heliuchuan authored Oct 18, 2023
1 parent dc4c12e commit a1d815d
Show file tree
Hide file tree
Showing 6 changed files with 348 additions and 280 deletions.
16 changes: 5 additions & 11 deletions src/api/aptos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import { Account } from "./account";
import { AptosConfig } from "./aptosConfig";
import { Coin } from "./coin";
import { Collection } from "./collection";
import { DigitalAsset } from "./digitalAsset";
import { Event } from "./event";
import { Faucet } from "./faucet";
import { FungibleAsset } from "./fungibleAsset";
import { General } from "./general";
import { Staking } from "./staking";
import { Token } from "./token";
import { Transaction } from "./transaction";
import { TransactionSubmission } from "./transactionSubmission";

Expand All @@ -28,7 +27,7 @@ export class Aptos {

readonly coin: Coin;

readonly collection: Collection;
readonly digitalAsset: DigitalAsset;

readonly event: Event;

Expand All @@ -40,8 +39,6 @@ export class Aptos {

readonly staking: Staking;

readonly token: Token;

readonly transaction: Transaction;

readonly transactionSubmission: TransactionSubmission;
Expand All @@ -50,13 +47,12 @@ export class Aptos {
this.config = new AptosConfig(settings);
this.account = new Account(this.config);
this.coin = new Coin(this.config);
this.collection = new Collection(this.config);
this.digitalAsset = new DigitalAsset(this.config);
this.event = new Event(this.config);
this.faucet = new Faucet(this.config);
this.fungibleAsset = new FungibleAsset(this.config);
this.general = new General(this.config);
this.staking = new Staking(this.config);
this.token = new Token(this.config);
this.transaction = new Transaction(this.config);
this.transactionSubmission = new TransactionSubmission(this.config);
}
Expand All @@ -65,13 +61,12 @@ export class Aptos {
export interface Aptos
extends Account,
Coin,
Collection,
DigitalAsset,
Event,
Faucet,
FungibleAsset,
General,
Staking,
Token,
Transaction,
TransactionSubmission {}

Expand All @@ -98,12 +93,11 @@ function applyMixin(targetClass: any, baseClass: any, baseClassProp: string) {

applyMixin(Aptos, Account, "account");
applyMixin(Aptos, Coin, "coin");
applyMixin(Aptos, Collection, "collection");
applyMixin(Aptos, DigitalAsset, "digitalAsset");
applyMixin(Aptos, Event, "event");
applyMixin(Aptos, Faucet, "faucet");
applyMixin(Aptos, FungibleAsset, "fungibleAsset");
applyMixin(Aptos, General, "general");
applyMixin(Aptos, Staking, "staking");
applyMixin(Aptos, Token, "token");
applyMixin(Aptos, Transaction, "transaction");
applyMixin(Aptos, TransactionSubmission, "transactionSubmission");
103 changes: 96 additions & 7 deletions src/api/collection.ts → src/api/digitalAsset.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import {
GetCollectionDataResponse,
GetCurrentTokenOwnershipResponse,
GetOwnedTokensResponse,
GetTokenActivityResponse,
GetTokenDataResponse,
HexInput,
OrderBy,
PaginationArgs,
TokenStandard,
} from "../types";
import { AptosConfig } from "./aptosConfig";
import { Account } from "../core";
import { GenerateTransactionOptions, SingleSignerTransaction } from "../transactions/types";
import {
CreateCollectionOptions,
createCollectionTransaction,
getCollectionId,
getCollectionData,
} from "../internal/collection";
import { Account } from "../core";
import { GenerateTransactionOptions, SingleSignerTransaction } from "../transactions/types";
import { GetCollectionDataResponse, HexInput, TokenStandard } from "../types";
getCollectionId,
getCurrentTokenOwnership,
getOwnedTokens,
getTokenActivity,
getTokenData,
mintTokenTransaction,
} from "../internal/digitalAsset";

/**
* A class to query all `Collection` related queries on Aptos.
* A class to query all `DigitalAsset` related queries on Aptos.
*/
export class Collection {
export class DigitalAsset {
readonly config: AptosConfig;

constructor(config: AptosConfig) {
Expand Down Expand Up @@ -100,4 +115,78 @@ export class Collection {
}): Promise<string> {
return getCollectionId({ aptosConfig: this.config, ...args });
}

/**
* Create a transaction to mint a token into the creators account within an existing collection.
*
* @param args.creator the creator of the collection
* @param args.collection the name of the collection the token belongs to
* @param args.description the description of the token
* @param args.name the name of the token
* @param args.uri the URI to additional info about the token
*
* @returns A SingleSignerTransaction that can be simulated or submitted to chain
*/
async mintTokenTransaction(args: {
creator: Account;
collection: string;
description: string;
name: string;
uri: string;
options?: GenerateTransactionOptions;
}): Promise<SingleSignerTransaction> {
return mintTokenTransaction({ aptosConfig: this.config, ...args });
}

/**
* Gets token data given the address of a token.
*
* @param args.tokenAddress The address of the token
* @returns GetTokenDataResponse containing relevant data to the token.
*/
async getTokenData(args: { tokenAddress: HexInput }): Promise<GetTokenDataResponse> {
return getTokenData({ aptosConfig: this.config, ...args });
}

/**
* Gets token ownership data given the address of a token.
*
* @param args.tokenAddress The address of the token
* @returns GetCurrentTokenOwnershipResponse containing relevant ownership data of the token.
*/
async getCurrentTokenOwnership(args: { tokenAddress: HexInput }): Promise<GetCurrentTokenOwnershipResponse> {
return getCurrentTokenOwnership({ aptosConfig: this.config, ...args });
}

/**
* Gets the tokens that the given address owns.
*
* @param args.ownerAddress The address of the owner
* @returns GetOwnedTokensResponse containing ownership data of the tokens belonging to the ownerAddresss.
*/
async getOwnedTokens(args: {
ownerAddress: HexInput;
options?: {
pagination?: PaginationArgs;
orderBy?: OrderBy<GetOwnedTokensResponse[0]>;
};
}): Promise<GetOwnedTokensResponse> {
return getOwnedTokens({ aptosConfig: this.config, ...args });
}

/**
* Gets the activity data given the address of a token.
*
* @param args.tokenAddress The address of the token
* @returns GetTokenActivityResponse containing relevant activity data to the token.
*/
async getTokenActivity(args: {
tokenAddress: HexInput;
options?: {
pagination?: PaginationArgs;
orderBy?: OrderBy<GetTokenActivityResponse[0]>;
};
}): Promise<GetTokenActivityResponse> {
return getTokenActivity({ aptosConfig: this.config, ...args });
}
}
107 changes: 0 additions & 107 deletions src/api/token.ts

This file was deleted.

Loading

0 comments on commit a1d815d

Please sign in to comment.