BlueWallet/class/abstract-wallet.js

109 lines
2 KiB
JavaScript
Raw Normal View History

import { BitcoinUnit, Chain } from '../models/bitcoinUnits';
2018-12-13 23:31:13 -05:00
2018-03-20 22:41:07 +02:00
export class AbstractWallet {
static type = 'abstract';
static typeReadable = 'abstract';
static fromJson(obj) {
let obj2 = JSON.parse(obj);
let temp = new this();
for (let key2 of Object.keys(obj2)) {
temp[key2] = obj2[key2];
}
return temp;
}
2018-03-20 22:41:07 +02:00
constructor() {
2018-12-28 18:02:39 +01:00
this.type = this.constructor.type;
this.typeReadable = this.constructor.typeReadable;
2018-03-20 22:41:07 +02:00
this.label = '';
this.secret = ''; // private key or recovery phrase
this.balance = 0;
this.unconfirmed_balance = 0;
2018-03-20 22:41:07 +02:00
this.transactions = [];
this._address = false; // cache
this.utxo = [];
this._lastTxFetch = 0;
this._lastBalanceFetch = 0;
2018-12-13 23:31:13 -05:00
this.preferredBalanceUnit = BitcoinUnit.BTC;
this.chain = Chain.ONCHAIN;
2019-08-03 17:29:15 -04:00
this.hideBalance = false;
2018-03-20 22:41:07 +02:00
}
getTransactions() {
return this.transactions;
2018-03-20 22:41:07 +02:00
}
/**
*
* @returns {string}
*/
getLabel() {
return this.label;
}
/**
*
* @returns {number} Available to spend amount, int, in sats
*/
2018-03-20 22:41:07 +02:00
getBalance() {
return this.balance;
}
2018-12-13 23:31:13 -05:00
getPreferredBalanceUnit() {
2018-12-23 13:18:27 -05:00
for (let value of Object.values(BitcoinUnit)) {
if (value === this.preferredBalanceUnit) {
return this.preferredBalanceUnit;
}
}
return BitcoinUnit.BTC;
2018-12-13 23:31:13 -05:00
}
2018-07-07 12:30:50 +01:00
allowReceive() {
return true;
}
allowSend() {
2018-10-06 01:45:24 +01:00
return true;
2018-07-07 12:30:50 +01:00
}
2018-10-31 20:14:28 +00:00
allowRBF() {
return false;
}
2019-06-08 00:06:21 +01:00
allowBatchSend() {
return false;
}
/**
* Returns delta of unconfirmed balance. For example, if theres no
* unconfirmed balance its 0
*
* @return {number}
*/
getUnconfirmedBalance() {
return this.unconfirmed_balance;
}
2018-03-20 22:41:07 +02:00
setLabel(newLabel) {
this.label = newLabel;
return this;
}
getSecret() {
return this.secret;
}
setSecret(newSecret) {
2018-07-21 13:52:54 +01:00
this.secret = newSecret.trim();
2018-03-20 22:41:07 +02:00
return this;
}
2018-06-24 23:22:46 +01:00
getLatestTransactionTime() {
return 0;
}
2018-03-20 22:41:07 +02:00
// createTx () { throw Error('not implemented') }
}