Repository navigation
Expand file tree
/
Copy pathdemo_candid_type_nat.cpp
More file actions
53 lines (42 loc) · 1.76 KB
/
Copy pathdemo_candid_type_nat.cpp
File metadata and controls
53 lines (42 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* file: https://github.com/icppWorld/icpp-demos/tree/main/canisters/api_reference/src/demo_candid_type_nat.cpp
$ icp canister call demo demo_candid_type_nat '(101 : nat)' --environment local
(101 : nat)
-> check the console of the local network. The canister will print:
[Canister bkyz2-fmaaa-aaaaa-qaaaq-cai] Method demo_candid_type_nat received value '101'
$ icp canister call demo demo_candid_type_nats '(101 : nat, 102 : nat)' --environment local
(101 : nat, 102 : nat)
-> check the console of the local network. The canister will print:
[Canister bkyz2-fmaaa-aaaaa-qaaaq-cai] Method demo_candid_type_nats received values '101' & '102'
*/
#include "demo_candid_type_nat.h"
#include <iostream>
#include <string>
#include "ic_api.h"
void demo_candid_type_nat() {
IC_API ic_api(CanisterQuery{std::string(__func__)}, false);
CandidTypePrincipal caller = ic_api.get_caller();
__uint128_t in{0};
ic_api.from_wire(CandidTypeNat{&in});
std::cout << "Method " + std::string(__func__) + " received value '" +
IC_API::to_string_128(in) + "'"
<< std::endl;
ic_api.to_wire(CandidTypeNat{in});
}
void demo_candid_type_nats() {
IC_API ic_api(CanisterQuery{std::string(__func__)}, false);
CandidTypePrincipal caller = ic_api.get_caller();
__uint128_t in1{0};
__uint128_t in2{0};
CandidArgs args_in;
args_in.append(CandidTypeNat(&in1));
args_in.append(CandidTypeNat(&in2));
ic_api.from_wire(args_in);
std::cout << "Method " + std::string(__func__) + " received values '" +
IC_API::to_string_128(in1) + "' & '" +
IC_API::to_string_128(in2) + "'"
<< std::endl;
CandidArgs args_out;
args_out.append(CandidTypeNat(in1));
args_out.append(CandidTypeNat(in2));
ic_api.to_wire(args_out);
}