Skip to content

Commit

Permalink
fix: remove unnecessary resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
Julieta11 committed Aug 9, 2023
1 parent 154f684 commit 4afd218
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 105 deletions.
12 changes: 1 addition & 11 deletions etc/urn-resolver.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ export type BlockchainCollectionV1Item = Omit<BlockchainCollectionV1Asset, 'type
tokenId: string;
};

// @public (undocumented)
export type BlockchainCollectionV1TokenId = BlockchainCollectionV1 & {
tokenId: string;
};

// @public (undocumented)
export type BlockchainCollectionV2 = BaseBlockchainAsset & {
namespace: 'decentraland';
Expand All @@ -97,19 +92,14 @@ export type BlockchainCollectionV2Item = Omit<BlockchainCollectionV2Asset, 'type
tokenId: string;
};

// @public (undocumented)
export type BlockchainCollectionV2TokenId = BlockchainCollectionV2 & {
tokenId: string;
};

// @public (undocumented)
export type BlockchainLandAsset = BlockchainAsset & {
x: number;
y: number;
};

// @public (undocumented)
export type DecentralandAssetIdentifier = BlockchainAsset | OffChainAsset | EntityV3Asset | BlockchainCollectionV1Asset | BlockchainCollectionV1Item | BlockchainCollectionV2Asset | BlockchainCollectionV2Item | BlockchainLandAsset | BlockchainCollectionV1 | BlockchainCollectionV1TokenId | BlockchainCollectionV2 | BlockchainCollectionV2TokenId | BlockchainCollectionThirdPartyName | BlockchainCollectionThirdPartyCollection | BlockchainCollectionThirdParty;
export type DecentralandAssetIdentifier = BlockchainAsset | OffChainAsset | EntityV3Asset | BlockchainCollectionV1Asset | BlockchainCollectionV1Item | BlockchainCollectionV2Asset | BlockchainCollectionV2Item | BlockchainLandAsset | BlockchainCollectionV1 | BlockchainCollectionV2 | BlockchainCollectionThirdPartyName | BlockchainCollectionThirdPartyCollection | BlockchainCollectionThirdParty;

// @public (undocumented)
export type EntityV3Asset = {
Expand Down
79 changes: 1 addition & 78 deletions src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import {
BlockchainCollectionThirdPartyName,
EntityV3Asset,
BlockchainCollectionV1Item,
BlockchainCollectionV2Item,
BlockchainCollectionV1TokenId,
BlockchainCollectionV2TokenId
BlockchainCollectionV2Item
} from './types'

/**
Expand Down Expand Up @@ -50,17 +48,10 @@ export const resolvers: RouteMap<DecentralandAssetIdentifier> = {
resolveCollectionV2AssetTokenId,
// collections v1 (by contract)
'decentraland:{network}:collections-v1:{contract(0x[a-fA-F0-9]+)}': resolveCollectionV1,
// collections v1 (by contract) tokenId
'decentraland:{network}:collections-v1:{contract(0x[a-fA-F0-9]+)}:{tokenId([0-9]+)}': resolveCollectionV1TokenId,
// collections v1 (by name) itemId
'decentraland:{network}:collections-v1:{collectionName}': resolveCollectionV1ByCollectionName,
// collections v1 (by name) itemId tokenId
'decentraland:{network}:collections-v1:{collectionName}:{tokenId([0-9]+)}':
resolveCollectionV1ByCollectionNameTokenId,
// collections v2
'decentraland:{network}:collections-v2:{contract(0x[a-fA-F0-9]+)}': resolveCollectionV2,
// collections v2 tokenId
'decentraland:{network}:collections-v2:{contract(0x[a-fA-F0-9]+)}:{tokenId([0-9]+)}': resolveCollectionV2TokenId,
// resolve LAND by position
'decentraland:{network}:LAND:{position}': resolveLandAsset,
// resolve third party names
Expand Down Expand Up @@ -370,30 +361,6 @@ export async function resolveCollectionV1(
}
}

export async function resolveCollectionV1TokenId(
uri: URL,
groups: Record<'network' | 'contract' | 'tokenId', string>
): Promise<BlockchainCollectionV1TokenId | void> {
if (!isValidNetwork(groups.network)) return

const contract = await getContract(groups.network, groups.contract)

if (contract) {
const collection = await getCollection(contract)

return {
namespace: 'decentraland',
uri,
blockchain: 'ethereum',
type: 'blockchain-collection-v1',
network: groups.network == 'ethereum' ? 'mainnet' : groups.network.toLowerCase(),
id: contract,
collectionName: collection ? collection.collectionId : null,
tokenId: groups.tokenId
}
}
}

export async function resolveCollectionV1ByCollectionName(
uri: URL,
groups: Record<'network' | 'collectionName', string>
Expand All @@ -416,29 +383,6 @@ export async function resolveCollectionV1ByCollectionName(
}
}

export async function resolveCollectionV1ByCollectionNameTokenId(
uri: URL,
groups: Record<'network' | 'collectionName' | 'tokenId', string>
): Promise<BlockchainCollectionV1TokenId | void> {
// this only works in mainnet
if (groups.network != 'ethereum') return

const collection = await getCollection(groups.collectionName)

if (collection) {
return {
namespace: 'decentraland',
uri,
blockchain: 'ethereum',
type: 'blockchain-collection-v1',
network: 'mainnet',
id: collection.contractAddress,
collectionName: groups.collectionName,
tokenId: groups.tokenId
}
}
}

export async function resolveCollectionV2(
uri: URL,
groups: Record<'network' | 'contract', string>
Expand All @@ -459,27 +403,6 @@ export async function resolveCollectionV2(
}
}

export async function resolveCollectionV2TokenId(
uri: URL,
groups: Record<'network' | 'contract' | 'tokenId', string>
): Promise<BlockchainCollectionV2TokenId | void> {
if (!isValidNetwork(groups.network)) return

const contract = await getContract(groups.network, groups.contract)

if (contract)
return {
namespace: 'decentraland',
uri,
blockchain: 'ethereum',
type: 'blockchain-collection-v2',
network: groups.network == 'ethereum' ? 'mainnet' : groups.network.toLowerCase(),
contractAddress: contract,
id: contract,
tokenId: groups.tokenId
}
}

export async function resolveThirdPartyCollection(
uri: URL,
groups: Record<'network' | 'thirdPartyName' | 'collectionId' | 'itemId', string>
Expand Down
16 changes: 0 additions & 16 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ export type BlockchainCollectionV1 = {
collectionName: string | null
}

/**
* @public
*/
export type BlockchainCollectionV1TokenId = BlockchainCollectionV1 & {
tokenId: string
}

/**
* @public
*/
Expand Down Expand Up @@ -135,13 +128,6 @@ export type BlockchainCollectionV2 = BaseBlockchainAsset & {
id: string
}

/**
* @public
*/
export type BlockchainCollectionV2TokenId = BlockchainCollectionV2 & {
tokenId: string
}

/**
* @public
*/
Expand Down Expand Up @@ -222,9 +208,7 @@ export type DecentralandAssetIdentifier =
| BlockchainCollectionV2Item
| BlockchainLandAsset
| BlockchainCollectionV1
| BlockchainCollectionV1TokenId
| BlockchainCollectionV2
| BlockchainCollectionV2TokenId
| BlockchainCollectionThirdPartyName
| BlockchainCollectionThirdPartyCollection
| BlockchainCollectionThirdParty

0 comments on commit 4afd218

Please sign in to comment.