OlinCoin
Test
mempool.h
1#pragma once
2
3#include <stdio.h>
4#include "constants.h"
5#include "uthash.h"
6#include "base_tx.h"
7
8typedef struct MemPool {
9 unsigned char id[TX_HASH_LEN];
10 Transaction *tx;
11 UT_hash_handle hh;
12} MemPool;
13
14MemPool *mempool;
15
16/* Initializes the global mempool variable */
17void mempool_init();
18
19/* Creates a new entry in the hashmap with the passed transaction
20 *
21 * Returns passed transaction pointer if entry created, NULL otherwise
22 *
23 * transaction: Transaction pointer that will be stored in entry
24 */
25Transaction *mempool_add(Transaction *tx);
26
27/* Removes the entry corresponding to tx_hash
28 *
29 * Returns the transaction pointer stored in removed entry if succesfully
30 * removed, NULL otherwise
31 *
32 * tx_hash: Buffer of length TX_HASH_LEN, hash of transaction
33 */
34Transaction *mempool_remove(unsigned char *tx_hash);
35
36/* Finds transaction corresponding to tx_hash
37 *
38 * Returns transaction pointer if found, NULL otherwise
39 *
40 * tx_hash: Buffer of length TX_HASH_LEN, hash of transaction
41 */
42Transaction *mempool_find(unsigned char *tx_hash);
43
44/* Finds entry corresponding to tx_hash
45 *
46 * Returns entry if found, NULL otherwise
47 *
48 * tx_hash: Buffer of length TX_HASH_LEN, hash of transaction
49 */
50MemPool *mempool_find_node(unsigned char *tx_hash);
51
52/*
53Prints a mempool item with the associated id/hash from the hasmap
54
55prefix: string to put in front of all print commands used for tabbing structure
56*/
57void print_mempool(MemPool *mempool, char *prefix);
58
59/*
60Prints all transactions in mempool hashmap to stdout
61
62prefix: string to put in front of all print commands used for tabbing structure
63*/
64void print_mempool_hashmap(char *prefix);
Definition: mempool.h:8
Definition: base_tx.h:19