(
matches: &ArgMatches,
args: Vec<String>,
destination_network: DestinationNetwork,
)
| 17 | } |
| 18 | |
| 19 | pub fn validate( |
| 20 | matches: &ArgMatches, |
| 21 | args: Vec<String>, |
| 22 | destination_network: DestinationNetwork, |
| 23 | ) -> Result<Vec<ArgType>, Response> { |
| 24 | let mut result: Vec<ArgType> = vec![]; |
| 25 | for arg in args.iter() { |
| 26 | match matches.get_one::<String>(arg) { |
| 27 | Some(value) => match arg.as_str() { |
| 28 | "DEPOSITOR_PUBLIC_KEY" => match PublicKey::from_str(value) { |
| 29 | Ok(pubkey) => result.push(ArgType::DepositorPublicKey(pubkey)), |
| 30 | Err(_) => { |
| 31 | return Err(error_response( |
| 32 | "Invalid public key. Use bitcoin public key format.".to_string(), |
| 33 | )) |
| 34 | } |
| 35 | }, |
| 36 | "DESTINATION_CHAIN_ADDRESS" | "WITHDRAWER_CHAIN_ADDRESS" => { |
| 37 | match Address::from_str(value) { |
| 38 | Ok(address) => result.push(ArgType::ChainAddress(address)), |
| 39 | Err(_) => { |
| 40 | return Err(error_response(format!( |
| 41 | "Invalid {}. Use {} address format.", |
| 42 | arg.as_str(), |
| 43 | destination_network |
| 44 | ))) |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | "OUTPOINT" => match OutPoint::from_str(value) { |
| 49 | Ok(outpoint) => result.push(ArgType::OutPoint(outpoint)), |
| 50 | Err(_) => { |
| 51 | return Err(error_response( |
| 52 | "Invalid OutPoint. Use <txid>:<vout> format.".to_string(), |
| 53 | )) |
| 54 | } |
| 55 | }, |
| 56 | "SATS" => match Amount::from_str_in(value, Denomination::Satoshi) { |
| 57 | Ok(amount) => result.push(ArgType::Satoshis(amount)), |
| 58 | Err(_) => { |
| 59 | return Err(error_response( |
| 60 | "Invalid amount of satoshis. Use u64.".to_string(), |
| 61 | )) |
| 62 | } |
| 63 | }, |
| 64 | "DEPOSIT" => match ecdsa::Signature::from_slice(value.as_bytes()) { |
| 65 | Ok(sig) => result.push(ArgType::EcdsaSignature(sig)), |
| 66 | Err(_) => { |
| 67 | return Err(error_response( |
| 68 | "Invalid format of ecdsa signature.".to_string(), |
| 69 | )) |
| 70 | } |
| 71 | }, |
| 72 | "CONFIRM" | "REFUND" => match taproot::Signature::from_slice(value.as_bytes()) { |
| 73 | Ok(sig) => result.push(ArgType::TaprootSignature(sig)), |
| 74 | Err(_) => { |
| 75 | return Err(error_response(format!( |
| 76 | "Invalid format of taproot signature for {} transaction.", |
no test coverage detected