enforce constrants on citation weights
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 38s Details

This commit is contained in:
Ladd Hoffman 2024-04-10 16:40:12 -05:00
parent dc18c69b09
commit 5cffb8f556
1 changed files with 11 additions and 4 deletions

View File

@ -36,6 +36,17 @@ contract Forum is Reputation {
for (uint i = 0; i < citations.length; i++) {
post.citations.push(citations[i]);
}
int totalCitationWeightAbs;
for (uint i = 0; i < post.citations.length; i++) {
int weight = post.citations[i].weightPercent;
require(weight >= -100, "Each citation weight must be >= -100");
require(weight <= 100, "Each citation weight must be <= 100");
totalCitationWeightAbs += weight > 0 ? weight : -weight;
}
require(
totalCitationWeightAbs <= 100,
"Sum of absolute value of citations must be <= 100"
);
emit PostAdded(postIndex);
}
@ -45,10 +56,6 @@ contract Forum is Reputation {
function _propagateValue(uint postIndex, int amount) internal {
Post storage post = posts[postIndex];
int totalCitationWeight;
for (uint i = 0; i < post.citations.length; i++) {
totalCitationWeight += post.citations[i].weightPercent;
}
int totalOutboundAmount;
for (uint i = 0; i < post.citations.length; i++) {
int share = (amount * post.citations[i].weightPercent) / 100;