futucli/cmd/proto_json/
verification.rs1use anyhow::{Result, bail};
4
5use crate::output::OutputFormat;
6
7use super::transport::{ensure_success, print_proto_response, send_proto};
8
9pub async fn run_verification(
10 gateway: &str,
11 verification_type: i32,
12 op: i32,
13 code: Option<String>,
14 output: OutputFormat,
15) -> Result<()> {
16 validate_verification_args(verification_type, op, code.as_deref())?;
17 let request = futu_proto::verification::Request {
18 c2s: futu_proto::verification::C2s {
19 r#type: verification_type,
20 op,
21 code,
22 },
23 };
24 let response: futu_proto::verification::Response = send_proto(
25 gateway,
26 futu_core::INTERNAL_UI_CLIENT_ID,
27 futu_core::proto_id::VERIFICATION,
28 request,
29 )
30 .await?;
31 ensure_success(
32 "verification",
33 response.ret_type,
34 response.ret_msg.as_deref(),
35 response.err_code,
36 )?;
37 print_proto_response(output, &response)
38}
39
40pub(super) fn validate_verification_args(
41 verification_type: i32,
42 op: i32,
43 code: Option<&str>,
44) -> Result<()> {
45 if !matches!(verification_type, 1 | 2) {
46 bail!("verification --type must be 1 (Picture) or 2 (Phone)");
47 }
48 if !matches!(op, 1 | 2) {
49 bail!("verification --op must be 1 (Request) or 2 (InputAndLogin)");
50 }
51 if op == 2 && code.is_none() {
52 bail!("verification --code is required for --op 2");
53 }
54 Ok(())
55}