-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
143 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,4 +124,4 @@ export default class Terminal { | |
} | ||
console.log(table(data, config)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import AbstractWallet from "./AbstractWallet"; | ||
import Coin from '../Coin' | ||
import request from 'request-promise' | ||
|
||
export default class BlockchainWallet extends AbstractWallet { | ||
/** | ||
* Returns the Bitcoin balance for addresses | ||
* @param addresses The Bitcoin wallet addressses. | ||
* @return {Promise} The address balances. | ||
*/ | ||
static _getBalanceForCredential(credentials) { | ||
return new Promise((resolve, reject) => { | ||
let addresses = credentials.addresses.join('|') | ||
let options = { | ||
uri: 'https://blockchain.info/nl/multiaddr?limit=0&active=' + encodeURIComponent(addresses), | ||
json: true | ||
} | ||
return request(options) | ||
.then(data => { | ||
let result = [] | ||
for (let address of data.addresses) { | ||
let amount = address.final_balance / Math.pow(10,8) | ||
result.push(new Coin('BTC', amount, 'Blockchain')) | ||
} | ||
resolve(result) | ||
}) | ||
.catch(err => { | ||
reject(err) | ||
}) | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import AbstractWallet from "./AbstractWallet"; | ||
import Coin from '../Coin' | ||
import request from 'request-promise' | ||
|
||
export default class EtherscanWallet extends AbstractWallet { | ||
/** | ||
* Returns the Ether balance for addresses | ||
* @param addresses The Bitcoin wallet addresss. | ||
* @return {Promise} The address balances. | ||
*/ | ||
static _getBalanceForCredential(credentials) { | ||
return new Promise((resolve, reject) => { | ||
let addresses = credentials.addresses.join(',') | ||
let options = { | ||
uri: 'https://api.etherscan.io/api?module=account&action=balancemulti&address=' + encodeURIComponent(addresses), | ||
json: true | ||
} | ||
return request(options) | ||
.then(data => { | ||
let result = [] | ||
for (let address of data.result) { | ||
let amount = address.balance / Math.pow(10,18) | ||
result.push(new Coin('ETH', amount, 'Etherscan')) | ||
} | ||
resolve(result) | ||
}) | ||
.catch(err => { | ||
reject(err) | ||
}) | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import assert from 'assert' | ||
import BlockchainWallet from "../../../src/model/integrations/BlockchainWallet"; | ||
|
||
import * as Settings from './../../../src/Settings' | ||
|
||
describe('Testing Blockchain integration', () => { | ||
before(function() { | ||
if (!Settings.accounts.blockchain) { | ||
this.skip() | ||
} | ||
}) | ||
it('Testing initial connection and balances', async () => { | ||
let wallet = new BlockchainWallet(Settings.accounts.blockchain[0]) | ||
let balance = await wallet.getBalance() | ||
assert(balance.length > 0) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import assert from 'assert' | ||
import EtherscanWallet from "../../../src/model/integrations/EtherscanWallet"; | ||
|
||
import * as Settings from './../../../src/Settings' | ||
|
||
describe('Testing Etherscan integration', () => { | ||
before(function() { | ||
if (!Settings.accounts.etherscan) { | ||
this.skip() | ||
} | ||
}) | ||
it('Testing initial connection and balances', async () => { | ||
let wallet = new EtherscanWallet(Settings.accounts.etherscan[0]) | ||
let balance = await wallet.getBalance() | ||
assert(balance.length > 0) | ||
}) | ||
}) |