0

I was trying to write a smart contract which will add a person information to the cities population only if the 2 people(both are city hall representatives) vote that the requested person lives in the city.

I am not able to understand the voting part. I think this will be executed by mapping and then using other 2 smart contracts(for city hall people) but how the voting is done was tough to implement. I also looked at The DAO smart contract but couldn't relate much. Any help will be good.

My code looks like,

mapping (bytes32 => bool) ConsensusStatus;


function addPerson(bytes32 _Name, uint _age, bytes32 _Value, bytes32 _Country, bytes32 _State, bytes32 _City, bytes32 _Email, uint _Phone) returns(bool success) {

Person memory newPerson;

newPerson.Name = _Name;
newPerson.age = _age;
newPerson.Male = _Value;
newPerson.Country = _Country;
newPerson.State = _State;
newPerson.City = _City;
newPerson.Email = _Email;
newPerson.Phone = _Phone;
// Below consensus code is most probably wrong

if (ConsensusStatus[_Name].Member1Vote && ConsensusStatus[_Name].Member2Vote) {
        People.push(newPerson); //People is the tuple storing the info of the city residents
return true;

        }

}
  • 1
    A couple of comments: 1. You probably want to store as little info as possible on each name on the blockchain for 2 reasons: a. privacy - remember that anyone would be able to see the email and phone in your example. b. it's expensive to store data on the blockchain. Therefore you might want to store only the bytes32 name data there. 2. It's not completely clear how that code would compile. Member1Vote and Member2Vote are used but never defined. You might want to update your code. – ronme Mar 5 '17 at 1:04
  • @ronme, I understand that part, but if I store very less info on the blockchain, then it will defeat the purpose of city registry (Something like yellow pages). 2) I have two other smart contracts for (town hall) voters, and Member1Vote and Member2Vote are their functions. It would be helpful if you could comment on my approach i.e. an if for everything their identity. I am thinking whether this approach if fine or that it has bugs. – Rajat Mar 5 '17 at 7:09
  • i'll reply in an answer as the comment space is too small and doesn't support formatting – ronme Mar 5 '17 at 19:27
  • 1
    "if I store very less info on the blockchain, then it will defeat the purpose of city registry" You could use a separate web service that stores a JSON payload and returns a digest hash of that, and then the smart contract approves the hash. – Jon Watte Aug 27 '17 at 21:54
1

A few comments:

  • Member1Vote and Member2Vote should have parans if they are function calls, e.g. Member1Vote()
  • I don't think you want to put public info such as email and phone on the blockchain, both because of privacy and because it's very expensive to do that and will just make it impractical for even small-sized cities.

If you want to build a city registry, consider putting that on a traditional server, with the blockchain just holding onto the trust-sensitive part (e.g. proof that member1 and member2 voted).

Consider also taking a looking at uPort for an identity related features that you might want to use.

  • @ronme thanks for all the suggestions. I am disappointed and at the same time glad that ConsenSys has already made the application. 1) I will look into the privacy part and might go with your suggestion. 2) I would, however, be grateful if you could share some more info on my voting idea. As an addPerson function is called two votes are needed to register the user. The problem I am facing is how to alert those two contracts on the update. Will seriously be grateful if you could direct me to some documentation or example which would be helpful. Thanks again for the advice – Rajat Mar 5 '17 at 19:58
  • 1
    @rajat i'm not sure if you want to alert the contracts, or the people. If it's the contracts, you can just make a call to them. If it's the people, you can issue Contract Events and have a server that listens to them. If you think I have answered your question above it'll be great if you accept my question by clicking on the check mark. Thank you and good luck with the project! – ronme Mar 6 '17 at 0:39

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.