ethereum/ethereumj

Ethereumj + mapping Smart Contract

Open

#1,085 建立於 2018年5月29日

在 GitHub 查看
 (6 留言) (0 反應) (0 負責人)Java (2,136 star) (1,089 fork)batch import
help wanted

描述

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

貢獻者指南