Last active
December 7, 2023 10:37
-
-
Save joske/7e08248a8d15a21851a546d09c67e41f to your computer and use it in GitHub Desktop.
create random block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use crate::locators::{ | |
test_helpers::{sample_block_locators, sample_block_locators_with_fork}, | |
CHECKPOINT_INTERVAL, NUM_RECENT_BLOCKS, | |
}; | |
use snarkos_node_bft_ledger_service::{MockLedgerService, TranslucentLedgerService}; | |
use snarkvm::{ | |
console::{ | |
account::{PrivateKey, ViewKey}, | |
network::AleoID, | |
program::{Entry, Identifier, Literal, Plaintext, Zero}, | |
}, | |
ledger::{ | |
authority::Authority, | |
header::{Header, Metadata}, | |
store::{helpers::memory::ConsensusMemory, ConsensusStore}, | |
transactions::Transactions, | |
Ledger, Ratifications, RecordsFilter, | |
}, | |
prelude::{Field, TestRng}, | |
synthesizer::{Program, VM}, | |
}; | |
use indexmap::indexset; | |
use snarkvm::ledger::committee::Committee; | |
use std::{ | |
net::{IpAddr, Ipv4Addr}, | |
str::FromStr, thread::sleep, time::Duration, | |
}; | |
type CurrentNetwork = snarkvm::prelude::Testnet3; | |
fn _create_block(height: u32) -> Block<snarkvm::prelude::Testnet3> { | |
let metadata = Metadata::new_unchecked(3, 2000, height, 1, 1, 1, 1, 1, 1, 1); | |
let stateroot = AleoID::default(); | |
let header = Header::<CurrentNetwork>::from_unchecked( | |
stateroot, | |
Field::zero(), | |
Field::zero(), | |
Field::zero(), | |
Field::zero(), | |
Field::zero(), | |
metadata, | |
); | |
let previous_hash = <CurrentNetwork as Network>::BlockHash::default(); | |
// let block_hash = | |
// CurrentNetwork::hash_bhp1024(&snarkvm::utilities::to_bits_le![previous_hash, header.to_root()?]).unwrap(); | |
let ratifications = Ratifications::try_from(vec![]).unwrap(); | |
let rng = &mut TestRng::default(); | |
let private_key = PrivateKey::new(rng).unwrap(); | |
let authority = Authority::new_beacon(&private_key, Field::zero(), rng).unwrap(); | |
let transactions = Transactions::from(&[]); | |
let block = Block::<CurrentNetwork>::from_unchecked( | |
AleoID::from(previous_hash), | |
previous_hash, | |
header, | |
authority, | |
ratifications, | |
None, | |
transactions, | |
vec![], | |
) | |
.unwrap(); | |
block | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment