Skip to content

Commit

Permalink
wallet option for setting api host
Browse files Browse the repository at this point in the history
  • Loading branch information
jtormey committed Jan 13, 2016
1 parent 6230ef9 commit f3143c6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
12 changes: 12 additions & 0 deletions MyWallet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ Options (optional):

* `secondPassword` - second wallet password (required only if wallet is double-encrypted)
* `apiCode` - Blockchain.info api code (will be automatically included in all further requests to the wallet)
* `apiHost` - set the host for the api calls (defaults to `https://blockchain.info/`)

## Wallet API v2 Compatibility

This module is compatible with the [Wallet API v2 service](https://github.com/blockchain/service-my-wallet-v3). To use the wallet service for api calls, set the `apiHost` option to point to where the service is running.

Example:

```js
var options = { apiCode: 'myAPICode', apiHost: 'http://localhost:3000' };
var wallet = new MyWallet('myIdentifier', 'myPassword123', options);
```

## Response objects

Expand Down
36 changes: 18 additions & 18 deletions MyWallet/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

var API = require('../api')
, endpoints = require('./endpoints')
, api = new API('https://blockchain.info', endpoints);
, endpoints = require('./endpoints');

function MyWallet(guid, password, options) {
options = options || {};
this.guid = guid;
this.api = new API(options.apiHost || 'https://blockchain.info', endpoints);
this.getParams = function () {
return {
password : password,
Expand All @@ -25,7 +25,7 @@ MyWallet.prototype.send = function (address, amount, options) {
params.from = options.from;
params.fee = options.fee;
params.note = options.note;
return api.post('payment', { guid: this.guid }, params);
return this.api.post('payment', { guid: this.guid }, params);
};

MyWallet.prototype.sendMany = function (recipients, options) {
Expand All @@ -35,64 +35,64 @@ MyWallet.prototype.sendMany = function (recipients, options) {
params.from = options.from;
params.fee = options.fee;
params.note = options.note;
return api.post('sendmany', { guid: this.guid }, params);
return this.api.post('sendmany', { guid: this.guid }, params);
};

MyWallet.prototype.getBalance = function () {
var params = this.getParams();
return api.post('balance', { guid: this.guid }, params);
return this.api.post('balance', { guid: this.guid }, params);
};

MyWallet.prototype.listAddresses = function () {
var params = this.getParams();
return api.post('list', { guid: this.guid }, params);
return this.api.post('list', { guid: this.guid }, params);
};

MyWallet.prototype.getAddress = function (address, options) {
options = options || {};
var params = this.getParams();
params.address = address;
params.confirmations = options.confirmations || 6;
return api.post('addrBalance', { guid: this.guid }, params);
return this.api.post('addrBalance', { guid: this.guid }, params);
};

MyWallet.prototype.newAddress = function (options) {
options = options || {};
var params = this.getParams();
params.label = options.label;
return api.post('newAddress', { guid: this.guid }, params);
return this.api.post('newAddress', { guid: this.guid }, params);
};

MyWallet.prototype.archiveAddress = function (address) {
var params = this.getParams();
params.address = address;
return api.post('archive', { guid: this.guid }, params);
return this.api.post('archive', { guid: this.guid }, params);
};

MyWallet.prototype.unarchiveAddress = function (address) {
var params = this.getParams();
params.address = address;
return api.post('unarchive', { guid: this.guid }, params);
return this.api.post('unarchive', { guid: this.guid }, params);
};

MyWallet.prototype.consolidate = function (options) {
options = options || {};
var params = this.getParams();
params.days = options.days || 60;
return api.post('consolidate', { guid: this.guid }, params);
return this.api.post('consolidate', { guid: this.guid }, params);
};

MyWallet.create = function (password, apiCode, options) {
options = options || {};
var params = {
password: password,
api_code: apiCode,
priv: options.priv,
label: options.label,
email: options.email
password : password,
api_code : apiCode,
priv : options.priv,
label : options.label,
email : options.email
};
return api.post('create', {}, params).then(function (response) {
var walletOptions = { apiCode: apiCode };
return this.api.post('create', {}, params).then(function (response) {
var walletOptions = { apiCode: apiCode, apiHost: options.apiHost };
return new MyWallet(response.guid, password, walletOptions);
});
};
Expand Down

0 comments on commit f3143c6

Please sign in to comment.