0.0.3 • Published 5 years ago

@carnesen/bitcoin-software v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

@carnesen/bitcoin-software Build Status

A Node.js library for installing bitcoin server software

Install

$ npm install @carnesen/bitcoin-software

The package includes runtime JavaScript files suitable for Node.js >=8 as well as the corresponding TypeScript type declarations.

Usage

Here is an example of a script that installs Bitcoin Core:

// example.ts
const { installSoftware } = require('@carnesen/bitcoin-software');
const { homedir } = require('os');

(async () => {
  console.log('Installing Bitcoin Core ...');
  const { changed, bitcoinHome } = await installSoftware({
    implementation: 'core',
    version: '0.17.1',
    destination: homedir(),
  });
  const message = changed
    ? `Installed Bitcoin Core to ${bitcoinHome}`
    : `Bitcoin Core is already installed at ${bitcoinHome}`;
  console.log(message);
})();

Here what that script looks like when run:

$ ts-node example.ts
Installing Bitcoin Core ...
Installed Bitcoin Core to /Users/carnesen/bitcoin-core-0.17.1

$ ts-node example.ts
Installing Bitcoin Core ...
Bitcoin Core is already installed at /Users/carnesen/bitcoin-core-0.17.1

The script would be the same in JavaScript just with the import ... from statements replaced by const ... require ones.

API

installSoftware({implementation?, destination?, version?}): Promise<{changed, bitcoinHome}>

Downloads and unpacks a tarball of bitcoin server software

implementation

Optional string. Defaults to 'core'. Supported values:

version

Optional string. Default value is implementation-dependent, e.g. '0.17.1' for Bitcoin Core.

destination

Optional string. Defaults to 'software'. An absolute or datadir-relative path of a directory below which the software will be installed.

changed

boolean. installSoftware is idempotent in the sense that it does not modify an existing installation if there is one, nor does it throw. If installSoftware actually downloads and extracts the tarball to destination, it returns an object with changed set to true. If install finds the software already installed, it returns an object with changed set to false.

bitcoinHome

string. Absolute directory path at which the software is installed. Effectively:

bitcoinHome = `${destination}/bitcoin-${implementation}-${version}` 

uninstallSoftware({implementation?, destination?, version?}): Promise<{changed, bitcoinHome}>

Uninstalls bitcoin server software from the specified destination. Parameters and return values are the same as described above for installSoftware above.

More information

This library has a number of unit tests with ~100% coverage. Check out the tests directory for more examples of how it works. If you encounter any bugs or have any questions or feature requests, please don't hesitate to file an issue or submit a pull request on this project's repository on GitHub.

Related

License

MIT © Chris Arnesen