Skip to content

Commit

Permalink
Merge pull request #216 from ainft-team/fix/hyeonwoong/ainftObject
Browse files Browse the repository at this point in the history
Update nftId to ainftObjectId & Update some functions name
  • Loading branch information
woomurf authored Oct 10, 2023
2 parents 8cef9c3 + f433dda commit 544a4ea
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/ainft721.ts → src/ainft721Object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Ain from "@ainblockchain/ain-js";
/**
* The class of AINFT 721.
*/
export default class Ainft721 extends FactoryBase {
export default class Ainft721Object extends FactoryBase {
readonly id: string;
readonly name: string;
readonly symbol: string;
Expand All @@ -26,12 +26,12 @@ export default class Ainft721 extends FactoryBase {
* @returns
*/
async get(tokenId: string) {
const { list } = await this.sendRequestWithoutSign(HttpMethod.GET, `native/search`, { nftId: this.id, tokenId });
const { list } = await this.sendRequestWithoutSign(HttpMethod.GET, `native/search/nfts`, { ainftObjectId: this.id, tokenId });
if (list.length === 0) {
throw new Error('Not found token');
}
const token = list[0];
return new AinftToken({ nftId: this.id, tokenId, tokenURI: token.tokenURI, metadata: token.metadata }, this.ain, this.baseUrl);
return new AinftToken({ ainftObjectId: this.id, tokenId, tokenURI: token.tokenURI, metadata: token.metadata }, this.ain, this.baseUrl);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/ainftToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { HttpMethod } from "./types";
* The class of AINFT Token.
*/
export class AinftToken extends FactoryBase {
readonly nftId: string;
readonly ainftObjectId: string;
readonly tokenId: string;
readonly metadata?: object;
readonly tokenURI: string;

constructor(tokenInfo: {nftId: string, tokenId: string, tokenURI: string, metadata?: object}, ain: Ain, baseUrl: string) {
constructor(tokenInfo: { ainftObjectId: string, tokenId: string, tokenURI: string, metadata?: object }, ain: Ain, baseUrl: string) {
super(ain, baseUrl);
this.nftId = tokenInfo.nftId;
this.ainftObjectId = tokenInfo.ainftObjectId;
this.tokenId = tokenInfo.tokenId;
this.tokenURI = tokenInfo.tokenURI;
this.metadata = tokenInfo.metadata;
Expand All @@ -26,7 +26,7 @@ export class AinftToken extends FactoryBase {
*/
async setMetadata(metadata: object) {
const address = await this.ain.signer.getAddress();
const body = { nftId: this.nftId, tokenId: this.tokenId, metadata, userAddress: address };
const body = { ainftObjectId: this.ainftObjectId, tokenId: this.tokenId, metadata, userAddress: address };
const trailingUrl = `native/metadata`;
const txBody = await this.sendRequestWithoutSign(HttpMethod.POST, trailingUrl, body);

Expand Down
48 changes: 24 additions & 24 deletions src/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
AinftTokenSearch,
AinftCollectionSearch,
} from './types';
import Ainft721 from './ainft721';
import Ainft721 from './ainft721Object';
import stringify from 'fast-json-stable-stringify';
import {SUPPORTED_AINFT_STANDARDS} from "./constants";

Expand All @@ -46,42 +46,42 @@ export default class Nft extends FactoryBase {

const body = { address, name, symbol };
const trailingUrl = 'native';
const { nftId, txBody, appId } = await this.sendRequest(HttpMethod.POST, trailingUrl, body);
const { ainftObjectId, txBody, appId } = await this.sendRequest(HttpMethod.POST, trailingUrl, body);
const txHash = await this.ain.sendTransaction(txBody);

console.log(`Ainft is created!`);
console.log('nft ID: ', nftId);
console.log(`AinftObject is created!`);
console.log('ainft object ID: ', ainftObjectId);
console.log('app ID: ', appId);
console.log(`txHash: `, txHash);

await this.register(nftId);
return this.get(nftId);
await this.register(ainftObjectId);
return this.get(ainftObjectId);
}

/**
* Register nft to factory server.
* @param nftId
* Register ainft object to factory server.
* @param ainftObjectId
* @returns
*/
async register(nftId: string) {
async register(ainftObjectId: string) {
const address = await this.ain.signer.getAddress();
const message = stringify({
address,
timestamp: Date.now(),
});
const signature = await this.ain.signer.signMessage(message, address);

const body = { signature, message, nftId };
const body = { signature, message, ainftObjectId };
const trailingUrl = 'native/register';
return this.sendRequest(HttpMethod.POST, trailingUrl, body);
}

/**
* Return Ainft instance by nftId.
* @param nftId
* Return Ainft instance by ainftObjectId.
* @param ainftObjectId
*/
async get(nftId: string) {
const { list } = await this.searchCollections({ nftId });
async get(ainftObjectId: string) {
const { list } = await this.searchAinftObjects({ ainftObjectId });
if (list.length === 0) {
throw new Error(`Not found ainft`);
}
Expand Down Expand Up @@ -267,31 +267,31 @@ export default class Nft extends FactoryBase {
}

/**
* Search nfts created on the ain blockchain.
* Search ainftObjects created on the ain blockchain.
* @returns
* @param {NftSearchParams & SearchOption} searchParams
*/
searchCollections(searchParams: NftSearchParams & SearchOption): Promise<SearchReponse<AinftCollectionSearch>> {
searchAinftObjects(searchParams: NftSearchParams & SearchOption): Promise<SearchReponse<AinftCollectionSearch>> {
let query: Record<string, any> = {};
if (searchParams) {
const { userAddress, nftId, name, symbol, limit, offset } = searchParams;
query = { userAddress, nftId, name, symbol, offset, limit };
const { userAddress, ainftObjectId, name, symbol, limit, offset } = searchParams;
query = { userAddress, ainftObjectId, name, symbol, offset, limit };
}
const trailingUrl = `native/search/collections`;
const trailingUrl = `native/search/ainftObjects`;
return this.sendRequest(HttpMethod.GET, trailingUrl, query);
}

/**
* Search nft assets on the ain blockchain.
* Search nfts on the ain blockchain.
* @param {NftSearchParams & SearchOption} searchParams
*/
searchAssets(searchParams: NftSearchParams & SearchOption): Promise<SearchReponse<AinftTokenSearch>> {
searchNfts(searchParams: NftSearchParams & SearchOption): Promise<SearchReponse<AinftTokenSearch>> {
let query: Record<string, any> = {};
if (searchParams) {
const { userAddress, nftId, name, symbol, limit, offset, tokenId } = searchParams;
query = { userAddress, nftId, name, symbol, offset, limit, tokenId };
const { userAddress, ainftObjectId, name, symbol, limit, offset, tokenId } = searchParams;
query = { userAddress, ainftObjectId, name, symbol, offset, limit, tokenId };
}
const trailingUrl = `native/search/assets`;
const trailingUrl = `native/search/nfts`;
return this.sendRequest(HttpMethod.GET, trailingUrl, query);
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ export interface MintNftParams extends Omit<getTxBodyMintNftParams, 'address'> {

export interface NftSearchParams {
userAddress?: string;
nftId?: string;
ainftObjectId?: string;
tokenId?: string;
name?: string;
symbol?: string;
Expand Down

0 comments on commit 544a4ea

Please sign in to comment.