melstf 0.12.3

Core state-transition function and data structures for Mel
Documentation
use std::collections::BinaryHeap;

use melvm::Covenant;
use melstructs::{CoinData, CoinID, CoinValue, Denom, Transaction, TxKind};

pub fn random_valid_txx_count(
    rng: &mut impl rand::Rng,
    start_coin: CoinID,
    start_coindata: CoinData,
    signer: tmelcrypt::Ed25519SK,
    covenant: &melvm::Covenant,
    fee: CoinValue,
    tx_count: u32,
) -> Vec<Transaction> {
    let mut pqueue: BinaryHeap<(u64, CoinID, CoinData)> = BinaryHeap::new();
    pqueue.push((rng.gen(), start_coin, start_coindata));
    let mut toret = Vec::new();
    for _ in 0..tx_count {
        // pop one item from pqueue
        let (_, to_spend, to_spend_data) = pqueue.pop().unwrap();
        assert_eq!(to_spend_data.covhash, covenant.hash());
        let mut new_tx = Transaction {
            kind: TxKind::Normal,
            inputs: vec![to_spend],
            outputs: vec![CoinData {
                covhash: covenant.hash(),
                value: to_spend_data.value - fee,
                denom: Denom::Mel,
                additional_data: vec![].into(),
            }],
            fee,
            covenants: vec![covenant.to_bytes(), Covenant::always_true().to_bytes()],
            data: vec![].into(),
            sigs: vec![],
        };
        new_tx = new_tx.signed_ed25519(signer);
        for (i, out) in new_tx.outputs.iter().enumerate() {
            let cin = CoinID {
                txhash: new_tx.hash_nosigs(),
                index: i as u8,
            };
            pqueue.push((rng.gen(), cin, out.clone()));
        }
        toret.push(new_tx);
    }
    toret
}

// pub fn fee_estimate() -> CoinValue {
//     // Assuming some fee for tx (use higher multiplier to ensure its enough)
//     let fee_multiplier = 10000;
//     let fee = TransactionFactory::new()
//         .build(|_| {})
//         .weight()
//         .saturating_mul(fee_multiplier);
//     fee.into()
// }