diff --git a/docs/index.md b/docs/index.md index f4208824..f1e15f47 100644 --- a/docs/index.md +++ b/docs/index.md @@ -430,6 +430,7 @@ expirationTime | date-time string | *Optional* Time after which the offer is no fillOrKill | boolean | *Optional* Treat the offer as a [Fill or Kill order](http://en.wikipedia.org/wiki/Fill_or_kill). Only attempt to match existing offers in the ledger, and only do so if the entire quantity can be exchanged. immediateOrCancel | boolean | *Optional* Treat the offer as an [Immediate or Cancel order](http://en.wikipedia.org/wiki/Immediate_or_cancel). If enabled, the offer will never become a ledger node: it only attempts to match existing offers in the ledger. memos | [memos](#transaction-memos) | *Optional* Array of memos to attach to the transaction. +orderToReplace | [sequence](#account-sequence-number) | *Optional* The [account sequence number](#account-sequence-number) of an order to cancel before the new order is created, effectively replacing the old order. passive | boolean | *Optional* If enabled, the offer will not consume offers that exactly match it, and instead becomes an Offer node in the ledger. It will still consume offers that cross it. ### Example diff --git a/src/common/schemas/specifications/order.json b/src/common/schemas/specifications/order.json index 84e5cb9b..5ee42b98 100644 --- a/src/common/schemas/specifications/order.json +++ b/src/common/schemas/specifications/order.json @@ -34,6 +34,10 @@ "format": "date-time", "description": "Time after which the offer is no longer active, as an [ISO 8601 date-time](https://en.wikipedia.org/wiki/ISO_8601)." }, + "orderToReplace": { + "$ref": "sequence", + "description": "The [account sequence number](#account-sequence-number) of an order to cancel before the new order is created, effectively replacing the old order." + }, "memos": {"$ref": "memos"} }, "required": ["direction", "quantity", "totalPrice"], diff --git a/src/transaction/order.js b/src/transaction/order.js index c7589044..d449dad8 100644 --- a/src/transaction/order.js +++ b/src/transaction/order.js @@ -1,5 +1,5 @@ /* @flow */ -'use strict'; +'use strict'; // eslint-disable-line const _ = require('lodash'); const utils = require('./utils'); const offerFlags = utils.common.txFlags.OfferCreate; @@ -35,6 +35,9 @@ function createOrderTransaction(account: string, order: Order): Object { if (order.expirationTime !== undefined) { txJSON.Expiration = iso8601ToRippleTime(order.expirationTime); } + if (order.orderToReplace !== undefined) { + txJSON.OfferSequence = order.orderToReplace; + } if (order.memos !== undefined) { txJSON.Memos = _.map(order.memos, utils.convertMemo); } diff --git a/test/fixtures/requests/prepare-order-sell.json b/test/fixtures/requests/prepare-order-sell.json index 6f1d587e..fca72e81 100644 --- a/test/fixtures/requests/prepare-order-sell.json +++ b/test/fixtures/requests/prepare-order-sell.json @@ -10,6 +10,7 @@ "value": "2" }, "immediateOrCancel": true, + "orderToReplace": 12345, "memos": [ { "type": "test", diff --git a/test/fixtures/responses/prepare-order-sell.json b/test/fixtures/responses/prepare-order-sell.json index 43afec8a..75a51282 100644 --- a/test/fixtures/responses/prepare-order-sell.json +++ b/test/fixtures/responses/prepare-order-sell.json @@ -1,5 +1,5 @@ { - "txJSON": "{\"TransactionType\":\"OfferCreate\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"TakerGets\":{\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\",\"value\":\"10.1\"},\"TakerPays\":\"2000000\",\"Flags\":2148139008,\"Memos\":[{\"Memo\":{\"MemoData\":\"7465787465642064617461\",\"MemoType\":\"74657374\",\"MemoFormat\":\"706C61696E2F74657874\"}}],\"LastLedgerSequence\":8820051,\"Fee\":\"12\",\"Sequence\":23}", + "txJSON": "{\"TransactionType\":\"OfferCreate\",\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"TakerGets\":{\"currency\":\"USD\",\"issuer\":\"rMH4UxPrbuMa1spCBR98hLLyNJp4d8p4tM\",\"value\":\"10.1\"},\"TakerPays\":\"2000000\",\"Flags\":2148139008,\"Memos\":[{\"Memo\":{\"MemoData\":\"7465787465642064617461\",\"MemoType\":\"74657374\",\"MemoFormat\":\"706C61696E2F74657874\"}}],\"LastLedgerSequence\":8820051,\"Fee\":\"12\",\"Sequence\":23,\"OfferSequence\":12345}", "instructions": { "fee": "0.000012", "sequence": 23,