Browse Source

Choose the generation transaction type and return the transaction length within libckpool.

master
Con Kolivas 7 years ago
parent
commit
b806916201
  1. 2
      src/ckpool.h
  2. 22
      src/libckpool.c
  3. 5
      src/libckpool.h
  4. 40
      src/stratifier.c

2
src/ckpool.h

@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2017 Con Kolivas * Copyright 2014-2018 Con Kolivas
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free * under the terms of the GNU General Public License as published by the Free

22
src/libckpool.c

@ -1730,7 +1730,9 @@ char *http_base64(const char *src)
return (str); return (str);
} }
void address_to_pubkeytxn(char *pkh, const char *addr) /* It's assumed that there is no chance of sending invalid chars to these
* functions as they should have been checked beforehand. */
static void address_to_pubkeytxn(char *pkh, const char *addr)
{ {
char b58bin[25] = {}; char b58bin[25] = {};
@ -1743,7 +1745,7 @@ void address_to_pubkeytxn(char *pkh, const char *addr)
pkh[24] = 0xac; pkh[24] = 0xac;
} }
void address_to_scripttxn(char *psh, const char *addr) static void address_to_scripttxn(char *psh, const char *addr)
{ {
char b58bin[25] = {}; char b58bin[25] = {};
@ -1754,6 +1756,22 @@ void address_to_scripttxn(char *psh, const char *addr)
psh[22] = 0x87; psh[22] = 0x87;
} }
/* Convert an address to a transaction and return the length of the transaction */
int address_to_txn(char *p2h, const char *addr, const bool script, const bool segwit)
{
if (unlikely(segwit)) {
/* It should be impossible to hit this for now */
LOGEMERG("Segwit bech32 address passed to address_to_txn while unsupported.");
return 0;
}
if (script) {
address_to_scripttxn(p2h, addr);
return 23;
}
address_to_pubkeytxn(p2h, addr);
return 25;
}
/* For encoding nHeight into coinbase, return how many bytes were used */ /* For encoding nHeight into coinbase, return how many bytes were used */
int ser_number(uchar *s, int32_t val) int ser_number(uchar *s, int32_t val)
{ {

5
src/libckpool.h

@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2017 Con Kolivas * Copyright 2014-2018 Con Kolivas
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free * under the terms of the GNU General Public License as published by the Free
@ -561,8 +561,7 @@ void b58tobin(char *b58bin, const char *b58);
int safecmp(const char *a, const char *b); int safecmp(const char *a, const char *b);
bool cmdmatch(const char *buf, const char *cmd); bool cmdmatch(const char *buf, const char *cmd);
void address_to_pubkeytxn(char *pkh, const char *addr); int address_to_txn(char *p2h, const char *addr, const bool script, const bool segwit);
void address_to_scripttxn(char *pkh, const char *addr);
int ser_number(uchar *s, int32_t val); int ser_number(uchar *s, int32_t val);
int get_sernumber(uchar *s); int get_sernumber(uchar *s);
bool fulltest(const uchar *hash, const uchar *target); bool fulltest(const uchar *hash, const uchar *target);

40
src/stratifier.c

@ -389,10 +389,10 @@ static const char *ckdb_seq_names[] = {
struct stratifier_data { struct stratifier_data {
ckpool_t *ckp; ckpool_t *ckp;
char pubkeytxnbin[25]; char txnbin[40];
int pubkeytxnlen; int txnlen;
char donkeytxnbin[25]; char dontxnbin[40];
int donkeytxnlen; int dontxnlen;
pool_stats_t stats; pool_stats_t stats;
/* Protects changes to pool stats */ /* Protects changes to pool stats */
@ -615,9 +615,9 @@ static void generate_coinbase(const ckpool_t *ckp, workbase_t *wb)
*u64 = htole64(g64); *u64 = htole64(g64);
wb->coinb2len += 8; wb->coinb2len += 8;
wb->coinb2bin[wb->coinb2len++] = sdata->pubkeytxnlen; wb->coinb2bin[wb->coinb2len++] = sdata->txnlen;
memcpy(wb->coinb2bin + wb->coinb2len, sdata->pubkeytxnbin, sdata->pubkeytxnlen); memcpy(wb->coinb2bin + wb->coinb2len, sdata->txnbin, sdata->txnlen);
wb->coinb2len += sdata->pubkeytxnlen; wb->coinb2len += sdata->txnlen;
if (wb->insert_witness) { if (wb->insert_witness) {
// 0 value // 0 value
@ -636,9 +636,9 @@ static void generate_coinbase(const ckpool_t *ckp, workbase_t *wb)
*u64 = htole64(d64); *u64 = htole64(d64);
wb->coinb2len += 8; wb->coinb2len += 8;
wb->coinb2bin[wb->coinb2len++] = sdata->donkeytxnlen; wb->coinb2bin[wb->coinb2len++] = sdata->dontxnlen;
memcpy(wb->coinb2bin + wb->coinb2len, sdata->donkeytxnbin, sdata->donkeytxnlen); memcpy(wb->coinb2bin + wb->coinb2len, sdata->dontxnbin, sdata->dontxnlen);
wb->coinb2len += sdata->donkeytxnlen; wb->coinb2len += sdata->dontxnlen;
} }
wb->coinb2len += 4; // Blank lock wb->coinb2len += 4; // Blank lock
@ -2354,8 +2354,8 @@ static sdata_t *duplicate_sdata(const sdata_t *sdata)
dsdata->ckp = sdata->ckp; dsdata->ckp = sdata->ckp;
/* Copy the transaction binaries for workbase creation */ /* Copy the transaction binaries for workbase creation */
memcpy(dsdata->pubkeytxnbin, sdata->pubkeytxnbin, 25); memcpy(dsdata->txnbin, sdata->txnbin, 40);
memcpy(dsdata->donkeytxnbin, sdata->donkeytxnbin, 25); memcpy(dsdata->dontxnbin, sdata->dontxnbin, 40);
/* Use the same work queues for all subproxies */ /* Use the same work queues for all subproxies */
dsdata->ssends = sdata->ssends; dsdata->ssends = sdata->ssends;
@ -8597,23 +8597,11 @@ void *stratifier(void *arg)
/* Store this for use elsewhere */ /* Store this for use elsewhere */
hex2bin(scriptsig_header_bin, scriptsig_header, 41); hex2bin(scriptsig_header_bin, scriptsig_header, 41);
if (ckp->script) { sdata->txnlen = address_to_txn(sdata->txnbin, ckp->btcaddress, ckp->script, ckp->segwit);
address_to_scripttxn(sdata->pubkeytxnbin, ckp->btcaddress);
sdata->pubkeytxnlen = 23;
} else {
address_to_pubkeytxn(sdata->pubkeytxnbin, ckp->btcaddress);
sdata->pubkeytxnlen = 25;
}
if (generator_checkaddr(ckp, ckp->donaddress, &ckp->donscript, &ckp->donsegwit)) { if (generator_checkaddr(ckp, ckp->donaddress, &ckp->donscript, &ckp->donsegwit)) {
ckp->donvalid = true; ckp->donvalid = true;
if (ckp->donscript) { sdata->dontxnlen = address_to_txn(sdata->dontxnbin, ckp->donaddress, ckp->script, ckp->segwit);
sdata->donkeytxnlen = 23;
address_to_scripttxn(sdata->donkeytxnbin, ckp->donaddress);
} else {
sdata->donkeytxnlen = 25;
address_to_pubkeytxn(sdata->donkeytxnbin, ckp->donaddress);
}
} }
} }

Loading…
Cancel
Save