0.9.3 • Published 7 years ago

ledger-balance v0.9.3

Weekly downloads
4
License
MPL-2.0
Repository
github
Last release
7 years ago

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 score

  • each 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 and 5000 that corresponds to the number of milli-seconds it to took to round-trip and process the request

  • if 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!

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.64

7 years ago

0.8.63

7 years ago

0.8.62

7 years ago

0.8.61

8 years ago

0.8.60

8 years ago

0.8.46

8 years ago

0.8.43

8 years ago

0.8.42

8 years ago

0.8.41

8 years ago

0.8.40

8 years ago

0.8.39

8 years ago