mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-22 05:05:48 +00:00
Add schemas for options for each ledger request
This commit is contained in:
@@ -1,32 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
||||||
"title": "options",
|
|
||||||
"description": "Options for a ledger request",
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"currency": {"$ref": "currency"},
|
|
||||||
"counterparty": {"$ref": "address"},
|
|
||||||
"limit": {
|
|
||||||
"type": "integer",
|
|
||||||
"minimum": 1
|
|
||||||
},
|
|
||||||
"ledgerHash": {
|
|
||||||
"type": "string",
|
|
||||||
"format": "ledgerHash"
|
|
||||||
},
|
|
||||||
"ledgerVersion": {"$ref": "ledgerVersion"},
|
|
||||||
"minLedgerVersion": {"$ref": "ledgerVersion"},
|
|
||||||
"maxLedgerVersion": {"$ref": "ledgerVersion"},
|
|
||||||
"marker": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"additionalProperties": false,
|
|
||||||
"dependencies": {
|
|
||||||
"marker": ["ledgerVersion"]
|
|
||||||
},
|
|
||||||
"not": {
|
|
||||||
"description": "Fixed fee and max fee are mutually exclusive",
|
|
||||||
"required": ["fee", "maxFee"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
14
src/api/common/schemas/orders-options.json
Normal file
14
src/api/common/schemas/orders-options.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "orders-options",
|
||||||
|
"description": "Options for getOrders and getOrderbook",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"limit": {
|
||||||
|
"type": "integer",
|
||||||
|
"minimum": 1
|
||||||
|
},
|
||||||
|
"ledgerVersion": {"$ref": "ledgerVersion"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
10
src/api/common/schemas/settings-options.json
Normal file
10
src/api/common/schemas/settings-options.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "settings-options",
|
||||||
|
"description": "Options for getSettings",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"ledgerVersion": {"$ref": "ledgerVersion"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
11
src/api/common/schemas/transaction-options.json
Normal file
11
src/api/common/schemas/transaction-options.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "transaction-options",
|
||||||
|
"description": "Options for getTransaction",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"minLedgerVersion": {"$ref": "ledgerVersion"},
|
||||||
|
"maxLedgerVersion": {"$ref": "ledgerVersion"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"title": "acct-tx-options",
|
"title": "transactions-options",
|
||||||
"description": "Options for getTransactions",
|
"description": "Options for getTransactions",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
16
src/api/common/schemas/trustlines-options.json
Normal file
16
src/api/common/schemas/trustlines-options.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"title": "trustlines-options",
|
||||||
|
"description": "Options for getTrustlines and getBalances",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"counterparty": {"$ref": "address"},
|
||||||
|
"currency": {"$ref": "currency"},
|
||||||
|
"limit": {
|
||||||
|
"type": "integer",
|
||||||
|
"minimum": 1
|
||||||
|
},
|
||||||
|
"ledgerVersion": {"$ref": "ledgerVersion"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
@@ -52,7 +52,13 @@ module.exports = {
|
|||||||
trustline: _.partial(schemaValidate, 'trustline'),
|
trustline: _.partial(schemaValidate, 'trustline'),
|
||||||
txJSON: _.partial(schemaValidate, 'tx'),
|
txJSON: _.partial(schemaValidate, 'tx'),
|
||||||
blob: _.partial(schemaValidate, 'blob'),
|
blob: _.partial(schemaValidate, 'blob'),
|
||||||
getTransactionsOptions: _.partial(validateOptions, 'acct-tx-options'),
|
getTransactionsOptions: _.partial(validateOptions, 'transactions-options'),
|
||||||
|
getSettingsOptions: _.partial(validateOptions, 'settings-options'),
|
||||||
|
getTrustlinesOptions: _.partial(validateOptions, 'trustlines-options'),
|
||||||
|
getBalancesOptions: _.partial(validateOptions, 'trustlines-options'),
|
||||||
|
getOrdersOptions: _.partial(validateOptions, 'orders-options'),
|
||||||
|
getOrderbookOptions: _.partial(validateOptions, 'orders-options'),
|
||||||
|
getTransactionOptions: _.partial(validateOptions, 'transaction-options'),
|
||||||
options: _.partial(validateOptions, 'options'),
|
options: _.partial(validateOptions, 'options'),
|
||||||
instructions: _.partial(schemaValidate, 'instructions')
|
instructions: _.partial(schemaValidate, 'instructions')
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ function formatBalances(balances) {
|
|||||||
|
|
||||||
function getBalances(account, options, callback) {
|
function getBalances(account, options, callback) {
|
||||||
validate.address(account);
|
validate.address(account);
|
||||||
validate.options(options);
|
validate.getBalancesOptions(options);
|
||||||
|
|
||||||
const ledgerVersion = options.ledgerVersion
|
const ledgerVersion = options.ledgerVersion
|
||||||
|| this.remote.getLedgerSequence();
|
|| this.remote.getLedgerSequence();
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ function formatBidsAndAsks(orderbook, offers) {
|
|||||||
function getOrderbook(account, orderbook, options, callback) {
|
function getOrderbook(account, orderbook, options, callback) {
|
||||||
validate.address(account);
|
validate.address(account);
|
||||||
validate.orderbook(orderbook);
|
validate.orderbook(orderbook);
|
||||||
validate.options(options);
|
validate.getOrderbookOptions(options);
|
||||||
|
|
||||||
const getter = _.partial(getBookOffers, this.remote, account,
|
const getter = _.partial(getBookOffers, this.remote, account,
|
||||||
options.ledgerVersion, options.limit);
|
options.ledgerVersion, options.limit);
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ function requestAccountOffers(remote, address, ledgerVersion, options,
|
|||||||
}), callback));
|
}), callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAccountOrders(account, options, callback) {
|
function getOrders(account, options, callback) {
|
||||||
validate.address(account);
|
validate.address(account);
|
||||||
validate.options(options);
|
validate.getOrdersOptions(options);
|
||||||
|
|
||||||
const defaultLimit = 100;
|
const defaultLimit = 100;
|
||||||
const limit = options.limit || defaultLimit;
|
const limit = options.limit || defaultLimit;
|
||||||
@@ -34,4 +34,4 @@ function getAccountOrders(account, options, callback) {
|
|||||||
(order) => order.properties.sequence), callback));
|
(order) => order.properties.sequence), callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = utils.wrapCatch(getAccountOrders);
|
module.exports = utils.wrapCatch(getOrders);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ function formatSettings(response) {
|
|||||||
|
|
||||||
function getSettings(account, options, callback) {
|
function getSettings(account, options, callback) {
|
||||||
validate.address(account);
|
validate.address(account);
|
||||||
validate.options(options);
|
validate.getSettingsOptions(options);
|
||||||
|
|
||||||
const request = {
|
const request = {
|
||||||
account: account,
|
account: account,
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ function isTransactionInRange(tx, options) {
|
|||||||
|
|
||||||
function getTransaction(identifier, options, callback) {
|
function getTransaction(identifier, options, callback) {
|
||||||
validate.identifier(identifier);
|
validate.identifier(identifier);
|
||||||
validate.options(options);
|
validate.getTransactionOptions(options);
|
||||||
|
|
||||||
const remote = this.remote;
|
const remote = this.remote;
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ function getTrustlines(
|
|||||||
callback: () => void
|
callback: () => void
|
||||||
): void {
|
): void {
|
||||||
validate.address(account);
|
validate.address(account);
|
||||||
validate.options(options);
|
validate.getTrustlinesOptions(options);
|
||||||
|
|
||||||
const defaultLimit = 100;
|
const defaultLimit = 100;
|
||||||
const limit = options.limit || defaultLimit;
|
const limit = options.limit || defaultLimit;
|
||||||
|
|||||||
Reference in New Issue
Block a user