external_call.sol 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. contract caller {
  2. function do_call(callee e, int64 v) public {
  3. e.set_x(v);
  4. }
  5. function do_call2(callee e, int64 v) view public returns (int64) {
  6. return v + e.get_x();
  7. }
  8. // call two different functions
  9. function do_call3(callee e, callee2 e2, int64[4] memory x, string memory y) pure public returns (int64, string memory) {
  10. return (e2.do_stuff(x), e.get_name());
  11. }
  12. // call two different functions
  13. function do_call4(callee e, callee2 e2, int64[4] memory x, string memory y) pure public returns (int64, string memory) {
  14. return (e2.do_stuff(x), e.call2(e2, y));
  15. }
  16. function who_am_i() public view returns (address) {
  17. return address(this);
  18. }
  19. }
  20. contract callee {
  21. int64 x;
  22. function set_x(int64 v) public {
  23. x = v;
  24. }
  25. function get_x() public view returns (int64) {
  26. return x;
  27. }
  28. function call2(callee2 e2, string s) public pure returns (string) {
  29. return e2.do_stuff2(s);
  30. }
  31. function get_name() public pure returns (string) {
  32. return "my name is callee";
  33. }
  34. }
  35. contract callee2 {
  36. function do_stuff(int64[4] memory x) public pure returns (int64) {
  37. int64 total = 0;
  38. for (uint i=0; i< x.length; i++) {
  39. total += x[i];
  40. }
  41. return total;
  42. }
  43. function do_stuff2(string x) public pure returns (string) {
  44. return string.concat("x:", x);
  45. }
  46. }