Skip to content

Commit

Permalink
fix: role event
Browse files Browse the repository at this point in the history
  • Loading branch information
longgu02 committed May 17, 2023
1 parent 26761d8 commit f1d655b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
10 changes: 10 additions & 0 deletions contracts/Roles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ contract Roles is AccessControl {

event MemberAdded(address account, uint256 addedDate); // Member addition
event MemberRemoved(address account, uint256 removedDate); // Member removal
event CarrierAdded(address account, uint256 addedDate); // Carrier addition
event CarrierRemoved(address account, uint256 removedDate); // Carrier removal

function addMember(address _account) public onlyRole(ADMIN_ROLE) {
require(!hasRole(MEMBER_ROLE, _account), "Already a member");
Expand All @@ -53,6 +55,13 @@ contract Roles is AccessControl {

function addCarrier(address _account) public onlyRole(ADMIN_ROLE) {
grantRole(CARRIER_ROLE, _account);
emit CarrierAdded(_account, block.timestamp);
}

function removeCarrier(address _account) public onlyRole(ADMIN_ROLE) {
require(hasRole(CARRIER_ROLE, _account), "Not a carrier");
revokeRole(CARRIER_ROLE, _account);
emit CarrierRemoved(_account, block.timestamp);
}

/**
Expand All @@ -62,5 +71,6 @@ contract Roles is AccessControl {
*/
function renounceCarrier(address _account) public onlyRole(CARRIER_ROLE) {
renounceRole(CARRIER_ROLE, _account);
emit CarrierRemoved(_account, block.timestamp);
}
}
40 changes: 17 additions & 23 deletions contracts/SupplyChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "./interfaces/ISupplyChain.sol";
* @notice Only addresses with MEMBER role can interact
*/

contract SupplyChain is ISupplyChain, Roles, Utils {
contract SupplyChain is ISupplyChain ,Roles, Utils {
Roles private roleContract;
Products private productContract;
// Utils private utilityContract;
Expand Down Expand Up @@ -199,12 +199,12 @@ contract SupplyChain is ISupplyChain, Roles, Utils {
if (confirmPermission[callerRoles[i]].prevStatus == order.status) {
orderList[_orderId].status = confirmPermission[callerRoles[i]]
.statusSet;
confirmed = true;
confirmed = true;
}
}
if (confirmed) {
if(confirmed){
emit OrderUpdated(_orderId, msg.sender, block.timestamp);
} else {
}else{
revert("Not your turn to confirm");
}
}
Expand All @@ -214,23 +214,17 @@ contract SupplyChain is ISupplyChain, Roles, Utils {
* @param _orderId order id
*/

function viewOrder(
uint _orderId
)
public
view
returns (
uint256 id,
uint256 productId,
address customer,
address[] memory suppliers,
address[] memory manufacturers,
uint256 createdDate,
OrderStatus status,
bool isPaid,
uint256 deposited
)
{
function viewOrder(uint _orderId) public view returns (
uint256 id,
uint256 productId,
address customer,
address[] memory suppliers,
address[] memory manufacturers,
uint256 createdDate,
OrderStatus status,
bool isPaid,
uint256 deposited
) {
require(_orderId <= orderCounter, "Order ID is not valid");
Order memory matchedOrder = orderList[_orderId];
return (
Expand All @@ -239,8 +233,8 @@ contract SupplyChain is ISupplyChain, Roles, Utils {
matchedOrder.customer,
matchedOrder.suppliers,
matchedOrder.manufacturers,
matchedOrder.createdDate,
matchedOrder.status,
matchedOrder.createdDate,
matchedOrder.status,
matchedOrder.isPaid,
matchedOrder.deposited
);
Expand Down
6 changes: 2 additions & 4 deletions contracts/interfaces/ISupplyChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,13 @@ interface ISupplyChain {
* @dev Event emitted when an order is paid.
* @param id The ID of the order.
* @param payer The address of the user who made the payment.
* @param receivers An array of addresses representing the users who will receive the payment.
* @param amount An array of uint256 values representing the amounts to be paid to each receiver.
* @param amount The remaining amount not includes deposit.
* @param paymentDate The timestamp when the payment was made.
*/
event OrderPaid(
uint id,
address payer,
address[] receivers,
uint256[] amount,
uint256 amount,
uint256 paymentDate
);

Expand Down

0 comments on commit f1d655b

Please sign in to comment.