Skip to content

Commit

Permalink
Reputation Change by Case Contract (Jurisdiction & Avatar)
Browse files Browse the repository at this point in the history
  • Loading branch information
toledoroy committed May 2, 2022
1 parent e00736d commit 7405cf2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 39 deletions.
5 changes: 5 additions & 0 deletions contracts/AvatarNFT.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down
21 changes: 9 additions & 12 deletions contracts/Case.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
}
}
Expand Down
11 changes: 6 additions & 5 deletions contracts/Hub.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
26 changes: 13 additions & 13 deletions contracts/Jurisdiction.sol
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions contracts/abstract/Rules.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
Expand All @@ -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);
}


}

0 comments on commit 7405cf2

Please sign in to comment.