all files / src/ account_response.js

100% Statements 38/38
100% Branches 14/14
100% Functions 11/11
100% Lines 9/9
2 statements, 5 branches Ignored     
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 43 44 45 46 47                                81×                                              
import {Account as BaseAccount} from "rover-base";
import forIn from "lodash/forIn";
 
/**
 * Do not create this object directly, use {@link Server#loadAccount}.
 *
 * Returns information and links relating to a single account.
 * The balances section in the returned JSON will also list all the trust lines this account has set up.
 * It also contains {@link Account} object and exposes it's methods so can be used in {@link TransactionBuilder}.
 *
 * @see [Account Details](https://www.stellar.org/developers/horizon/reference/accounts-single.html)
 * @param {string} response Response from orbit account endpoint.
 * @returns {AccountResponse}
 */
export class AccountResponse {
    constructor(response) {
        this._baseAccount = new BaseAccount(response.account_id, response.sequence);
        // Extract response fields
        forIn(response, (value, key) => {
            this[key] = value;
        });
    }
 
    /**
     * Returns Rover  account ID, ex. `GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA`
     * @returns {string}
     */
    accountId() {
        return this._baseAccount.accountId();
    }
 
    /**
     * @returns {string}
     */
    sequenceNumber() {
        return this._baseAccount.sequenceNumber();
    }
 
    /**
     * Increments sequence number in this object by one.
     */
    incrementSequenceNumber() {
        this._baseAccount.incrementSequenceNumber();
        this.sequence = this._baseAccount.sequenceNumber();
    }
}