/// Send a convert_from transaction to the server, to be included on the blockchain.
/// Returns the result of the proof verification.
/// Note: This method is only user by a server.
Send a convert_from transaction to the server, to be included on the blockchain.
Returns the result of the proof verification.
Note: This method is only user by a server.
Send a convert_from transaction to the server to be included on the blockchain . Returns the result of the proof verification . Note : This method is only user by a server .
pub fn send_c_from(
    sk_addr: [u8; 32],
    pk_addr: AddressPublicKey,
    note: &Note,
    witness: MerkleWitness,
    rt_note: MerkleRoot,
    pk_addr_sndr: AddressPublicKey,
) -> std::io::Result<bool> {
    let mut stream = TcpStream::connect(format!("{}:{}", constants::HOST, constants::PORT))?;
    send(&mut stream, Command::CFrom)?;
    let mut stream_reader = BufReader::new(&stream);
    let mut stream_writer = BufWriter::new(&stream);
    let cred = Credentials {
        sk_addr,
        pk_addr,
        s_cred: jubjub::Scalar::zero(),
    };
    let time_start = Instant::now();
    let proof =
        convert_from::prover::create_proof(&cred, note, &witness, &constants::C_FROM_PARAMS);
    let duration = time_start.elapsed();
    println!("Proof generation took {} seconds.", duration.as_secs_f64());
    let eta = cred.prf_eta(&witness);
    let t_new = TransactionTime::current();
    stream_writer.write_all(&rt_note.to_bytes())?;
    stream_writer.write_all(&eta)?;
    stream_writer.write_all(&cred.pk_addr)?;
    stream_writer.write_all(&t_new.0)?;
    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 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!(
                "{}",
                CFromTransaction {
                    rt_note,
                    eta,
                    pk_addr: cred.pk_addr,
                    t_new,
                    proof,
                    signature,
                }
            );
            println!(
                "€{} transferred back to regular account of user with public address key 0x{}.",
                u8_array_to_u64(&note.v_note),
                hex::encode(pk_addr_sndr)
            );
            Ok(true)
        }
        _ => Ok(false),
    }
}
pub fn send_c_from ( sk_addr : [ u8 ; 32 ] , pk_addr : AddressPublicKey , note : & Note , witness : MerkleWitness , rt_note : MerkleRoot , pk_addr_sndr : AddressPublicKey , ) -> std :: io :: Result < bool > { let mut stream = TcpStream :: connect ( format ! ( " " constants HOST constants PORT ) ) ? ; send ( & mut stream , Command :: CFrom ) ? ; let mut stream_reader = BufReader :: new ( & stream ) ; let mut stream_writer = BufWriter :: new ( & stream ) ; let cred = Credentials { sk_addr , pk_addr , s_cred : jubjub :: Scalar :: zero ( ) , } ; let time_start = Instant :: now ( ) ; let proof = convert_from :: prover :: create_proof ( & cred , note , & witness , & constants :: C_FROM_PARAMS ) ; let duration = time_start . elapsed ( ) ; println ! ( " " duration as_secs_f64 ( ) ) ; let eta = cred . prf_eta ( & witness ) ; let t_new = TransactionTime :: current ( ) ; stream_writer . write_all ( & rt_note . to_bytes ( ) ) ? ; stream_writer . write_all ( & eta ) ? ; stream_writer . write_all ( & cred . pk_addr ) ? ; stream_writer . write_all ( & t_new . 0 ) ? ; 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 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 ! ( " " CFromTransaction { rt_note eta pk_addr cred pk_addr t_new proof signature } ) ; println ! ( " u8_array_to_u64 ( note v_note ) hex encode ( pk_addr_sndr ) ) ; Ok ( true ) } _ => Ok ( false ) , } }
Send a convert_from transaction to the server, to be included on the blockchain.
Send a convert_from transaction to the server to be included on the blockchain .
sk_addr
[u8; 32]
pk_addr
AddressPublicKey
note
&Note
witness
MerkleWitness
rt_note
MerkleRoot
pk_addr_sndr
AddressPublicKey