api shard1 support

shard_contract_support
jenya 2 years ago
parent a14d7b3ef4
commit d717b3f7ad
  1. 46
      src/api/controllers/ERC1155.ts
  2. 26
      src/api/controllers/ERC20.ts
  3. 30
      src/api/controllers/ERC721.ts
  4. 24
      src/api/rest/routes/ERC1155.ts
  5. 14
      src/api/rest/routes/ERC20.ts
  6. 14
      src/api/rest/routes/ERC721.ts
  7. 6
      src/api/rest/server.ts

@ -4,61 +4,79 @@ import {withCache} from 'src/api/controllers/cache'
import {validator} from 'src/utils/validators/validators'
import {isAddress, isShard} from 'src/utils/validators'
export async function getAllERC1155(): Promise<IERC1155[] | null> {
export async function getAllERC1155(shardID: ShardID): Promise<IERC1155[] | null> {
validator({
shardID: isShard(shardID),
})
return await withCache(
['getAllERC1155', arguments],
() => stores[0].erc1155.getAllERC1155(),
[shardID, 'getAllERC1155', arguments],
() => stores[shardID].erc1155.getAllERC1155(),
1000 * 60 * 15
)
}
export async function getUserERC1155Balances(address: Address): Promise<IERC20Balance[] | null> {
export async function getUserERC1155Balances(
shardID: ShardID,
address: Address
): Promise<IERC20Balance[] | null> {
validator({
address: isAddress(address),
shardID: isShard(shardID),
})
return await withCache(
['getUserERC1155Balances', arguments],
() => stores[0].erc1155.getUserBalances(address),
[shardID, 'getUserERC1155Balances', arguments],
() => stores[shardID].erc1155.getUserBalances(address),
1000 * 2
)
}
export async function getTokenERC1155Balances(address: Address): Promise<IERC20Balance[] | null> {
export async function getTokenERC1155Balances(
shardID: ShardID,
address: Address
): Promise<IERC20Balance[] | null> {
validator({
shardID: isShard(shardID),
address: isAddress(address),
})
return await withCache(
['getTokenERC1155Balances', arguments],
() => stores[0].erc1155.getTokenBalances(address),
[shardID, 'getTokenERC1155Balances', arguments],
() => stores[shardID].erc1155.getTokenBalances(address),
1000 * 10
)
}
export async function getTokenERC1155Assets(address: Address): Promise<IERC20Balance[] | null> {
export async function getTokenERC1155Assets(
shardID: ShardID,
address: Address
): Promise<IERC20Balance[] | null> {
validator({
shardID: isShard(shardID),
address: isAddress(address),
})
return await withCache(
['getTokenERC1155Assets', arguments],
() => stores[0].erc1155.getTokenAssets(address),
[shardID, 'getTokenERC1155Assets', arguments],
() => stores[shardID].erc1155.getTokenAssets(address),
1000 * 60 * 5
)
}
export async function getTokenERC1155AssetDetails(
shardID: ShardID,
address: Address,
tokenID: string
): Promise<IERC20Balance[] | null> {
validator({
shardID: isShard(shardID),
address: isAddress(address),
})
return await withCache(
['getTokenERC1155Assets', arguments],
() => stores[0].erc1155.getTokenAssetDetails(address, tokenID),
[shardID, 'getTokenERC1155Assets', arguments],
() => stores[shardID].erc1155.getTokenAssetDetails(address, tokenID),
1000 * 60 * 5
)
}

@ -4,40 +4,50 @@ import {withCache} from 'src/api/controllers/cache'
import {validator} from 'src/utils/validators/validators'
import {isAddress, isShard, isOffset, isLimit} from 'src/utils/validators'
export async function getAllERC20(): Promise<IERC20[] | null> {
export async function getAllERC20(shardID: ShardID): Promise<IERC20[] | null> {
validator({
shardID: isShard(shardID),
})
return await withCache(
['getAllERC20', arguments],
() => stores[0].erc20.getAllERC20(),
[shardID, 'getAllERC20', arguments],
() => stores[shardID].erc20.getAllERC20(),
1000 * 60 * 5
)
}
export async function getUserERC20Balances(address: Address): Promise<IERC20Balance[] | null> {
export async function getUserERC20Balances(
shardID: ShardID,
address: Address
): Promise<IERC20Balance[] | null> {
validator({
shardID: isShard(shardID),
address: isAddress(address),
})
return await withCache(
['getAllERC20', arguments],
() => stores[0].erc20.getUserBalances(address),
[shardID, 'getAllERC20', arguments],
() => stores[shardID].erc20.getUserBalances(address),
1000 * 60 * 5
)
}
export async function getERC20TokenHolders(
shardID: ShardID,
address: Address,
limit = 100,
offset = 0
): Promise<IERC20Balance[] | null> {
validator({
shardID: isShard(shardID),
address: isAddress(address),
offset: isOffset(offset),
limit: isLimit(limit),
})
return await withCache(
['getERC20TokenHolders', arguments],
() => stores[0].erc20.getHolders(address, limit, offset),
[shardID, 'getERC20TokenHolders', arguments],
() => stores[shardID].erc20.getHolders(address, limit, offset),
1000 * 10
)
}

@ -4,34 +4,46 @@ import {withCache} from 'src/api/controllers/cache'
import {validator} from 'src/utils/validators/validators'
import {isAddress, isShard} from 'src/utils/validators'
export async function getAllERC721(): Promise<IERC20[] | null> {
export async function getAllERC721(shardID: ShardID): Promise<IERC20[] | null> {
validator({
shardID: isShard(shardID),
})
return await withCache(
['getAllERC721', arguments],
() => stores[0].erc721.getAllERC721(),
[shardID, 'getAllERC721', arguments],
() => stores[shardID].erc721.getAllERC721(),
1000 * 60 * 5
)
}
export async function getUserERC721Assets(address: Address): Promise<IERC20Balance[] | null> {
export async function getUserERC721Assets(
shardID: ShardID,
address: Address
): Promise<IERC20Balance[] | null> {
validator({
shardID: isShard(shardID),
address: isAddress(address),
})
return await withCache(
['getUserERC721Assets', arguments],
() => stores[0].erc721.getUserAssets(address),
[shardID, 'getUserERC721Assets', arguments],
() => stores[shardID].erc721.getUserAssets(address),
1000 * 2
)
}
export async function getTokenERC721Assets(address: Address): Promise<IERC20Balance[] | null> {
export async function getTokenERC721Assets(
shardID: ShardID,
address: Address
): Promise<IERC20Balance[] | null> {
validator({
shardID: isShard(shardID),
address: isAddress(address),
})
return await withCache(
['getTokenERC721Assets', arguments],
() => stores[0].erc721.getTokenAssets(address),
[shardID, 'getTokenERC721Assets', arguments],
() => stores[shardID].erc721.getTokenAssets(address),
1000 * 2
)
}

@ -7,38 +7,44 @@ export const erc1155Router = Router({mergeParams: true})
erc1155Router.get('/', catchAsync(getAllERC1155))
export async function getAllERC1155(req: Request, res: Response, next: NextFunction) {
const data = await controllers.getAllERC1155()
const {shardID} = req.params
const s = +shardID as ShardID
const data = await controllers.getAllERC1155(s)
next(data)
}
erc1155Router.get('/address/:address/balances', catchAsync(getUserERC1155Balances))
export async function getUserERC1155Balances(req: Request, res: Response, next: NextFunction) {
const {address} = req.params
const data = await controllers.getUserERC1155Balances(address)
const s = +shardID as ShardID
const {address, shardID} = req.params
const data = await controllers.getUserERC1155Balances(s, address)
next(data)
}
erc1155Router.get('/token/:address/balances', catchAsync(getTokenERC1155Balances))
export async function getTokenERC1155Balances(req: Request, res: Response, next: NextFunction) {
const {address} = req.params
const data = await controllers.getTokenERC1155Balances(address)
const s = +shardID as ShardID
const {address, shardID} = req.params
const data = await controllers.getTokenERC1155Balances(s, address)
next(data)
}
erc1155Router.get('/token/:address/assets', catchAsync(getTokenERC1155Assets))
export async function getTokenERC1155Assets(req: Request, res: Response, next: NextFunction) {
const {address} = req.params
const data = await controllers.getTokenERC1155Assets(address)
const s = +shardID as ShardID
const {address, shardID} = req.params
const data = await controllers.getTokenERC1155Assets(s, address)
next(data)
}
erc1155Router.get('/token/:address/asset/:tokenID', catchAsync(getTokenERC1155AssetDetails))
export async function getTokenERC1155AssetDetails(req: Request, res: Response, next: NextFunction) {
const {address, tokenID} = req.params
const data = await controllers.getTokenERC1155AssetDetails(address, tokenID)
const s = +shardID as ShardID
const {address, tokenID, shardID} = req.params
const data = await controllers.getTokenERC1155AssetDetails(s, address, tokenID)
next(data)
}

@ -7,27 +7,31 @@ export const erc20Router = Router({mergeParams: true})
erc20Router.get('/', catchAsync(getAllERC20))
export async function getAllERC20(req: Request, res: Response, next: NextFunction) {
const data = await controllers.getAllERC20()
const {shardID} = req.params
const s = +shardID as ShardID
const data = await controllers.getAllERC20(s)
next(data)
}
erc20Router.get('/address/:address/balances', catchAsync(getUserERC20Balances))
export async function getUserERC20Balances(req: Request, res: Response, next: NextFunction) {
const {address} = req.params
const data = await controllers.getUserERC20Balances(address)
const {address, shardID} = req.params
const s = +shardID as ShardID
const data = await controllers.getUserERC20Balances(s, address)
next(data)
}
erc20Router.get('/token/:address/holders', catchAsync(getERC20TokenHolders))
export async function getERC20TokenHolders(req: Request, res: Response, next: NextFunction) {
const {address} = req.params
const {address, shardID} = req.params
const s = +shardID as ShardID
const {offset, limit} = req.query
const filter = {
offset: (+offset! as number) || 0,
limit: (+limit! as number) || 100,
}
const data = await controllers.getERC20TokenHolders(address, filter.limit, filter.offset)
const data = await controllers.getERC20TokenHolders(s, address, filter.limit, filter.offset)
next(data)
}

@ -7,22 +7,26 @@ export const erc721Router = Router({mergeParams: true})
erc721Router.get('/', catchAsync(getAllERC721))
export async function getAllERC721(req: Request, res: Response, next: NextFunction) {
const data = await controllers.getAllERC721()
const {shardID} = req.params
const s = +shardID as ShardID
const data = await controllers.getAllERC721(s)
next(data)
}
erc721Router.get('/address/:address/balances', catchAsync(getUserERC721Assets))
export async function getUserERC721Assets(req: Request, res: Response, next: NextFunction) {
const {address} = req.params
const data = await controllers.getUserERC721Assets(address)
const {address, shardID} = req.params
const s = +shardID as ShardID
const data = await controllers.getUserERC721Assets(s, address)
next(data)
}
erc721Router.get('/token/:address/balances', catchAsync(getTokenERC721Assets))
export async function getTokenERC721Assets(req: Request, res: Response, next: NextFunction) {
const {address} = req.params
const data = await controllers.getTokenERC721Assets(address)
const {address, shardID} = req.params
const s = +shardID as ShardID
const data = await controllers.getTokenERC721Assets(s, address)
next(data)
}

@ -65,15 +65,15 @@ export const RESTServer = async () => {
mainRouter0.use('/address', addressRouter)
mainRouter0.use('/internalTransaction', internalTransactionRouter)
mainRouter0.use('/logs', logsRouter)
mainRouter0.use('/erc20', erc20Router, transport)
mainRouter0.use('/erc721', erc721Router, transport)
mainRouter0.use('/erc1155', erc1155Router, transport)
const routerWithShards0 = Router({mergeParams: true})
routerWithShards0.use('/shard/:shardID', mainRouter0, transport)
routerWithShards0.use('/signature', signatureRouter, transport)
routerWithShards0.use('/price', priceRouter, transport)
routerWithShards0.use('/metrics', metricsRouter, transport)
routerWithShards0.use('/erc20', erc20Router, transport)
routerWithShards0.use('/erc721', erc721Router, transport)
routerWithShards0.use('/erc1155', erc1155Router, transport)
routerWithShards0.use('/1wallet', oneWalletMetricsRouter, transport)
if (config.api.json_rpc.isEnabled) {

Loading…
Cancel
Save