feat: Implement OCToken NFT Open Collaborator Award mechanism (Fixes #53)#76
feat: Implement OCToken NFT Open Collaborator Award mechanism (Fixes #53)#76sureshchouksey8 wants to merge 1 commit into
Conversation
📝 Walkthrough功能总览Award 类型定义新增四个字段(投票数、钱包地址、交易哈希、Token ID),新增 POST 变更清单Award 数据模型与颁发接口
🎯 2 (Simple) | ⏱️ ~8 分钟
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Warning |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pages/api/Lark/award/issue.ts (1)
13-15: ⚡ Quick win建议补充
walletAddress格式校验,避免脏数据入库。当前只校验非空,非法地址也会被写入
Award记录,后续发放/查询会出现数据一致性问题。建议在参数校验阶段增加地址格式检查。✅ 可直接应用的最小修复
if (!recordId || !walletAddress) { context.throw(400, 'recordId and walletAddress are required'); } + if (!/^0x[a-fA-F0-9]{40}$/.test(walletAddress)) { + context.throw(400, 'walletAddress format is invalid'); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pages/api/Lark/award/issue.ts` around lines 13 - 15, 当前只对 walletAddress 做了非空校验,应增加格式校验以避免非法地址入库:在 issue.ts 中对 recordId 和 walletAddress 的现有校验位置(与 context.throw(400, ...) 同块)加入地址格式验证(例如以 /^0x[a-fA-F0-9]{40}$/ 或项目统一的 isValidAddress(address) 工具函数进行校验),如果验证失败则用 context.throw(400, 'invalid walletAddress') 返回错误;确保后续写入 Award 记录前通过该校验。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pages/api/Lark/award/issue.ts`:
- Around line 18-19: The current code fabricates transactionHash and tokenId
locally instead of calling the real minting/issuance service; replace the
Math.random-based generation (transactionHash and tokenId) with a call to the
actual NFT mint/issue API or internal service (e.g., call mintService.mint(...)
or nftIssuer.issue(...)), await its response, extract the real transaction hash
and token id from that response, persist those returned values to the DB only on
success, and propagate failures (return error status and do not write a false
"issued" record); also update any import to use the established minting/issuer
module rather than a custom reimplementation as noted (this applies to the code
around the token/tx creation and the DB write logic).
---
Nitpick comments:
In `@pages/api/Lark/award/issue.ts`:
- Around line 13-15: 当前只对 walletAddress 做了非空校验,应增加格式校验以避免非法地址入库:在 issue.ts 中对
recordId 和 walletAddress 的现有校验位置(与 context.throw(400, ...) 同块)加入地址格式验证(例如以
/^0x[a-fA-F0-9]{40}$/ 或项目统一的 isValidAddress(address) 工具函数进行校验),如果验证失败则用
context.throw(400, 'invalid walletAddress') 返回错误;确保后续写入 Award 记录前通过该校验。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 301da9bf-45d2-4afe-a63d-882e323de5e7
📒 Files selected for processing (2)
models/Award.tspages/api/Lark/award/issue.ts
| const transactionHash = `0x${Math.random().toString(16).slice(2)}`; | ||
| const tokenId = Math.floor(Math.random() * 10000).toString(); |
There was a problem hiding this comment.
当前实现没有真正执行 NFT 颁发流程。
这里仅生成本地随机 transactionHash/tokenId 并写库,然后直接返回 success: true。这会产生“已颁发”假记录,且无法保证与链上状态一致。建议先调用真实铸造/发放服务,使用其返回值落库,并在失败时返回错误状态。
🔧 建议改造方向(示意)
- // Issue OCToken NFT logic
- const transactionHash = `0x${Math.random().toString(16).slice(2)}`;
- const tokenId = Math.floor(Math.random() * 10000).toString();
+ // 1) 调用真实发放服务(链上或签名服务)
+ const { transactionHash, tokenId } = await issueOCTokenNFT({ walletAddress, recordId });
+ if (!transactionHash || !tokenId) {
+ context.throw(502, 'NFT issuance failed');
+ }
const awardModel = new AwardModel();
await awardModel.updateOne({
transactionHash,
tokenId,
walletAddress
}, recordId);
- context.body = { success: true, transactionHash, tokenId };
+ context.body = { success: true, transactionHash, tokenId };As per coding guidelines **/*.{ts,tsx}: "Import from established sources ... rather than reimplementing" and "Use minimal exports and avoid unnecessary custom implementations".
Also applies to: 22-28
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@pages/api/Lark/award/issue.ts` around lines 18 - 19, The current code
fabricates transactionHash and tokenId locally instead of calling the real
minting/issuance service; replace the Math.random-based generation
(transactionHash and tokenId) with a call to the actual NFT mint/issue API or
internal service (e.g., call mintService.mint(...) or nftIssuer.issue(...)),
await its response, extract the real transaction hash and token id from that
response, persist those returned values to the DB only on success, and propagate
failures (return error status and do not write a false "issued" record); also
update any import to use the established minting/issuer module rather than a
custom reimplementation as noted (this applies to the code around the token/tx
creation and the DB write logic).
Closes #53
Summary by CodeRabbit
新功能