MCPcopy Create free account
hub / github.com/dfinity/orbit / parse_arguments

Function parse_arguments

tools/dfx-orbit/src/canister/util.rs:17–42  ·  view source on GitHub ↗
(
    arg_string: &Option<String>,
    arg_path: &Option<String>,
    raw_arg: &Option<String>,
)

Source from the content-addressed store, hash-verified

15}
16
17pub(super) fn parse_arguments(
18 arg_string: &Option<String>,
19 arg_path: &Option<String>,
20 raw_arg: &Option<String>,
21) -> anyhow::Result<Option<Vec<u8>>> {
22 // TODO: It would be really nice to be able to use `blob_from_arguments(..)` here, as in dfx, to get all the nice things such as help composing the argument.
23 // First try to read the argument file, if it was provided
24
25 let candid = arg_path
26 .as_ref()
27 .map(std::fs::read_to_string)
28 .transpose()?
29 // Otherwise use the argument from the command line
30 .or_else(|| arg_string.clone())
31 // Parse the candid
32 .map(|arg_string| {
33 candid_parser::parse_idl_args(&arg_string)
34 .with_context(|| "Invalid Candid values".to_string())?
35 .to_bytes()
36 })
37 .transpose()?;
38
39 let raw_arg = raw_arg.as_ref().map(hex::decode).transpose()?;
40 let arg = candid.or(raw_arg);
41 Ok(arg)
42}
43
44pub(super) fn log_hashes(
45 logger: &Logger,

Callers 3

load_module_and_argsMethod · 0.85
into_requestMethod · 0.85
verifyMethod · 0.85

Calls 2

mapMethod · 0.80
to_bytesMethod · 0.45

Tested by

no test coverage detected