-
Notifications
You must be signed in to change notification settings - Fork 11
/
account_factory.ts
42 lines (38 loc) · 1.27 KB
/
account_factory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { VarArray } from "js-xdr";
import { xdr } from "stellar-base";
import { Account, IAccount } from "../account";
import { SignerFactory } from "./";
import { AccountFlagsFactory } from "./account_flags_factory";
import { AccountThresholdsFactory } from "./account_thresholds_factory";
export interface IAccountTableRow {
accountid: string;
balance: string;
seqnum: string;
numsubentries: number;
inflationdest: string;
homedomain: string;
thresholds: string;
flags: number;
lastmodified: number;
signers: string | null;
}
export class AccountFactory {
public static fromDb(row: IAccountTableRow): Account {
const data: IAccount = {
id: row.accountid,
balance: row.balance,
sequenceNumber: row.seqnum,
numSubentries: row.numsubentries,
inflationDestination: row.inflationdest,
homeDomain: row.homedomain,
lastModified: row.lastmodified,
thresholds: AccountThresholdsFactory.fromValue(row.thresholds),
flags: AccountFlagsFactory.fromValue(row.flags)
};
if (row.signers) {
const signersArray = new VarArray(xdr.Signer).fromXDR(row.signers, "base64");
data.signers = signersArray.map((signerXDR: any) => SignerFactory.fromXDR(signerXDR, row.accountid));
}
return new Account(data);
}
}