Monitoring a BCH address with Tasker (Part 3: Showing Different Units)

3 329
Avatar for elrikpiro
4 years ago

Link to Part1
Link to Part2

Let's continue improving our little project, some of you reached me privately and told me that if the Smart Band notification has an 8x4 character area plus a scrolling title I could have trouble showing up big numbers. On the other side, some people told me that it is pretty much a very laborious work to add all the addresses on a wallet, as you must copy and paste around forty addresses in the request URL. In this article I'll propose both of the solutions I adopted for those problems.

Improvement #2 : the %ADDRESSES variable and how to fill it

In order to add and remove addresses easily we can modify the HTTP Request like this:

  • HTTP Request (Method: GET, URL: https://api.blockchair.com/bitcoin-cash/dashboards/addresses/%ADDRESSES

As you can see, the %ADRESSES global variable must be set with all of those you are going to monitor, separated by a comma and without any space. Having this on a variable will enable us to easily add a new address or a new bunch of addresses.

In order to get a list of addresses that you can paste into your global %ADDRESSES variable you can easily get a comma-separated list if your ledger has a Python Console (I use electron cash).

Attention: DON'T USE THE CONSOLE WITHOUT KNOWING WHAT ARE YOU DOING IF YOU WANT TO TEST CODE DO IT ONLY ON READ-ONLY WALLETS

In order to get a comma-separated list of all the addresses on a wallet you can use the next line:

','.join(listaddresses())

That is the Python witchcraft dialect for "get a list for all addresses on this wallet and join them all using a comma"

The output is something like this:

'qqsewpgv4lh27eg6d72kdu6cwf3ds4kltqazfktj2s,qpfplgltv76sxnd7d8v3p8s2d9weuh6udvcvl358cv,qz5qe9dz8wyrdk5r8mj0peqzmud63wmaeu7l83lrws,qq84zn8056l9kv0qvu95ljfh0s8qv6fjyvaxk2g4ye,qrjwaw5ajrfl9apxtq5j69gy7uc7epqd65fyp8zlcj,qre2sl93v3vn2fkafwwa0pppfpesrxjctv0ls4lxw8,qql44kwaqrpfs9dyv7dn9kttel8xm9sfs558f0k96m,qrz0ylrxx38akez9xew85epgzs7yvvyxtvdl8deflw,qz5j8fh2cehlfvuh7rvd6hrxalxkcy0gkg9hyykc5p,qp08aqlkxz2qmtval3gm3ws6kclg298cvvw6syqeqm,qq2z7fux4zd3yx3eqy469pmj9h2v6vzt9sh9c6kjzv,qpy4hydkheam7jcanpfphknh34cvpk73ask30ky6td,qr6l5vhwd2m6tya2xxhchylxdj878khxqserfgrrhs,qzxpt3rvexeyxe0ym3ajkh2p7885yt48pv2eqyj6wv,qrjm0ncfe709ha6n3qvmpw605lsn2rnpxyjt97xkzt,qq3dlxzp375u8cay442tj4sazkx6x35zhqwmkkq9d6,qzgfge3gjxjt0ydgs9q2xqq9ewwjd0ye2gdv2s3kmy,qpql0z67aa9u28w9v6v9vzl0r3jazuq07gwlyxefwg,qrx7d57c72ju6xj3myacvsu4wf9yzm4q0unxjnu6qj,qrecuvzrpek4jzzeh8xcwwcapqlt2dupnqwnnuprju,qrar8ndlk5jxrpwl0gqgf68kzut2y8mwsq5s9lgf28,qq9dzw307k360y45ggsp6t6ksfkec6ezlcwk007qhz,qzp5vlpnt6x4pgnfptnel778nljs9p9fmyxfvt9wp8,qz4eq98dkf5jlvcymw64ql327lup592ewy2445cv8k,qpwhna9kfrgs07g6nh9zx3d8k7wxgtlatulay94hf2,qpgj8j4g30y8wsewlznnqhxj0hf5majetuwnhkpca0,qp2yhapqevvp8qm8c5hsl6dr9d2ddj23pvjytw4um9,qzz895aymqpzvvvnjw76jmky2nv6mg54wuc20g6v8f,qpn6rv2qydmmxlzhpy4wuz0laf7dcmetsyjx9gegjx,qq94nxevjrx6arzh8q5n3zjpvvehvhzm5q5fhncwgz,qz9vklg00sd9jj44eklj4n0qmpdhy8gkuy5pjup32z,qpha29rse87gwq4lap6zgwpdd64hxl94hgfa2kwq58,qq47yzk849f2hp2x5sypwsx357980v5k6cl5ssvxdc,qrc23w67v98gazjs2g9h5yujqn4p6248pg47y0qas7,qrd5e0f8wz278h2h5ctq3yju46v5uelnpc8hshqqwc,qznmz4qv4d0jp5tyuse72nzyl7jnt9xaccg88pz6mz,qqw4tzr5d0vv8zmjnav9rcthu7yk94l9ryjg7gp5s0,qqm4sk8pu965whpa2l5hrkktplr4c469jcryr6xd3g,qp8qtpdxd7e6y50pakj3naw9azycjw044ckc26af39,qq547q9ysfu0ewr9aqq6q5qg6j529s0uag9udq5v9g'

Well, Wasn't that was faster than copying each address individually? Now you just have to paste this in your %ADDRESSES Variable and you'll have the whole wallet balance on your watch.

Improvement #3 : fitting units efficiently at the Mi Band 3

Let's refresh how is our script doing:

  • HTTP Request (Method: GET, URL: https://api.blockchair.com/bitcoin-cash/dashboards/addresses/%ADDRESSES

  • Variable Set (Name: %JSON To: %http_data)

  • JavaScriptlet (code:
    var balance = JSON.parse(global('%JSON')).data.set.balance;
    setGlobal( "%BALANCE",balance );
    var usd = JSON.parse(global('%JSON')).data.set.balance_usd;
    setGlobal( "%BALANCE_USD", Math.round(usd*100)/100 );
    )

  • If (Condition: %BALANCE neq %LAST_BALANCE)

    • Variable Set (Name: %USD_DIF To: %BALANCE_USD - %USD Do Maths: Checked )

    • Variable Set (Name: %LAST_BALANCE To: %BALANCE)

    • Variable Set (Name: %USD To: %BALANCE_USD)

    • Notification

  • Else If (Condition: %USD neq %BALANCE_USD)

    • Variable Set (Name: %USD_DIF To: %BALANCE_USD - %USD Do Maths: Checked )

    • Variable Set (Name: %USD To: %BALANCE_USD)

    • Notification

So, right now we are only showing the balance in pure satoshi, but, you know, if your screen is only 8 characters wide, you can represent accurately (with a $200 per BCH) from $0.00 to $6,906.36. If we were to use BCH instead with a fixed amount of zeroes (let's say 2) we could represent from $2 to $19,999,998.

The logical path here is to use satoshi when the balance is lower and use BCH when the balance is higher and that's is what we're going to do! But... with another optional improvement: I'll be using read.cash's (provisional name) Ror Unit.

I'll use this unit as a 2 decimal fixed-point unit as it allows me to represent spendable amount of BCH (the 546 dust limit, near $0.001) as the smallest unit (a Ror cent) and it escalates to 99,999.99 Ror (around 5,459,999,454 satoshis, 54.60 BCH or $10,920) as the highest representable value.

As I am committed to becoming stingy rich blogging on read.cash ( :P ) someday I'll add a 2 decimal fixed-point BCH representation as a fallback when Ror isn't enough to represent the values at my wallet and I'll worry later on my first-world problems on being unable to represent more than 19 Million dollars worth of BCH.

Before:

  • If (Condition: %BALANCE neq %LAST_BALANCE)

    • Variable Set (Name: %USD_DIF To: %BALANCE_USD - %USD Do Maths: Checked )

    • Variable Set (Name: %LAST_BALANCE To: %BALANCE)

    • Variable Set (Name: %USD To: %BALANCE_USD)

    • Notification

After:

  • If (Condition: %BALANCE neq %LAST_BALANCE)

    • Variable Set (Name: %USD_DIF To: %BALANCE_USD - %USD Do Maths: Checked )

    • Variable Set (Name: %LAST_BALANCE To: %BALANCE)

    • Variable Set (Name: %USD To: %BALANCE_USD)

    • If (Condition: %LAST_BALANCE > 5459999454 )

      • Variable Set (Name: %UNIT To: "BCH")

      • Variable Set (Name: %FORMAT_BALANCE To: %LAST_BALANCE / 100000000Do Maths: Checked Max Rounding Digits: 2 )

    • Else

      • Variable Set (Name: %UNIT To: "Ror")

      • Variable Set (Name: %FORMAT_BALANCE To: %LAST_BALANCE / 54600Do Maths: Checked Max Rounding Digits: 2 )

    • Notification

Now we are talking :)

Subscribe if you enjoyed it and comment if you have any requests! More updates soon!

Sponsors of elrikpiro
empty
empty
empty

4
$ 4.20
$ 2.00 from @Read.Cash
$ 2.00 from @btcfork
$ 0.10 from @HenryCashlitt
+ 1
Avatar for elrikpiro
4 years ago
Enjoyed this article?  Earn Bitcoin Cash by sharing it! Explain
...and you will also help the author collect more tips.

Comments

i loved this article ...really good information..lets subscribe each other

$ 0.00
4 years ago

Fantastic DIY project! I love when people do such things!

Kudos on using the Ror unit! 👍😁

$ 0.05
4 years ago

Really glad you like it!

$ 0.05
4 years ago