Skip to content

Commit

Permalink
Merge pull request #4 from bitcoinvault/4-add-explicit-prettier-config
Browse files Browse the repository at this point in the history
Add explicit prettier config
  • Loading branch information
mateuszpmroz authored Apr 2, 2020
2 parents 4053e4d + b424c7d commit fb86652
Show file tree
Hide file tree
Showing 103 changed files with 8,587 additions and 10,596 deletions.
10 changes: 10 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
bracketSpacing: true,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
printWidth: 120,
semi: true,
tabWidth: 2,
useTabs: false,
};
58 changes: 24 additions & 34 deletions class/abstract-hd-wallet.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { LegacyWallet } from "./legacy-wallet";
import { LegacyWallet } from './legacy-wallet';

const bip39 = require("bip39");
const BlueElectrum = require("../BlueElectrum");
const bip39 = require('bip39');
const BlueElectrum = require('../BlueElectrum');

export class AbstractHDWallet extends LegacyWallet {
static type = "abstract";
static typeReadable = "abstract";
static type = 'abstract';
static typeReadable = 'abstract';

constructor() {
super();
this._xpub = ""; // cache
this._xpub = ''; // cache
this._address = [];
this._address_to_wif_cache = {};
this._addr_balances = {};
Expand All @@ -23,7 +23,7 @@ export class AbstractHDWallet extends LegacyWallet {
}

generate() {
throw new Error("Not implemented");
throw new Error('Not implemented');
}

allowSend() {
Expand All @@ -36,9 +36,7 @@ export class AbstractHDWallet extends LegacyWallet {

setSecret(newSecret) {
this.secret = newSecret.trim().toLowerCase();
this.secret = this.secret
.replace(/[^a-zA-Z0-9]/g, " ")
.replace(/\s+/g, " ");
this.secret = this.secret.replace(/[^a-zA-Z0-9]/g, ' ').replace(/\s+/g, ' ');
this.generateAddresses();
return this;
}
Expand Down Expand Up @@ -73,36 +71,33 @@ export class AbstractHDWallet extends LegacyWallet {
}

_getExternalWIFByIndex(index) {
throw new Error("Not implemented");
throw new Error('Not implemented');
}

_getInternalWIFByIndex(index) {
throw new Error("Not implemented");
throw new Error('Not implemented');
}

_getExternalAddressByIndex(index) {
throw new Error("Not implemented");
throw new Error('Not implemented');
}

_getInternalAddressByIndex(index) {
throw new Error("Not implemented");
throw new Error('Not implemented');
}

getXpub() {
throw new Error("Not implemented");
throw new Error('Not implemented');
}

async fetchTransactions() {
const txids_to_update = [];
try {
this._lastTxFetch = +new Date();
const tx_addr_dict = await BlueElectrum.multiGetHistoryByAddress(
this.getAddress()
);
const tx_addr_dict = await BlueElectrum.multiGetHistoryByAddress(this.getAddress());
for (const addr in tx_addr_dict) {
for (const tx of tx_addr_dict[addr]) {
if (!this.transactionConfirmed(tx.tx_hash))
txids_to_update.push(tx.tx_hash);
if (!this.transactionConfirmed(tx.tx_hash)) txids_to_update.push(tx.tx_hash);
}
}
if (txids_to_update) await this._update_unconfirmed_tx(txids_to_update);
Expand All @@ -122,30 +117,25 @@ export class AbstractHDWallet extends LegacyWallet {
* @return {String} WIF if found
*/
_getWifForAddress(address) {
if (this._address_to_wif_cache[address])
return this._address_to_wif_cache[address];
throw new Error("Could not find WIF for " + address);
if (this._address_to_wif_cache[address]) return this._address_to_wif_cache[address];
throw new Error('Could not find WIF for ' + address);
}

createTx() {
throw new Error("Not implemented");
throw new Error('Not implemented');
}

async fetchBalance() {
try {
const balance = await BlueElectrum.multiGetBalanceByAddress(
this.getAddress()
);
const balance = await BlueElectrum.multiGetBalanceByAddress(this.getAddress());
this.balance = balance.balance + balance.unconfirmed_balance;
this.unconfirmed_balance = balance.unconfirmed_balance;
this._lastBalanceFetch = +new Date();
for (const address in balance.addresses) {
this._addr_balances[address] = {
total:
balance.addresses[address].unconfirmed +
balance.addresses[address].confirmed,
total: balance.addresses[address].unconfirmed + balance.addresses[address].confirmed,
c: balance.addresses[address].confirmed,
u: balance.addresses[address].unconfirmed
u: balance.addresses[address].unconfirmed,
};
}
} catch (err) {
Expand All @@ -168,14 +158,14 @@ export class AbstractHDWallet extends LegacyWallet {
}

_getDerivationPathByAddress(address) {
throw new Error("Not implemented");
throw new Error('Not implemented');
}

_getNodePubkeyByIndex(address) {
throw new Error("Not implemented");
throw new Error('Not implemented');
}

generateAddresses() {
throw new Error("Not implemented");
throw new Error('Not implemented');
}
}
18 changes: 9 additions & 9 deletions class/abstract-wallet.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BitcoinUnit, Chain } from "../models/bitcoinUnits";
import { BitcoinUnit, Chain } from '../models/bitcoinUnits';

const createHash = require("create-hash");
const createHash = require('create-hash');

export class AbstractWallet {
static type = "abstract";
static typeReadable = "abstract";
static type = 'abstract';
static typeReadable = 'abstract';

static fromJson(obj) {
const obj2 = JSON.parse(obj);
Expand All @@ -19,8 +19,8 @@ export class AbstractWallet {
constructor() {
this.type = this.constructor.type;
this.typeReadable = this.constructor.typeReadable;
this.label = "";
this.secret = ""; // private key or recovery phrase
this.label = '';
this.secret = ''; // private key or recovery phrase
this.balance = 0; // SAT
this.unconfirmed_balance = 0; // SAT
this.transactions = [];
Expand All @@ -35,10 +35,10 @@ export class AbstractWallet {
}

getID() {
return createHash("sha256")
return createHash('sha256')
.update(this.getSecret())
.digest()
.toString("hex");
.toString('hex');
}

getTransactions() {
Expand Down Expand Up @@ -129,7 +129,7 @@ export class AbstractWallet {
// createTx () { throw Error('not implemented') }

getAddress() {
throw Error("not implemented");
throw Error('not implemented');
}

getAddressAsync() {
Expand Down
Loading

0 comments on commit fb86652

Please sign in to comment.