2026-03-30 01:07:19 +02:00
|
|
|
#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);
|
2026-03-30 11:47:36 +02:00
|
|
|
void format_hashrate_hz(double rate_hz, char *out, size_t out_len);
|
|
|
|
|
void format_hashrate_khs(double rate_khs, char *out, size_t out_len);
|
2026-03-30 01:07:19 +02:00
|
|
|
|
|
|
|
|
#endif
|