Mining: blocks now include mempool txs, select spendable txs by fee, and pay coinbase as base reward + fees in main.c. - Consensus: block validation now enforces coinbase accounting and rejects invalid coinbase placement, including coinbase on amount2, in block.c and transaction.c. - Chain state: rollback now rebuilds currentSupply/currentReward, and block addition preflights spendability before mutating balances in chain.c. - Orphans/reorgs: orphan retry is safer, rollback-triggered sync reattaches orphans immediately, and transient orphan failures no longer drop blocks in orphan_pool.c and main.c. - Networking/mempool: node lifecycle now initializes the mempool, broadcasts can exclude one peer, and mempool snapshotting supports mining selection in net_node.c and txmempool.c. - Ledger simulation: added non-mutating spendable-transaction selection for block assembly in balance_sheet.c.
42 lines
1.2 KiB
C
42 lines
1.2 KiB
C
#ifndef BALANCE_SHEET_H
|
|
#define BALANCE_SHEET_H
|
|
|
|
#include <stdint.h>
|
|
#include <dynarr.h>
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <khash/khash.h>
|
|
#include <crypto/crypto.h>
|
|
#include <block/transaction.h>
|
|
#include <string.h>
|
|
#include <utils.h>
|
|
#include <uint256.h>
|
|
|
|
typedef struct {
|
|
uint8_t address[32]; // For now just the SHA-256 of the public key; allows representation in different encodings (base58, bech32, etc) without changing the underlying data structure
|
|
uint256_t balance;
|
|
// TODO: Additional things
|
|
} balance_sheet_entry_t;
|
|
|
|
KHASH_INIT(balance_sheet_map_m, key32_t, balance_sheet_entry_t, 1, hash_key32, eq_key32)
|
|
extern khash_t(balance_sheet_map_m)* sheetMap;
|
|
|
|
void BalanceSheet_Init();
|
|
int BalanceSheet_Insert(balance_sheet_entry_t entry);
|
|
bool BalanceSheet_Lookup(uint8_t* address, balance_sheet_entry_t* out);
|
|
bool BalanceSheet_SaveToFile(const char* outPath);
|
|
bool BalanceSheet_LoadFromFile(const char* inPath);
|
|
void BalanceSheet_Print();
|
|
void BalanceSheet_Destroy();
|
|
|
|
bool BalanceSheet_SelectSpendableTransactions(
|
|
const signed_transaction_t* candidates,
|
|
size_t candidateCount,
|
|
signed_transaction_t** outAccepted,
|
|
size_t* outAcceptedCount,
|
|
uint64_t* outTotalFees
|
|
);
|
|
|
|
#endif
|