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

【XRPL対応】mintメソッドの実装 #141

Merged
merged 29 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a156991
add API interface
passion0102 Apr 24, 2024
3c96c01
add XRPL blockchain interface
passion0102 May 3, 2024
56b5148
fix lint
passion0102 May 3, 2024
e7fe41a
migrate mumbai -> amoy
passion0102 May 3, 2024
f30a81c
convert to monorepo
passion0102 May 14, 2024
a153910
save
passion0102 May 14, 2024
5934cc2
fix CI
passion0102 May 18, 2024
f744a8d
fix: rm node_modules
thashimoto1998 Jun 11, 2024
b1b0825
Revert "fix: rm node_modules"
seki-seki Jun 11, 2024
d14caef
rm: node_modules
thashimoto1998 May 29, 2024
b87e675
chore: marge main to this branch
thashimoto1998 May 29, 2024
7267239
cherry pick: aa10a29
Huzitatuguharu May 20, 2024
cf8303f
feat: marge pr #148 & #150
thashimoto1998 Jun 12, 2024
1976da7
add mint & payment logic on XRPL
passion0102 Jun 16, 2024
0bf32d0
resolve divergence
passion0102 Jun 16, 2024
5470906
resolve conflicts
passion0102 Jun 26, 2024
2dda96a
pull multi-package
passion0102 Jun 26, 2024
696ee43
fix dependencies from vwbl-core
passion0102 Jun 26, 2024
a6288c8
add payMintFee & createManagedToken
passion0102 Jun 29, 2024
f6f89a9
update evm & core
passion0102 Jun 29, 2024
b12796b
resolve conflict
passion0102 Jun 29, 2024
41778b9
add README.md & LICENSE
passion0102 Jun 29, 2024
50cd8e9
update package.json
passion0102 Jun 29, 2024
e3b48d0
add types
passion0102 Jun 30, 2024
0688b7d
update README
passion0102 Jul 14, 2024
b2cce15
setKey for IPFS
passion0102 Jul 31, 2024
3cdd459
debug mint func
passion0102 Aug 4, 2024
c1691f7
fix API call
passion0102 Aug 6, 2024
86967c4
fetch minimum tx fee
passion0102 Aug 6, 2024
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
File renamed without changes.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/**/*
.eslintrc.*
**/test/**/*
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Lint & Test

on:
pull_request:
branches: "*"
branches: ["*"]

jobs:
ci:
Expand Down
3,533 changes: 2,059 additions & 1,474 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build:all": "nx run-many --target=build --all",
"build:core": "nx build vwbl-core",
"build:evm": "nx build vwbl-sdk",
"build:xrpl": "nx build vwbl-sdk-xrpl",
"lint:all": "npm run lint -ws",
"lint:core": "npm run lint -w vwbl-core",
"lint:evm": "npm run lint -w vwbl-sdk",
Expand All @@ -28,12 +29,17 @@
},
"devDependencies": {
"@eslint/js": "^9.4.0",
"@types/eslint__js": "^8.42.3",
"@nx/js": "19.3.0",
"@types/eslint__js": "^8.42.3",
"eslint": "^8.57.0",
"nx": "19.3.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"typescript-eslint": "^7.13.0"
},
"nx": {}
"nx": {},
"dependencies": {
"dotenv": "^16.4.5",
"xumm-sdk": "^1.11.1"
}
}
2 changes: 1 addition & 1 deletion packages/core/src/storage/aws/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const uploadThumbnail = async (
};

export const uploadMetadata = async (
tokenId: number,
tokenId: string | number,
name: string,
description: string,
previewImageUrl: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/vwbl/metadata/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export type ExtractMetadata = Metadata & {
ownFiles: ArrayBuffer[] | Stream[];
};

export type ExtendedMetadeta = Metadata & {
export type ExtendedMetadata = Metadata & {
address: string;
};
2 changes: 1 addition & 1 deletion packages/core/src/vwbl/types/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type UploadEncryptedFile = (
type UploadThumbnail = (thumbnailImage: FileOrPath, uuid: string) => Promise<string>;

type UploadMetadata = (
tokenId: number,
tokenId: string | number,
name: string,
description: string,
previewImageUrl: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export {
PlainMetadata,
Metadata,
ExtractMetadata,
ExtendedMetadeta,
ExtendedMetadata,
EncryptLogic,
UploadEncryptedFile,
UploadThumbnail,
Expand Down
164 changes: 121 additions & 43 deletions packages/evm/src/vwbl/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from "axios";
import { ethers } from "ethers";

import vwblDataCollector from "../contract/VWBLDataCollector.json";
import { ExtendedMetadeta, PlainMetadata } from "vwbl-core";
import { ExtendedMetadata, PlainMetadata } from "vwbl-core";
import { ViewerConstructorProps, ViewerOption } from "./types";

type TokenInfo = {
Expand All @@ -22,17 +22,31 @@ export class VWBLViewer {
this.dataCollector =
"eth" in provider
? new provider.eth.Contract(vwblDataCollector.abi, dataCollectorAddress)
: new ethers.Contract(dataCollectorAddress, vwblDataCollector.abi, provider);
: new ethers.Contract(
dataCollectorAddress,
vwblDataCollector.abi,
provider
);
}

getMetadata = async (contractAddress: string, tokenId: number): Promise<ExtendedMetadeta | undefined> => {
getMetadata = async (
contractAddress: string,
tokenId: number
): Promise<ExtendedMetadata | undefined> => {
if (!this.dataCollector) throw new Error("please set dataCollectorAddress");
const metadataUrl =
"callStatic" in this.dataCollector
? await this.dataCollector.callStatic.getTokenURI(contractAddress, tokenId)
: await this.dataCollector.methods.getTokenURI(contractAddress, tokenId).call();
? await this.dataCollector.callStatic.getTokenURI(
contractAddress,
tokenId
)
: await this.dataCollector.methods
.getTokenURI(contractAddress, tokenId)
.call();
if (!metadataUrl) return undefined;
const metadata: PlainMetadata = (await axios.get(metadataUrl).catch(() => undefined))?.data;
const metadata: PlainMetadata = (
await axios.get(metadataUrl).catch(() => undefined)
)?.data;
if (!metadata) return undefined;
return {
id: tokenId,
Expand All @@ -45,15 +59,23 @@ export class VWBLViewer {
};
};

listMetadata = async (contractAddress: string): Promise<(ExtendedMetadeta | undefined)[]> => {
listMetadata = async (
contractAddress: string
): Promise<(ExtendedMetadata | undefined)[]> => {
if (!this.dataCollector) throw new Error("please set dataCollectorAddress");
const tokens =
"callStatic" in this.dataCollector
? await this.dataCollector.callStatic.getAllTokensFromOptionalContract(contractAddress)
: await this.dataCollector.methods.getAllTokensFromOptionalContract(contractAddress).call();
const items: (ExtendedMetadeta | undefined)[] = await Promise.all(
? await this.dataCollector.callStatic.getAllTokensFromOptionalContract(
contractAddress
)
: await this.dataCollector.methods
.getAllTokensFromOptionalContract(contractAddress)
.call();
const items: (ExtendedMetadata | undefined)[] = await Promise.all(
tokens.map(async (token: TokenInfo) => {
const metadata: PlainMetadata = (await axios.get(token.tokenURI).catch(() => undefined))?.data;
const metadata: PlainMetadata = (
await axios.get(token.tokenURI).catch(() => undefined)
)?.data;
if (!metadata) return undefined;
return {
id: token.tokenId,
Expand All @@ -69,25 +91,33 @@ export class VWBLViewer {
return items;
};

listMetadataFormMultiContracts = async (contracts: string[]): Promise<(ExtendedMetadeta | undefined)[]> => {
listMetadataFormMultiContracts = async (
contracts: string[]
): Promise<(ExtendedMetadata | undefined)[]> => {
if (!this.dataCollector) throw new Error("please set dataCollectorAddress");
const allItems: (ExtendedMetadeta | undefined)[] = [];
const allItems: (ExtendedMetadata | undefined)[] = [];
for (const addr of contracts) {
const items = await this.listMetadata(addr);
allItems.push(...items);
}
return allItems;
};

listAllOwnedMetadata = async (userAddress: string): Promise<(ExtendedMetadeta | undefined)[]> => {
listAllOwnedMetadata = async (
userAddress: string
): Promise<(ExtendedMetadata | undefined)[]> => {
if (!this.dataCollector) throw new Error("please set dataCollectorAddress");
const tokens =
"callStatic" in this.dataCollector
? await this.dataCollector.callStatic.getAllOwnedTokens(userAddress)
: await this.dataCollector.methods.getAllOwnedTokens(userAddress).call();
const items: (ExtendedMetadeta | undefined)[] = await Promise.all(
: await this.dataCollector.methods
.getAllOwnedTokens(userAddress)
.call();
const items: (ExtendedMetadata | undefined)[] = await Promise.all(
tokens.map(async (token: TokenInfo) => {
const metadata: PlainMetadata = (await axios.get(token.tokenURI).catch(() => undefined))?.data;
const metadata: PlainMetadata = (
await axios.get(token.tokenURI).catch(() => undefined)
)?.data;
if (!metadata) return undefined;
return {
id: token.tokenId,
Expand All @@ -103,15 +133,19 @@ export class VWBLViewer {
return items;
};

listOwnedNFTMetadata = async (userAddress: string): Promise<(ExtendedMetadeta | undefined)[]> => {
listOwnedNFTMetadata = async (
userAddress: string
): Promise<(ExtendedMetadata | undefined)[]> => {
if (!this.dataCollector) throw new Error("please set dataCollectorAddress");
const tokens =
"callStatic" in this.dataCollector
? await this.dataCollector.callStatic.getOwnedNFTs(userAddress)
: await this.dataCollector.methods.getOwnedNFTs(userAddress).call();
const items: (ExtendedMetadeta | undefined)[] = await Promise.all(
const items: (ExtendedMetadata | undefined)[] = await Promise.all(
tokens.map(async (token: TokenInfo) => {
const metadata: PlainMetadata = (await axios.get(token.tokenURI).catch(() => undefined))?.data;
const metadata: PlainMetadata = (
await axios.get(token.tokenURI).catch(() => undefined)
)?.data;
if (!metadata) return undefined;
return {
id: token.tokenId,
Expand All @@ -127,15 +161,19 @@ export class VWBLViewer {
return items;
};

listOwnedERC1155Metadata = async (userAddress: string): Promise<(ExtendedMetadeta | undefined)[]> => {
listOwnedERC1155Metadata = async (
userAddress: string
): Promise<(ExtendedMetadata | undefined)[]> => {
if (!this.dataCollector) throw new Error("please set dataCollectorAddress");
const tokens =
"callStatic" in this.dataCollector
? await this.dataCollector.callStatic.getOwnedERC1155s(userAddress)
: await this.dataCollector.methods.getOwnedERC1155s(userAddress).call();
const items: (ExtendedMetadeta | undefined)[] = await Promise.all(
const items: (ExtendedMetadata | undefined)[] = await Promise.all(
tokens.map(async (token: TokenInfo) => {
const metadata: PlainMetadata = (await axios.get(token.tokenURI).catch(() => undefined))?.data;
const metadata: PlainMetadata = (
await axios.get(token.tokenURI).catch(() => undefined)
)?.data;
if (!metadata) return undefined;
return {
id: token.tokenId,
Expand All @@ -151,15 +189,21 @@ export class VWBLViewer {
return items;
};

listAllMintedMetadata = async (userAddress: string): Promise<(ExtendedMetadeta | undefined)[]> => {
listAllMintedMetadata = async (
userAddress: string
): Promise<(ExtendedMetadata | undefined)[]> => {
if (!this.dataCollector) throw new Error("please set dataCollectorAddress");
const tokens =
"callStatic" in this.dataCollector
? await this.dataCollector.callStatic.getAllMintedTokens(userAddress)
: await this.dataCollector.methods.getAllMintedTokens(userAddress).call();
const items: (ExtendedMetadeta | undefined)[] = await Promise.all(
: await this.dataCollector.methods
.getAllMintedTokens(userAddress)
.call();
const items: (ExtendedMetadata | undefined)[] = await Promise.all(
tokens.map(async (token: TokenInfo) => {
const metadata: PlainMetadata = (await axios.get(token.tokenURI).catch(() => undefined))?.data;
const metadata: PlainMetadata = (
await axios.get(token.tokenURI).catch(() => undefined)
)?.data;
if (!metadata) return undefined;
return {
id: token.tokenId,
Expand All @@ -175,15 +219,19 @@ export class VWBLViewer {
return items;
};

listMintedNFTMetadata = async (userAddress: string): Promise<(ExtendedMetadeta | undefined)[]> => {
listMintedNFTMetadata = async (
userAddress: string
): Promise<(ExtendedMetadata | undefined)[]> => {
if (!this.dataCollector) throw new Error("please set dataCollectorAddress");
const tokens =
"callStatic" in this.dataCollector
? await this.dataCollector.callStatic.getMintedNFTs(userAddress)
: await this.dataCollector.methods.getMintedNFTs(userAddress).call();
const items: (ExtendedMetadeta | undefined)[] = await Promise.all(
const items: (ExtendedMetadata | undefined)[] = await Promise.all(
tokens.map(async (token: TokenInfo) => {
const metadata: PlainMetadata = (await axios.get(token.tokenURI).catch(() => undefined))?.data;
const metadata: PlainMetadata = (
await axios.get(token.tokenURI).catch(() => undefined)
)?.data;
if (!metadata) return undefined;
return {
id: token.tokenId,
Expand All @@ -199,15 +247,21 @@ export class VWBLViewer {
return items;
};

listMintedERC1155Metadata = async (userAddress: string): Promise<(ExtendedMetadeta | undefined)[]> => {
listMintedERC1155Metadata = async (
userAddress: string
): Promise<(ExtendedMetadata | undefined)[]> => {
if (!this.dataCollector) throw new Error("please set dataCollectorAddress");
const tokens =
"callStatic" in this.dataCollector
? await this.dataCollector.callStatic.getMintedERC1155s(userAddress)
: await this.dataCollector.methods.getMintedERC1155s(userAddress).call();
const items: (ExtendedMetadeta | undefined)[] = await Promise.all(
: await this.dataCollector.methods
.getMintedERC1155s(userAddress)
.call();
const items: (ExtendedMetadata | undefined)[] = await Promise.all(
tokens.map(async (token: TokenInfo) => {
const metadata: PlainMetadata = (await axios.get(token.tokenURI).catch(() => undefined))?.data;
const metadata: PlainMetadata = (
await axios.get(token.tokenURI).catch(() => undefined)
)?.data;
if (!metadata) return undefined;
return {
id: token.tokenId,
Expand All @@ -223,32 +277,56 @@ export class VWBLViewer {
return items;
};

getMetadataUrl = async (contractAddress: string, tokenId: number): Promise<string | undefined> => {
getMetadataUrl = async (
contractAddress: string,
tokenId: number
): Promise<string | undefined> => {
if (!this.dataCollector) throw new Error("please set dataCollectorAddress");
const metadataUrl =
"callStatic" in this.dataCollector
? await this.dataCollector.callStatic.getTokenURI(contractAddress, tokenId)
: await this.dataCollector.methods.getTokenURI(contractAddress, tokenId).call();
? await this.dataCollector.callStatic.getTokenURI(
contractAddress,
tokenId
)
: await this.dataCollector.methods
.getTokenURI(contractAddress, tokenId)
.call();
if (!metadataUrl) return undefined;
return metadataUrl;
};

getDocumentId = async (contractAddress: string, tokenId: number): Promise<string | undefined> => {
getDocumentId = async (
contractAddress: string,
tokenId: number
): Promise<string | undefined> => {
if (!this.dataCollector) throw new Error("please set dataCollectorAddress");
const documentId =
"callStatic" in this.dataCollector
? await this.dataCollector.callStatic.getDocumentId(contractAddress, tokenId)
: await this.dataCollector.methods.getDocumentId(contractAddress, tokenId).call();
? await this.dataCollector.callStatic.getDocumentId(
contractAddress,
tokenId
)
: await this.dataCollector.methods
.getDocumentId(contractAddress, tokenId)
.call();
if (!documentId) return undefined;
return documentId;
};

getNFTOwner = async (contractAddress: string, tokenId: number): Promise<string> => {
getNFTOwner = async (
contractAddress: string,
tokenId: number
): Promise<string> => {
if (!this.dataCollector) throw new Error("please set dataCollectorAddress");
const owner =
"callStatic" in this.dataCollector
? await this.dataCollector.callStatic.getNFTOwner(contractAddress, tokenId)
: await this.dataCollector.methods.getNFTOwner(contractAddress, tokenId).call();
? await this.dataCollector.callStatic.getNFTOwner(
contractAddress,
tokenId
)
: await this.dataCollector.methods
.getNFTOwner(contractAddress, tokenId)
.call();
return owner;
};
}
Empty file added packages/xrpl/.env.example
Empty file.
6 changes: 6 additions & 0 deletions packages/xrpl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.idea
dist
.DS_Store

*.env
Loading