I am new to the development of smart contract using web3j. I am facing issue, while converting Bytes32[] returned from wrapper of contract(.sol) method to array.
I have contract as:
pragma solidity ^0.4.4;
contract Person
{
Person[] public people;
struct Person
{
bytes32 firstName;
bytes32 lastName;
}
function addPerson(bytes32 _firstName, bytes32 _lastname) returns (bool success)
{
Person memory newPerson;
newPerson.firstName = _firstName;
newPerson.lastName = _lastname;
people.push(newPerson);
return true;
}
function getPeople() constant returns (bytes32[], bytes32[])
{
uint leng = people.length;
bytes32[] memory first_names = new bytes32[](leng);
bytes32[] memory last_names = new bytes32[](leng);
for (uint i = 0; i < people.length; i++ )
{
Person memory currentPerson;
currentPerson = people[i];
first_names[i] = (currentPerson.firstName);
last_names[i] = (currentPerson.lastName);
}
return (first_names,last_names);
}
}
Function from generated java wrapper as:
public RemoteCall<Tuple2<List<byte[]>, List<byte[]>>> getPeople() {
final Function function = new Function("getPeople",
Arrays.<Type>asList(),
Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Bytes32>>() {}, new TypeReference<DynamicArray<Bytes32>>() {}));
return new RemoteCall<Tuple2<List<byte[]>, List<byte[]>>>(
new Callable<Tuple2<List<byte[]>, List<byte[]>>>() {
@Override
public Tuple2<List<byte[]>, List<byte[]>> call() throws Exception {
List<Type> results = executeCallMultipleValueReturn(function);;
return new Tuple2<List<byte[]>, List<byte[]>>(
(List<byte[]>) results.get(0).getValue(),
(List<byte[]>) results.get(1).getValue());
}
});
}
In my main function, I am trying access Bytes of Array returned from getPeople method. But I am not note able to converted Bytes of array to string. I am storing tuples values in main method as:
Tuple2<List<byte[]>, List<byte[]>> x = contract.getPeople().send();
I want to convert value, x.getValue1()
to string. Can anyone please tell me how to do it.