Skip to content

Commit

Permalink
Merge pull request #493 from clark800/max-amount-2
Browse files Browse the repository at this point in the history
Rename source.amount to source.maxAmount
  • Loading branch information
clark800 committed Aug 10, 2015
2 parents 2b2fdf1 + a6662cc commit fcbe7d3
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/api/common/schema-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const _ = require('lodash');
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const validator = require('is-my-json-valid');
const core = require('./utils').core;
const ValidationError = require('./errors').ValidationError;
Expand Down Expand Up @@ -33,6 +34,9 @@ function endsWith(str, suffix) {
function loadSchemas(dir) {
const filenames = fs.readdirSync(dir).filter(name => endsWith(name, '.json'));
const schemas = filenames.map(name => loadSchema(path.join(dir, name)));
const titles = _.map(schemas, schema => schema.title);
const duplicates = _.keys(_.pick(_.countBy(titles), count => count > 1));
assert(duplicates.length === 0, 'Duplicate schemas for: ' + duplicates);
return _.indexBy(schemas, 'title');
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/common/schemas/balance.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"properties": {
"value": {
"description": "The balance on the trustline",
"$ref": "signed-value"
"$ref": "signedValue"
},
"currency": {
"description": "The three-character code or hex string used to denote currencies",
Expand Down
24 changes: 24 additions & 0 deletions src/api/common/schemas/max-adjustment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "maxAdjustment",
"type": "object",
"properties": {
"address": {"$ref": "address"},
"maxAmount": {
"type": "object",
"properties": {
"currency": {"$ref": "currency"},
"counterparty": {"$ref": "address"},
"value": {"$ref": "value"}
},
"required": ["currency", "value"],
"additionalProperties": false
},
"tag": {
"description": "A string representing an unsigned 32-bit integer most commonly used to refer to a sender's hosted account at a Ripple gateway",
"$ref": "uint32"
}
},
"required": ["address", "maxAmount"],
"additionalProperties": false
}
2 changes: 1 addition & 1 deletion src/api/common/schemas/order-change.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "order-change",
"title": "orderChange",
"type": "object",
"properties": {
"direction": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/common/schemas/outcome.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"description": "Key is the maker's ripple address; value is an array of changes",
"additionalProperties": {
"type": "array",
"items": {"$ref": "order-change"}
"items": {"$ref": "orderChange"}
}
},
"ledgerVersion": {"$ref": "ledgerVersion"},
Expand Down
2 changes: 1 addition & 1 deletion src/api/common/schemas/payment.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"title": "payment",
"type": "object",
"properties": {
"source": {"$ref": "adjustment"},
"source": {"$ref": "maxAdjustment"},
"destination": {"$ref": "adjustment"},
"paths": {"type": "string"},
"memos": {
Expand Down
4 changes: 2 additions & 2 deletions src/api/common/schemas/signed-value.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "value",
"title": "signedValue",
"description": "A string representation of a floating point number",
"type": "string",
"pattern": "[-]?^[0-9]*[.]?[0-9]+([eE][-+]?[0-9]+)?$"
"pattern": "^[-]?[0-9]*[.]?[0-9]+([eE][-+]?[0-9]+)?$"
}
2 changes: 1 addition & 1 deletion src/api/ledger/parse/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function parsePayment(tx: Object): Object {

const source = {
address: tx.Account,
amount: removeGenericCounterparty(
maxAmount: removeGenericCounterparty(
parseAmount(tx.SendMax || tx.Amount), tx.Account),
tag: tx.SourceTag
};
Expand Down
8 changes: 4 additions & 4 deletions src/api/transaction/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const toRippledAmount = utils.common.toRippledAmount;
const Transaction = utils.common.core.Transaction;

function isXRPToXRPPayment(payment) {
const sourceCurrency = _.get(payment, 'source.amount.currency');
const sourceCurrency = _.get(payment, 'source.maxAmount.currency');
const destinationCurrency = _.get(payment, 'destination.amount.currency');
return sourceCurrency === 'XRP' && destinationCurrency === 'XRP';
}
Expand All @@ -23,8 +23,8 @@ function applyAnyCounterpartyEncoding(payment) {
// https://ripple.com/build/transactions/
// #special-issuer-values-for-sendmax-and-amount
// https://ripple.com/build/ripple-rest/#counterparties-in-payments
if (isIOUWithoutCounterparty(payment.source.amount)) {
payment.source.amount.counterparty = payment.source.address;
if (isIOUWithoutCounterparty(payment.source.maxAmount)) {
payment.source.maxAmount.counterparty = payment.source.address;
}
if (isIOUWithoutCounterparty(payment.destination.amount)) {
payment.destination.amount.counterparty = payment.destination.address;
Expand Down Expand Up @@ -71,7 +71,7 @@ function createPaymentTransaction(account, payment) {
// temREDUNDANT_SEND_MAX removed in:
// https://github.com/ripple/rippled/commit/
// c522ffa6db2648f1d8a987843e7feabf1a0b7de8/
transaction.sendMax(toRippledAmount(payment.source.amount));
transaction.sendMax(toRippledAmount(payment.source.maxAmount));

if (payment.paths) {
transaction.paths(JSON.parse(payment.paths));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"amount": {
"maxAmount": {
"value": "0.01",
"currency": "XRP"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"amount": {
"maxAmount": {
"value": "0.01",
"currency": "USD"
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/api/requests/prepare-payment.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"amount": {
"maxAmount": {
"value": "0.01",
"currency": "USD",
"counterparty": "rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM"
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/api/responses/get-transaction-payment.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"specification": {
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"amount": {
"maxAmount": {
"currency": "XRP",
"value": "1.112209"
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/api/responses/get-transactions.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"amount": {
"maxAmount": {
"currency": "XRP",
"value": "1.112209"
}
Expand Down Expand Up @@ -104,7 +104,7 @@
],
"source": {
"address": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"amount": {
"maxAmount": {
"currency": "XRP",
"value": "1.112209"
}
Expand Down

0 comments on commit fcbe7d3

Please sign in to comment.