1

I am trying to modify the contract function type to endorse the fact that ONLY the owner of the contract can verify if a Company has done the payment of 2 Ethers required.

I tried with the following function which I called "isPaymentOK" but anyone has a better idea?

contract KYCPurchase {
  uint public price = 2 ether;

  struct Company {
      string registeredNumber;
      string companyName;
  }

  mapping (address => Company) companies;

  function buy(string registeredNumber, string companyName) public payable {
    require(msg.value == price);

    // Keep a list of buyers who have transferred enough ether
    companies[msg.sender] = Company(registeredNumber, companyName);

  }

  function isKYCPaymentOK (string registeredNumber, string companyName) pure private returns (string, string) {
        return (registeredNumber, companyName);

  }
}

Thanks.

  • Just to clarify, you want to make it so that only a certain person can read from the contract? – Shawn Tabrizi Nov 24 '18 at 20:59
  • Well, I need one person A (a sort of Public Institution in my case) to be able to check if Company B has done a payment. Then, it is not a problem if other companies or people can verify the same and have access to the same information, but I'd prefer only person A to be able to perform such check rather than giving to all companies access to the same function/information. I am not 100% this can be done, though. – Marialuisa Marchese Nov 24 '18 at 23:27
  • WIll that one institution be responsible for confirming whether all other companies have made the payment or just a single company? What I am trying to ask is that are you looking to implement a function, which only the owner of the contract can check? – Rohan Dhar Nov 25 '18 at 7:39
  • Could you kindly upvote my answer too :)? – Rohan Dhar Nov 25 '18 at 11:34
2

You can try something like this:

    contract KYCPurchase {
      uint public price = 2 ether;
      address owner;

      constructor() public{
      owner = msg.sender
}
      modifier _ownerOnly(){
      require(msg.sender == owner);
}
      struct Company {
          string registeredNumber;
          string companyName;
      }

      mapping (address => Company) companies;

      function buy(string registeredNumber, string companyName) public payable {
        require(msg.value == price);

        // Keep a list of buyers who have transferred enough ether
        companies[msg.sender] = Company(registeredNumber, companyName);

      }

      function isKYCPaymentOK (address companyAddress) pure _ownerOnly returns (string, string) {
            require(companies[companyAddress].registeredNumber > 0);
            return (companies[companyAddress].registeredNumber, companies[companyAddress].companyName);

      }
    }

If you don't want the authorizing organization to handle complex ethereum addresses, then you can try out the following(provided that registered number is unique for every company):

    contract KYCPurchase {
      uint public price = 2 ether;
      address owner;

      constructor() public{
      owner = msg.sender
}
      modifier _ownerOnly(){
      require(msg.sender == owner);
}
      struct Company {
          address companyAddress;
          string companyName;
      }

      mapping (string => Company) companies;

      function buy(string registeredNumber, string companyName) public payable {
        require(msg.value == price);

        // Keep a list of buyers who have transferred enough ether
        companies[registeredNumber] = Company(msg.sender, companyName);

      }

      function isKYCPaymentOK (string _registeredNumber) pure _ownerOnly returns (string, string) {
            require(companies[_registeredNumber].companyAddress != address(0));
            return (companies[companyAddress].registeredNumber, companies[companyAddress].companyName);

      }
    }
1

Everything that happens inside the blockchain is public information. So all the data you have is readable for anyone who knows how to access it.

The only way for you to hide some information is by encrypting it before it reaches blockchain (so somewhere in your backend). This way nobody can interpret the data without the right encryption key, but this also means that the smart contract can't interpret & use the data either.

So what you want to achieve is not very doable. But typically it shouldn't be a problem if someone else can read data as well - as long as only certain parties can write data and that you can check with their used public keys.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.