Skip to content

Commit

Permalink
peercoin changes part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
backpacker69 committed Oct 15, 2019
1 parent fea2c97 commit 84b674d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion common/amount.h
Expand Up @@ -7,7 +7,7 @@
#include <stdbool.h>

#define MSAT_PER_SAT ((u64)1000)
#define SAT_PER_BTC ((u64)100000000)
#define SAT_PER_BTC ((u64)1000000)
#define MSAT_PER_BTC (MSAT_PER_SAT * SAT_PER_BTC)

/* Use these to wrap amounts, for typesafety. Please use ops where possible,
Expand Down
13 changes: 6 additions & 7 deletions common/json_helpers.c
Expand Up @@ -10,25 +10,24 @@ bool json_to_bitcoin_amount(const char *buffer, const jsmntok_t *tok,
uint64_t *satoshi)
{
char *end;
char zeros[]="000000";
unsigned long btc, sat;

btc = strtoul(buffer + tok->start, &end, 10);
if (btc == ULONG_MAX && errno == ERANGE)
return false;
if (end != buffer + tok->end) {
/* Expect always 8 decimal places. */
if (*end != '.') // || buffer + tok->end - end != 9)
if (*end != '.')
return false;
sat = strtoul(end+1, &end, 10);
strncpy(zeros, end+1, tok->end-(end+1-buffer));
sat = strtoul(zeros, &end, 10);
if (sat == ULONG_MAX && errno == ERANGE)
return false;
if (end != buffer + tok->end)
return false;
} else
sat = 0;

*satoshi = btc * (uint64_t)100000000 + sat;
if (*satoshi != btc * (uint64_t)100000000 + sat)
*satoshi = btc * (uint64_t)1000000 + sat;
if (*satoshi != btc * (uint64_t)1000000 + sat)
return false;

return true;
Expand Down
4 changes: 2 additions & 2 deletions common/wallet_tx.c
Expand Up @@ -193,9 +193,9 @@ struct command_result *wtx_from_utxos(struct wallet_tx *tx,
total_amount = AMOUNT_SAT(0);

/* The transaction has `tal_count(tx.utxos)` inputs and one output */
/* (version + in count + out count + locktime) (index + value + script length) */
/* (version + timestamp + in count + out count + locktime) (index + value + script length) */
/* + segwit marker + flag */
weight = 4 * (4 + 1 + 1 + 4) + 4 * (8 + 1 + out_len) + 1 + 1;
weight = 4 * (4 + 4 + 1 + 1 + 4) + 4 * (8 + 1 + out_len) + 1 + 1;
for (size_t i = 0; i < tal_count(utxos); i++) {
if (!*utxos[i]->blockheight || *utxos[i]->blockheight > maxheight) {
tal_arr_remove(&utxos, i);
Expand Down
10 changes: 2 additions & 8 deletions lightningd/chaintopology.c
Expand Up @@ -462,11 +462,8 @@ u32 feerate_from_style(u32 feerate, enum feerate_style style)
{
switch (style) {
case FEERATE_PER_KSIPA:
return feerate;
case FEERATE_PER_KBYTE:
/* Everyone uses satoshi per kbyte, but we use satoshi per ksipa
* (don't round down to zero though)! */
return (feerate + 3) / 4;
return feerate;
}
abort();
}
Expand All @@ -475,11 +472,8 @@ u32 feerate_to_style(u32 feerate_perkw, enum feerate_style style)
{
switch (style) {
case FEERATE_PER_KSIPA:
return feerate_perkw;
case FEERATE_PER_KBYTE:
if ((u64)feerate_perkw * 4 > UINT_MAX)
return UINT_MAX;
return feerate_perkw * 4;
return feerate_perkw;
}
abort();
}
Expand Down

0 comments on commit 84b674d

Please sign in to comment.