/// Send a credential transaction to the server, to be included on the blockchain.
/// Returns the created `Credentials` on success.
Send a credential transaction to the server, to be included on the blockchain.
Returns the created `Credentials` on success.
Send a credential transaction to the server to be included on the blockchain . Returns the created ` Credentials ` on success .
pub fn send_cred() -> std::io::Result<Option<Credentials>> {
    let mut stream = TcpStream::connect(format!("{}:{}", constants::HOST, constants::PORT))?;
    send(&mut stream, Command::Cred)?;
    let mut stream_reader = BufReader::new(&stream);
    let mut stream_writer = BufWriter::new(&stream);
    let mut rng = OsRng;
    let cred = Credentials::generate_random(&mut rng);
    let time_start = Instant::now();
    let proof = credential::prover::create_proof(&cred, &constants::CRED_PARAMS);
    let duration = time_start.elapsed();
    println!("Proof generation took {} seconds.", duration.as_secs_f64());
    stream_writer.write_all(&cred.pk_addr)?;
    let cm_cred = cred.comm_cred();
    stream_writer.write_all(&cm_cred.to_bytes())?;
    proof.write(stream_writer.by_ref())?;
    stream_writer.flush()?;
    let mut result = [0; 1];
    stream_reader.read_exact(&mut result)?;
    match result[0] {
        1 => {
            let mut t_new = [0; 8];
            stream_reader.read_exact(&mut t_new)?;
            let t_new = TransactionTime(t_new);
            let mut vec_len = [0; 8];
            stream_reader.read_exact(&mut vec_len)?;
            let mut signature = vec![0; u8_array_to_u64(&vec_len) as usize];
            stream_reader.read_exact(&mut signature)?;
            println!("Transaction sent:");
            println!(
                "{}",
                CredTransaction {
                    cm_cred,
                    pk_addr: cred.pk_addr,
                    t_new,
                    proof,
                    signature,
                }
            );
            Ok(Some(cred))
        }
        _ => Ok(None),
    }
}
pub fn send_cred ( ) -> std :: io :: Result < Option < Credentials > > { let mut stream = TcpStream :: connect ( format ! ( " " constants HOST constants PORT ) ) ? ; send ( & mut stream , Command :: Cred ) ? ; let mut stream_reader = BufReader :: new ( & stream ) ; let mut stream_writer = BufWriter :: new ( & stream ) ; let mut rng = OsRng ; let cred = Credentials :: generate_random ( & mut rng ) ; let time_start = Instant :: now ( ) ; let proof = credential :: prover :: create_proof ( & cred , & constants :: CRED_PARAMS ) ; let duration = time_start . elapsed ( ) ; println ! ( " " duration as_secs_f64 ( ) ) ; stream_writer . write_all ( & cred . pk_addr ) ? ; let cm_cred = cred . comm_cred ( ) ; stream_writer . write_all ( & cm_cred . to_bytes ( ) ) ? ; proof . write ( stream_writer . by_ref ( ) ) ? ; stream_writer . flush ( ) ? ; let mut result = [ 0 ; 1 ] ; stream_reader . read_exact ( & mut result ) ? ; match result [ 0 ] { 1 => { let mut t_new = [ 0 ; 8 ] ; stream_reader . read_exact ( & mut t_new ) ? ; let t_new = TransactionTime ( t_new ) ; let mut vec_len = [ 0 ; 8 ] ; stream_reader . read_exact ( & mut vec_len ) ? ; let mut signature = vec ! [ 0 u8_array_to_u64 ( vec_len ) as usize ] ; stream_reader . read_exact ( & mut signature ) ? ; println ! ( " " ) ; println ! ( " " CredTransaction { cm_cred pk_addr cred pk_addr t_new proof signature } ) ; Ok ( Some ( cred ) ) } _ => Ok ( None ) , } }
Send a credential transaction to the server, to be included on the blockchain.
Send a credential transaction to the server to be included on the blockchain .