mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-04-10 12:59:25 +02:00
mining: add method to construct coinbase tx
This commit is contained in:
parent
799d00dc2b
commit
10fc3d017e
@ -1,3 +1,3 @@
|
||||
idf_component_register(SRCS "stratum_api.c"
|
||||
idf_component_register(SRCS "mining.c" "stratum_api.c"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES json)
|
4
components/stratum/include/mining.h
Normal file
4
components/stratum/include/mining.h
Normal file
@ -0,0 +1,4 @@
|
||||
#include "stratum_api.h"
|
||||
|
||||
char * construct_coinbase_tx(const char * coinbase_1, const char * coinbase_2,
|
||||
const char * extranonce, int extranonce_2_len);
|
20
components/stratum/mining.c
Normal file
20
components/stratum/mining.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include <string.h>
|
||||
|
||||
char * construct_coinbase_tx(const char * coinbase_1, const char * coinbase_2,
|
||||
const char * extranonce, int extranonce_2_len)
|
||||
{
|
||||
int coinbase_tx_len = strlen(coinbase_1) + strlen(coinbase_2)
|
||||
+ strlen(extranonce) + extranonce_2_len * 2 + 1;
|
||||
|
||||
char extranonce_2[extranonce_2_len * 2];
|
||||
memset(extranonce_2, '9', extranonce_2_len * 2);
|
||||
|
||||
char * coinbase_tx = malloc(coinbase_tx_len * sizeof(char));
|
||||
strcpy(coinbase_tx, coinbase_1);
|
||||
strcat(coinbase_tx, extranonce);
|
||||
strcat(coinbase_tx, extranonce_2);
|
||||
strcat(coinbase_tx, coinbase_2);
|
||||
coinbase_tx[coinbase_tx_len - 1] = '\0';
|
||||
|
||||
return coinbase_tx;
|
||||
}
|
12
components/stratum/test/test_mining.c
Normal file
12
components/stratum/test/test_mining.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include "unity.h"
|
||||
#include "mining.h"
|
||||
|
||||
TEST_CASE("Check coinbase tx construction", "[mining]")
|
||||
{
|
||||
const char * coinbase_1 = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff20020862062f503253482f04b8864e5008";
|
||||
const char * coinbase_2 = "072f736c7573682f000000000100f2052a010000001976a914d23fcdf86f7e756a64a7a9688ef9903327048ed988ac00000000";
|
||||
const char * extranonce = "e9695791";
|
||||
const int extranonce_2_len = 4;
|
||||
char * coinbase_tx = construct_coinbase_tx(coinbase_1, coinbase_2, extranonce, extranonce_2_len);
|
||||
TEST_ASSERT_EQUAL_STRING(coinbase_tx, "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff20020862062f503253482f04b8864e5008e969579199999999072f736c7573682f000000000100f2052a010000001976a914d23fcdf86f7e756a64a7a9688ef9903327048ed988ac00000000");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user