GetLedger by hash option (#980)

* update ledger input schema
* include ledgerHash option
This commit is contained in:
Alexandru Chiriac
2018-12-12 19:02:50 +00:00
committed by Elliot Lee
parent 8d37da0952
commit 5419e67dbc
9 changed files with 56 additions and 0 deletions

View File

@@ -4387,6 +4387,7 @@ options | object | *Optional* Options affecting what ledger and how much data to
*options.* includeAllData | boolean | *Optional* Include full transactions and/or state information if `includeTransactions` and/or `includeState` is set.
*options.* includeState | boolean | *Optional* Return an array of hashes for all state data or an array of all state data in this ledger version, depending on whether `includeAllData` is set.
*options.* includeTransactions | boolean | *Optional* Return an array of hashes for each transaction or an array of all transactions that were validated in this ledger version, depending on whether `includeAllData` is set.
*options.* ledgerHash | string | *Optional* Get ledger data for this historical ledger hash.
*options.* ledgerVersion | integer | *Optional* Get ledger data for this historical ledger version.
*options.* ledgerVersion | string | *Optional* Get ledger data for this historical ledger version.

View File

@@ -7,6 +7,10 @@
"options": {
"description": "Options affecting what ledger and how much data to return.",
"properties": {
"ledgerHash": {
"type": "string",
"description": "Get ledger data for this historical ledger hash."
},
"ledgerVersion": {
"$ref": "ledgerVersion",
"description": "Get ledger data for this historical ledger version."

View File

@@ -3,6 +3,7 @@ import {FormattedLedger, parseLedger} from './parse/ledger'
import {RippleAPI} from '../api'
export type GetLedgerOptions = {
ledgerHash?: string,
ledgerVersion?: number,
includeAllData?: boolean,
includeTransactions?: boolean,
@@ -16,6 +17,7 @@ async function getLedger(
validate.getLedger({options})
// 2. Make Request
const response = await this.request('ledger', {
ledger_hash: options.ledgerHash,
ledger_index: options.ledgerVersion || 'validated',
expand: options.includeAllData,
transactions: options.includeTransactions,

View File

@@ -3090,6 +3090,11 @@ describe('RippleAPI', function () {
_.partial(checkResult, responses.getLedger.header, 'getLedger'));
});
it('getLedger - by hash', function () {
return this.api.getLedger({ ledgerHash: '15F20E5FA6EA9770BBFFDBD62787400960B04BE32803B20C41F117F41C13830D' }).then(
_.partial(checkResult, responses.getLedger.headerByHash, 'getLedger'));
});
it('getLedger - future ledger version', function () {
return this.api.getLedger({ ledgerVersion: 14661789 }).then(response => {
assert(response)

View File

@@ -0,0 +1,12 @@
{
"stateHash": "A155BFE86054BE654796EC449E7C374CD5CAA3789BA75D302E7F0F4CE470CCB3",
"closeTime": "2018-12-07T11:10:30.000Z",
"closeTimeResolution": 10,
"closeFlags": 0,
"ledgerHash": "15F20E5FA6EA9770BBFFDBD62787400960B04BE32803B20C41F117F41C13830D",
"ledgerVersion": 14995338,
"parentLedgerHash": "E0BC4F5FB8D9025087BE238664833DFA5658C9E7CE413B3B6F7DF4FFF1EDBF40",
"parentCloseTime": "2018-12-07T11:10:22.000Z",
"totalDrops": "99997114637345372",
"transactionHash": "52C0B6604D2EF203710FEA24F4A3750A4F2BCD5C67D6EB5FB1B2DBAE9A14DCE8"
}

View File

@@ -83,6 +83,7 @@ module.exports = {
},
getLedger: {
header: require('./get-ledger'),
headerByHash: require('./get-ledger-by-hash'),
full: require('./get-ledger-full'),
withSettingsTx: require('./get-ledger-with-settings-tx'),
withStateAsHashes: require('./get-ledger-with-state-as-hashes'),

View File

@@ -7,6 +7,7 @@ module.exports = {
},
ledger: {
normal: require('./ledger'),
normalByHash: require('./ledger-by-hash'),
notFound: require('./ledger-not-found'),
withoutCloseTime: require('./ledger-without-close-time'),
withSettingsTx: require('./ledger-with-settings-tx'),

View File

@@ -0,0 +1,28 @@
{
"id":1,
"result": {
"ledger": {
"accepted": true,
"account_hash": "A155BFE86054BE654796EC449E7C374CD5CAA3789BA75D302E7F0F4CE470CCB3",
"close_flags": 0,
"close_time": 597496230,
"close_time_human": "2018-Dec-07 11:10:30.000000000",
"close_time_resolution": 10,
"closed": true,
"hash": "15F20E5FA6EA9770BBFFDBD62787400960B04BE32803B20C41F117F41C13830D",
"ledger_hash": "15F20E5FA6EA9770BBFFDBD62787400960B04BE32803B20C41F117F41C13830D",
"ledger_index": "14995338",
"parent_close_time": 597496222,
"parent_hash": "E0BC4F5FB8D9025087BE238664833DFA5658C9E7CE413B3B6F7DF4FFF1EDBF40",
"seqNum": "14995338",
"totalCoins": "99997114637345372",
"total_coins": "99997114637345372",
"transaction_hash": "52C0B6604D2EF203710FEA24F4A3750A4F2BCD5C67D6EB5FB1B2DBAE9A14DCE8"
},
"ledger_hash": "15F20E5FA6EA9770BBFFDBD62787400960B04BE32803B20C41F117F41C13830D",
"ledger_index": 14995338,
"validated": true
},
"status": "success",
"type": "response"
}

View File

@@ -268,6 +268,8 @@ module.exports = function createMockRippled(port) {
const response = _.assign({}, fixtures.ledger.normal,
{ result: { ledger: fullLedger } });
conn.send(createLedgerResponse(request, response));
} else if (request.ledger_hash === '15F20E5FA6EA9770BBFFDBD62787400960B04BE32803B20C41F117F41C13830D') {
conn.send(createLedgerResponse(request, fixtures.ledger.normalByHash));
} else if (request.ledger_index === 'validated' ||
request.ledger_index === 14661789 ||
request.ledger_index === 14661788 /* getTransaction - order */) {