Untitled
unknown
plain_text
2 years ago
4.4 kB
2
Indexable
//SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; contract SharedStructs { struct Service { address actorID; string serviceName; string servicePurpose; string operation; string[] personalData; } } contract DataUsage is SharedStructs { mapping(address => Service[]) public services; address[] public actorAddresses; function addService(string memory _serviceName, string memory _servicePurpose, string memory _operation, string[] memory _personalData) public { Service memory newService = Service(msg.sender, _serviceName, _servicePurpose, _operation, _personalData); services[msg.sender].push(newService); bool actorExists = false; for (uint256 i = 0; i < actorAddresses.length; i++) { if (actorAddresses[i] == msg.sender) { actorExists = true; break; } } if (!actorExists) { actorAddresses.push(msg.sender); } } function getService(address _actorID, uint256 index) public view returns (Service memory) { require(index < services[_actorID].length, "Index out of bounds"); return services[_actorID][index]; } function getServicesCount(address _actorID) public view returns (uint256) { return services[_actorID].length; } function getActorAddressesCount() public view returns (uint256) { return actorAddresses.length; } } // 'Banking Transactions', 'Banking Services', 'Write', ['Account Number', 'Transaction History'] 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2 // 'Financial Transactions', 'Financial Services', 'Read', ['Phone Number', 'Account History'] 0x17F6AD8Ef982297579C203069C1DbfFE4348c372 contract Agreement is SharedStructs { struct Consent { bytes32 purposeHash; address actorID; string operation; string[] personalData; address userId; bool isPositive; } event LogServiceParams( address indexed actorID, string serviceName, string servicePurpose, string operation, string[] personalData ); Consent[] public consents; function giveConsent(bytes32 _purposeHash, address _actorID, string memory _operation, string[] memory _personalData, bool _isPositive) public { Consent memory newConsent = Consent(_purposeHash, _actorID, _operation, _personalData, msg.sender, _isPositive); consents.push(newConsent); } function getConsent(address actorID, address userId) public view returns (Consent[] memory) { uint16 count = 0; for (uint16 i = 0; i < consents.length; i++) { if (consents[i].actorID == actorID && consents[i].userId == userId) { count++; } } Consent[] memory userConsents = new Consent[](count); uint16 index = 0; for (uint16 i = 0; i < consents.length; i++) { if (consents[i].actorID == actorID && consents[i].userId == userId) { userConsents[index] = consents[i]; index++; } } return userConsents; } function callGetService(address dataUsageContractAddress) public { DataUsage dataUsage = DataUsage(dataUsageContractAddress); uint256 numActors = dataUsage.getActorAddressesCount(); for (uint256 i = 0; i < numActors; i++) { address actorAddress = dataUsage.actorAddresses(i); uint256 numServices = dataUsage.getServicesCount(actorAddress); for (uint256 j = 0; j < numServices; j++) { Service memory service = dataUsage.getService(actorAddress, j); emit LogServiceParams( service.actorID, service.serviceName, service.servicePurpose, service.operation, service.personalData ); } } } } //0xc5075f64488d32a067f76bd1d177b5376e72e8a9e3f0fb2395c1014b928d0181, 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2, 'Write', ['Account Number', 'Transaction History'], false //0xc5075f64488d32a067f76bd1d177b5376e72e8a9e3f0fb2395c1014b928d0181, 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2, 'Read', ['Account Number', 'Transaction History'], true
Editor is loading...