/// Send a convert_to transaction to the server, to be included on the blockchain.
/// Returns the result of the proof verification.
Send a convert_to transaction to the server, to be included on the blockchain.
Returns the result of the proof verification.
Send a convert_to transaction to the server to be included on the blockchain . Returns the result of the proof verification .
pub fn send_c_to(data: &mut UserData) -> std::io::Result<bool> {
    let mut stream = TcpStream::connect(format!("{}:{}", constants::HOST, constants::PORT))?;
    send(&mut stream, Command::CTo)?;
    let mut stream_reader = BufReader::new(&stream);
    let mut stream_writer = BufWriter::new(&stream);
    print!("Deposit amount:   €");
    std::io::stdout().flush()?;
    let mut value = String::new();
    std::io::stdin().read_line(&mut value)?;
    match value.trim().parse::<u64>() {
        Ok(value) => {
            let v_note: [u8; 8] = u64_array_to_u8_vector(&[value])
                .as_slice()
                .try_into()
                .expect("Value should fit");
            stream_writer.write_all(&data.cred.pk_addr)?;
            stream_writer.write_all(data.public_key.as_ref())?;
            stream_writer.write_all(&v_note)?;
            stream_writer.flush()?;
            let mut cm_note = [0; 32];
            stream_reader.read_exact(&mut cm_note)?;
            let proof = Proof::<Bls12>::read(stream_reader.by_ref())?;
            let cm_note = fr_from_repr(cm_note)?;
            let time_start = Instant::now();
            let result = convert_to::verifier::verify_proof(&proof, &cm_note, &constants::C_TO_PVK);
            let duration = time_start.elapsed();
            println!("Proof validation took {} seconds.", duration.as_secs_f64());
            stream_writer.write_all(&[result as u8])?;
            stream_writer.flush()?;
            Ok(result)
        }
        Err(e) => Err(std::io::Error::new(std::io::ErrorKind::Other, e)),
    }
}
pub fn send_c_to ( data : & mut UserData ) -> std :: io :: Result < bool > { let mut stream = TcpStream :: connect ( format ! ( " " constants HOST constants PORT ) ) ? ; send ( & mut stream , Command :: CTo ) ? ; let mut stream_reader = BufReader :: new ( & stream ) ; let mut stream_writer = BufWriter :: new ( & stream ) ; print ! ( " ; std :: io :: stdout ( ) . flush ( ) ? ; let mut value = String :: new ( ) ; std :: io :: stdin ( ) . read_line ( & mut value ) ? ; match value . trim ( ) . parse :: < u64 > ( ) { Ok ( value ) => { let v_note : [ u8 ; 8 ] = u64_array_to_u8_vector ( & [ value ] ) . as_slice ( ) . try_into ( ) . expect ( " " ) ; stream_writer . write_all ( & data . cred . pk_addr ) ? ; stream_writer . write_all ( data . public_key . as_ref ( ) ) ? ; stream_writer . write_all ( & v_note ) ? ; stream_writer . flush ( ) ? ; let mut cm_note = [ 0 ; 32 ] ; stream_reader . read_exact ( & mut cm_note ) ? ; let proof = Proof :: < Bls12 > :: read ( stream_reader . by_ref ( ) ) ? ; let cm_note = fr_from_repr ( cm_note ) ? ; let time_start = Instant :: now ( ) ; let result = convert_to :: verifier :: verify_proof ( & proof , & cm_note , & constants :: C_TO_PVK ) ; let duration = time_start . elapsed ( ) ; println ! ( " " duration as_secs_f64 ( ) ) ; stream_writer . write_all ( & [ result as u8 ] ) ? ; stream_writer . flush ( ) ? ; Ok ( result ) } Err ( e ) => Err ( std :: io :: Error :: new ( std :: io :: ErrorKind :: Other , e ) ) , } }
Send a convert_to transaction to the server, to be included on the blockchain.
Send a convert_to transaction to the server to be included on the blockchain .
data
&mut UserData