Finish binding Tendermint into Tributary and define a Tributary master object

This commit is contained in:
Luke Parker
2023-04-13 18:43:03 -04:00
parent 5858b6c03e
commit e73a51bfa5
12 changed files with 245 additions and 37 deletions

View File

@@ -8,6 +8,7 @@ use crate::{Signed, TransactionKind, Transaction, ProvidedTransactions, BlockErr
pub struct Blockchain<T: Transaction> {
genesis: [u8; 32],
// TODO: db
block_number: u64,
tip: [u8; 32],
next_nonces: HashMap<<Ristretto as Ciphersuite>::G, u32>,
@@ -17,7 +18,7 @@ pub struct Blockchain<T: Transaction> {
impl<T: Transaction> Blockchain<T> {
pub fn new(genesis: [u8; 32], participants: &[<Ristretto as Ciphersuite>::G]) -> Self {
// TODO: Reload next_nonces/provided/mempool
// TODO: Reload block_number/tip/next_nonces/provided/mempool
let mut next_nonces = HashMap::new();
for participant in participants {
@@ -27,6 +28,7 @@ impl<T: Transaction> Blockchain<T> {
Self {
genesis,
block_number: 0,
tip: genesis,
next_nonces,
@@ -39,6 +41,10 @@ impl<T: Transaction> Blockchain<T> {
self.tip
}
pub fn block_number(&self) -> u64 {
self.block_number
}
pub fn add_transaction(&mut self, tx: T) -> bool {
self.mempool.add(&self.next_nonces, tx)
}
@@ -73,6 +79,7 @@ impl<T: Transaction> Blockchain<T> {
// None of the following assertions should be reachable since we verified the block
self.tip = block.hash();
self.block_number += 1;
for tx in &block.transactions {
match tx.kind() {
TransactionKind::Provided => {