feat(route): add Etherscan 转账追踪 (#8517)

Co-authored-by: WangHe2077 <pretty9.cn@protonmail.com>
Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
Pretty9 2021-11-27 16:58:51 +08:00 committed by GitHub
parent 6ec9005946
commit 098339ca66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 0 deletions

View File

@ -109,6 +109,12 @@ pageClass: routes
<Route author="ntzyz" example="/dhl/12345678" path="/dhl/:shipment_id" :paramsDesc="['运单号']"/>
## Etherscan
### Etherscan 转账追踪
<Route author="Pretty9" example="/etherscan/transactions/0x283af0b28c62c092c9727f1ee09c02ca627eb7f5" path="/etherscan/transactions/:address" :paramsDesc="['地址']"/>
## Grand-Challenge
### Challenge 列表

View File

@ -4221,6 +4221,9 @@ router.get('/now/news/rank', lazyloadRouteHandler('./routes/now/rank'));
// s-hentai
router.get('/s-hentai/:id?', lazyloadRouteHandler('./routes/s-hentai'));
// etherscan
router.get('/etherscan/transactions/:address', lazyloadRouteHandler('./routes/etherscan/transactions'));
// foreverblog
router.get('/blogs/foreverblog', lazyloadRouteHandler('./routes/blogs/foreverblog'));

View File

@ -0,0 +1,37 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const { address } = ctx.params;
const response = await got({
method: 'get',
url: `https://api.etherscan.io/api?module=account&action=txlist&address=${address}&page=1&offset=0&sort=desc`,
});
const list = response.data.result.slice(0, 20);
ctx.state.data = {
title: 'etherscan transactions',
link: 'https://etherscan.io/',
language: 'en',
description: 'ethereum address transactions',
item:
list &&
list.map((item) => {
const title = ` TransactionHash: ${item.hash} `;
const value = (parseFloat(item.value) / 10 ** 18).toFixed(8);
const description = `
From: ${item.from} <br> To: ${item.to} <br> Value: ${value} <br> Block: ${item.blockNumber}`;
const link = `https://etherscan.io/tx/${item.hash}`;
return {
title,
description,
link,
pubDate: parseDate(item.timestamp),
guid: item.hash,
};
}),
};
};