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

fixed chain/get & chain/getAll to check chainOverride #444

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@sinclair/typebox": "^0.31.28",
"@t3-oss/env-core": "^0.6.0",
"@thirdweb-dev/auth": "^4.1.27",
"@thirdweb-dev/chains": "0.1.70",
"@thirdweb-dev/chains": "^0.1.77",
"@thirdweb-dev/sdk": "4.0.36-nightly-fa637c2e3-20240214074441",
"@thirdweb-dev/service-utils": "0.4.17",
"@thirdweb-dev/wallets": "^2.1.5",
Expand Down
18 changes: 15 additions & 3 deletions src/server/routes/chain/get.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { Static, Type } from "@sinclair/typebox";
import {
Chain,
getChainByChainIdAsync,
getChainBySlugAsync,
minimizeChain,
} from "@thirdweb-dev/chains";
import { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { getConfig } from "../../../utils/cache/getConfig";
import { createCustomError } from "../../middleware/error";
import {
chainRequestQuerystringSchema,
chainResponseSchema,
} from "../../schemas/chain";
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: chainResponseSchema,
});
Expand Down Expand Up @@ -58,10 +60,20 @@ export async function getChainData(fastify: FastifyInstance) {
},
handler: async (request, reply) => {
const { chain } = request.query;
const config = await getConfig();

let chainData: Chain | null = null;
if (config.chainOverrides) {
chainData = JSON.parse(config.chainOverrides).find(
(dt: Chain) => dt.slug === chain || dt.chainId === parseInt(chain),
);
}

let chainData = await getChainBySlugAsync(chain);
if (!chainData) {
chainData = await getChainByChainIdAsync(parseInt(chain));
chainData = await getChainBySlugAsync(chain);
if (!chainData) {
chainData = await getChainByChainIdAsync(parseInt(chain));
}
}

if (!chainData) {
Expand Down
28 changes: 25 additions & 3 deletions src/server/routes/chain/getAll.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Static, Type } from "@sinclair/typebox";
import { allChains, minimizeChain } from "@thirdweb-dev/chains";
import { Chain, fetchChains, minimizeChain } from "@thirdweb-dev/chains";
import { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { getConfig } from "../../../utils/cache/getConfig";
import { chainResponseSchema } from "../../schemas/chain";
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(chainResponseSchema),
});
Expand Down Expand Up @@ -63,14 +64,35 @@ export async function getAllChainData(fastify: FastifyInstance) {
},
},
handler: async (request, reply) => {
const chain = allChains.map((chain) => {
const allChainsData = await fetchChains();
const config = await getConfig();

let chain = (allChainsData ?? ([] as Chain[])).map((chain) => {
const minimizeChainData = minimizeChain(chain);
if (chain.rpc.length === 0) {
return { ...minimizeChainData, rpc: [""] };
}
return { ...minimizeChainData, rpc: [minimizeChainData.rpc[0]] };
});

let chainOverrides: typeof chain = [];

if (config.chainOverrides) {
chainOverrides = (JSON.parse(config.chainOverrides) as Chain[]).map(
(overrideChain) => {
const shortName = overrideChain.shortName
? overrideChain.shortName
: "";
const rpc =
overrideChain.rpc.length === 0 ? [""] : [overrideChain.rpc[0]];
return { ...overrideChain, shortName, rpc };
},
);
}

// Concatenate chain and chainOverrides
chain = chain.concat(chainOverrides);

reply.status(StatusCodes.OK).send({
result: chain,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const requestQueryString = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Boolean(),
});
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/contract/extensions/erc1155/read/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const querystringSchema = Type.Object({
}),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: nftSchema,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const requestQueryString = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: claimConditionOutputSchema,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const querystringSchema = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(nftSchema),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const requestQueryString = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(claimConditionOutputSchema),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const requestQueryString = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(Type.Union([Type.String(), Type.Enum(ClaimEligibility)])),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const requestQueryString = Type.Object({
}),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: claimerProofSchema,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const querystringSchema = Type.Object({
}),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(nftSchema),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getChainIdFromChain } from "../../../../../utils/chain";
// INPUT
const requestSchema = erc1155ContractParamSchema;

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Optional(Type.String()),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const querystringSchema = Type.Object({
}),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Optional(Type.String()),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const requestQueryString = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Boolean(),
});
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/contract/extensions/erc20/read/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getChainIdFromChain } from "../../../../../utils/chain";
// INPUT
const requestSchema = erc20ContractParamSchema;

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Object({
name: Type.String(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const requestQueryString = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: claimConditionOutputSchema,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const requestQueryString = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(claimConditionOutputSchema),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const requestQueryString = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(Type.Union([Type.String(), Type.Enum(ClaimEligibility)])),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const requestQueryString = Type.Object({
}),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: claimerProofSchema,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getChainIdFromChain } from "../../../../../utils/chain";
// INPUT
const requestSchema = erc20ContractParamSchema;

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: erc20MetadataSchema,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const requestQueryString = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Boolean(),
});
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/contract/extensions/erc721/read/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const querystringSchema = Type.Object({
}),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: nftSchema,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const requestQueryString = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: claimConditionOutputSchema,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const querystringSchema = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(nftSchema),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const requestQueryString = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(claimConditionOutputSchema),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const requestQueryString = Type.Object({
),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(Type.Union([Type.String(), Type.Enum(ClaimEligibility)])),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const requestQueryString = Type.Object({
}),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: claimerProofSchema,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const querystringSchema = Type.Object({
}),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(nftSchema),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getChainIdFromChain } from "../../../../../utils/chain";
// INPUT
const requestSchema = contractParamSchema;

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Optional(Type.String()),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getChainIdFromChain } from "../../../../../utils/chain";
// INPUT
const requestSchema = contractParamSchema;

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Optional(Type.String()),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getChainIdFromChain } from "../../../../../utils/chain";
// INPUT
const requestSchema = contractParamSchema;

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Optional(Type.String()),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { formatDirectListingV3Result } from "../../../../../../utils/marketplace
const requestSchema = marketplaceV3ContractParamSchema;
const requestQuerySchema = Type.Omit(marketplaceFilterSchema, ["offeror"]);

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(directListingV3OutputSchema),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { formatDirectListingV3Result } from "../../../../../../utils/marketplace
const requestSchema = marketplaceV3ContractParamSchema;
const requestQuerySchema = Type.Omit(marketplaceFilterSchema, ["offeror"]);

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(directListingV3OutputSchema),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const requestQuerySchema = Type.Object({
}),
});

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: directListingV3OutputSchema,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getChainIdFromChain } from "../../../../../../utils/chain";
// INPUT
const requestSchema = marketplaceV3ContractParamSchema;

// OUPUT
// OUTPUT
const responseSchema = Type.Object({
result: Type.String(),
});
Expand Down
Loading