mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 04:35:49 +00:00
change snake_case to camelCase in responses from api.submit and api.getServerInfo and add schema for it
This commit is contained in:
@@ -11,5 +11,6 @@ module.exports = {
|
||||
toRippledAmount: utils.toRippledAmount,
|
||||
wrapCatch: utils.wrapCatch,
|
||||
composeAsync: utils.composeAsync,
|
||||
convertExceptions: utils.convertExceptions
|
||||
convertExceptions: utils.convertExceptions,
|
||||
convertKeysFromSnakeCaseToCamelCase: utils.convertKeysFromSnakeCaseToCamelCase
|
||||
};
|
||||
|
||||
49
src/api/common/schemas/get-server-info.json
Normal file
49
src/api/common/schemas/get-server-info.json
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getServerInfo",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"buildVersion": {"type": "string"},
|
||||
"completeLedgers": {"type": "string", "pattern": "[0-9,-]+"},
|
||||
"hostid": {"type": "string"},
|
||||
"ioLatencyMs": {"type": "number"},
|
||||
"load": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"job_types": {
|
||||
"type": "array",
|
||||
"items": {"type": "object"}
|
||||
},
|
||||
"threads": {"type": "number"}
|
||||
}
|
||||
},
|
||||
"lastClose": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"convergeTimeS": {"type": "number"},
|
||||
"proposers": {"type": "integer", "minimum": 0}
|
||||
}
|
||||
},
|
||||
"loadFactor": {"type": "number"},
|
||||
"peers": {"type": "integer", "minimum": 0},
|
||||
"pubkeyNode": {"type": "string"},
|
||||
"pubkeyValidator": {"type": "string"},
|
||||
"serverState": {
|
||||
"type": "string",
|
||||
"enum": ["disconnected", "connected", "syncing", "tracking", "full", "validating", "proposing"]
|
||||
},
|
||||
"validatedLedger": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"age": {"type": "integer", "minimum": 0},
|
||||
"baseFeeXrp": {"type": "number"},
|
||||
"hash": {"$ref": "hash256"},
|
||||
"reserveBaseXrp": {"type": "integer", "minimum": 0},
|
||||
"reserveIncXrp": {"type": "integer", "minimum": 0},
|
||||
"seq": {"type": "integer", "minimum": 0}
|
||||
}
|
||||
},
|
||||
"validationQuorum": {"type": "number"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
15
src/api/common/schemas/submit.json
Normal file
15
src/api/common/schemas/submit.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "submit",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"success": {"type": "boolean"},
|
||||
"engineResult": {"type": "string"},
|
||||
"engineResultCode": {"type": "integer"},
|
||||
"engineResultMessage": {"type": "string"},
|
||||
"txBlob": {"type": "string"},
|
||||
"txJson": {"type": "object"}
|
||||
},
|
||||
"required": ["success", "engineResult", "engineResultCode"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
/* @flow */
|
||||
'use strict';
|
||||
const _ = require('lodash');
|
||||
const BigNumber = require('bignumber.js');
|
||||
const core = require('../../core');
|
||||
const errors = require('./errors');
|
||||
@@ -68,6 +69,22 @@ function convertExceptions<T>(f: () => T): () => T {
|
||||
};
|
||||
}
|
||||
|
||||
const FINDSNAKE = /([a-zA-Z]_[a-zA-Z])/g;
|
||||
function convertKeysFromSnakeCaseToCamelCase(obj: any): any {
|
||||
if (typeof obj === 'object') {
|
||||
let newKey;
|
||||
return _.reduce(obj, (result, value, key) => {
|
||||
newKey = key;
|
||||
if (FINDSNAKE.test(key)) {
|
||||
newKey = key.replace(FINDSNAKE, r => r[0] + r[2].toUpperCase());
|
||||
}
|
||||
result[newKey] = convertKeysFromSnakeCaseToCamelCase(value);
|
||||
return result;
|
||||
}, {});
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
core,
|
||||
dropsToXrp,
|
||||
@@ -75,5 +92,6 @@ module.exports = {
|
||||
toRippledAmount,
|
||||
wrapCatch,
|
||||
composeAsync,
|
||||
convertExceptions
|
||||
convertExceptions,
|
||||
convertKeysFromSnakeCaseToCamelCase
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ function getServerInfo(callback: (err: any, data: any) => void): void {
|
||||
const message = _.get(error, ['remote', 'error_message'], error.message);
|
||||
callback(new common.errors.RippledNetworkError(message));
|
||||
} else {
|
||||
callback(null, response.info);
|
||||
callback(null, common.convertKeysFromSnakeCaseToCamelCase(response.info));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ function submit(txBlob: string, callback: (err: any, data: any) => void): void {
|
||||
validate.blob(txBlob);
|
||||
const request = new Request(this.remote, 'submit');
|
||||
request.message.tx_blob = txBlob;
|
||||
request.request(null, callback);
|
||||
request.request(null,
|
||||
utils.common.composeAsync(
|
||||
data => utils.common.convertKeysFromSnakeCaseToCamelCase(data),
|
||||
callback));
|
||||
}
|
||||
|
||||
module.exports = submit;
|
||||
|
||||
@@ -162,7 +162,7 @@ describe('RippleAPI', function() {
|
||||
|
||||
it('submit', function(done) {
|
||||
this.api.submit(responses.sign.signedTransaction,
|
||||
_.partial(checkResult, responses.submit, null, done));
|
||||
_.partial(checkResult, responses.submit, 'submit', done));
|
||||
});
|
||||
|
||||
it('getBalances', function(done) {
|
||||
@@ -478,7 +478,7 @@ describe('RippleAPI', function() {
|
||||
|
||||
it('getServerInfo', function(done) {
|
||||
this.api.getServerInfo(
|
||||
_.partial(checkResult, responses.getServerInfo, null, done));
|
||||
_.partial(checkResult, responses.getServerInfo, 'getServerInfo', done));
|
||||
});
|
||||
|
||||
it('getServerInfo - error', function(done) {
|
||||
|
||||
24
test/fixtures/api/responses/get-server-info.json
vendored
24
test/fixtures/api/responses/get-server-info.json
vendored
@@ -1,22 +1,22 @@
|
||||
{
|
||||
"build_version": "0.24.0-rc1",
|
||||
"complete_ledgers": "32570-6595042",
|
||||
"buildVersion": "0.24.0-rc1",
|
||||
"completeLedgers": "32570-6595042",
|
||||
"hostid": "ARTS",
|
||||
"last_close": {
|
||||
"converge_time_s": 2.007,
|
||||
"lastClose": {
|
||||
"convergeTimeS": 2.007,
|
||||
"proposers": 4
|
||||
},
|
||||
"load_factor": 1,
|
||||
"loadFactor": 1,
|
||||
"peers": 53,
|
||||
"pubkey_node": "n94wWvFUmaKGYrKUGgpv1DyYgDeXRGdACkNQaSe7zJiy5Znio7UC",
|
||||
"server_state": "full",
|
||||
"validated_ledger": {
|
||||
"pubkeyNode": "n94wWvFUmaKGYrKUGgpv1DyYgDeXRGdACkNQaSe7zJiy5Znio7UC",
|
||||
"serverState": "full",
|
||||
"validatedLedger": {
|
||||
"age": 5,
|
||||
"base_fee_xrp": 0.00001,
|
||||
"baseFeeXrp": 0.00001,
|
||||
"hash": "4482DEE5362332F54A4036ED57EE1767C9F33CF7CE5A6670355C16CECE381D46",
|
||||
"reserve_base_xrp": 20,
|
||||
"reserve_inc_xrp": 5,
|
||||
"reserveBaseXrp": 20,
|
||||
"reserveIncXrp": 5,
|
||||
"seq": 6595042
|
||||
},
|
||||
"validation_quorum": 3
|
||||
"validationQuorum": 3
|
||||
}
|
||||
|
||||
10
test/fixtures/api/responses/submit.json
vendored
10
test/fixtures/api/responses/submit.json
vendored
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"success": true,
|
||||
"engine_result": "tesSUCCESS",
|
||||
"engine_result_code": 0,
|
||||
"engine_result_message": "The transaction was applied. Only final in a validated ledger.",
|
||||
"tx_blob": "12000322000000002400000017201B0086955468400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D87446304402207660BDEF67105CE1EBA9AD35DC7156BAB43FF1D47633199EE257D70B6B9AAFBF02207F5517BC8AEF2ADC1325897ECDBA8C673838048BCA62F4E98B252F19BE88796D770A726970706C652E636F6D81144FBFF73DA4ECF9B701940F27341FA8020C313443",
|
||||
"tx_json": {}
|
||||
"engineResult": "tesSUCCESS",
|
||||
"engineResultCode": 0,
|
||||
"engineResultMessage": "The transaction was applied. Only final in a validated ledger.",
|
||||
"txBlob": "12000322000000002400000017201B0086955468400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D87446304402207660BDEF67105CE1EBA9AD35DC7156BAB43FF1D47633199EE257D70B6B9AAFBF02207F5517BC8AEF2ADC1325897ECDBA8C673838048BCA62F4E98B252F19BE88796D770A726970706C652E636F6D81144FBFF73DA4ECF9B701940F27341FA8020C313443",
|
||||
"txJson": {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user