import { AccountID , AccountThresholds } from "./" ; import { Signer } from "./signer" ; export interface IAccountValues { id : AccountID ; balance : string ; sequenceNumber : string ; numSubentries : number ; inflationDestination : AccountID ; homeDomain : string ; thresholds : AccountThresholds ; signers : Signer [ ] ; } export class AccountValues implements IAccountValues { public id : string ; public balance : string ; public sequenceNumber : string ; public numSubentries : number ; public inflationDestination : string ; public homeDomain : string ; public thresholds : AccountThresholds ; public signers : Signer [ ] ; constructor ( data ) { this . id = data . id ; this . balance = data . balance ; this . sequenceNumber = data . sequenceNumber ; this . numSubentries = data . numSubentries ; this . inflationDestination = data . inflationDestination ; this . homeDomain = data . homeDomain ; this . thresholds = data . thresholds ; this . signers = Signer . sortArray ( data . signers ) ; } public diffAttrs ( other ) { if ( this . id !== other . id ) { throw new Error ( "Cannot compare AccountValues for different accounts" ) ; } const changedAttrs = [ ] ; const easyToCompareAttrs = [ "balance" , "sequenceNumber" , "numSubentries" , "inflationDestination" , "homeDomain" ] ; for ( const attr of easyToCompareAttrs ) { if ( this [ attr ] !== other [ attr ] ) { changedAttrs . push ( attr ) ; } } if ( ! this . thresholds . equals ( other . thresholds ) ) { changedAttrs . push ( "thresholds" ) ; } if ( this . signers . length !== other . signers . length ) { changedAttrs . push ( "signers" ) ; } else { const allSignersAreEqual = this . signers . every ( ( s , i ) => { return s . signer === other . signers [ i ] . signer && s . weight === other . signers [ i ] . weight ; } ) ; if ( ! allSignersAreEqual ) { changedAttrs . push ( "signers" ) ; } } return changedAttrs ; } }