/// Tries to decode the string as hex and base64, if it works, returns the bytes.
/// If not, tries to open a filename with the given string as relative path, if it works, returns
/// the content bytes.
/// Also returns an enum value indicating which source worked.
Tries to decode the string as hex and base64, if it works, returns the bytes.
If not, tries to open a filename with the given string as relative path, if it works, returns
the content bytes.
Also returns an enum value indicating which source worked.
Tries to decode the string as hex and base64 if it works returns the bytes . If not tries to open a filename with the given string as relative path if it works returns the content bytes . Also returns an enum value indicating which source worked .
fn file_or_raw(flag: &str) -> (Vec<u8>, PsbtSource) {
	if let Ok(raw) = hex::decode(&flag) {
		(raw, PsbtSource::Hex)
	} else if let Ok(raw) = base64::decode(&flag) {
		(raw, PsbtSource::Base64)
	} else if let Ok(mut file) = File::open(&flag) {
		let mut buf = Vec::new();
		file.read_to_end(&mut buf).expect("error reading file");
		(buf, PsbtSource::File)
	} else {
		panic!("Can't load PSBT: invalid hex, base64 or unknown file");
	}
}
fn file_or_raw ( flag : & str ) -> ( Vec < u8 > , PsbtSource ) { if let Ok ( raw ) = hex :: decode ( & flag ) { ( raw , PsbtSource :: Hex ) } else if let Ok ( raw ) = base64 :: decode ( & flag ) { ( raw , PsbtSource :: Base64 ) } else if let Ok ( mut file ) = File :: open ( & flag ) { let mut buf = Vec :: new ( ) ; file . read_to_end ( & mut buf ) . expect ( " " ) ; ( buf , PsbtSource :: File ) } else { panic ! ( " " ) ; } }
Tries to decode the string as hex and base64, if it works, returns the bytes.
Tries to decode the string as hex and base64 if it works returns the bytes .
flag
&str