pub fn c_from(
    stream: TcpStream,
    blockchain: Arc<RwLock<BlockChain>>,
    server_data: Arc<ServerData>,
) -> std::io::Result<bool> {
    let mut stream_reader = BufReader::new(&stream);
    let mut stream_writer = BufWriter::new(&stream);
    let mut rt_note = [0; 32];
    let mut eta = [0; 32];
    let mut pk_addr: AddressPublicKey = [0; 32];
    let mut t_new = [0; 8];
    let mut message = vec![];
    stream_reader.read_exact(&mut rt_note)?;
    let rt_note = fr_from_repr(rt_note)?;
    stream_reader.read_exact(&mut eta)?;
    stream_reader.read_exact(&mut pk_addr)?;
    stream_reader.read_exact(&mut t_new)?;
    let t_new = TransactionTime(t_new);
    let proof = Proof::<Bls12>::read(stream_reader.by_ref())?;
    let time_start = Instant::now();
    let result = convert_from::verifier::verify_proof(
        &proof,
        &rt_note,
        &eta,
        &pk_addr,
        &constants::C_FROM_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()?;
    match result {
        true => {
            message.extend_from_slice(&rt_note.to_bytes());
            message.extend_from_slice(&eta);
            message.extend_from_slice(&pk_addr);
            proof.write(message.by_ref())?;
            let signature = sign(message.as_slice(), &server_data.signature_keypair)
                .expect("Signing should not fail.")
                .as_ref()
                .to_vec();
            stream_writer.write_all(&u64_array_to_u8_vector(&[signature.len() as u64]))?;
            stream_writer.write_all(&signature)?;
            stream_writer.flush()?;

            let mut blockchain = blockchain.write().unwrap();
            blockchain
                .new_block
                .as_mut()
                .expect("A new block should be ready.")
                .add_transaction(Box::new(CFromTransaction {
                    rt_note,
                    eta,
                    pk_addr,
                    t_new,
                    proof,
                    signature,
                }));
            Ok(true)
        }
        false => Ok(false),
    }
}
/// This function handles the server side of a `ConvertFrom` command.
/// It returns the result of the proof verification.
This function handles the server side of a `ConvertFrom` command.
It returns the result of the proof verification.
This function handles the server side of a ` ConvertFrom ` command . It returns the result of the proof verification .
pub fn c_from(
    stream: TcpStream,
    blockchain: Arc<RwLock<BlockChain>>,
    server_data: Arc<ServerData>,
) -> std::io::Result<bool> {
    let mut stream_reader = BufReader::new(&stream);
    let mut stream_writer = BufWriter::new(&stream);
    let mut rt_note = [0; 32];
    let mut eta = [0; 32];
    let mut pk_addr: AddressPublicKey = [0; 32];
    let mut t_new = [0; 8];
    let mut message = vec![];
    stream_reader.read_exact(&mut rt_note)?;
    let rt_note = fr_from_repr(rt_note)?;
    stream_reader.read_exact(&mut eta)?;
    stream_reader.read_exact(&mut pk_addr)?;
    stream_reader.read_exact(&mut t_new)?;
    let t_new = TransactionTime(t_new);
    let proof = Proof::<Bls12>::read(stream_reader.by_ref())?;
    let time_start = Instant::now();
    let result = convert_from::verifier::verify_proof(
        &proof,
        &rt_note,
        &eta,
        &pk_addr,
        &constants::C_FROM_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()?;
    match result {
        true => {
            message.extend_from_slice(&rt_note.to_bytes());
            message.extend_from_slice(&eta);
            message.extend_from_slice(&pk_addr);
            proof.write(message.by_ref())?;
            let signature = sign(message.as_slice(), &server_data.signature_keypair)
                .expect("Signing should not fail.")
                .as_ref()
                .to_vec();
            stream_writer.write_all(&u64_array_to_u8_vector(&[signature.len() as u64]))?;
            stream_writer.write_all(&signature)?;
            stream_writer.flush()?;
            let mut blockchain = blockchain.write().unwrap();
            blockchain
                .new_block
                .as_mut()
                .expect("A new block should be ready.")
                .add_transaction(Box::new(CFromTransaction {
                    rt_note,
                    eta,
                    pk_addr,
                    t_new,
                    proof,
                    signature,
                }));
            Ok(true)
        }
        false => Ok(false),
    }
}
pub fn c_from ( stream : TcpStream , blockchain : Arc < RwLock < BlockChain > > , server_data : Arc < ServerData > , ) -> std :: io :: Result < bool > { let mut stream_reader = BufReader :: new ( & stream ) ; let mut stream_writer = BufWriter :: new ( & stream ) ; let mut rt_note = [ 0 ; 32 ] ; let mut eta = [ 0 ; 32 ] ; let mut pk_addr : AddressPublicKey = [ 0 ; 32 ] ; let mut t_new = [ 0 ; 8 ] ; let mut message = vec ! [ ] ; stream_reader . read_exact ( & mut rt_note ) ? ; let rt_note = fr_from_repr ( rt_note ) ? ; stream_reader . read_exact ( & mut eta ) ? ; stream_reader . read_exact ( & mut pk_addr ) ? ; stream_reader . read_exact ( & mut t_new ) ? ; let t_new = TransactionTime ( t_new ) ; let proof = Proof :: < Bls12 > :: read ( stream_reader . by_ref ( ) ) ? ; let time_start = Instant :: now ( ) ; let result = convert_from :: verifier :: verify_proof ( & proof , & rt_note , & eta , & pk_addr , & constants :: C_FROM_PVK , ) ; let duration = time_start . elapsed ( ) ; println ! ( " " duration as_secs_f64 ( ) ) ; stream_writer . write_all ( & [ result as u8 ] ) ? ; stream_writer . flush ( ) ? ; match result { true => { message . extend_from_slice ( & rt_note . to_bytes ( ) ) ; message . extend_from_slice ( & eta ) ; message . extend_from_slice ( & pk_addr ) ; proof . write ( message . by_ref ( ) ) ? ; let signature = sign ( message . as_slice ( ) , & server_data . signature_keypair ) . expect ( " " ) . as_ref ( ) . to_vec ( ) ; stream_writer . write_all ( & u64_array_to_u8_vector ( & [ signature . len ( ) as u64 ] ) ) ? ; stream_writer . write_all ( & signature ) ? ; stream_writer . flush ( ) ? ; let mut blockchain = blockchain . write ( ) . unwrap ( ) ; blockchain . new_block . as_mut ( ) . expect ( " " ) . add_transaction ( Box :: new ( CFromTransaction { rt_note , eta , pk_addr , t_new , proof , signature , } ) ) ; Ok ( true ) } false => Ok ( false ) , } }
This function handles the server side of a `ConvertFrom` command.
This function handles the server side of a ` ConvertFrom ` command .
stream
TcpStream
blockchain
Arc<RwLock<BlockChain>>
server_data
Arc<ServerData>
stream
TcpStream
blockchain
Arc<RwLock<BlockChain>>
server_data
Arc<ServerData>