bcalc

cli bitcoin unit calculator
git clone git://jb55.com/bcalc
Log | Files | Refs | README | LICENSE

commit 3ee18475434d8876bb22050f5977254e1daaf7e7
parent 584da45e235096bb7801db09a5e3182351f45f77
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 23 Dec 2017 15:07:56 -0800

cli: invert print unit options

It's now on by default

Diffstat:
MREADME.md | 18+++++++++---------
Mbcalc.c | 14+++++++-------
Mtest/tests.csv | 54+++++++++++++++++++++++++++---------------------------
3 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/README.md b/README.md @@ -9,45 +9,45 @@ Basic example - $ bcalc --msat -p 1 msat + 2 sats + 3 bits + $ bcalc --msat 1 msat + 2 sats + 3 bits 302001 msat BTC to satoshis - $ bcalc -p 0.02 BTC + $ bcalc 0.02 BTC 2000000 sat satoshis to millisatoshis (for payment channels) - $ bcalc --msat 100 sat + $ bcalc --no-unit --msat 100 sat 100000 mBTC + bits to BTC - $ bcalc -p --btc 100 mBTC + 20 bits + $ bcalc --btc 100 mBTC + 20 bits 0.10002 BTC Division - $ bcalc -p --bits 1 BTC / 100 + $ bcalc --bits 1 BTC / 100 10000 bits Multiplication - $ bcalc -pb '10 mbtc * 30' + $ bcalc -b '10 mbtc * 30' 300000 bits Fiat currencies - $ bcalc -p --price 20000 --bits 30 usd + $ bcalc --price 20000 --bits 30 usd 1500 bits - $ bcalc -p --price 16000 --usd 780 bits + $ bcalc --price 16000 --usd 780 bits 12.48 usd The Bitcoin pizza - $ bcalc -p --price 0.0041 --btc 41 usd + $ bcalc --price 0.0041 --btc 41 usd 10000 BTC ## Install diff --git a/bcalc.c b/bcalc.c @@ -23,8 +23,8 @@ struct settings { ((struct settings*)self->data)->format = unit; \ } -static void print_unit(command_t *self) { \ - ((struct settings*)self->data)->print_unit = 1; \ +static void no_print_unit(command_t *self) { \ + ((struct settings*)self->data)->print_unit = 0; \ } format_setting(btc, UNIT_BTC) @@ -90,7 +90,7 @@ int main(int argc, char *argv[argc]) { command_t cmd; char *buffer, *p; int yybuffer; - struct settings settings = { .print_unit = 0, .format = UNIT_SATOSHI }; + struct settings settings = { .print_unit = 1, .format = UNIT_SATOSHI }; cmd.data = (void*)&settings; g_other.unit = UNIT_NONE; @@ -103,10 +103,10 @@ int main(int argc, char *argv[argc]) { command_option(&cmd, "-s", "--sat", "output satoshis (default)", sat); command_option(&cmd, "-m", "--msat", "output millisatoshis", msat); command_option(&cmd, "-P", "--price <arg>", "set price for arbitrary unit per BTC", setprice); - command_option(&cmd, "-o", "--other", "output arbitrary unit, set by --price", optother); - command_option(&cmd, "-u", "--usd", "output arbitrary usd units", optusd); - command_option(&cmd, "-p", "--print-unit", "output the selected unit at the end", - print_unit); + command_option(&cmd, "-o", "--other", "output arbitrary unit, set by --price", optother); + command_option(&cmd, "-u", "--usd", "output arbitrary usd units", optusd); + command_option(&cmd, "-n", "--no-unit", "dont output the selected unit at the end", + no_print_unit); command_parse(&cmd, argc, argv); diff --git a/test/tests.csv b/test/tests.csv @@ -1,30 +1,30 @@ description,args,input,expected output -scalar division,--btc -p,1 BTC / 10,0.1 BTC -scalar multiplication,--btc,10 * 1 BTC,10 -multiply 1 BTC to the smallest unit,-pm,1 BTC * 0.00000000001,1 msat -multiply 10 BTC to the smallest unit,-pm,10 BTC * 0.000000000001,1 msat -multiply 100 BTC to the smallest unit,-pm,100 BTC * 0.0000000000001,1 msat -multiply 1000 BTC to the smallest unit,-pm,1000 BTC * 0.00000000000001,1 msat -multiply 100000 BTC to the smallest unit,-pm,100000 BTC * 0.0000000000000001,1 msat -lots of msats,-B,2 msat * 100000000000,2 -chained multiply,-B,2100 btc * 0.1 * 0.1,21 -10000 satoshis in bits,--bits,10000 sats,100 -satoshis in bits to smallest bit,-bp,10000 sats * 0.01,1 bits -parens,-B,(10 finney * 1000) / 10,0.0001 -finney plural,-f,10 finneys,10 -finney singular,-f,10 finney,10 -satoshi singular,-sp,10 sat,10 sat -satoshi plural,-sp,10 sats,10 sat -msat singular,-mp,1 msat,1 msat -msat plural,-mp,1 msats,1 msat -arg tokens work,-p --mbtc 1 BTC,,1000 mBTC -simple fiat test,-p --price 15000 --msat,1 fiat,6666666 msat -simple fiat test with bits,-p --price 15000 --bits,1 fiat,66.66666 bits -1 usd is 1 BTC,-p --price 1 --btc,1 usd,1 BTC -1 BTC is 10 usd,-p --price 10 --usd,1 btc,10 USD -1 BTC is 1000000 other,-p --price 1000000 --other,100 mbtc,100000 other -1 other @15k is 66.66666 bits,-p --price 15000 --bits,1 other,66.66666 bits -1 btc/2 should work,--btc,1 btc / 2,0.5 +scalar division,--btc,1 BTC / 10,0.1 BTC +scalar multiplication,--btc -n,10 * 1 BTC,10 +multiply 1 BTC to the smallest unit,-m,1 BTC * 0.00000000001,1 msat +multiply 10 BTC to the smallest unit,-m,10 BTC * 0.000000000001,1 msat +multiply 100 BTC to the smallest unit,-m,100 BTC * 0.0000000000001,1 msat +multiply 1000 BTC to the smallest unit,-m,1000 BTC * 0.00000000000001,1 msat +multiply 100000 BTC to the smallest unit,-m,100000 BTC * 0.0000000000000001,1 msat +lots of msats,-nB,2 msat * 100000000000,2 +chained multiply,-nB,2100 btc * 0.1 * 0.1,21 +10000 satoshis in bits,-n --bits,10000 sats,100 +satoshis in bits to smallest bit,-b,10000 sats * 0.01,1 bits +parens,-nB,(10 finney * 1000) / 10,0.0001 +finney plural,-nf,10 finneys,10 +finney singular,-nf,10 finney,10 +satoshi singular,-s,10 sat,10 sat +satoshi plural,-s,10 sats,10 sat +msat singular,-m,1 msat,1 msat +msat plural,-m,1 msats,1 msat +arg tokens work,--mbtc 1 BTC,,1000 mBTC +simple fiat test,--price 15000 --msat,1 fiat,6666666 msat +simple fiat test with bits,--price 15000 --bits,1 fiat,66.66666 bits +1 usd is 1 BTC,--price 1 --btc,1 usd,1 BTC +1 BTC is 10 usd,--price 10 --usd,1 btc,10 USD +1 BTC is 1000000 other,--price 1000000 --other,100 mbtc,100000 other +1 other @15k is 66.66666 bits,--price 15000 --bits,1 other,66.66666 bits +1 btc/2 should work,--btc -n,1 btc / 2,0.5 # failing 1/2 btc should work,--btc,1/2 btc,0.5 -1 BTC is 15000 usd,-p --price 15000 --usd,1 btc,15000 USD +1 BTC is 15000 usd,--price 15000 --usd,1 btc,15000 USD