增加用户中token分页查询

This commit is contained in:
xxq250 2024-09-09 17:09:05 +08:00
parent d893c3a104
commit b89df3b611
5 changed files with 48 additions and 31 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -170,17 +170,15 @@ contract OpenSource {
}
// select single user balance by page
function selectUserBalance(string memory username, string memory token_name, int256 start, int256 page_num)
function selectUserBalanceByPage(string memory username, string memory token_name, int256 start, int256 page_num)
public
view
returns (string[] memory, string[] memory, uint256[] memory, uint256)
{
Table user_table = tableFactory.openTable(USER_TABLE);
Condition condition = user_table.newCondition();
Condition condition = tableFactory.openTable(USER_TABLE).newCondition();
condition.EQ("token_name", token_name);
Entries entries = user_table.select(username, condition);
Entries entries = tableFactory.openTable(USER_TABLE).select(username, condition);
if (start + page_num > entries.size()) {
page_num = entries.size() - start;
@ -189,20 +187,17 @@ contract OpenSource {
}
}
uint256 total_count = uint256(entries.size());
string[] memory username_list = new string[](uint256(entries.size()));
string[] memory token_name_list = new string[](uint256(entries.size()));
uint256[] memory balance_list = new uint256[](uint256(entries.size()));
for (int256 i = 0; i < entries.size(); ++i) {
Entry entry = entries.get(i);
username_list[uint256(i)] = entry.getString("user");
token_name_list[uint256(i)] = entry.getString("token_name");
balance_list[uint256(i)] = entry.getUInt("balance");
username_list[uint256(i)] = entries.get(i).getString("user");
token_name_list[uint256(i)] = entries.get(i).getString("token_name");
balance_list[uint256(i)] = entries.get(i).getUInt("balance");
}
return (username_list, token_name_list, balance_list, total_count);
return (username_list, token_name_list, balance_list, uint256(entries.size()));
}
// add user balance

View File

@ -18,4 +18,16 @@
## 3. 测试合约部署情况
使用postmanget请求合约地址例如http://8.130.51.51:3023/),正常情况下返回"hello world"
使用postmanget请求合约地址例如http://8.130.51.51:3023/),正常情况下返回"hello world"
## solidity 修改合约接口
- 生成abi文件
./tools/solc-0.4.25 --abi contract/opensource/opensource.sol
- 生成bin文件
./tools/solc-0.4.25 --bin contract/opensource/opensource.sol
-
- 生成go文件
./tools/abigen --bin=./contract/opensource/opensource.bin --abi=./contract/opensource/opensource.abi --pkg=opensource --out=OpenSource.go