Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit fdc31a5

Browse files
committed
Moved hex functions
1 parent d4acbd6 commit fdc31a5

File tree

3 files changed

+51
-44
lines changed

3 files changed

+51
-44
lines changed

common.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,48 @@ void bbp_print_hex(const char *label, const uint8_t *v, size_t len) {
1818
printf("\n");
1919
}
2020

21+
uint8_t bbp_hex2byte(const char ch) {
22+
if ((ch >= '0') && (ch <= '9')) {
23+
return ch - '0';
24+
}
25+
if ((ch >= 'a') && (ch <= 'f')) {
26+
return ch - 'a' + 10;
27+
}
28+
return 0;
29+
}
30+
31+
void bbp_parse_hex(bbp_endian_t e, uint8_t *v, const char *str) {
32+
const size_t count = strlen(str) / 2;
33+
const size_t mul = ((e == BBP_LITTLE) ? 0 : 1);
34+
size_t i;
35+
36+
for (i = 0; i < count; ++i) {
37+
const char hi = bbp_hex2byte(str[i * 2]);
38+
const char lo = bbp_hex2byte(str[i * 2 + 1]);
39+
const size_t offset = mul * (count - 2 * i - 1);
40+
41+
v[i + offset] = hi * 16 + lo;
42+
}
43+
}
44+
45+
uint8_t *bbp_alloc_hex(bbp_endian_t e, const char *str, size_t *len) {
46+
const size_t count = strlen(str) / 2;
47+
const size_t mul = ((e == BBP_LITTLE) ? 0 : 1);
48+
size_t i;
49+
50+
uint8_t *v = malloc(count);
51+
52+
for (i = 0; i < count; ++i) {
53+
const char hi = bbp_hex2byte(str[i * 2]);
54+
const char lo = bbp_hex2byte(str[i * 2 + 1]);
55+
const size_t offset = mul * (count - 2 * i - 1);
56+
57+
v[i + offset] = hi * 16 + lo;
58+
}
59+
60+
*len = count;
61+
62+
return v;
63+
}
64+
2165
#endif

endian.h

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -82,48 +82,4 @@ void bbp_ecopy(bbp_endian_t e, uint8_t *dst, uint8_t *src, size_t len) {
8282
}
8383
}
8484

85-
uint8_t bbp_hex2byte(const char ch) {
86-
if ((ch >= '0') && (ch <= '9')) {
87-
return ch - '0';
88-
}
89-
if ((ch >= 'a') && (ch <= 'f')) {
90-
return ch - 'a' + 10;
91-
}
92-
return 0;
93-
}
94-
95-
void bbp_parse_hex(bbp_endian_t e, uint8_t *v, const char *str) {
96-
const size_t count = strlen(str) / 2;
97-
const size_t mul = ((e == BBP_LITTLE) ? 0 : 1);
98-
size_t i;
99-
100-
for (i = 0; i < count; ++i) {
101-
const char hi = bbp_hex2byte(str[i * 2]);
102-
const char lo = bbp_hex2byte(str[i * 2 + 1]);
103-
const size_t offset = mul * (count - 2 * i - 1);
104-
105-
v[i + offset] = hi * 16 + lo;
106-
}
107-
}
108-
109-
uint8_t *bbp_alloc_hex(bbp_endian_t e, const char *str, size_t *len) {
110-
const size_t count = strlen(str) / 2;
111-
const size_t mul = ((e == BBP_LITTLE) ? 0 : 1);
112-
size_t i;
113-
114-
uint8_t *v = malloc(count);
115-
116-
for (i = 0; i < count; ++i) {
117-
const char hi = bbp_hex2byte(str[i * 2]);
118-
const char lo = bbp_hex2byte(str[i * 2 + 1]);
119-
const size_t offset = mul * (count - 2 * i - 1);
120-
121-
v[i + offset] = hi * 16 + lo;
122-
}
123-
124-
*len = count;
125-
126-
return v;
127-
}
128-
12985
#endif

tx.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ void bbp_txin_create_signable(bbp_txin_t *txin, const bbp_outpoint_t *outpoint,
8181
txin->sequence = 0xffffffff;
8282
}
8383

84+
void bbp_txin_create_truncated(bbp_txin_t *txin, const bbp_outpoint_t *outpoint) {
85+
memcpy(&txin->outpoint, outpoint, sizeof(bbp_outpoint_t));
86+
txin->script_len = 0;
87+
txin->script = NULL;
88+
txin->sequence = 0xffffffff;
89+
}
90+
8491
size_t bbp_tx_size(const bbp_tx_t *tx, bbp_sighash_t flag) {
8592
size_t size = 0;
8693
int i;

0 commit comments

Comments
 (0)