/
demo_candid_type_text.cpp
50 lines (38 loc) · 1.68 KB
/
demo_candid_type_text.cpp
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
/* file: https://github.com/icppWorld/icpp-demos/tree/main/canisters/api_reference/src/demo_candid_type_text.cpp
$ dfx canister call --type idl --output idl demo demo_candid_type_text '("demo A" : text)'
("demo A")
-> check the console of the local network. The canister will print:
[Canister bkyz2-fmaaa-aaaaa-qaaaq-cai] Method demo_candid_type_text received value 'demo A'
$ dfx canister call --type idl --output idl demo demo_candid_type_texts '("demo A" : text, "demo B" : text)'
("demo A", "demo B")
-> check the console of the local network. The canister will print:
[Canister bkyz2-fmaaa-aaaaa-qaaaq-cai] Method demo_candid_type_texts received values 'demo A' & 'demo B'
*/
#include "demo_candid_type_text.h"
#include <string>
#include "ic_api.h"
void demo_candid_type_text() {
IC_API ic_api(CanisterQuery{std::string(__func__)}, false);
CandidTypePrincipal caller = ic_api.get_caller();
std::string in{""};
ic_api.from_wire(CandidTypeText{&in});
IC_API::debug_print("Method " + std::string(__func__) + " received value '" +
in + "'");
ic_api.to_wire(CandidTypeText{in});
}
void demo_candid_type_texts() {
IC_API ic_api(CanisterQuery{std::string(__func__)}, false);
CandidTypePrincipal caller = ic_api.get_caller();
std::string in1{""};
std::string in2{""};
CandidArgs args_in;
args_in.append(CandidTypeText(&in1));
args_in.append(CandidTypeText(&in2));
ic_api.from_wire(args_in);
IC_API::debug_print("Method " + std::string(__func__) + " received values '" +
in1 + "' & '" + in2 + "'");
CandidArgs args_out;
args_out.append(CandidTypeText(in1));
args_out.append(CandidTypeText(in2));
ic_api.to_wire(args_out);
}