Merge pull request #427 from clark800/account-info

Add getAccountInfo method and move sequence field in response
This commit is contained in:
sublimator
2015-07-16 09:48:02 +08:00
13 changed files with 60 additions and 15 deletions

View File

@@ -26,7 +26,6 @@ const AccountFlagIndices = {
};
const AccountFields = {
Sequence: {name: 'sequence'},
EmailHash: {name: 'emailHash', encoding: 'hex',
length: 32, defaults: '0'},
WalletLocator: {name: 'walletLocator', encoding: 'hex',

View File

@@ -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"}

View File

@@ -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'),

View File

@@ -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,

View 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);

View File

@@ -36,6 +36,7 @@ function parseTransaction(tx: Object): Object {
return utils.removeUndefined({
type: type,
address: tx.Account,
sequence: tx.Sequence,
id: tx.hash,
specification: utils.removeUndefined(specification),
outcome: outcome ? utils.removeUndefined(outcome) : undefined

View File

@@ -62,8 +62,7 @@ function parseOutcome(tx: Object): ?Object {
balanceChanges: balanceChanges,
orderbookChanges: orderbookChanges,
ledgerVersion: tx.ledger_index,
indexInLedger: tx.meta.TransactionIndex,
sequence: tx.Sequence
indexInLedger: tx.meta.TransactionIndex
};
}

View File

@@ -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));

View File

@@ -0,0 +1,7 @@
{
"sequence": 23,
"xrpBalance": "922.913243",
"ownerCount": 1,
"previousAffectingTransactionID": "19899273706A9E040FDB5885EE991A1DC2BAD878A0D6E7DBCFB714E63BF737F7",
"previousAffectingTransactionLedgerVersion": 6614625
}

View File

@@ -2,6 +2,7 @@
{
"type": "payment",
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"sequence": 4,
"id": "4C37C92576DEB000D13B07F4D3F99F968BD86B6B83A840BEFFB2BFC8A042A81B",
"specification": {
"source": {
@@ -80,14 +81,14 @@
]
},
"ledgerVersion": 348860,
"indexInLedger": 0,
"sequence": 4
"indexInLedger": 0
}
},
{
"type": "payment",
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"id": "4C37C92576DEB000D13B07F4D3F99F968BD86B6B83A840BEFFB2BFC8A042A81B",
"sequence": 4,
"specification": {
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
@@ -165,8 +166,7 @@
]
},
"ledgerVersion": 348860,
"indexInLedger": 0,
"sequence": 4
"indexInLedger": 0
}
}
]

View File

@@ -1,7 +1,6 @@
{
"requireDestinationTag": true,
"disallowIncomingXRP": true,
"sequence": 23,
"emailHash": "23463B99B62A72F26ED677CC556C44E8",
"walletLocator": "00000000000000000000000000000000000000000000000000000000DEADBEEF",
"domain": "example.com",

View File

@@ -1,12 +1,12 @@
{
"type": "settings",
"address": "rLVKsA4F9iJBbA6rX2x4wCmkj6drgtqpQe",
"sequence": 1,
"id": "4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA1B",
"specification": {
"requireAuthorization": true,
"disallowIncomingXRP": true,
"globalFreeze": false,
"sequence": 1
"globalFreeze": false
},
"outcome": {
"result": "tesSUCCESS",
@@ -22,7 +22,6 @@
},
"orderbookChanges": {},
"ledgerVersion": 8206418,
"indexInLedger": 5,
"sequence": 1
"indexInLedger": 5
}
}

View File

@@ -1,6 +1,7 @@
{
"type": "payment",
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"sequence": 4,
"id": "F4AB442A6D4CBB935D66E1DA7309A5FC71C7143ED4049053EC14E3875B0CF9BF",
"specification": {
"source": {
@@ -80,7 +81,6 @@
]
},
"ledgerVersion": 348860,
"indexInLedger": 0,
"sequence": 4
"indexInLedger": 0
}
}