mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-03 18:45:48 +00:00
Add getAccountInfo method and unit test
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "settings-options",
|
||||
"description": "Options for getSettings",
|
||||
"description": "Options for getSettings and getAccountInfo",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ledgerVersion": {"$ref": "ledgerVersion"}
|
||||
|
||||
@@ -54,6 +54,7 @@ module.exports = {
|
||||
blob: _.partial(schemaValidate, 'blob'),
|
||||
getTransactionsOptions: _.partial(validateOptions, 'transactions-options'),
|
||||
getSettingsOptions: _.partial(validateOptions, 'settings-options'),
|
||||
getAccountInfoOptions: _.partial(validateOptions, 'settings-options'),
|
||||
getTrustlinesOptions: _.partial(validateOptions, 'trustlines-options'),
|
||||
getBalancesOptions: _.partial(validateOptions, 'trustlines-options'),
|
||||
getOrdersOptions: _.partial(validateOptions, 'orders-options'),
|
||||
|
||||
@@ -16,6 +16,7 @@ const getPaths = require('./ledger/pathfind');
|
||||
const getOrders = require('./ledger/orders');
|
||||
const getOrderbook = require('./ledger/orderbook');
|
||||
const getSettings = require('./ledger/settings');
|
||||
const getAccountInfo = require('./ledger/accountinfo');
|
||||
const preparePayment = require('./transaction/payment');
|
||||
const prepareTrustline = require('./transaction/trustline');
|
||||
const prepareOrder = require('./transaction/order');
|
||||
@@ -48,6 +49,7 @@ RippleAPI.prototype = {
|
||||
getOrders,
|
||||
getOrderbook,
|
||||
getSettings,
|
||||
getAccountInfo,
|
||||
|
||||
preparePayment,
|
||||
prepareTrustline,
|
||||
|
||||
32
src/api/ledger/accountinfo.js
Normal file
32
src/api/ledger/accountinfo.js
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
const utils = require('./utils');
|
||||
const removeUndefined = require('./parse/utils').removeUndefined;
|
||||
const validate = utils.common.validate;
|
||||
const composeAsync = utils.common.composeAsync;
|
||||
|
||||
function formatAccountInfo(response) {
|
||||
const data = response.account_data;
|
||||
return removeUndefined({
|
||||
sequence: data.Sequence,
|
||||
xrpBalance: utils.common.dropsToXrp(data.Balance),
|
||||
ownerCount: data.OwnerCount,
|
||||
previousInitiatedTransactionID: data.AccountTxnID,
|
||||
previousAffectingTransactionID: data.PreviousTxnID,
|
||||
previousAffectingTransactionLedgerVersion: data.PreviousTxnLgrSeq
|
||||
});
|
||||
}
|
||||
|
||||
function getAccountInfo(account, options, callback) {
|
||||
validate.address(account);
|
||||
validate.getAccountInfoOptions(options);
|
||||
|
||||
const request = {
|
||||
account: account,
|
||||
ledger: options.ledgerVersion
|
||||
};
|
||||
|
||||
this.remote.requestAccountInfo(request,
|
||||
composeAsync(formatAccountInfo, callback));
|
||||
}
|
||||
|
||||
module.exports = utils.wrapCatch(getAccountInfo);
|
||||
@@ -16,6 +16,7 @@ const orderCancellationResponse =
|
||||
require('./fixtures/ordercancellation-response');
|
||||
const settingsSpecification = require('./fixtures/settings-specification');
|
||||
const settingsResponse = require('./fixtures/settings-response');
|
||||
const getAccountInfoResponse = require('./fixtures/account-info-response');
|
||||
const regularKeyResponse = require('./fixtures/regular-key-response');
|
||||
const signInput = require('./fixtures/sign-input');
|
||||
const signOutput = require('./fixtures/sign-output');
|
||||
@@ -163,6 +164,11 @@ describe('RippleAPI', function() {
|
||||
_.partial(checkResult, getSettingsResponse, done));
|
||||
});
|
||||
|
||||
it('getAccountInfo', function(done) {
|
||||
this.api.getAccountInfo(address, {},
|
||||
_.partial(checkResult, getAccountInfoResponse, done));
|
||||
});
|
||||
|
||||
it('getOrders', function(done) {
|
||||
this.api.getOrders(address, {},
|
||||
_.partial(checkResult, getOrdersResponse, done));
|
||||
|
||||
7
test/fixtures/account-info-response.json
vendored
Normal file
7
test/fixtures/account-info-response.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"sequence": 23,
|
||||
"xrpBalance": "922.913243",
|
||||
"ownerCount": 1,
|
||||
"previousAffectingTransactionID": "19899273706A9E040FDB5885EE991A1DC2BAD878A0D6E7DBCFB714E63BF737F7",
|
||||
"previousAffectingTransactionLedgerVersion": 6614625
|
||||
}
|
||||
Reference in New Issue
Block a user