mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Organize JSON schemas for documentation generation
This commit is contained in:
@@ -17,5 +17,6 @@ module.exports = {
|
||||
convertKeysFromSnakeCaseToCamelCase:
|
||||
utils.convertKeysFromSnakeCaseToCamelCase,
|
||||
iso8601ToRippleTime: utils.iso8601ToRippleTime,
|
||||
rippleTimeToISO8601: utils.rippleTimeToISO8601
|
||||
rippleTimeToISO8601: utils.rippleTimeToISO8601,
|
||||
isValidSecret: utils.isValidSecret
|
||||
};
|
||||
|
||||
@@ -6,79 +6,93 @@ const assert = require('assert');
|
||||
const Ajv = require('ajv');
|
||||
const ValidationError = require('./errors').ValidationError;
|
||||
const {isValidAddress} = require('ripple-address-codec');
|
||||
const {isValidSecret} = require('./utils');
|
||||
|
||||
function loadSchemas() {
|
||||
// listed explicitly for webpack (instead of scanning schemas directory)
|
||||
const schemas = [
|
||||
require('./schemas/objects/address.json'),
|
||||
require('./schemas/objects/adjustment.json'),
|
||||
require('./schemas/objects/amount.json'),
|
||||
require('./schemas/objects/amount-base.json'),
|
||||
require('./schemas/objects/balance.json'),
|
||||
require('./schemas/objects/blob.json'),
|
||||
require('./schemas/objects/currency.json'),
|
||||
require('./schemas/output/get-account-info.json'),
|
||||
require('./schemas/output/get-balances.json'),
|
||||
require('./schemas/output/get-balance-sheet'),
|
||||
require('./schemas/input/balance-sheet-options.json'),
|
||||
require('./schemas/output/get-ledger.json'),
|
||||
require('./schemas/output/get-orderbook.json'),
|
||||
require('./schemas/output/get-orders.json'),
|
||||
require('./schemas/output/get-paths.json'),
|
||||
require('./schemas/output/get-server-info.json'),
|
||||
require('./schemas/output/get-settings.json'),
|
||||
require('./schemas/output/get-transaction.json'),
|
||||
require('./schemas/output/get-transactions.json'),
|
||||
require('./schemas/output/get-trustlines.json'),
|
||||
require('./schemas/objects/tx-json.json'),
|
||||
require('./schemas/objects/hash128.json'),
|
||||
require('./schemas/objects/hash256.json'),
|
||||
require('./schemas/input/instructions.json'),
|
||||
require('./schemas/objects/sequence.json'),
|
||||
require('./schemas/objects/issue.json'),
|
||||
require('./schemas/input/ledger-options.json'),
|
||||
require('./schemas/objects/ledgerversion.json'),
|
||||
require('./schemas/objects/max-adjustment.json'),
|
||||
require('./schemas/objects/memo.json'),
|
||||
require('./schemas/output/order-cancellation-transaction.json'),
|
||||
require('./schemas/input/order-cancellation.json'),
|
||||
require('./schemas/output/order-change.json'),
|
||||
require('./schemas/output/order-transaction.json'),
|
||||
require('./schemas/input/order.json'),
|
||||
require('./schemas/output/orderbook-orders.json'),
|
||||
require('./schemas/input/orderbook.json'),
|
||||
require('./schemas/input/orders-options.json'),
|
||||
require('./schemas/output/outcome.json'),
|
||||
require('./schemas/input/pathfind.json'),
|
||||
require('./schemas/output/payment-transaction.json'),
|
||||
require('./schemas/input/payment.json'),
|
||||
require('./schemas/objects/quality.json'),
|
||||
require('./schemas/input/api-options.json'),
|
||||
require('./schemas/objects/sequence.json'),
|
||||
require('./schemas/input/settings-options.json'),
|
||||
require('./schemas/output/settings-transaction.json'),
|
||||
require('./schemas/input/settings.json'),
|
||||
require('./schemas/output/sign.json'),
|
||||
require('./schemas/objects/signed-value.json'),
|
||||
require('./schemas/output/submit.json'),
|
||||
require('./schemas/input/suspended-payment-cancellation.json'),
|
||||
require('./schemas/input/suspended-payment-execution.json'),
|
||||
require('./schemas/input/suspended-payment-creation.json'),
|
||||
require('./schemas/input/transaction-options.json'),
|
||||
require('./schemas/input/transactions-options.json'),
|
||||
require('./schemas/output/trustline-transaction.json'),
|
||||
require('./schemas/input/trustline.json'),
|
||||
require('./schemas/input/trustlines-options.json'),
|
||||
require('./schemas/objects/tx-json.json'),
|
||||
require('./schemas/objects/uint32.json'),
|
||||
require('./schemas/objects/value.json'),
|
||||
require('./schemas/output/prepare.json'),
|
||||
require('./schemas/output/ledger-closed.json'),
|
||||
require('./schemas/objects/source-adjustment.json'),
|
||||
require('./schemas/objects/destination-adjustment.json'),
|
||||
require('./schemas/objects/tag.json'),
|
||||
require('./schemas/objects/lax-amount.json'),
|
||||
require('./schemas/objects/lax-lax-amount.json'),
|
||||
require('./schemas/objects/min-adjustment.json'),
|
||||
require('./schemas/objects/lax-adjustment.json')
|
||||
require('./schemas/objects/lax-adjustment.json'),
|
||||
require('./schemas/objects/tx-hash.json'),
|
||||
require('./schemas/objects/address.json'),
|
||||
require('./schemas/objects/adjustment.json'),
|
||||
require('./schemas/objects/quality.json'),
|
||||
require('./schemas/objects/amount.json'),
|
||||
require('./schemas/objects/amount-base.json'),
|
||||
require('./schemas/objects/balance.json'),
|
||||
require('./schemas/objects/blob.json'),
|
||||
require('./schemas/objects/currency.json'),
|
||||
require('./schemas/objects/signed-value.json'),
|
||||
require('./schemas/objects/orderbook.json'),
|
||||
require('./schemas/objects/instructions.json'),
|
||||
require('./schemas/specifications/settings.json'),
|
||||
require('./schemas/specifications/payment.json'),
|
||||
require('./schemas/specifications/suspended-payment-cancellation.json'),
|
||||
require('./schemas/specifications/order-cancellation.json'),
|
||||
require('./schemas/specifications/order.json'),
|
||||
require('./schemas/specifications/suspended-payment-execution.json'),
|
||||
require('./schemas/specifications/suspended-payment-creation.json'),
|
||||
require('./schemas/specifications/trustline.json'),
|
||||
require('./schemas/output/sign.json'),
|
||||
require('./schemas/output/submit.json'),
|
||||
require('./schemas/output/get-account-info.json'),
|
||||
require('./schemas/output/get-balances.json'),
|
||||
require('./schemas/output/get-balance-sheet'),
|
||||
require('./schemas/output/get-ledger.json'),
|
||||
require('./schemas/output/get-orderbook.json'),
|
||||
require('./schemas/output/settings-transaction.json'),
|
||||
require('./schemas/output/get-orders.json'),
|
||||
require('./schemas/output/order-change.json'),
|
||||
require('./schemas/output/order-cancellation-transaction.json'),
|
||||
require('./schemas/output/prepare.json'),
|
||||
require('./schemas/output/ledger-closed.json'),
|
||||
require('./schemas/output/order-transaction.json'),
|
||||
require('./schemas/output/get-paths.json'),
|
||||
require('./schemas/output/trustline-transaction.json'),
|
||||
require('./schemas/output/get-server-info.json'),
|
||||
require('./schemas/output/get-settings.json'),
|
||||
require('./schemas/output/orderbook-orders.json'),
|
||||
require('./schemas/output/payment-transaction.json'),
|
||||
require('./schemas/output/outcome.json'),
|
||||
require('./schemas/output/get-transaction.json'),
|
||||
require('./schemas/output/get-transactions.json'),
|
||||
require('./schemas/output/get-trustlines.json'),
|
||||
require('./schemas/input/get-balance-sheet.json'),
|
||||
require('./schemas/input/get-ledger.json'),
|
||||
require('./schemas/input/get-orders.json'),
|
||||
require('./schemas/input/get-orderbook.json'),
|
||||
require('./schemas/input/get-paths.json'),
|
||||
require('./schemas/input/api-options.json'),
|
||||
require('./schemas/input/get-settings.json'),
|
||||
require('./schemas/input/get-transaction.json'),
|
||||
require('./schemas/input/get-transactions.json'),
|
||||
require('./schemas/input/get-trustlines.json'),
|
||||
require('./schemas/input/prepare-payment.json'),
|
||||
require('./schemas/input/prepare-order.json'),
|
||||
require('./schemas/input/prepare-trustline.json'),
|
||||
require('./schemas/input/prepare-order-cancellation.json'),
|
||||
require('./schemas/input/prepare-settings.json'),
|
||||
require('./schemas/input/prepare-suspended-payment-creation.json'),
|
||||
require('./schemas/input/prepare-suspended-payment-cancellation.json'),
|
||||
require('./schemas/input/prepare-suspended-payment-execution.json'),
|
||||
require('./schemas/input/compute-ledger-hash'),
|
||||
require('./schemas/input/sign'),
|
||||
require('./schemas/input/submit')
|
||||
];
|
||||
const titles = _.map(schemas, schema => schema.title);
|
||||
const duplicates = _.keys(_.pick(_.countBy(titles), count => count > 1));
|
||||
@@ -86,6 +100,7 @@ function loadSchemas() {
|
||||
const ajv = new Ajv();
|
||||
_.forEach(schemas, schema => ajv.addSchema(schema, schema.title));
|
||||
ajv.addFormat('address', isValidAddress);
|
||||
ajv.addFormat('secret', isValidSecret);
|
||||
return ajv;
|
||||
}
|
||||
|
||||
@@ -99,5 +114,6 @@ function schemaValidate(schemaName: string, object: any): void {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
schemaValidate
|
||||
schemaValidate,
|
||||
isValidSecret
|
||||
};
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "balance-sheet-options",
|
||||
"description": "Options for getBalanceSheet",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"excludeAddresses": {
|
||||
"type": "array",
|
||||
"items": {"$ref": "address"},
|
||||
"uniqueItems": true
|
||||
},
|
||||
"ledgerVersion": {"$ref": "ledgerVersion"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
10
src/common/schemas/input/compute-ledger-hash.json
Normal file
10
src/common/schemas/input/compute-ledger-hash.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "computeLedgerHashParameters",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ledger": {"$ref": "getLedger"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["ledger"]
|
||||
}
|
||||
22
src/common/schemas/input/get-balance-sheet.json
Normal file
22
src/common/schemas/input/get-balance-sheet.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getBalanceSheetParameters",
|
||||
"description": "Parameters for getBalanceSheet",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"options": {
|
||||
"properties": {
|
||||
"excludeAddresses": {
|
||||
"type": "array",
|
||||
"items": {"$ref": "address"},
|
||||
"uniqueItems": true
|
||||
},
|
||||
"ledgerVersion": {"$ref": "ledgerVersion"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["address"]
|
||||
}
|
||||
18
src/common/schemas/input/get-ledger.json
Normal file
18
src/common/schemas/input/get-ledger.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getLedgerParameters",
|
||||
"description": "Parameters for getLedger",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"options": {
|
||||
"properties": {
|
||||
"ledgerVersion": {"$ref": "ledgerVersion"},
|
||||
"includeAllData": {"type": "boolean"},
|
||||
"includeTransactions": {"type": "boolean"},
|
||||
"includeState": {"type": "boolean"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
25
src/common/schemas/input/get-orderbook.json
Normal file
25
src/common/schemas/input/get-orderbook.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getOrderbookParameters",
|
||||
"description": "Parameters for getOrderbook",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {
|
||||
"$ref": "address",
|
||||
"description": "Address of an account to use as point-of-view. (This affects which unfunded offers are returned.)"
|
||||
},
|
||||
"orderbook": {"$ref": "orderbook"},
|
||||
"options": {
|
||||
"properties": {
|
||||
"limit": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
},
|
||||
"ledgerVersion": {"$ref": "ledgerVersion"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": ["address", "orderbook"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
21
src/common/schemas/input/get-orders.json
Normal file
21
src/common/schemas/input/get-orders.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getOrdersParameters",
|
||||
"description": "Parameters for getOrders",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"options": {
|
||||
"properties": {
|
||||
"limit": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
},
|
||||
"ledgerVersion": {"$ref": "ledgerVersion"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": ["address"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
49
src/common/schemas/input/get-paths.json
Normal file
49
src/common/schemas/input/get-paths.json
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getPathsParameters",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"pathfind": {
|
||||
"properties": {
|
||||
"source": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"amount": {"$ref": "laxAmount"},
|
||||
"currencies": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"currency": {"$ref": "currency"},
|
||||
"counterparty": {"$ref": "address"}
|
||||
},
|
||||
"required": ["currency"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
"not": {
|
||||
"required": ["amount", "currencies"]
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["address"]
|
||||
},
|
||||
"destination": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"amount": {"$ref": "laxLaxAmount"}
|
||||
},
|
||||
"required": ["address", "amount"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": ["source", "destination"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["pathfind"]
|
||||
}
|
||||
17
src/common/schemas/input/get-settings.json
Normal file
17
src/common/schemas/input/get-settings.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getSettingsParameters",
|
||||
"description": "Parameters for getSettings and getAccountInfo",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"options": {
|
||||
"properties": {
|
||||
"ledgerVersion": {"$ref": "ledgerVersion"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": ["address"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
18
src/common/schemas/input/get-transaction.json
Normal file
18
src/common/schemas/input/get-transaction.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getTransactionParameters",
|
||||
"description": "Parameters for getTransaction",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"identifier": {"$ref": "identifier"},
|
||||
"options": {
|
||||
"properties": {
|
||||
"minLedgerVersion": {"$ref": "ledgerVersion"},
|
||||
"maxLedgerVersion": {"$ref": "ledgerVersion"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["identifier"]
|
||||
}
|
||||
46
src/common/schemas/input/get-transactions.json
Normal file
46
src/common/schemas/input/get-transactions.json
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getTransactionsParameters",
|
||||
"description": "Parameters for getTransactions",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"options": {
|
||||
"properties": {
|
||||
"start": {"$ref": "hash256"},
|
||||
"limit": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
},
|
||||
"minLedgerVersion": {"$ref": "ledgerVersion"},
|
||||
"maxLedgerVersion": {"$ref": "ledgerVersion"},
|
||||
"earliestFirst": {"type": "boolean"},
|
||||
"excludeFailures": {"type": "boolean"},
|
||||
"initiated": {"type": "boolean"},
|
||||
"counterparty": {"$ref": "address"},
|
||||
"types": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"enum": [
|
||||
"payment",
|
||||
"trustline",
|
||||
"order",
|
||||
"orderCancellation",
|
||||
"settings"
|
||||
]
|
||||
}
|
||||
},
|
||||
"binary": {"type": "boolean"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"not": {
|
||||
"anyOf": [
|
||||
{"required": ["start", "minLedgerVersion"]},
|
||||
{"required": ["start", "maxLedgerVersion"]}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["address"]
|
||||
}
|
||||
23
src/common/schemas/input/get-trustlines.json
Normal file
23
src/common/schemas/input/get-trustlines.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getTrustlinesParameters",
|
||||
"description": "Parameters for getTrustlines and getBalances",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"options": {
|
||||
"properties": {
|
||||
"counterparty": {"$ref": "address"},
|
||||
"currency": {"$ref": "currency"},
|
||||
"limit": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
},
|
||||
"ledgerVersion": {"$ref": "ledgerVersion"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["address"]
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "ledger-options",
|
||||
"description": "Options for getLedger",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ledgerVersion": {"$ref": "ledgerVersion"},
|
||||
"includeAllData": {"type": "boolean"},
|
||||
"includeTransactions": {"type": "boolean"},
|
||||
"includeState": {"type": "boolean"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"$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
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "pathfind",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"source": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"amount": {"$ref": "laxAmount"},
|
||||
"currencies": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"currency": {"$ref": "currency"},
|
||||
"counterparty": {"$ref": "address"}
|
||||
},
|
||||
"required": ["currency"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"uniqueItems": true
|
||||
},
|
||||
"not": {
|
||||
"required": ["amount", "currencies"]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["address"]
|
||||
},
|
||||
"destination": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"amount": {"$ref": "laxLaxAmount"}
|
||||
},
|
||||
"required": ["address", "amount"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"required": ["source", "destination"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
12
src/common/schemas/input/prepare-order-cancellation.json
Normal file
12
src/common/schemas/input/prepare-order-cancellation.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "prepareOrderCancellationParameters",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"sequence": {"$ref": "sequence"},
|
||||
"instructions": {"$ref": "instructions"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["address", "sequence"]
|
||||
}
|
||||
12
src/common/schemas/input/prepare-order.json
Normal file
12
src/common/schemas/input/prepare-order.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "prepareOrderParameters",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"order": {"$ref": "order"},
|
||||
"instructions": {"$ref": "instructions"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["address", "order"]
|
||||
}
|
||||
12
src/common/schemas/input/prepare-payment.json
Normal file
12
src/common/schemas/input/prepare-payment.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "preparePaymentParameters",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"payment": {"$ref": "payment"},
|
||||
"instructions": {"$ref": "instructions"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["address", "payment"]
|
||||
}
|
||||
12
src/common/schemas/input/prepare-settings.json
Normal file
12
src/common/schemas/input/prepare-settings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "prepareSettingsParameters",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"settings": {"$ref": "settings"},
|
||||
"instructions": {"$ref": "instructions"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["address", "settings"]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "prepareSuspendedPaymentCancellationParameters",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"suspendedPaymentCancellation": {"$ref": "suspendedPaymentCancellation"},
|
||||
"instructions": {"$ref": "instructions"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["address", "suspendedPaymentCancellation"]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "prepareSuspendedPaymentCreationParameters",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"suspendedPaymentCreation": {"$ref": "suspendedPaymentCreation"},
|
||||
"instructions": {"$ref": "instructions"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["address", "suspendedPaymentCreation"]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "prepareSuspendedPaymentExecutionParameters",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"suspendedPaymentExecution": {"$ref": "suspendedPaymentExecution"},
|
||||
"instructions": {"$ref": "instructions"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["address", "suspendedPaymentExecution"]
|
||||
}
|
||||
12
src/common/schemas/input/prepare-trustline.json
Normal file
12
src/common/schemas/input/prepare-trustline.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "prepareTrustlineParameters",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"address": {"$ref": "address"},
|
||||
"trustline": {"$ref": "trustline"},
|
||||
"instructions": {"$ref": "instructions"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["address", "trustline"]
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "settings-options",
|
||||
"description": "Options for getSettings and getAccountInfo",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ledgerVersion": {"$ref": "ledgerVersion"}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
18
src/common/schemas/input/sign.json
Normal file
18
src/common/schemas/input/sign.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "signParameters",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"txJSON": {
|
||||
"type": "string",
|
||||
"description": "Transaction represented as a JSON string in rippled format."
|
||||
},
|
||||
"secret": {
|
||||
"type": "string",
|
||||
"format": "secret",
|
||||
"description": "The secret of the account that is initiating the transaction."
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["txJSON", "secret"]
|
||||
}
|
||||
10
src/common/schemas/input/submit.json
Normal file
10
src/common/schemas/input/submit.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "submitParameters",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"txBlob": {"$ref": "blob"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": ["txBlob"]
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"$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,40 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "transactions-options",
|
||||
"description": "Options for getTransactions",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"start": {"$ref": "hash256"},
|
||||
"limit": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
},
|
||||
"minLedgerVersion": {"$ref": "ledgerVersion"},
|
||||
"maxLedgerVersion": {"$ref": "ledgerVersion"},
|
||||
"earliestFirst": {"type": "boolean"},
|
||||
"excludeFailures": {"type": "boolean"},
|
||||
"initiated": {"type": "boolean"},
|
||||
"counterparty": {"$ref": "address"},
|
||||
"types": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"enum": [
|
||||
"payment",
|
||||
"trustline",
|
||||
"order",
|
||||
"orderCancellation",
|
||||
"settings"
|
||||
]
|
||||
}
|
||||
},
|
||||
"binary": {"type": "boolean"}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"not": {
|
||||
"anyOf": [
|
||||
{"required": ["incoming", "outgoing"]},
|
||||
{"required": ["start", "minLedgerVersion"]},
|
||||
{"required": ["start", "maxLedgerVersion"]}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"$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
|
||||
}
|
||||
@@ -4,5 +4,6 @@
|
||||
"description": "A Ripple account address",
|
||||
"type": "string",
|
||||
"format": "address",
|
||||
"link": "ripple-address",
|
||||
"pattern": "^r[1-9A-HJ-NP-Za-km-z]{25,34}$"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "amount",
|
||||
"link": "amount",
|
||||
"description": "An Amount on the Ripple Protocol, used also for XRP in the ripple-rest API",
|
||||
"allOf": [
|
||||
{"$ref": "amountbase"},
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "balance",
|
||||
"description": "Balance amount",
|
||||
"link": "amount",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"value": {
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
"title": "currency",
|
||||
"description": "The three-character code or hex string used to denote currencies",
|
||||
"type": "string",
|
||||
"link": "currency",
|
||||
"pattern": "^([a-zA-Z0-9<>(){}[\\]|?!@#$%^&*]{3}|[A-F0-9]{40})$"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "instructions",
|
||||
"link": "transaction-instructions",
|
||||
"description": "Instructions for executing a transaction",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -2,6 +2,7 @@
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "laxAmount",
|
||||
"description": "Amount where counterparty is optional",
|
||||
"link": "amount",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"currency": {"$ref": "currency"},
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "laxLaxAmount",
|
||||
"description": "Amount where counterparty and value are optional",
|
||||
"link": "amount",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"currency": {"$ref": "currency"},
|
||||
|
||||
8
src/common/schemas/objects/tx-hash.json
Normal file
8
src/common/schemas/objects/tx-hash.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "identifier",
|
||||
"link": "transaction-identifier",
|
||||
"description": "A hash of a transaction used to identify the transaction, represented in hexadecimal.",
|
||||
"type": "string",
|
||||
"pattern": "^[A-F0-9]{64}$"
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "tx",
|
||||
"link": "https://ripple.com/build/transactions/",
|
||||
"description": "An object in rippled txJSON format",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -3,47 +3,117 @@
|
||||
"title": "getServerInfo",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"buildVersion": {"type": "string"},
|
||||
"completeLedgers": {"type": "string", "pattern": "[0-9,-]+"},
|
||||
"hostid": {"type": "string"},
|
||||
"ioLatencyMs": {"type": "number"},
|
||||
"buildVersion": {
|
||||
"type": "string",
|
||||
"description": "The version number of the running rippled version."
|
||||
},
|
||||
"completeLedgers": {
|
||||
"type": "string",
|
||||
"pattern": "[0-9,-]+",
|
||||
"description": "Range expression indicating the sequence numbers of the ledger versions the local rippled has in its database. It is possible to be a disjoint sequence, e.g. “2500-5000,32570-7695432”."
|
||||
},
|
||||
"hostid": {
|
||||
"type": "string",
|
||||
"description": "On an admin request, returns the hostname of the server running the rippled instance; otherwise, returns a unique four letter word."
|
||||
},
|
||||
"ioLatencyMs": {
|
||||
"type": "number",
|
||||
"description": "Amount of time spent waiting for I/O operations to be performed, in milliseconds. If this number is not very, very low, then the rippled server is probably having serious load issues."
|
||||
},
|
||||
"load": {
|
||||
"type": "object",
|
||||
"description": "*(Admin only)* Detailed information about the current load state of the server.",
|
||||
"properties": {
|
||||
"jobTypes": {
|
||||
"type": "array",
|
||||
"description": "*(Admin only)* Information about the rate of different types of jobs being performed by the server and how much time it spends on each.",
|
||||
"items": {"type": "object"}
|
||||
},
|
||||
"threads": {"type": "number"}
|
||||
"threads": {
|
||||
"type": "number",
|
||||
"description": "*(Admin only)* The number of threads in the server’s main job pool, performing various Ripple Network operations."
|
||||
}
|
||||
},
|
||||
"required": ["jobTypes", "threads"]
|
||||
},
|
||||
"lastClose": {
|
||||
"type": "object",
|
||||
"description": "Information about the last time the server closed a ledger.",
|
||||
"properties": {
|
||||
"convergeTimeS": {"type": "number"},
|
||||
"proposers": {"type": "integer", "minimum": 0}
|
||||
}
|
||||
"convergeTimeS": {
|
||||
"type": "number",
|
||||
"description": "The time it took to reach a consensus for the last ledger closing."
|
||||
},
|
||||
"proposers": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"description": "Number of trusted validators participating in the ledger closing."}
|
||||
},
|
||||
"required": ["convergeTimeS", "proposers"]
|
||||
},
|
||||
"loadFactor": {
|
||||
"type": "number",
|
||||
"description": "The load factor the server is currently enforcing, as a multiplier on the base transaction fee. The load factor is determined by the highest of the individual server’s load factor, cluster’s load factor, and the overall network’s load factor."
|
||||
},
|
||||
"peers": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"description": "How many other rippled servers the node is currently connected to."
|
||||
},
|
||||
"pubkeyNode": {
|
||||
"type": "string",
|
||||
"description": "Public key used to verify this node for internal communications; this key is automatically generated by the server the first time it starts up. (If deleted, the node can just create a new pair of keys.)"
|
||||
},
|
||||
"pubkeyValidator": {
|
||||
"type": "string",
|
||||
"description": "*(Admin only)* Public key used by this node to sign ledger validations."
|
||||
},
|
||||
"loadFactor": {"type": "number"},
|
||||
"peers": {"type": "integer", "minimum": 0},
|
||||
"pubkeyNode": {"type": "string"},
|
||||
"pubkeyValidator": {"type": "string"},
|
||||
"serverState": {
|
||||
"type": "string",
|
||||
"description": "A string indicating to what extent the server is participating in the network. See [Possible Server States](https://ripple.com/build/rippled-apis/#possible-server-states) for more details.",
|
||||
"enum": ["disconnected", "connected", "syncing", "tracking", "full", "validating", "proposing"]
|
||||
},
|
||||
"validatedLedger": {
|
||||
"type": "object",
|
||||
"description": "Information about the fully-validated ledger with the highest sequence number (the most recent).",
|
||||
"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}
|
||||
"age": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"description": "The time since the ledger was closed, in seconds."
|
||||
},
|
||||
"baseFeeXrp": {
|
||||
"type": "number",
|
||||
"description": "Base fee, in XRP. This may be represented in scientific notation such as 1e-05 for 0.00005."
|
||||
},
|
||||
"hash": {
|
||||
"$ref": "hash256",
|
||||
"description": "Unique hash for the ledger, as hex."
|
||||
},
|
||||
"reserveBaseXrp": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"description": "Minimum amount of XRP (not drops) necessary for every account to keep in reserve."
|
||||
},
|
||||
"reserveIncXrp": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"description": "Amount of XRP (not drops) added to the account reserve for each object an account is responsible for in the ledger."
|
||||
},
|
||||
"seq": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"description": "Identifying sequence number of this ledger version."
|
||||
}
|
||||
},
|
||||
"validationQuorum": {"type": "number"}
|
||||
"additionalProperties": false,
|
||||
"required": ["age", "baseFeeXrp", "hash", "reserveBaseXrp", "reserveIncXrp", "seq"]
|
||||
},
|
||||
"validationQuorum": {
|
||||
"type": "number",
|
||||
"description": "Minimum number of trusted validations required in order to validate a ledger version. Some circumstances may cause the server to require more validations."
|
||||
}
|
||||
},
|
||||
"required": ["buildVersion", "completeLedgers", "hostid", "ioLatencyMs", "lastClose", "loadFactor", "peers", "pubkeyNode", "serverState", "validatedLedger", "validationQuorum"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "getSettings",
|
||||
"link": "settings-specification",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"passwordSpent": {"type": "boolean"},
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "outcome",
|
||||
"type": "object",
|
||||
"link": "transaction-outcome",
|
||||
"properties": {
|
||||
"result": {"type": "string"},
|
||||
"timestamp": {"type": "string", "format": "date-time"},
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
"address": {"$ref": "address"},
|
||||
"sequence": {"$ref": "sequence"}
|
||||
},
|
||||
"required": ["type", "id", "address", "sequence", "specification"],
|
||||
"required": ["type", "id", "address", "sequence", "specification", "outcome"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "orderCancellation",
|
||||
"link": "order-cancellation-specification",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"orderSequence": {"$ref": "sequence"}
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "order",
|
||||
"link": "order-specification",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"direction": {
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "payment",
|
||||
"link": "payment-specification",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"source": {"$ref": "sourceAdjustment"},
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "settings",
|
||||
"link": "settings-specification",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "getSettings"
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "suspended-payment-cancellation",
|
||||
"title": "suspendedPaymentCancellation",
|
||||
"link": "suspended-payment-cancellation-specification",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"memos": {
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "suspended-payment-creation",
|
||||
"title": "suspendedPaymentCreation",
|
||||
"link": "suspended-payment-creation-specification",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"source": {"$ref": "maxAdjustment"},
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "suspended-payment-execution",
|
||||
"title": "suspendedPaymentExecution",
|
||||
"link": "suspended-payment-execution-specification",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"memos": {
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "trustline",
|
||||
"link": "trustline-specification",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"currency": {"$ref": "currency"},
|
||||
@@ -4,9 +4,19 @@ const _ = require('lodash');
|
||||
const BigNumber = require('bignumber.js');
|
||||
const errors = require('./errors');
|
||||
const keypairs = require('ripple-keypairs');
|
||||
const {deriveKeypair} = require('ripple-keypairs');
|
||||
|
||||
import type {Amount, RippledAmount} from './types.js';
|
||||
|
||||
function isValidSecret(secret: string): boolean {
|
||||
try {
|
||||
deriveKeypair(secret);
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function dropsToXrp(drops: string): string {
|
||||
return (new BigNumber(drops)).dividedBy(1000000.0).toString();
|
||||
}
|
||||
@@ -96,5 +106,6 @@ module.exports = {
|
||||
convertKeysFromSnakeCaseToCamelCase,
|
||||
removeUndefined,
|
||||
rippleTimeToISO8601,
|
||||
iso8601ToRippleTime
|
||||
iso8601ToRippleTime,
|
||||
isValidSecret
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/* @flow */
|
||||
'use strict';
|
||||
const _ = require('lodash');
|
||||
const deriveKeypair = require('ripple-keypairs').deriveKeypair;
|
||||
const ValidationError = require('./errors').ValidationError;
|
||||
const schemaValidate = require('./schema-validator').schemaValidate;
|
||||
|
||||
@@ -9,27 +8,8 @@ function error(text) {
|
||||
return new ValidationError(text);
|
||||
}
|
||||
|
||||
function isValidSecret(secret) {
|
||||
try {
|
||||
deriveKeypair(secret);
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function validateSecret(secret: string): void {
|
||||
if (!secret) {
|
||||
throw error('Parameter missing: secret');
|
||||
}
|
||||
if (typeof secret !== 'string' || secret[0] !== 's'
|
||||
|| !isValidSecret(secret)) {
|
||||
throw error('Invalid parameter: secret');
|
||||
}
|
||||
}
|
||||
|
||||
function validateLedgerRange(options) {
|
||||
if (!_.isUndefined(options.minLedgerVersion)
|
||||
if (!_.isUndefined(options) && !_.isUndefined(options.minLedgerVersion)
|
||||
&& !_.isUndefined(options.maxLedgerVersion)) {
|
||||
if (Number(options.minLedgerVersion) > Number(options.maxLedgerVersion)) {
|
||||
throw error('minLedgerVersion must not be greater than maxLedgerVersion');
|
||||
@@ -37,43 +17,38 @@ function validateLedgerRange(options) {
|
||||
}
|
||||
}
|
||||
|
||||
function validateOptions(schema, options) {
|
||||
schemaValidate(schema, options);
|
||||
validateLedgerRange(options);
|
||||
function validateOptions(schema, instance) {
|
||||
schemaValidate(schema, instance);
|
||||
validateLedgerRange(instance.options);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
address: _.partial(schemaValidate, 'address'),
|
||||
secret: validateSecret,
|
||||
currency: _.partial(schemaValidate, 'currency'),
|
||||
identifier: _.partial(schemaValidate, 'hash256'),
|
||||
ledgerVersion: _.partial(schemaValidate, 'ledgerVersion'),
|
||||
sequence: _.partial(schemaValidate, 'sequence'),
|
||||
order: _.partial(schemaValidate, 'order'),
|
||||
orderbook: _.partial(schemaValidate, 'orderbook'),
|
||||
payment: _.partial(schemaValidate, 'payment'),
|
||||
suspendedPaymentCreation:
|
||||
_.partial(schemaValidate, 'suspended-payment-creation'),
|
||||
suspendedPaymentExecution:
|
||||
_.partial(schemaValidate, 'suspended-payment-execution'),
|
||||
suspendedPaymentCancellation:
|
||||
_.partial(schemaValidate, 'suspended-payment-cancellation'),
|
||||
pathfind: _.partial(schemaValidate, 'pathfind'),
|
||||
settings: _.partial(schemaValidate, 'settings'),
|
||||
trustline: _.partial(schemaValidate, 'trustline'),
|
||||
txJSON: _.partial(schemaValidate, 'tx'),
|
||||
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'),
|
||||
getBalanceSheetOptions: _.partial(validateOptions, 'balance-sheet-options'),
|
||||
getOrdersOptions: _.partial(validateOptions, 'orders-options'),
|
||||
getOrderbookOptions: _.partial(validateOptions, 'orders-options'),
|
||||
getTransactionOptions: _.partial(validateOptions, 'transaction-options'),
|
||||
getLedgerOptions: _.partial(validateOptions, 'ledger-options'),
|
||||
options: _.partial(validateOptions, 'options'),
|
||||
getPaths: _.partial(schemaValidate, 'getPathsParameters'),
|
||||
getTransactions: _.partial(validateOptions, 'getTransactionsParameters'),
|
||||
getSettings: _.partial(validateOptions, 'getSettingsParameters'),
|
||||
getAccountInfo: _.partial(validateOptions, 'getSettingsParameters'),
|
||||
getTrustlines: _.partial(validateOptions, 'getTrustlinesParameters'),
|
||||
getBalances: _.partial(validateOptions, 'getTrustlinesParameters'),
|
||||
getBalanceSheet: _.partial(validateOptions, 'getBalanceSheetParameters'),
|
||||
getOrders: _.partial(validateOptions, 'getOrdersParameters'),
|
||||
getOrderbook: _.partial(validateOptions, 'getOrderbookParameters'),
|
||||
getTransaction: _.partial(validateOptions, 'getTransactionParameters'),
|
||||
getLedger: _.partial(validateOptions, 'getLedgerParameters'),
|
||||
preparePayment: _.partial(schemaValidate, 'preparePaymentParameters'),
|
||||
prepareOrder: _.partial(schemaValidate, 'prepareOrderParameters'),
|
||||
prepareOrderCancellation:
|
||||
_.partial(schemaValidate, 'prepareOrderCancellationParameters'),
|
||||
prepareTrustline: _.partial(schemaValidate, 'prepareTrustlineParameters'),
|
||||
prepareSettings: _.partial(schemaValidate, 'prepareSettingsParameters'),
|
||||
prepareSuspendedPaymentCreation: _.partial(schemaValidate,
|
||||
'prepareSuspendedPaymentCreationParameters'),
|
||||
prepareSuspendedPaymentCancellation: _.partial(schemaValidate,
|
||||
'prepareSuspendedPaymentCancellationParameters'),
|
||||
prepareSuspendedPaymentExecution: _.partial(schemaValidate,
|
||||
'prepareSuspendedPaymentExecutionParameters'),
|
||||
sign: _.partial(schemaValidate, 'signParameters'),
|
||||
submit: _.partial(schemaValidate, 'submitParameters'),
|
||||
computeLedgerHash: _.partial(schemaValidate, 'computeLedgerHashParameters'),
|
||||
apiOptions: _.partial(schemaValidate, 'api-options'),
|
||||
instructions: _.partial(schemaValidate, 'instructions')
|
||||
};
|
||||
|
||||
@@ -50,14 +50,13 @@ function formatAccountInfo(response: AccountDataResponse) {
|
||||
});
|
||||
}
|
||||
|
||||
function getAccountInfo(account: string, options: AccountInfoOptions = {}
|
||||
function getAccountInfo(address: string, options: AccountInfoOptions = {}
|
||||
): Promise<AccountInfoResponse> {
|
||||
validate.address(account);
|
||||
validate.getAccountInfoOptions(options);
|
||||
validate.getAccountInfo({address, options});
|
||||
|
||||
const request = {
|
||||
command: 'account_info',
|
||||
account: account,
|
||||
account: address,
|
||||
ledger_index: options.ledgerVersion || 'validated'
|
||||
};
|
||||
|
||||
|
||||
@@ -49,8 +49,7 @@ function formatBalanceSheet(balanceSheet): GetBalanceSheet {
|
||||
|
||||
function getBalanceSheet(address: string, options: BalanceSheetOptions = {}
|
||||
): Promise<GetBalanceSheet> {
|
||||
validate.address(address);
|
||||
validate.getBalanceSheetOptions(options);
|
||||
validate.getBalanceSheet({address, options});
|
||||
|
||||
return utils.ensureLedgerVersion.call(this, options).then(_options => {
|
||||
const request = {
|
||||
|
||||
@@ -48,16 +48,15 @@ function getLedgerVersionHelper(connection: Connection, optionValue?: number
|
||||
return connection.getLedgerVersion();
|
||||
}
|
||||
|
||||
function getBalances(account: string, options: TrustlinesOptions = {}
|
||||
function getBalances(address: string, options: TrustlinesOptions = {}
|
||||
): Promise<GetBalances> {
|
||||
validate.address(account);
|
||||
validate.getBalancesOptions(options);
|
||||
validate.getTrustlines({address, options});
|
||||
|
||||
return Promise.all([
|
||||
getLedgerVersionHelper(this.connection, options.ledgerVersion).then(
|
||||
ledgerVersion =>
|
||||
utils.getXRPBalance(this.connection, account, ledgerVersion)),
|
||||
this.getTrustlines(account, options)
|
||||
utils.getXRPBalance(this.connection, address, ledgerVersion)),
|
||||
this.getTrustlines(address, options)
|
||||
]).then(results =>
|
||||
formatBalances(options, {xrp: results[0], trustlines: results[1]}));
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ type LedgerOptions = {
|
||||
|
||||
|
||||
function getLedger(options: LedgerOptions = {}): Promise<GetLedger> {
|
||||
validate.getLedgerOptions(options);
|
||||
validate.getLedger({options});
|
||||
|
||||
const request = {
|
||||
command: 'ledger',
|
||||
|
||||
@@ -91,14 +91,12 @@ function formatBidsAndAsks(orderbook: Orderbook, offers) {
|
||||
return {bids, asks};
|
||||
}
|
||||
|
||||
function getOrderbook(account: string, orderbook: Orderbook,
|
||||
function getOrderbook(address: string, orderbook: Orderbook,
|
||||
options: OrdersOptions = {}
|
||||
): Promise<GetOrderbook> {
|
||||
validate.address(account);
|
||||
validate.orderbook(orderbook);
|
||||
validate.getOrderbookOptions(options);
|
||||
validate.getOrderbook({address, orderbook, options});
|
||||
|
||||
const getter = _.partial(getBookOffers, this.connection, account,
|
||||
const getter = _.partial(getBookOffers, this.connection, address,
|
||||
options.ledgerVersion, options.limit);
|
||||
const getOffers = _.partial(getter, orderbook.base, orderbook.counter);
|
||||
const getReverseOffers = _.partial(getter, orderbook.counter, orderbook.base);
|
||||
|
||||
@@ -26,13 +26,12 @@ function requestAccountOffers(connection: Connection, address: string,
|
||||
});
|
||||
}
|
||||
|
||||
function getOrders(account: string, options: OrdersOptions = {}
|
||||
function getOrders(address: string, options: OrdersOptions = {}
|
||||
): Promise<GetOrders> {
|
||||
validate.address(account);
|
||||
validate.getOrdersOptions(options);
|
||||
validate.getOrders({address, options});
|
||||
|
||||
return utils.ensureLedgerVersion.call(this, options).then(_options => {
|
||||
const getter = _.partial(requestAccountOffers, this.connection, account,
|
||||
const getter = _.partial(requestAccountOffers, this.connection, address,
|
||||
_options.ledgerVersion);
|
||||
return utils.getRecursive(getter, _options.limit).then(orders =>
|
||||
_.sortBy(orders, (order) => order.properties.sequence));
|
||||
|
||||
@@ -111,7 +111,7 @@ function formatResponse(pathfind: PathFind, paths: RippledPathsResponse) {
|
||||
}
|
||||
|
||||
function getPaths(pathfind: PathFind): Promise<GetPaths> {
|
||||
validate.pathfind(pathfind);
|
||||
validate.getPaths({pathfind});
|
||||
|
||||
const address = pathfind.source.address;
|
||||
return requestPathFind(this.connection, pathfind).then(paths =>
|
||||
|
||||
@@ -48,14 +48,13 @@ function formatSettings(response) {
|
||||
return _.assign({}, parsedFlags, parsedFields);
|
||||
}
|
||||
|
||||
function getSettings(account: string, options: SettingsOptions = {}
|
||||
function getSettings(address: string, options: SettingsOptions = {}
|
||||
): Promise<GetSettings> {
|
||||
validate.address(account);
|
||||
validate.getSettingsOptions(options);
|
||||
validate.getSettings({address, options});
|
||||
|
||||
const request = {
|
||||
command: 'account_info',
|
||||
account: account,
|
||||
account: address,
|
||||
ledger_index: options.ledgerVersion || 'validated'
|
||||
};
|
||||
|
||||
|
||||
@@ -78,8 +78,7 @@ function formatResponse(options: TransactionOptions, tx: TransactionType
|
||||
function getTransaction(identifier: string,
|
||||
options: TransactionOptions = {}
|
||||
): Promise<TransactionType> {
|
||||
validate.identifier(identifier);
|
||||
validate.getTransactionOptions(options);
|
||||
validate.getTransaction({identifier, options});
|
||||
|
||||
const request = {
|
||||
command: 'tx',
|
||||
|
||||
@@ -163,10 +163,9 @@ function getTransactionsInternal(connection: Connection, address: string,
|
||||
return utils.getRecursive(getter, options.limit).then(format);
|
||||
}
|
||||
|
||||
function getTransactions(account: string, options: TransactionsOptions = {}
|
||||
function getTransactions(address: string, options: TransactionsOptions = {}
|
||||
): Promise<GetTransactionsResponse> {
|
||||
validate.address(account);
|
||||
validate.getTransactionsOptions(options);
|
||||
validate.getTransactions({address, options});
|
||||
|
||||
const defaults = {maxLedgerVersion: -1};
|
||||
if (options.start) {
|
||||
@@ -175,11 +174,11 @@ function getTransactions(account: string, options: TransactionsOptions = {}
|
||||
const bound = options.earliestFirst ?
|
||||
{minLedgerVersion: ledgerVersion} : {maxLedgerVersion: ledgerVersion};
|
||||
const newOptions = _.assign(defaults, options, {startTx: tx}, bound);
|
||||
return getTransactionsInternal(this.connection, account, newOptions);
|
||||
return getTransactionsInternal(this.connection, address, newOptions);
|
||||
});
|
||||
}
|
||||
const newOptions = _.assign(defaults, options);
|
||||
return getTransactionsInternal(this.connection, account, newOptions);
|
||||
return getTransactionsInternal(this.connection, address, newOptions);
|
||||
}
|
||||
|
||||
module.exports = getTransactions;
|
||||
|
||||
@@ -38,13 +38,12 @@ function getAccountLines(connection: Connection, address: string,
|
||||
return connection.request(request).then(_.partial(formatResponse, options));
|
||||
}
|
||||
|
||||
function getTrustlines(account: string, options: TrustlinesOptions = {}
|
||||
function getTrustlines(address: string, options: TrustlinesOptions = {}
|
||||
): Promise<GetTrustlinesResponse> {
|
||||
validate.address(account);
|
||||
validate.getTrustlinesOptions(options);
|
||||
validate.getTrustlines({address, options});
|
||||
|
||||
return this.getLedgerVersion().then(ledgerVersion => {
|
||||
const getter = _.partial(getAccountLines, this.connection, account,
|
||||
const getter = _.partial(getAccountLines, this.connection, address,
|
||||
options.ledgerVersion || ledgerVersion, options);
|
||||
return utils.getRecursive(getter, options.limit);
|
||||
});
|
||||
|
||||
@@ -7,9 +7,6 @@ import type {Instructions, Prepare} from './types.js';
|
||||
import type {Order} from '../ledger/transaction-types.js';
|
||||
|
||||
function createOrderTransaction(account: string, order: Order): Object {
|
||||
validate.address(account);
|
||||
validate.order(order);
|
||||
|
||||
const takerPays = utils.common.toRippledAmount(order.direction === 'buy' ?
|
||||
order.quantity : order.totalPrice);
|
||||
const takerGets = utils.common.toRippledAmount(order.direction === 'buy' ?
|
||||
@@ -40,10 +37,11 @@ function createOrderTransaction(account: string, order: Order): Object {
|
||||
return txJSON;
|
||||
}
|
||||
|
||||
function prepareOrder(account: string, order: Order,
|
||||
function prepareOrder(address: string, order: Order,
|
||||
instructions: Instructions = {}
|
||||
): Promise<Prepare> {
|
||||
const txJSON = createOrderTransaction(account, order);
|
||||
validate.prepareOrder({address, order, instructions});
|
||||
const txJSON = createOrderTransaction(address, order);
|
||||
return utils.prepareTransaction(txJSON, this, instructions);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,6 @@ import type {Instructions, Prepare} from './types.js';
|
||||
function createOrderCancellationTransaction(account: string,
|
||||
sequence: number
|
||||
): Object {
|
||||
validate.address(account);
|
||||
validate.sequence(sequence);
|
||||
|
||||
return {
|
||||
TransactionType: 'OfferCancel',
|
||||
Account: account,
|
||||
@@ -17,10 +14,11 @@ function createOrderCancellationTransaction(account: string,
|
||||
};
|
||||
}
|
||||
|
||||
function prepareOrderCancellation(account: string, sequence: number,
|
||||
function prepareOrderCancellation(address: string, sequence: number,
|
||||
instructions: Instructions = {}
|
||||
): Promise<Prepare> {
|
||||
const txJSON = createOrderCancellationTransaction(account, sequence);
|
||||
validate.prepareOrderCancellation({address, sequence, instructions});
|
||||
const txJSON = createOrderCancellationTransaction(address, sequence);
|
||||
return utils.prepareTransaction(txJSON, this, instructions);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,12 +65,14 @@ function createMaximalAmount(amount: Amount): Amount {
|
||||
return _.assign(amount, {value: maxValue});
|
||||
}
|
||||
|
||||
function createPaymentTransaction(account: string, paymentArgument: Payment
|
||||
function createPaymentTransaction(address: string, paymentArgument: Payment
|
||||
): Object {
|
||||
const payment = _.cloneDeep(paymentArgument);
|
||||
applyAnyCounterpartyEncoding(payment);
|
||||
validate.address(account);
|
||||
validate.payment(payment);
|
||||
|
||||
if (address !== payment.source.address) {
|
||||
throw new ValidationError('address must match payment.source.address');
|
||||
}
|
||||
|
||||
if ((payment.source.maxAmount && payment.destination.minAmount) ||
|
||||
(payment.source.amount && payment.destination.amount)) {
|
||||
@@ -141,10 +143,11 @@ function createPaymentTransaction(account: string, paymentArgument: Payment
|
||||
return txJSON;
|
||||
}
|
||||
|
||||
function preparePayment(account: string, payment: Payment,
|
||||
instructions: Instructions
|
||||
function preparePayment(address: string, payment: Payment,
|
||||
instructions: Instructions = {}
|
||||
): Promise<Prepare> {
|
||||
const txJSON = createPaymentTransaction(account, payment);
|
||||
validate.preparePayment({address, payment, instructions});
|
||||
const txJSON = createPaymentTransaction(address, payment);
|
||||
return utils.prepareTransaction(txJSON, this, instructions);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,9 +71,6 @@ function convertTransferRate(transferRate: number | string): number | string {
|
||||
|
||||
function createSettingsTransaction(account: string, settings: Settings
|
||||
): Object {
|
||||
validate.address(account);
|
||||
validate.settings(settings);
|
||||
|
||||
if (settings.regularKey) {
|
||||
return {
|
||||
TransactionType: 'SetRegularKey',
|
||||
@@ -95,10 +92,11 @@ function createSettingsTransaction(account: string, settings: Settings
|
||||
return txJSON;
|
||||
}
|
||||
|
||||
function prepareSettings(account: string, settings: Settings,
|
||||
function prepareSettings(address: string, settings: Settings,
|
||||
instructions: Instructions = {}
|
||||
): Promise<Prepare> {
|
||||
const txJSON = createSettingsTransaction(account, settings);
|
||||
validate.prepareSettings({address, settings, instructions});
|
||||
const txJSON = createSettingsTransaction(address, settings);
|
||||
return utils.prepareTransaction(txJSON, this, instructions);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,11 @@ function computeSignature(txJSON, privateKey) {
|
||||
|
||||
function sign(txJSON: string, secret: string
|
||||
): {signedTransaction: string; id: string} {
|
||||
const tx = JSON.parse(txJSON);
|
||||
validate.txJSON(tx);
|
||||
validate.sign({txJSON, secret});
|
||||
// we can't validate that the secret matches the account because
|
||||
// the secret could correspond to the regular key
|
||||
validate.secret(secret);
|
||||
|
||||
const tx = JSON.parse(txJSON);
|
||||
const keypair = keypairs.deriveKeypair(secret);
|
||||
if (tx.SigningPubKey === undefined) {
|
||||
tx.SigningPubKey = keypair.publicKey;
|
||||
|
||||
@@ -31,7 +31,7 @@ function formatResponse(response) {
|
||||
}
|
||||
|
||||
function submit(txBlob: string): Promise<Submit> {
|
||||
validate.blob(txBlob);
|
||||
validate.submit({txBlob});
|
||||
const request = {
|
||||
command: 'submit',
|
||||
tx_blob: txBlob
|
||||
|
||||
@@ -15,9 +15,6 @@ type SuspendedPaymentCancellation = {
|
||||
function createSuspendedPaymentCancellationTransaction(account: string,
|
||||
payment: SuspendedPaymentCancellation
|
||||
): Object {
|
||||
validate.address(account);
|
||||
validate.suspendedPaymentCancellation(payment);
|
||||
|
||||
const txJSON: Object = {
|
||||
TransactionType: 'SuspendedPaymentCancel',
|
||||
Account: account,
|
||||
@@ -30,11 +27,14 @@ function createSuspendedPaymentCancellationTransaction(account: string,
|
||||
return txJSON;
|
||||
}
|
||||
|
||||
function prepareSuspendedPaymentCancellation(account: string,
|
||||
payment: SuspendedPaymentCancellation, instructions: Instructions = {}
|
||||
function prepareSuspendedPaymentCancellation(address: string,
|
||||
suspendedPaymentCancellation: SuspendedPaymentCancellation,
|
||||
instructions: Instructions = {}
|
||||
): Promise<Prepare> {
|
||||
const txJSON =
|
||||
createSuspendedPaymentCancellationTransaction(account, payment);
|
||||
validate.prepareSuspendedPaymentCancellation(
|
||||
{address, suspendedPaymentCancellation, instructions});
|
||||
const txJSON = createSuspendedPaymentCancellationTransaction(
|
||||
address, suspendedPaymentCancellation);
|
||||
return utils.prepareTransaction(txJSON, this, instructions);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,6 @@ type SuspendedPaymentCreation = {
|
||||
function createSuspendedPaymentCreationTransaction(account: string,
|
||||
payment: SuspendedPaymentCreation
|
||||
): Object {
|
||||
validate.address(account);
|
||||
validate.suspendedPaymentCreation(payment);
|
||||
|
||||
const txJSON: Object = {
|
||||
TransactionType: 'SuspendedPaymentCreate',
|
||||
Account: account,
|
||||
@@ -49,10 +46,14 @@ function createSuspendedPaymentCreationTransaction(account: string,
|
||||
return txJSON;
|
||||
}
|
||||
|
||||
function prepareSuspendedPaymentCreation(account: string,
|
||||
payment: SuspendedPaymentCreation, instructions: Instructions = {}
|
||||
function prepareSuspendedPaymentCreation(address: string,
|
||||
suspendedPaymentCreation: SuspendedPaymentCreation,
|
||||
instructions: Instructions = {}
|
||||
): Promise<Prepare> {
|
||||
const txJSON = createSuspendedPaymentCreationTransaction(account, payment);
|
||||
validate.prepareSuspendedPaymentCreation(
|
||||
{address, suspendedPaymentCreation, instructions});
|
||||
const txJSON = createSuspendedPaymentCreationTransaction(
|
||||
address, suspendedPaymentCreation);
|
||||
return utils.prepareTransaction(txJSON, this, instructions);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,6 @@ type SuspendedPaymentExecution = {
|
||||
function createSuspendedPaymentExecutionTransaction(account: string,
|
||||
payment: SuspendedPaymentExecution
|
||||
): Object {
|
||||
validate.address(account);
|
||||
validate.suspendedPaymentExecution(payment);
|
||||
|
||||
const txJSON: Object = {
|
||||
TransactionType: 'SuspendedPaymentFinish',
|
||||
Account: account,
|
||||
@@ -43,10 +40,14 @@ function createSuspendedPaymentExecutionTransaction(account: string,
|
||||
return txJSON;
|
||||
}
|
||||
|
||||
function prepareSuspendedPaymentExecution(account: string,
|
||||
payment: SuspendedPaymentExecution, instructions: Instructions = {}
|
||||
function prepareSuspendedPaymentExecution(address: string,
|
||||
suspendedPaymentExecution: SuspendedPaymentExecution,
|
||||
instructions: Instructions = {}
|
||||
): Promise<Prepare> {
|
||||
const txJSON = createSuspendedPaymentExecutionTransaction(account, payment);
|
||||
validate.prepareSuspendedPaymentExecution(
|
||||
{address, suspendedPaymentExecution, instructions});
|
||||
const txJSON = createSuspendedPaymentExecutionTransaction(
|
||||
address, suspendedPaymentExecution);
|
||||
return utils.prepareTransaction(txJSON, this, instructions);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,6 @@ function convertQuality(quality) {
|
||||
function createTrustlineTransaction(account: string,
|
||||
trustline: TrustLineSpecification
|
||||
): Object {
|
||||
validate.address(account);
|
||||
validate.trustline(trustline);
|
||||
|
||||
const limit = {
|
||||
currency: trustline.currency,
|
||||
issuer: trustline.counterparty,
|
||||
@@ -50,10 +47,11 @@ function createTrustlineTransaction(account: string,
|
||||
return txJSON;
|
||||
}
|
||||
|
||||
function prepareTrustline(account: string,
|
||||
function prepareTrustline(address: string,
|
||||
trustline: TrustLineSpecification, instructions: Instructions = {}
|
||||
): Promise<Prepare> {
|
||||
const txJSON = createTrustlineTransaction(account, trustline);
|
||||
validate.prepareTrustline({address, trustline, instructions});
|
||||
const txJSON = createTrustlineTransaction(address, trustline);
|
||||
return utils.prepareTransaction(txJSON, this, instructions);
|
||||
}
|
||||
|
||||
|
||||
@@ -834,26 +834,32 @@ describe('RippleAPI', function() {
|
||||
minLedgerVersion: 20000,
|
||||
maxLedgerVersion: 10000
|
||||
};
|
||||
assert.throws(_.partial(validate.getTransactionsOptions, options),
|
||||
this.api.errors.ValidationError);
|
||||
assert.throws(_.partial(validate.getTransactionsOptions, options),
|
||||
const thunk = _.partial(validate.getTransactions,
|
||||
{address, options});
|
||||
assert.throws(thunk, this.api.errors.ValidationError);
|
||||
assert.throws(thunk,
|
||||
/minLedgerVersion must not be greater than maxLedgerVersion/);
|
||||
});
|
||||
|
||||
it('secret', function() {
|
||||
assert.doesNotThrow(_.partial(validate.secret,
|
||||
function validateSecret(secret) {
|
||||
validate.sign({txJSON: '', secret});
|
||||
}
|
||||
assert.doesNotThrow(_.partial(validateSecret,
|
||||
'shzjfakiK79YQdMjy4h8cGGfQSV6u'));
|
||||
assert.throws(_.partial(validate.secret, 1),
|
||||
/Invalid parameter/);
|
||||
assert.throws(_.partial(validate.secret, ''),
|
||||
assert.throws(_.partial(validateSecret,
|
||||
'shzjfakiK79YQdMjy4h8cGGfQSV6v'), this.api.errors.ValidationError);
|
||||
assert.throws(_.partial(validateSecret, 1),
|
||||
this.api.errors.ValidationError);
|
||||
assert.throws(_.partial(validate.secret, 's!!!'),
|
||||
assert.throws(_.partial(validateSecret, ''),
|
||||
this.api.errors.ValidationError);
|
||||
assert.throws(_.partial(validate.secret, 'passphrase'),
|
||||
assert.throws(_.partial(validateSecret, 's!!!'),
|
||||
this.api.errors.ValidationError);
|
||||
assert.throws(_.partial(validateSecret, 'passphrase'),
|
||||
this.api.errors.ValidationError);
|
||||
// 32 0s is a valid hex repr of seed bytes
|
||||
const hex = new Array(33).join('0');
|
||||
assert.throws(_.partial(validate.secret, hex),
|
||||
assert.throws(_.partial(validateSecret, hex),
|
||||
this.api.errors.ValidationError);
|
||||
});
|
||||
|
||||
|
||||
1
test/fixtures/responses/get-server-info.json
vendored
1
test/fixtures/responses/get-server-info.json
vendored
@@ -2,6 +2,7 @@
|
||||
"buildVersion": "0.24.0-rc1",
|
||||
"completeLedgers": "32570-6595042",
|
||||
"hostid": "ARTS",
|
||||
"ioLatencyMs": 1,
|
||||
"lastClose": {
|
||||
"convergeTimeS": 2.007,
|
||||
"proposers": 4
|
||||
|
||||
1
test/fixtures/rippled/server-info.json
vendored
1
test/fixtures/rippled/server-info.json
vendored
@@ -7,6 +7,7 @@
|
||||
"build_version": "0.24.0-rc1",
|
||||
"complete_ledgers": "32570-6595042",
|
||||
"hostid": "ARTS",
|
||||
"io_latency_ms": 1,
|
||||
"last_close": {
|
||||
"converge_time_s": 2.007,
|
||||
"proposers": 4
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
const _ = require('lodash');
|
||||
const assert = require('assert');
|
||||
const errors = require('../../src/common/errors');
|
||||
const validate = require('../../src/common').validate;
|
||||
const wallet = require('./wallet');
|
||||
const requests = require('../fixtures/requests');
|
||||
const RippleAPI = require('../../src').RippleAPI;
|
||||
const {isValidAddress} = require('ripple-address-codec');
|
||||
const {isValidSecret} = require('../../src/common');
|
||||
|
||||
|
||||
const TIMEOUT = 30000; // how long before each test case times out
|
||||
@@ -292,8 +293,8 @@ describe('integration tests', function() {
|
||||
it('generateWallet', function() {
|
||||
const newWallet = this.api.generateAddress();
|
||||
assert(newWallet && newWallet.address && newWallet.secret);
|
||||
validate.address(newWallet.address);
|
||||
validate.secret(newWallet.secret);
|
||||
assert(isValidAddress(newWallet.address));
|
||||
assert(isValidSecret(newWallet.secret));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user