金库协议-bug

git clone https://github.com/whale3070/git-connect-helper-edbe1c7c

前端运行

git reset --hard 841c394d38fb25beb09586405e1e1a58c1132762
回退版本

rm -rf node_modules
产出之前的依赖
npm install
重新编译依赖库
npm run build
npm run preview -- --host --port 5173

访问http://ip:5173

后端运行

cd backend/
go run main.go

查看redis数据库

既然你的“终焉大盘系统”需要通过 Redis 来管理 Hash Code 的状态(如 Reward_Paid,那么安装一个稳定运行的 Redis 是当务之急。

鉴于你目前正在 Linux 服务器(Root 权限)上操作,以下是最快捷的安装与运行步骤:


1. 安装 Redis

在 Ubuntu/Debian 系统上,直接使用包管理器安装最稳妥:

1
2
3
4
# 更新源并安装
apt update
apt install redis-server -y

2. 配置与启动

安装完成后,Redis 通常会自动启动。你可以通过以下命令管理它:

  • 检查状态: systemctl status redis-server
  • 启动服务: systemctl start redis-server
  • 开机自启: systemctl enable redis-server

3. 验证运行状态

使用 Redis 自带的客户端工具进行“Ping-Pong”测试:

1
2
3
redis-cli ping
# 如果返回 PONG,说明一切正常。


4. 针对你项目的进阶配置

由于你的项目涉及 DOT 奖励发放代付 gas 服务费,数据的安全性非常重要。建议进行以下微调:

设置密码(保护你的 Hash Code 数据)

  1. 打开配置文件:vim /etc/redis/redis.conf
  2. 找到 # requirepass foobared 这一行。
  3. 去掉注释,改为:requirepass 你的强密码
  4. 重启服务:systemctl restart redis-server

查看hashcode

cd backend/
python python tell_me_valid_hash.py

复制hashcode,访问http://ip:5173/valut_mint_nft/

部署工厂合约

成功部署的工厂合约地址:
0xfd19cc70af0a45d032df566ef8cc8027189fd5f3

工厂合约的源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "./QuickNFT.sol";

/**
* @title BookFactory
* @dev 工厂合约 - 出版社通过此合约部署新书的 NFT 合约
*/
contract BookFactory {
// 收款地址(平台方)
address public treasury;

// 部署费用(单位:Wei)
uint256 public deployFee;

// 所有已部署的书籍合约
address[] public deployedBooks;

// 出版社地址 => 其部署的书籍合约列表
mapping(address => address[]) public publisherBooks;

// 书籍合约地址 => 书籍信息
struct BookInfo {
string name;
string symbol;
string author;
address publisher;
uint256 deployedAt;
}
mapping(address => BookInfo) public bookInfo;

event BookDeployed(
address indexed bookContract,
address indexed publisher,
string name,
string symbol,
string author
);

event DeployFeeUpdated(uint256 oldFee, uint256 newFee);
event TreasuryUpdated(address oldTreasury, address newTreasury);

/**
* @dev 构造函数
* @param _treasury 收款地址
* @param _deployFee 部署费用(建议 10-50 CFX)
*/
constructor(address _treasury, uint256 _deployFee) {
require(_treasury != address(0), "Invalid treasury address");
treasury = _treasury;
deployFee = _deployFee;
}

/**
* @dev 部署新书 NFT 合约
* @param bookName 书籍名称
* @param symbol 书籍代号(如 "BOOK001")
* @param authorName 作者名称
* @param baseURI 元数据基础 URI
* @param relayer Relayer 地址(用于代付 Gas mint)
*/
function deployBook(
string memory bookName,
string memory symbol,
string memory authorName,
string memory baseURI,
address relayer
) external payable returns (address) {
require(msg.value >= deployFee, "Insufficient deploy fee");
require(bytes(bookName).length > 0, "Book name required");
require(bytes(symbol).length > 0, "Symbol required");

// 部署新的 QuickNFT 合约
QuickNFT newBook = new QuickNFT(
bookName,
symbol,
authorName,
msg.sender, // 出版社成为 Owner
baseURI
);

address bookAddress = address(newBook);

// 授权 Relayer
if (relayer != address(0)) {
newBook.setRelayerAuthorization(relayer, true);
}

// 记录书籍信息
deployedBooks.push(bookAddress);
publisherBooks[msg.sender].push(bookAddress);
bookInfo[bookAddress] = BookInfo({
name: bookName,
symbol: symbol,
author: authorName,
publisher: msg.sender,
deployedAt: block.timestamp
});

// 转账给平台 - 使用 call 替代 transfer
if (msg.value > 0) {
(bool success, ) = payable(treasury).call{value: msg.value}("");
require(success, "Transfer failed");
}

emit BookDeployed(bookAddress, msg.sender, bookName, symbol, authorName);

return bookAddress;
}

/**
* @dev 获取所有已部署书籍数量
*/
function totalBooks() external view returns (uint256) {
return deployedBooks.length;
}

/**
* @dev 获取出版社部署的书籍列表
*/
function getPublisherBooks(address publisher) external view returns (address[] memory) {
return publisherBooks[publisher];
}

/**
* @dev 获取书籍销量(调用书籍合约的 totalSales)
*/
function getBookSales(address bookContract) external view returns (uint256) {
return QuickNFT(bookContract).totalSales();
}

// ========== 管理函数 ==========

/**
* @dev 更新部署费用(仅平台方)
*/
function updateDeployFee(uint256 newFee) external {
require(msg.sender == treasury, "Only treasury");
emit DeployFeeUpdated(deployFee, newFee);
deployFee = newFee;
}

/**
* @dev 更新收款地址(仅当前收款方)
*/
function updateTreasury(address newTreasury) external {
require(msg.sender == treasury, "Only treasury");
require(newTreasury != address(0), "Invalid address");
emit TreasuryUpdated(treasury, newTreasury);
treasury = newTreasury;
}

/**
* @dev 接收 ETH 的回退函数
*/
receive() external payable {}
}

手动部署子合约

1
2
3
4
5
6
7
8
cast send 0xfd19cc70af0a45d032df566ef8cc8027189fd5f3 \
"deployBook(string,string,string,string,address)" \
"Whale3070 Autobiography" "W3070" "Whale3070" "https://arweave.net/example_cid" \
0x0000000000000000000000000000000000000000 \
--rpc-url https://evmtestnet.confluxrpc.com \
--private-key $PUBLISHER_PRIVATE_KEY \
--value 1ether \
--legacy

可以成功部署子合约,也可以通过子合约mint nft

问题

输入出版社的hashcode
进到后台,通过前端调用智能合约,无法部署子合约。