@collabland/chain
Advanced tools
Comparing version 0.14.5 to 0.15.0
@@ -0,5 +1,6 @@ | ||
import { AssetMetadata, AssetResource } from '.'; | ||
import { AssetName, AssetTypeParams } from './caip'; | ||
import { ChainConnector } from './chain-connector'; | ||
import { AccountIdResource, AssetResource, ChainIdResource } from './chain-resource'; | ||
import { Amount, AssetMetadata, AssetRequest, AssetResponse, ChainOptions, ChainType, NativeCurrency, NFTAssetOptions, TokenAsset, TokenId, TokenMetadata } from './types'; | ||
import { AccountIdResource, ChainIdResource } from './chain-resource'; | ||
import { Amount, AssetRequest, AssetResponse, ChainOptions, ChainType, NativeCurrency, NFTAssetOptions, TokenAsset, TokenId, TokenMetadata } from './types'; | ||
/** | ||
@@ -6,0 +7,0 @@ * Base chain connector |
@@ -12,2 +12,3 @@ "use strict"; | ||
const chain_resource_1 = require("./chain-resource"); | ||
const ipfs_1 = require("./ipfs"); | ||
const types_1 = require("./types"); | ||
@@ -83,29 +84,42 @@ const debug = (0, common_1.debugFactory)('collabland:connector'); | ||
}); | ||
if (this.isNative(req.namespace)) { | ||
const nativeBalance = await this.getBalance(account); | ||
asset = { balance: nativeBalance, asset: assetUri }; | ||
return asset; | ||
try { | ||
if (this.isNative(req.namespace)) { | ||
const nativeBalance = await this.getBalance(account); | ||
asset = { balance: nativeBalance, asset: assetUri }; | ||
return asset; | ||
} | ||
else if (req.namespace.toLowerCase() === 'ft' || | ||
(await this.isFT(req.namespace))) { | ||
const ftBalance = await this.getFTBalance(account, assetName); | ||
asset = { balance: ftBalance, asset: assetUri }; | ||
return asset; | ||
} | ||
else if (req.namespace.toLowerCase() === 'nft' || | ||
(await this.isNFT(req.namespace))) { | ||
const metadata = (_b = req.metadata) !== null && _b !== void 0 ? _b : options === null || options === void 0 ? void 0 : options.metadata; | ||
const nftOptions = { | ||
tokenId, | ||
metadata: metadata !== false, | ||
}; | ||
const nfts = await this.getNFTBalance(account, assetName, nftOptions); | ||
asset = { | ||
balance: this.toAmount(nfts.length), | ||
tokens: nfts, | ||
asset: assetUri, | ||
}; | ||
return asset; | ||
} | ||
throw new common_1.HttpErrors.BadRequest(`Invalid asset request: ${assetName}/${req.tokenId}`); | ||
} | ||
else if (req.namespace.toLowerCase() === 'ft' || | ||
(await this.isFT(req.namespace))) { | ||
const ftBalance = await this.getFTBalance(account, assetName); | ||
asset = { balance: ftBalance, asset: assetUri }; | ||
return asset; | ||
catch (err) { | ||
debug('Fail to get balance of %s for %s: %O', assetUri, account, err); | ||
if (err.code === 'CALL_EXCEPTION') { | ||
return { | ||
balance: this.toAmount(0), | ||
tokens: [], | ||
asset: assetUri, | ||
}; | ||
} | ||
throw err; | ||
} | ||
else if (req.namespace.toLowerCase() === 'nft' || | ||
(await this.isNFT(req.namespace))) { | ||
const metadata = (_b = req.metadata) !== null && _b !== void 0 ? _b : options === null || options === void 0 ? void 0 : options.metadata; | ||
const nftOptions = { | ||
tokenId, | ||
metadata: metadata !== false, | ||
}; | ||
const nfts = await this.getNFTBalance(account, assetName, nftOptions); | ||
asset = { | ||
balance: this.toAmount(nfts.length), | ||
tokens: nfts, | ||
asset: assetUri, | ||
}; | ||
return asset; | ||
} | ||
throw new common_1.HttpErrors.BadRequest(`Invalid asset request: ${assetName}/${req.tokenId}`); | ||
}, { concurrency: this.concurrency }); | ||
@@ -137,6 +151,6 @@ debug('Assets: %s', (0, common_1.stringify)(assets)); | ||
if (url.startsWith('ipfs://')) { | ||
const ipfsGateway = (0, common_1.getEnvVar)('IPFS_GATEWAY_URL', 'https://ipfs.io'); | ||
const ipfsGateway = (0, common_1.getEnvVar)('IPFS_GATEWAY_URL', 'https://collabland.mypinata.cloud'); | ||
// https://{gateway URL}/ipfs/{CID}/{optional path to resource} | ||
// https://{CID}.ipfs.{gatewayURL}/{optional path to resource} | ||
url = url.replace('ipfs://', `${ipfsGateway}/`); | ||
url = (0, ipfs_1.getIPFSGatewayUrl)(url, ipfsGateway); | ||
debug('IPFS http url: %s', url); | ||
@@ -143,0 +157,0 @@ } |
@@ -12,4 +12,4 @@ "use strict"; | ||
// See https://github.com/ChainAgnostic/CAIPs/issues/63 | ||
const assetReference = '[-a-zA-Z0-9._]{1,64}'; | ||
const accountAddress = '[a-zA-Z0-9._]{1,64}'; | ||
const assetReference = '[-a-zA-Z0-9._]{1,128}'; | ||
const accountAddress = '[a-zA-Z0-9._]{1,128}'; | ||
/** | ||
@@ -16,0 +16,0 @@ * Extension: we want to allow multiple token ids, such as `1-100` or `1,3,100`. |
{ | ||
"name": "@collabland/chain", | ||
"version": "0.14.5", | ||
"version": "0.15.0", | ||
"description": "CollabLand Ethereum Integration", | ||
@@ -34,15 +34,16 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@collabland/common": "^0.25.2", | ||
"@collabland/common": "^0.26.0", | ||
"is-ipfs": "^6.0.2", | ||
"tslib": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@loopback/build": "^7.0.1", | ||
"@loopback/eslint-config": "^11.0.1", | ||
"@loopback/testlab": "^3.4.3", | ||
"@loopback/build": "^7.0.2", | ||
"@loopback/eslint-config": "^11.0.2", | ||
"@loopback/testlab": "^3.4.4", | ||
"@types/node": "^12.12.6", | ||
"typescript": "~4.4.2" | ||
"typescript": "~4.4.4" | ||
}, | ||
"copyright.owner": "Abridged, Inc.", | ||
"author": "Abridged, Inc.", | ||
"gitHead": "3b88a84c0572e426788dcf3632a73ea06fbd2a17" | ||
"gitHead": "2fb2a2a33b8afa9d6208ddac65c4ddc6dd66dca8" | ||
} |
@@ -16,2 +16,3 @@ // Copyright Abridged, Inc. 2021. All Rights Reserved. | ||
} from '@collabland/common'; | ||
import {AssetMetadata, AssetResource} from '.'; | ||
import {AssetName, AssetTypeParams} from './caip'; | ||
@@ -22,3 +23,2 @@ import {AssetNameId} from './caip/asset-name-id'; | ||
AccountIdResource, | ||
AssetResource, | ||
ChainIdResource, | ||
@@ -28,5 +28,5 @@ getChainUri, | ||
} from './chain-resource'; | ||
import {getIPFSGatewayUrl} from './ipfs'; | ||
import { | ||
Amount, | ||
AssetMetadata, | ||
AssetRequest, | ||
@@ -154,33 +154,49 @@ AssetResponse, | ||
}); | ||
if (this.isNative(req.namespace)) { | ||
const nativeBalance = await this.getBalance(account); | ||
asset = {balance: nativeBalance, asset: assetUri}; | ||
return asset; | ||
} else if ( | ||
req.namespace.toLowerCase() === 'ft' || | ||
(await this.isFT(req.namespace)) | ||
) { | ||
const ftBalance = await this.getFTBalance(account, assetName); | ||
asset = {balance: ftBalance, asset: assetUri}; | ||
return asset; | ||
} else if ( | ||
req.namespace.toLowerCase() === 'nft' || | ||
(await this.isNFT(req.namespace)) | ||
) { | ||
const metadata = req.metadata ?? options?.metadata; | ||
const nftOptions: NFTAssetOptions = { | ||
tokenId, | ||
metadata: metadata !== false, | ||
}; | ||
const nfts = await this.getNFTBalance(account, assetName, nftOptions); | ||
asset = { | ||
balance: this.toAmount(nfts.length), | ||
tokens: nfts, | ||
asset: assetUri, | ||
}; | ||
return asset; | ||
try { | ||
if (this.isNative(req.namespace)) { | ||
const nativeBalance = await this.getBalance(account); | ||
asset = {balance: nativeBalance, asset: assetUri}; | ||
return asset; | ||
} else if ( | ||
req.namespace.toLowerCase() === 'ft' || | ||
(await this.isFT(req.namespace)) | ||
) { | ||
const ftBalance = await this.getFTBalance(account, assetName); | ||
asset = {balance: ftBalance, asset: assetUri}; | ||
return asset; | ||
} else if ( | ||
req.namespace.toLowerCase() === 'nft' || | ||
(await this.isNFT(req.namespace)) | ||
) { | ||
const metadata = req.metadata ?? options?.metadata; | ||
const nftOptions: NFTAssetOptions = { | ||
tokenId, | ||
metadata: metadata !== false, | ||
}; | ||
const nfts = await this.getNFTBalance( | ||
account, | ||
assetName, | ||
nftOptions, | ||
); | ||
asset = { | ||
balance: this.toAmount(nfts.length), | ||
tokens: nfts, | ||
asset: assetUri, | ||
}; | ||
return asset; | ||
} | ||
throw new HttpErrors.BadRequest( | ||
`Invalid asset request: ${assetName}/${req.tokenId}`, | ||
); | ||
} catch (err: AnyError) { | ||
debug('Fail to get balance of %s for %s: %O', assetUri, account, err); | ||
if (err.code === 'CALL_EXCEPTION') { | ||
return { | ||
balance: this.toAmount(0), | ||
tokens: [], | ||
asset: assetUri, | ||
}; | ||
} | ||
throw err; | ||
} | ||
throw new HttpErrors.BadRequest( | ||
`Invalid asset request: ${assetName}/${req.tokenId}`, | ||
); | ||
}, | ||
@@ -222,6 +238,9 @@ {concurrency: this.concurrency}, | ||
if (url.startsWith('ipfs://')) { | ||
const ipfsGateway = getEnvVar('IPFS_GATEWAY_URL', 'https://ipfs.io'); | ||
const ipfsGateway = getEnvVar( | ||
'IPFS_GATEWAY_URL', | ||
'https://collabland.mypinata.cloud', | ||
); | ||
// https://{gateway URL}/ipfs/{CID}/{optional path to resource} | ||
// https://{CID}.ipfs.{gatewayURL}/{optional path to resource} | ||
url = url.replace('ipfs://', `${ipfsGateway}/`); | ||
url = getIPFSGatewayUrl(url, ipfsGateway!); | ||
debug('IPFS http url: %s', url); | ||
@@ -228,0 +247,0 @@ } |
@@ -13,4 +13,4 @@ // Copyright Abridged, Inc. 2021. All Rights Reserved. | ||
// See https://github.com/ChainAgnostic/CAIPs/issues/63 | ||
const assetReference = '[-a-zA-Z0-9._]{1,64}'; | ||
const accountAddress = '[a-zA-Z0-9._]{1,64}'; | ||
const assetReference = '[-a-zA-Z0-9._]{1,128}'; | ||
const accountAddress = '[a-zA-Z0-9._]{1,128}'; | ||
@@ -17,0 +17,0 @@ /** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132065
71
3458
3
+ Addedis-ipfs@^6.0.2
+ Added@collabland/common@0.26.0(transitive)
+ Addeddns-over-http-resolver@1.2.3(transitive)
+ Addederr-code@3.0.1(transitive)
+ Addedip-regex@4.3.0(transitive)
+ Addedis-ip@3.1.0(transitive)
+ Addedis-ipfs@6.0.2(transitive)
+ Addediso-url@1.2.1(transitive)
+ Addedmafmt@10.0.0(transitive)
+ Addedmultiaddr@10.0.1(transitive)
+ Addedmultiformats@9.9.0(transitive)
+ Addednative-fetch@3.0.0(transitive)
+ Addedon-exit-leak-free@0.2.0(transitive)
+ Addedpino@7.11.0(transitive)
+ Addedpino-std-serializers@4.0.0(transitive)
+ Addedreal-require@0.1.0(transitive)
+ Addedreceptacle@1.3.2(transitive)
+ Addedsafe-stable-stringify@2.5.0(transitive)
+ Addedthread-stream@0.15.2(transitive)
+ Addeduint8arrays@3.1.1(transitive)
+ Addedvarint@6.0.0(transitive)
- Removed@collabland/common@0.25.2(transitive)
- Removedflatstr@1.0.12(transitive)
- Removedpino@6.14.0(transitive)
- Removedpino-std-serializers@3.2.0(transitive)
- Removedsonic-boom@1.4.1(transitive)
Updated@collabland/common@^0.26.0