From 7405cf2f225747e566120715ffa498fc632c4a96 Mon Sep 17 00:00:00 2001 From: Roy Date: Mon, 2 May 2022 10:50:12 -0700 Subject: [PATCH] Reputation Change by Case Contract (Jurisdiction & Avatar) --- contracts/AvatarNFT.sol | 5 +++++ contracts/Case.sol | 21 +++++++++------------ contracts/Hub.sol | 11 ++++++----- contracts/Jurisdiction.sol | 26 +++++++++++++------------- contracts/abstract/Rules.sol | 14 +++++--------- 5 files changed, 38 insertions(+), 39 deletions(-) diff --git a/contracts/AvatarNFT.sol b/contracts/AvatarNFT.sol index f6893d3..3202d3d 100644 --- a/contracts/AvatarNFT.sol +++ b/contracts/AvatarNFT.sol @@ -1,6 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.4; +// import "hardhat/console.sol"; + // import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; //https://eips.ethereum.org/EIPS/eip-721 import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; //Individual Metadata URI Storage Functions import "@openzeppelin/contracts/utils/Counters.sol"; @@ -91,6 +93,9 @@ contract AvatarNFT is function repAdd(uint256 tokenId, string calldata domain, bool rating, uint8 amount) external override { //Validate - Only By Hub require(_msgSender() == address(_HUB), "UNAUTHORIZED_ACCESS"); + + // console.log("Avatar: Add Reputation to Token:", tokenId, domain, amount); + //Set _repAdd(address(this), tokenId, domain, rating, amount); } diff --git a/contracts/Case.sol b/contracts/Case.sol index 17a5289..04f8cda 100644 --- a/contracts/Case.sol +++ b/contracts/Case.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: MIT pragma solidity 0.8.4; -import "hardhat/console.sol"; +// import "hardhat/console.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; import "./libraries/DataTypes.sol"; @@ -296,32 +296,29 @@ contract Case is ICase, CommonYJUpgradable, ERC1155RolesUpgradable { //Validate Avatar Contract Interface require(IERC165(address(avatarContract)).supportsInterface(type(IAvatar).interfaceId), "Invalid Avatar Contract"); - - console.log("Case: Rule Confirmed:", ruleId); + // console.log("Case: Rule Confirmed:", ruleId); //Fetch Case's Subject(s) address[] memory subjects = uniqueRoleMembers("subject"); //Each Subject for (uint256 i = 0; i < subjects.length; ++i) { - - //TODO! Get Token ID For Subject + //Get Subject's Token ID For uint256 tokenId = avatarContract.tokenByAddress(subjects[i]); - - console.log("Case: Update Rep for Subject:", subjects[i], tokenId); - - // console.log("Case: Update Rep for Subject:", subjects[i]); - // console.log("Case: Update Rep for Subject Token:", tokenId); + if(tokenId > 0){ // DataTypes.Rule memory rule = ruleGet(ruleId); DataTypes.Effect[] memory effects = ruleGetEffects(ruleId); + // console.log("Case: Update Rep for tokenId:", tokenId, effects.length); + // console.log("Case Rule:", ruleId, "Effects Count:", effects.length); + //Run Each Effect for (uint256 i = 0; i < effects.length; ++i) { + // console.log("Case Running Effect", i); DataTypes.Effect memory effect = effects[i]; bool direction = effect.direction; - //Register Rep in Jurisdiction - //{name:'professional', value:5, direction:false} + //Register Rep in Jurisdiction //{name:'professional', value:5, direction:false} IJurisdiction(_jurisdiction).repAdd(address(avatarContract), tokenId, effect.name, direction, effect.value); } } diff --git a/contracts/Hub.sol b/contracts/Hub.sol index 228a7f6..bb69673 100644 --- a/contracts/Hub.sol +++ b/contracts/Hub.sol @@ -1,7 +1,7 @@ //SPDX-License-Identifier: MIT pragma solidity 0.8.4; -import "hardhat/console.sol"; +// import "hardhat/console.sol"; import "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol"; import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol"; @@ -95,7 +95,7 @@ contract Hub is IHub, Ownable { //--- Factory - /// Make a new Jurisdiction + /// TODO: Make a new Jurisdiction // function jurisdictionMake() public override returns (address) { //Register Jurisdiction @@ -147,9 +147,10 @@ contract Hub is IHub, Ownable { //TODO: Validate - Known Jurisdiction // require(_jurisdictions[_msgSender()], "NOT A VALID JURISDICTION"); - console.log("Hub: Add Reputation to Contract:", contractAddr, tokenId, amount); - - //Update Avatar's Reputation + // console.log("Hub: Add Reputation to Contract:", contractAddr, tokenId, amount); + // console.log("Hub: Add Reputation in Domain:", domain); + + //Update Avatar's Reputation //TODO: Just Check if Contract Implements IRating if(avatarContract != address(0) && avatarContract == contractAddr){ _repAddAvatar(tokenId, domain, rating, amount); } diff --git a/contracts/Jurisdiction.sol b/contracts/Jurisdiction.sol index 1877259..343f25d 100644 --- a/contracts/Jurisdiction.sol +++ b/contracts/Jurisdiction.sol @@ -1,8 +1,7 @@ //SPDX-License-Identifier: MIT pragma solidity 0.8.4; - -// import "hardhat/console.sol"; +import "hardhat/console.sol"; // import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; // import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol"; //Track Token Supply & Check @@ -117,11 +116,10 @@ contract Jurisdiction is DataTypes.RuleRef[] calldata addRules, DataTypes.InputRole[] calldata assignRoles, PostInput[] calldata posts - // ) public returns (uint256, address) { ) public returns (address) { //TODO: Validate Caller Permissions (Member of Jurisdiction) - // roleHas(_msgSender(), "admin") - // roleHas(_msgSender(), "member") + // roleHas(_msgSender(), "admin") + // roleHas(_msgSender(), "member") //Assign Case ID _caseIds.increment(); //Start with 1 @@ -157,13 +155,14 @@ contract Jurisdiction is //** Custom Rating Functions /// Add Reputation (Positive or Negative) - function repAdd(address contractAddr, uint256 tokenId, DataTypes.Domain domain, DataTypes.Rating rating, uint8 amount) external { + // function repAdd(address contractAddr, uint256 tokenId, string calldata domain, DataTypes.Rating rating, uint8 amount) external override { + function repAdd(address contractAddr, uint256 tokenId, string calldata domain, bool rating, uint8 amount) external override { //Validate - Called by Child Case - require(_active[_msgSender()], "NOT A VALID CASE"); + require(caseHas(_msgSender()), "NOT A VALID CASE"); //Run _repAdd(contractAddr, tokenId, domain, rating, amount); - //TODO: Update Hub - + //Update Hub + _HUB.repAdd(contractAddr, tokenId, domain, rating, amount); } //** Role Management @@ -235,22 +234,23 @@ contract Jurisdiction is //** Rule Management /// Create New Rule - function ruleAdd(DataTypes.Rule memory rule, DataTypes.Confirmation memory confirmation) public override returns (uint256) { + function ruleAdd(DataTypes.Rule memory rule, DataTypes.Confirmation memory confirmation, DataTypes.Effect[] memory effects) public override returns (uint256) { //Validate Caller's Permissions require(roleHas(_msgSender(), "admin"), "Admin Only"); //Add Rule - uint256 id = _ruleAdd(rule); + uint256 id = _ruleAdd(rule, effects); //Set Confirmations _confirmationSet(id, confirmation); return id; } /// Update Rule - function ruleUpdate(uint256 id, DataTypes.Rule memory rule) external override { + // function ruleUpdate(uint256 id, DataTypes.Rule memory rule) external override { + function ruleUpdate(uint256 id, DataTypes.Rule memory rule, DataTypes.Effect[] memory effects) external override { //Validate Caller's Permissions require(roleHas(_msgSender(), "admin"), "Admin Only"); //Update Rule - _ruleUpdate(id, rule); + _ruleSet(id, rule, effects); } /// Get Token URI diff --git a/contracts/abstract/Rules.sol b/contracts/abstract/Rules.sol index e9b65b7..58b2d9b 100644 --- a/contracts/abstract/Rules.sol +++ b/contracts/abstract/Rules.sol @@ -66,12 +66,7 @@ abstract contract Rules is IRules { uint256 id = _ruleIds.current(); //Set _ruleSet(id, rule, effects); - /* - _rules[id] = rule; - //Event - emit Rule(id, rule.about, rule.affected, rule.uri, rule.negation); - emit RuleEffects(id, rule.effects.environmental, rule.effects.personal, rule.effects.social, rule.effects.professional); - */ + //Return return id; } @@ -91,10 +86,10 @@ abstract contract Rules is IRules { emit Rule(id, rule.about, rule.affected, rule.uri, rule.negation); // emit RuleEffects(id, rule.effects.environmental, rule.effects.personal, rule.effects.social, rule.effects.professional); for (uint256 i = 0; i < effects.length; ++i) { - // DataTypes.Effect effect = rule.effects[i] + _effects[id].push(effects[i]); + //Effect Added Event emit RuleEffect(id, effects[i].direction, effects[i].value, effects[i].name); } - } /// Get Rule's Confirmation Method @@ -108,15 +103,16 @@ abstract contract Rules is IRules { _confirmationSet(id, confirmation); } */ + /// Get Rule's Effects function effectsGet(uint256 id) public view override returns (DataTypes.Effect[] memory){ return _effects[id]; } + /// Set Action's Confirmation Object function _confirmationSet(uint256 id, DataTypes.Confirmation memory confirmation) internal { _ruleConfirmation[id] = confirmation; emit Confirmation(id, confirmation.ruling, confirmation.evidence, confirmation.witness); } - }