use mx_proto::{
    Message,
    generated::proto::{Batch, Transaction},
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let tx = Transaction {
        nonce: 42,
        snd_addr: vec![0x11; 32].into(),
        rcv_addr: vec![0x22; 32].into(),
        data: b"transfer@01".to_vec().into(),
        ..Default::default()
    };

    let tx_bytes = tx.encode_to_vec();
    let decoded = Transaction::decode(tx_bytes.as_slice())?;

    println!("nonce={}", decoded.nonce);
    println!("hash={:02x?}", decoded.get_tx_hash());
    println!("sender={:?}", decoded.sender_bech32()?);
    println!("receiver={:?}", decoded.receiver_bech32()?);
    println!("relayer={:?}", decoded.relayer_bech32()?);

    let batch = Batch {
        data: vec![tx_bytes.into()],
        ..Default::default()
    };
    let batch_bytes = batch.encode_to_vec();
    let decoded_batch = Batch::decode(batch_bytes.as_slice())?;

    println!("batch_items={}", decoded_batch.data.len());
    Ok(())
}
