Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregator contract needed #1

Open
numpde opened this issue May 4, 2023 · 0 comments
Open

Aggregator contract needed #1

numpde opened this issue May 4, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@numpde
Copy link
Owner

numpde commented May 4, 2023

Adoption of the main contract in several places (e.g., cities) will lead to a fragmentation of the on-chain database. An aggregator contract could allow for checking of the registration/missing status across multiple instances of the main contract. Moreover, the main contract could point to this contract/function, as well.

Something along the lines of:

pragma solidity ^0.8.0;

import "./BicycleComponentV1.sol";

contract Aggregator {
    // Array to store registered bicycle component contracts
    address[] public registeredContracts;

    // Function to add a bicycle component contract instance
    function addBicycleComponentContract(address contractAddress) external {
        // Add checks to ensure only authorized entities can add a contract
        registeredContracts.push(contractAddress);
    }

    // Function to check if a bicycle component with the given serial number is missing
    // and return the contract's address if it's missing
    function isMissing(string memory serialNumber) external view returns (address) {
        // Iterate over registered contracts
        for (uint256 i = 0; i < registeredContracts.length; i++) {
            // Create an instance of the BicycleComponentV1 contract
            BicycleComponentV1 bicycleComponent = BicycleComponentV1(registeredContracts[i]);

            // Generate tokenId from serialNumber
            uint256 tokenId = bicycleComponent.generateTokenId(serialNumber);

            // Check if the bicycle component is missing in the current contract
            bool missing = bicycleComponent.missingStatus(tokenId);

            // If the bicycle component is missing, return the contract's address
            if (missing) {
                return registeredContracts[i];
            }
        }

        // If the bicycle component is not missing in any contract, return an empty address
        return address(0);
    }
}
@numpde numpde added the enhancement New feature or request label May 4, 2023
@numpde numpde self-assigned this May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant