2018-12-13 23:31:13 -05:00
|
|
|
import { BitcoinUnit } from '../models/bitcoinUnits';
|
|
|
|
|
2018-03-20 22:41:07 +02:00
|
|
|
export class AbstractWallet {
|
|
|
|
constructor() {
|
|
|
|
this.type = 'abstract';
|
|
|
|
this.label = '';
|
|
|
|
this.secret = ''; // private key or recovery phrase
|
|
|
|
this.balance = 0;
|
2018-07-05 01:56:31 +01:00
|
|
|
this.unconfirmed_balance = 0;
|
2018-03-20 22:41:07 +02:00
|
|
|
this.transactions = [];
|
|
|
|
this._address = false; // cache
|
|
|
|
this.utxo = [];
|
2018-07-28 21:19:11 +01:00
|
|
|
this._lastTxFetch = 0;
|
|
|
|
this._lastBalanceFetch = 0;
|
2018-12-13 23:31:13 -05:00
|
|
|
this.preferredBalanceUnit = BitcoinUnit.BTC;
|
2018-03-20 22:41:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getTransactions() {
|
|
|
|
return this.transactions;
|
|
|
|
}
|
|
|
|
|
|
|
|
getTypeReadable() {
|
|
|
|
return this.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
getLabel() {
|
|
|
|
return this.label;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-07-05 01:56:31 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
getAddress() {}
|
|
|
|
|
|
|
|
// createTx () { throw Error('not implemented') }
|
|
|
|
}
|