lib.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-License-Identifier: Apache-2.0
  2. #![cfg_attr(not(feature = "std"), no_std, no_main)]
  3. #[ink::contract]
  4. mod caller {
  5. use ink::env::{
  6. call::{build_call, ExecutionInput, Selector},
  7. DefaultEnvironment,
  8. };
  9. #[ink(storage)]
  10. #[derive(Default)]
  11. pub struct Caller {}
  12. impl Caller {
  13. #[ink(constructor)]
  14. pub fn new() -> Self {
  15. Default::default()
  16. }
  17. /// Do a proxy call to `callee` and return its result.
  18. /// The message under `selector` should have exactly one `u32` argument and return a `u32`.
  19. #[ink(message)]
  20. pub fn u32_proxy(
  21. &self,
  22. callee: AccountId,
  23. selector: [u8; 4],
  24. arg: u32,
  25. max_gas: Option<u64>,
  26. transfer_value: Option<u128>,
  27. ) -> u32 {
  28. build_call::<DefaultEnvironment>()
  29. .call_v1(callee)
  30. .gas_limit(max_gas.unwrap_or(u64::MAX))
  31. .transferred_value(transfer_value.unwrap_or_default())
  32. .exec_input(ExecutionInput::new(Selector::new(selector)).push_arg(arg))
  33. .returns::<u32>() // FIXME: This should be Result<u32, u8> to respect LanguageError
  34. .invoke()
  35. }
  36. }
  37. }