ethereum/ethereumj

Ethereumj + mapping Smart Contract

Open

#1.085 aberto em 29 de mai. de 2018

Ver no GitHub
 (6 comments) (0 reactions) (0 assignees)Java (1.089 forks)batch import
help wanted

Métricas do repositório

Stars
 (2.136 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

hi i am working with smart contract deployed in Ethereumj changing the example EventListenerSample, where i can set value in the method addPeople that save the value in a mapping. This is the code of smartcontract

contract Health {

	struct Person {
		address adr;
		string name;
		uint weight;
		string diseases;
		string medication;
	}

	mapping(uint => Person) public peopleData;

	function Health() {
		
	}

    function addPeople(string _name, uint _weight, uint _publicPass)  {
		peopleData[_publicPass] = Person({
			 			adr: msg.sender,
			 			name: _name,
			 			weight: _weight,
			 			diseases: "none",
			 			medication: ""
			 		});
    }

    function changeWeight(uint _publicPass, uint _weight) {
    	peopleData[_publicPass].weight = _weight;
    }

    function addDisease(uint _publicPass, string _diseases) {
		peopleData[_publicPass].diseases = _diseases;
    }

    function addMedication(uint _publicPass, string _medication) {
		peopleData[_publicPass].medication = _medication;
    }

    function changePublicPass(uint _newPublicPass, uint _oldPublicPass) {
    	if(msg.sender != peopleData[_oldPublicPass].adr) {
    		revert();
    	}
    	peopleData[_newPublicPass] = peopleData[_oldPublicPass];
    	delete peopleData[_oldPublicPass];
    }

    function purchasedMedication(uint _publicPass) {
    	peopleData[_publicPass].medication = "";
    }
	
}

in Harmony i can see that the value was saved

public void contractIncCall(byte[] privateKey, String name, int adr, int weight,
                                 String contractABI, byte[] contractAddress) throws InterruptedException {
        logger.info("Calling the contract function 'inc'");
        CallTransaction.Contract contract = new CallTransaction.Contract(contractABI);
        CallTransaction.Function inc = contract.getByName("addPeople");
        byte[] functionCallBytes = inc.encode(name, adr, weight);
        TransactionReceipt receipt = sendTxAndWait(contractAddress, functionCallBytes, privateKey);
        if (!receipt.isSuccessful()) {
            logger.error("Some troubles invoking the contract: " + receipt.getError());
            return;
        }
        logger.info("Contract modified!");
    }

image

but i dont know how get the value of a mapping from Ethereumj

Guia do colaborador