mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-01-19 05:45:15 +01:00
REF: now BIP44 works through electrum
This commit is contained in:
parent
825492a1da
commit
e072c02bd9
@ -295,7 +295,7 @@ module.exports.multiGetHistoryByAddress = async function(addresses, batchsize) {
|
||||
};
|
||||
|
||||
module.exports.multiGetTransactionByTxid = async function(txids, batchsize, verbose) {
|
||||
batchsize = batchsize || 81;
|
||||
batchsize = batchsize || 61;
|
||||
// this value is fine-tuned so althrough wallets in test suite will occasionally
|
||||
// throw 'response too large (over 1,000,000 bytes', test suite will pass
|
||||
verbose = verbose !== false;
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { AbstractHDWallet } from './abstract-hd-wallet';
|
||||
import Frisbee from 'frisbee';
|
||||
import { AbstractHDElectrumWallet } from './abstract-hd-electrum-wallet';
|
||||
import bip39 from 'bip39';
|
||||
const bip32 = require('bip32');
|
||||
const bitcoinjs = require('bitcoinjs-lib');
|
||||
@ -8,7 +7,7 @@ const bitcoinjs = require('bitcoinjs-lib');
|
||||
* HD Wallet (BIP39).
|
||||
* In particular, Breadwallet-compatible (Legacy addresses)
|
||||
*/
|
||||
export class HDLegacyBreadwalletWallet extends AbstractHDWallet {
|
||||
export class HDLegacyBreadwalletWallet extends AbstractHDElectrumWallet {
|
||||
static type = 'HDLegacyBreadwallet';
|
||||
static typeReadable = 'HD Legacy Breadwallet (P2PKH)';
|
||||
|
||||
@ -90,26 +89,4 @@ export class HDLegacyBreadwalletWallet extends AbstractHDWallet {
|
||||
|
||||
return child.keyPair.toWIF();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
async fetchBalance() {
|
||||
try {
|
||||
const api = new Frisbee({ baseURI: 'https://blockchain.info' });
|
||||
|
||||
let response = await api.get('/balance?active=' + this.getXpub());
|
||||
|
||||
if (response && response.body) {
|
||||
for (let xpub of Object.keys(response.body)) {
|
||||
this.balance = response.body[xpub].final_balance / 100000000;
|
||||
}
|
||||
this._lastBalanceFetch = +new Date();
|
||||
} else {
|
||||
throw new Error('Could not fetch balance from API: ' + response.err);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { AbstractHDWallet } from './abstract-hd-wallet';
|
||||
import bip39 from 'bip39';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import signer from '../models/signer';
|
||||
import { AbstractHDElectrumWallet } from './abstract-hd-electrum-wallet';
|
||||
const bitcoin = require('bitcoinjs-lib');
|
||||
const HDNode = require('bip32');
|
||||
|
||||
@ -10,7 +10,7 @@ const HDNode = require('bip32');
|
||||
* In particular, BIP44 (P2PKH legacy addressess)
|
||||
* @see https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
|
||||
*/
|
||||
export class HDLegacyP2PKHWallet extends AbstractHDWallet {
|
||||
export class HDLegacyP2PKHWallet extends AbstractHDElectrumWallet {
|
||||
static type = 'HDlegacyP2PKH';
|
||||
static typeReadable = 'HD Legacy (BIP44 P2PKH)';
|
||||
|
||||
|
@ -306,7 +306,7 @@ it('Legacy HD (BIP44) can generate addressess based on xpub', async function() {
|
||||
assert.strictEqual(hd._getInternalAddressByIndex(1), '13CW9WWBsWpDUvLtbFqYziWBWTYUoQb4nU');
|
||||
});
|
||||
|
||||
it.skip('Legacy HD (BIP44) can create TX', async () => {
|
||||
it('Legacy HD (BIP44) can create TX', async () => {
|
||||
if (!process.env.HD_MNEMONIC) {
|
||||
console.error('process.env.HD_MNEMONIC not set, skipped');
|
||||
return;
|
||||
@ -315,15 +315,14 @@ it.skip('Legacy HD (BIP44) can create TX', async () => {
|
||||
hd.setSecret(process.env.HD_MNEMONIC);
|
||||
assert.ok(hd.validateMnemonic());
|
||||
|
||||
await hd.fetchBalance();
|
||||
await hd.fetchUtxo();
|
||||
assert.strictEqual(hd.utxo.length, 4);
|
||||
await hd.getChangeAddressAsync(); // to refresh internal pointer to next free address
|
||||
await hd.getAddressAsync(); // to refresh internal pointer to next free address
|
||||
let txhex = hd.createTx(hd.utxo, 0.0008, 0.000005, '3GcKN7q7gZuZ8eHygAhHrvPa5zZbG5Q1rK');
|
||||
|
||||
assert.strictEqual(
|
||||
txhex,
|
||||
'01000000045fbc74110c2d6fcf4d1161a59913fbcd2b6ab3c5a9eb4d0dc0859515cbc8654f030000006b4830450221009be5dbe37db5a8409ddce3570140c95d162a07651b1e48cf39a6a741892adc53022061a25b8024d8f3cb1b94f264245de0c6e9a103ea557ddeb66245b40ec8e9384b012102ad7b2216f3a2b38d56db8a7ee5c540fd12c4bbb7013106eff78cc2ace65aa002ffffffff5fbc74110c2d6fcf4d1161a59913fbcd2b6ab3c5a9eb4d0dc0859515cbc8654f000000006a47304402207106e9fa4e2e35d351fbccc9c0fad3356d85d0cd35a9d7e9cbcefce5440da1e5022073c1905b5927447378c0f660e62900c1d4b2691730799458889fb87d86f5159101210316e84a2556f30a199541633f5dda6787710ccab26771b7084f4c9e1104f47667ffffffff5fbc74110c2d6fcf4d1161a59913fbcd2b6ab3c5a9eb4d0dc0859515cbc8654f020000006a4730440220250b15094096c4d4fe6793da8e45fa118ed057cc2759a480c115e76e23590791022079cdbdc9e630d713395602071e2837ecc1d192a36a24d8ec71bc51d5e62b203b01210316e84a2556f30a199541633f5dda6787710ccab26771b7084f4c9e1104f47667ffffffff5fbc74110c2d6fcf4d1161a59913fbcd2b6ab3c5a9eb4d0dc0859515cbc8654f010000006b483045022100879da610e6ed12c84d55f12baf3bf6222d59b5282502b3c7f4db1d22152c16900220759a1c88583cbdaf7fde21c273ad985dfdf94a2fa85e42ee41dcea2fd69136fd012102ad7b2216f3a2b38d56db8a7ee5c540fd12c4bbb7013106eff78cc2ace65aa002ffffffff02803801000000000017a914a3a65daca3064280ae072b9d6773c027b30abace872c4c0000000000001976a9146ee5e3e66dc73587a3a2d77a1a6c8554fae21b8a88ac00000000',
|
||||
'01000000045fbc74110c2d6fcf4d1161a59913fbcd2b6ab3c5a9eb4d0dc0859515cbc8654f000000006a47304402203b543d6fbc3ac5244b97af77c11c5d95851a0fe81c40c1a94f8485b1c5591f1c022067ef8be793822bb0265f61084203c7fe196df8efe99f0cb822a8ce258631568601210316e84a2556f30a199541633f5dda6787710ccab26771b7084f4c9e1104f47667ffffffff5fbc74110c2d6fcf4d1161a59913fbcd2b6ab3c5a9eb4d0dc0859515cbc8654f020000006b483045022100e2dab95c3753eb6055563e446758d385c309872ffb47f24b0b7850f0e4958e6b02206d3953d300469310cc2fd25963929cf8292be63f6decf990d5df5dd34df80a1b01210316e84a2556f30a199541633f5dda6787710ccab26771b7084f4c9e1104f47667ffffffff5fbc74110c2d6fcf4d1161a59913fbcd2b6ab3c5a9eb4d0dc0859515cbc8654f010000006a47304402206a7962ccf7f9cc022fb287899ff4a5ced3a60e319c8ca83176ef19c5c91c439602203e9828b9de33d4cdfefd550f00c373d7927e8014f2bbe7c9309118f0307e4e44012102ad7b2216f3a2b38d56db8a7ee5c540fd12c4bbb7013106eff78cc2ace65aa002ffffffff5fbc74110c2d6fcf4d1161a59913fbcd2b6ab3c5a9eb4d0dc0859515cbc8654f030000006a4730440220612e39b9b2cbc0802c7ca6bf204f8356a3e4f50764e36542ad9a52bf7a39f2920220654c20af5d8828cc0f8094acc509b8682d613e7bded6a2126a570723461cfb35012102ad7b2216f3a2b38d56db8a7ee5c540fd12c4bbb7013106eff78cc2ace65aa002ffffffff02803801000000000017a914a3a65daca3064280ae072b9d6773c027b30abace872c4c0000000000001976a9146ee5e3e66dc73587a3a2d77a1a6c8554fae21b8a88ac00000000',
|
||||
);
|
||||
|
||||
var tx = bitcoin.Transaction.fromHex(txhex);
|
||||
@ -346,22 +345,7 @@ it.skip('Legacy HD (BIP44) can create TX', async () => {
|
||||
assert.strictEqual(tx.outs[0].value, 99800);
|
||||
});
|
||||
|
||||
it('Legacy HD (BIP44) can fetch UTXO', async function() {
|
||||
let hd = new HDLegacyP2PKHWallet();
|
||||
hd.usedAddresses = ['1Ez69SnzzmePmZX3WpEzMKTrcBF2gpNQ55', '1BiTCHeYzJNMxBLFCMkwYXNdFEdPJP53ZV']; // hacking internals
|
||||
await hd.fetchUtxo();
|
||||
assert.ok(hd.utxo.length >= 12);
|
||||
assert.ok(typeof hd.utxo[0].confirmations === 'number');
|
||||
assert.ok(hd.utxo[0].txid);
|
||||
assert.ok(hd.utxo[0].vout);
|
||||
assert.ok(hd.utxo[0].amount);
|
||||
assert.ok(
|
||||
hd.utxo[0].address &&
|
||||
(hd.utxo[0].address === '1Ez69SnzzmePmZX3WpEzMKTrcBF2gpNQ55' || hd.utxo[0].address === '1BiTCHeYzJNMxBLFCMkwYXNdFEdPJP53ZV'),
|
||||
);
|
||||
});
|
||||
|
||||
it.skip('HD breadwallet works', async function() {
|
||||
it('HD breadwallet works', async function() {
|
||||
if (!process.env.HD_MNEMONIC_BREAD) {
|
||||
console.error('process.env.HD_MNEMONIC_BREAD not set, skipped');
|
||||
return;
|
||||
@ -379,7 +363,7 @@ it.skip('HD breadwallet works', async function() {
|
||||
'xpub68nLLEi3KERQY7jyznC9PQSpSjmekrEmN8324YRCXayMXaavbdEJsK4gEcX2bNf9vGzT4xRks9utZ7ot1CTHLtdyCn9udvv1NWvtY7HXroh',
|
||||
);
|
||||
await hdBread.fetchBalance();
|
||||
assert.strictEqual(hdBread.balance, 0);
|
||||
assert.strictEqual(hdBread.getBalance(), 0);
|
||||
|
||||
assert.ok(hdBread._lastTxFetch === 0);
|
||||
await hdBread.fetchTransactions();
|
||||
|
Loading…
Reference in New Issue
Block a user