Guest User

Untitled

a guest
Jan 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. struct Person
  2. {
  3. bytes32 firstName;
  4. bytes32 lastName;
  5.  
  6. }
  7.  
  8. function addPerson(bytes32 _firstName, bytes32 _lastname) returns (bool success)
  9. {
  10. Person memory newPerson;
  11.  
  12. newPerson.firstName = _firstName;
  13. newPerson.lastName = _lastname;
  14.  
  15.  
  16. people.push(newPerson);
  17. return true;
  18. }
  19.  
  20. function getPeople() constant returns (bytes32[], bytes32[])
  21. {
  22. uint leng = people.length;
  23.  
  24. bytes32[] memory first_names = new bytes32[](leng);
  25. bytes32[] memory last_names = new bytes32[](leng);
  26.  
  27.  
  28. for (uint i = 0; i < people.length; i++ )
  29. {
  30. Person memory currentPerson;
  31. currentPerson = people[i];
  32. first_names[i] = (currentPerson.firstName);
  33. last_names[i] = (currentPerson.lastName);
  34.  
  35.  
  36. }
  37. return (first_names,last_names);
  38. }
  39.  
  40. public RemoteCall<Tuple2<List<byte[]>, List<byte[]>>> getPeople() {
  41. final Function function = new Function("getPeople",
  42. Arrays.<Type>asList(),
  43. Arrays.<TypeReference<?>>asList(new TypeReference<DynamicArray<Bytes32>>() {}, new TypeReference<DynamicArray<Bytes32>>() {}));
  44. return new RemoteCall<Tuple2<List<byte[]>, List<byte[]>>>(
  45. new Callable<Tuple2<List<byte[]>, List<byte[]>>>() {
  46. @Override
  47. public Tuple2<List<byte[]>, List<byte[]>> call() throws Exception {
  48. List<Type> results = executeCallMultipleValueReturn(function);;
  49. return new Tuple2<List<byte[]>, List<byte[]>>(
  50. (List<byte[]>) results.get(0).getValue(),
  51. (List<byte[]>) results.get(1).getValue());
  52. }
  53. });
  54. }
Add Comment
Please, Sign In to add comment