tx mempool start, hello packet
This commit is contained in:
@@ -12,29 +12,12 @@
|
||||
#include <utils.h>
|
||||
#include <uint256.h>
|
||||
|
||||
typedef struct {
|
||||
uint8_t bytes[32];
|
||||
} key32_t;
|
||||
|
||||
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;
|
||||
|
||||
static inline uint32_t hash_key32(key32_t k) {
|
||||
uint32_t hash = 2166136261u;
|
||||
for (int i = 0; i < 32; i++) {
|
||||
hash ^= k.bytes[i];
|
||||
hash *= 16777619;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
static inline int eq_key32(key32_t a, key32_t b) {
|
||||
return memcmp(a.bytes, b.bytes, 32) == 0;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <block/chain.h>
|
||||
#include <block/block.h>
|
||||
|
||||
extern uint64_t currentBlockHeight;
|
||||
|
||||
// Nets
|
||||
#define MAX_CONS 32 // Some baseline for now
|
||||
#define LISTEN_PORT 9393
|
||||
|
||||
@@ -55,6 +55,9 @@ size_t DynArr_capacity(DynArr* p);
|
||||
|
||||
void DynArr_destroy(DynArr* p);
|
||||
|
||||
// Note: Make sure to not overread or overwrite
|
||||
void* DynArr_c_arr(DynArr* p);
|
||||
|
||||
#define DYNARR_CREATE(T, initialCapacity) DynArr_create(sizeof(T), initialCapacity)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <dynarr.h>
|
||||
|
||||
typedef struct {
|
||||
tcp_server_t* server;
|
||||
tcp_client_t outboundClients[MAX_CONS];
|
||||
|
||||
@@ -5,9 +5,14 @@
|
||||
|
||||
typedef enum {
|
||||
PACKET_TYPE_NONE = 0,
|
||||
PACKET_TYPE_REQUEST = 1,
|
||||
PACKET_TYPE_RESPONSE = 2,
|
||||
PACKET_TYPE_MAX = 3
|
||||
PACKET_TYPE_HELLO = 1, // Hello, let's connect! Here's who I am, and what I have!
|
||||
PACKET_TYPE_FETCH_BLOCK = 2, // I want a Block
|
||||
PACKET_TYPE_BLOCK_DATA = 3, // Here's a Block (response to fetch) - I don't care what you do with it, but you wanted it, so here it is!
|
||||
PACKET_TYPE_BROADCAST_BLOCK = 4, // Here's a new Block I want to share with the network (unsolicited - e.g. just mined it)
|
||||
PACKET_TYPE_ACK_BLOCK = 5, // I have received your block, here's what I did with it (response to broadcast)
|
||||
PACKET_TYPE_BROADCAST_TX = 6, // Here's a new transaction I want to share with the network
|
||||
PACKET_TYPE_ACK_TX = 7, // I have received your transaction, here's what I did with it (response to broadcast)
|
||||
PACKET_TYPE_MAX = 9
|
||||
} packet_type_t;
|
||||
|
||||
static inline int PacketType_IsValid(uint8_t packetType) {
|
||||
|
||||
18
include/txmempool.h
Normal file
18
include/txmempool.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef TXMEMPOOL_H
|
||||
#define TXMEMPOOL_H
|
||||
|
||||
#include <block/transaction.h>
|
||||
#include <khash/khash.h>
|
||||
#include <utils.h>
|
||||
#include <uint256.h>
|
||||
|
||||
KHASH_INIT(tx_mempool_map_m, key32_t, signed_transaction_t, 1, hash_key32, eq_key32)
|
||||
extern khash_t(tx_mempool_map_m)* txMempool;
|
||||
|
||||
void TxMempool_Init();
|
||||
int TxMempool_Insert(signed_transaction_t tx);
|
||||
bool TxMempool_Lookup(uint8_t* txHash, signed_transaction_t* out);
|
||||
void TxMempool_Print();
|
||||
void TxMempool_Destroy();
|
||||
|
||||
#endif
|
||||
@@ -6,6 +6,23 @@
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
uint8_t bytes[32];
|
||||
} key32_t;
|
||||
|
||||
static inline uint32_t hash_key32(key32_t k) {
|
||||
uint32_t hash = 2166136261u;
|
||||
for (int i = 0; i < 32; i++) {
|
||||
hash ^= k.bytes[i];
|
||||
hash *= 16777619;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
static inline int eq_key32(key32_t a, key32_t b) {
|
||||
return memcmp(a.bytes, b.bytes, 32) == 0;
|
||||
}
|
||||
|
||||
static inline void AddressToHexString(const uint8_t address[32], char out[65]) {
|
||||
if (!address || !out) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user