Skip to content

Commit

Permalink
去掉exists
Browse files Browse the repository at this point in the history
  • Loading branch information
fulldecent committed Dec 20, 2023
1 parent 69d1aeb commit 5ba87bf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
5 changes: 3 additions & 2 deletions contracts/public_data_storage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ contract PublicDataStorage {
require(block.number > cycleNumber * blocksPerCycle + startBlock);
CycleInfo storage cycleInfo = cycle_infos[_cycleNumber()];
CycleDataInfo storage dataInfo = cycleInfo.data_infos[dataMixedHash];
require(cycleInfo.score_list.exists(dataMixedHash));
uint256 scoreListRanking = cycleInfo.score_list.getRanking(dataMixedHash);
require(scoreListRanking > 0);

// 看看是谁来取
uint8 withdrawUser = _getWithdrawUser(dataMixedHash);
Expand All @@ -352,7 +353,7 @@ contract PublicDataStorage {
uint256 totalReward = cycleInfo.total_award * 8 / 10;
// 积分规则我先自己定一个, 参见最顶上的注释
uint256 totalScore = (1 + topRewards) * topRewards / 2;
uint256 ranking = topRewards - cycleInfo.score_list.getRanking(dataMixedHash) + 1;
uint256 ranking = topRewards - scoreListRanking + 1;
uint256 dataReward = totalReward * ranking / totalScore;

uint256 reward = _calcuteReward(withdrawUser, dataReward);
Expand Down
4 changes: 0 additions & 4 deletions contracts/test_list.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ contract TestList {
return list.maxlen();
}

function exists(bytes32 mixedHash) public view returns (bool) {
return list.exists(mixedHash);
}

function getRanking(bytes32 mixedHash) public view returns (uint256) {
return list.getRanking(mixedHash);
}
Expand Down
8 changes: 4 additions & 4 deletions test/test_public_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ describe("PublicDataStorage", function () {

nftContract = await (await hre.ethers.deployContract("FakeNFTContract")).waitForDeployment();

contract = await (await hre.ethers.deployContract("PublicDataStorage", {libraries: {
SortedScoreList: await listLibrary.getAddress()
}})).waitForDeployment();
// contract = await (await hre.ethers.deployContract("PublicDataStorage", {libraries: {
// SortedScoreList: await listLibrary.getAddress()
// }})).waitForDeployment();
}

before(async () => {
await deployContracts();

await ((await nftContract.addData("", 1)).wait());
// await ((await nftContract.addData("", 1)).wait());
});

it("create NFT public data");
Expand Down
1 change: 0 additions & 1 deletion test/test_sortedlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ describe("ShortedList", function () {
it("one element", async () => {
await (await contract.addScore(testDatas[0].hash, testDatas[0].score)).wait();

expect(await contract.exists(testDatas[0].hash)).to.equal(true);
expect(await contract.getLength()).to.equal(1);

expect(await contract.getRanking(testDatas[0].hash)).to.equal(1);
Expand Down

0 comments on commit 5ba87bf

Please sign in to comment.