@fruitsjs/core
Version:
Principal package with functions and models for building Fruits Eco-Blockchain applications.
98 lines (92 loc) • 3.67 kB
text/typescript
import { Keys } from '@fruitsjs/crypto';
import { Transaction } from './transaction';
import { AssetBalance } from './assetBalance';
import { UnconfirmedAssetBalance } from './unconfirmedAssetBalance';
export interface MultiKeys {
passphrase: string;
eth: EthKeys;
btc: BtcKeys;
}
export interface EthKeys {
address: string;
privateKey: string;
balance: string;
}
export interface BtcKeys {
address: string;
privateKey: string;
publicKey: string;
balance: string;
}
// TODO: reduce this to simple response type (DTO). All the info her inside is application dependendent (i.e. Phoenix)
// - move this class to Phoenix (Web/Desktop/Mobile) and substitute by DTO
/**
* Account class
*
* The account class serves as a model for a Fruitscoin account.
* It's meant to model the response from BRS API, except publicKey
* has been moved into the keys object.
* @module core
*/
export class Account {
public account: string;
public accountRS: string;
public accountRSExtended: string;
public assetBalances: AssetBalance[];
public balanceNQT: string;
public description: string;
public effectiveBalanceNQT: string;
public keys: Keys;
public name: string;
public pinHash: string;
public selected: boolean;
public transactions: Transaction[];
public type: string;
public unconfirmedAssetBalances: UnconfirmedAssetBalance[];
public unconfirmedBalanceNQT: string;
public commitmentNQT: string;
public committedBalanceNQT: string;
public confirmed: boolean;
public multiWallet: boolean;
public multiKeys: MultiKeys;
public multiWalletIndex: number;
public encryptedPassphrase: string;
public oldAccount: string;
public activatorTime: number;
constructor(data: any = {}) {
this.account = data.account || undefined;
this.accountRS = data.accountRS || undefined;
this.accountRSExtended = data.accountRSExtended || undefined;
this.assetBalances = data.assetBalances || undefined;
this.balanceNQT = data.balanceNQT || 0;
this.commitmentNQT = data.commitmentNQT || 0;
this.committedBalanceNQT = data.committedBalanceNQT || 0;
this.description = data.description || undefined;
this.effectiveBalanceNQT = data.effectiveBalanceNQT || 0;
if (data.publicKey || data.keys !== undefined) {
this.pinHash = data.pinHash || undefined;
this.keys = {
publicKey: data.publicKey || data.keys.publicKey,
signPrivateKey: data.keys.signPrivateKey,
agreementPrivateKey: data.keys.agreementPrivateKey,
};
}
this.name = data.name || undefined;
this.selected = data.selected || false;
if (data.transactions !== undefined && data.transactions.length > 0) {
this.transactions = data.transactions;
} else {
this.transactions = [];
}
this.type = data.type || 'offline';
this.unconfirmedAssetBalances = data.unconfirmedAssetBalances || undefined;
this.unconfirmedBalanceNQT = data.unconfirmedBalanceNQT || 0;
this.confirmed = data.confirmed || false;
this.multiWallet = data.multiWallet || false;
this.multiKeys = data.multiKeys || undefined;
this.multiWalletIndex = data.multiWalletIndex || 0;
this.encryptedPassphrase = data.encryptedPassphrase || undefined;
this.oldAccount = data.oldAccount || undefined;
this.activatorTime = data.activatorTime || 0;
}
}