feat(c-miner): port miner pipeline to modular C implementation

This commit is contained in:
2026-03-30 01:07:19 +02:00
parent 9a0a170799
commit d2c118833b
18 changed files with 3299 additions and 0 deletions

37
utils.h Normal file
View File

@@ -0,0 +1,37 @@
#ifndef UTILS_H
#define UTILS_H
#include <stddef.h>
#include <stdint.h>
#include "config.h"
typedef struct {
char *data;
size_t len;
size_t cap;
} StrBuf;
void sb_init(StrBuf *sb);
void sb_free(StrBuf *sb);
int sb_reserve(StrBuf *sb, size_t extra);
int sb_append(StrBuf *sb, const char *s);
int sb_append_n(StrBuf *sb, const char *s, size_t n);
int sb_append_byte_hex(StrBuf *sb, uint8_t b);
char *sb_take(StrBuf *sb);
int hex_char_to_val(char c);
int hex_to_bytes(const char *hex, uint8_t **out, size_t *out_len);
char *bytes_to_hex(const uint8_t *data, size_t len);
int hex_to_fixed_bytes(const char *hex, uint8_t *out, size_t out_len);
void reverse_bytes(uint8_t *data, size_t n);
void double_sha256(const uint8_t *data, size_t len, uint8_t out[32]);
int encode_varint_hex(uint64_t value, StrBuf *sb);
char *decode_nbits_hex(uint32_t nbits);
char *calculate_target_hex(const char *bits_hex, double difficulty_factor, const char *network);
char *hex_add_width(const char *base_hex, int add_value);
#endif