ledger-balance
v0.9.3
Published
Find the balance associated with a Bitcoin wallet.
Downloads
16
Readme
ledger-balance
Find the balance associated with a Bitcoin wallet. Do so using a list of blockchain reporters (providers) that is weighted over time.
API
Get the Balance of a Bitcoin wallet
var getBalance = require('ledger-balance').getBalance
var address = '3...'
getBalance(address, function (err, provider, result) {
if (err) return console.log((provider ? (provider.name + ': ') : '') + err.toString())
console.log('address=' + address + ' provider=' + provider.name + ' satoshis=' + result)
})
This method works by using a modified round-robin algorithm with a simple scoring system:
each time that
getBalance
is called, it shuffles the list of providers and then orders them according to each provider's scoreeach provider is tried in order and the first (successful) result is returned
if the attempt is successful, then the provider's score is set to a number between
-250
and5000
that corresponds to the number of milli-seconds it to took to round-trip and process the requestif the attempt fails, then the provider score is set to one of:
on DNS (or other network) error: -350;
on timeout: -500;
HTTP error: -750; or,
on internal error: -1001 (thereby disqualifying the provider from further consideration)
Add to the list of Providers
Each of these properties is mandatory:
require('ledger-balance').providers.push({ name : 'commonly-known name of provider'
, site : 'https://example.com/'
, server : 'https://api.example.com'
, path : '"/v1/address" + address'
, confirmed : 'body.confirmed_satoshis'
})
The default value for the method
is "GET"
;
(or "POST"
if the value for the payload
property is present).
Both the mandatory path
property and the optional payload
property are evaluated with this context:
{ address: '3...' }
The mandatory confirmed
property is evaluated with this context:
{ body: JSON.parse(HTTP_response_body) }
There is also an optional unconfirmed
property that is evaluated in the same context.
Finally...
All of the blockchain reporters in this package are available using public APIs without any API key.
If you want to have your blockchain reporter added to the package, please send an email to Brave Software.
If you want to have your blockchain reporter removed from the package, also send an email.
Enjoy!