From 3fe5d715a5dcf89f09e5cd43238f465afb747887 Mon Sep 17 00:00:00 2001 From: cryptcoin-junkey <16408160+cryptcoin-junkey@users.noreply.github.com> Date: Sun, 25 Feb 2018 16:52:45 +0900 Subject: [PATCH 1/7] Generate/publish *.ts.d (#851) For TypeScript --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index cdceed6be7..98c396e272 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,7 +15,7 @@ "removeComments": false, "preserveConstEnums": false, "suppressImplicitAnyIndexErrors": false, - "declaration": false, + "declaration": true, "sourceMap": true, "skipLibCheck": true }, From 68b34f7532a3e7e3fce1d378294d0fecd42b9997 Mon Sep 17 00:00:00 2001 From: Elliot Lee Date: Mon, 26 Feb 2018 17:39:06 -0800 Subject: [PATCH 2/7] Improve documentation of getTransactions params (#856) * Improve documentation of getTransactions params - Resolve #855 --- docs/index.md | 6 +++--- src/common/schemas/input/get-transactions.json | 2 +- src/common/schemas/specifications/payment.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/index.md b/docs/index.md index dd096dd395..cd5b581e29 100644 --- a/docs/index.md +++ b/docs/index.md @@ -346,11 +346,11 @@ destination | object | The destination of the funds to be sent. *destination.* tag | integer | *Optional* An arbitrary unsigned 32-bit integer that identifies a reason for payment or a non-Ripple account. *destination.* address | [address](#address) | The address to send to. *destination.* minAmount | [laxAmount](#amount) | The minimum amount to be delivered. (This field is exclusive with destination.amount) -allowPartialPayment | boolean | *Optional* A boolean that, if set to true, indicates that this payment should go through even if the whole amount cannot be delivered because of a lack of liquidity or funds in the source account account +allowPartialPayment | boolean | *Optional* If true, this payment should proceed even if the whole amount cannot be delivered due to a lack of liquidity or a lack of funds in the source account. invoiceID | string | *Optional* A 256-bit hash that can be used to identify a particular payment. limitQuality | boolean | *Optional* Only take paths where all the conversions have an input:output ratio that is equal or better than the ratio of destination.amount:source.maxAmount. memos | [memos](#transaction-memos) | *Optional* Array of memos to attach to the transaction. -noDirectRipple | boolean | *Optional* A boolean that can be set to true if paths are specified and the sender would like the Ripple Network to disregard any direct paths from the source account to the destination account. This may be used to take advantage of an arbitrage opportunity or by gateways wishing to issue balances from a hot wallet to a user who has mistakenly set a trustline directly to the hot wallet +noDirectRipple | boolean | *Optional* If true and paths are specified, the sender would like the XRP Ledger to disregard any direct paths from the source account to the destination account. This may be used to take advantage of an arbitrage opportunity or by gateways wishing to issue balances from a hot wallet to a user who has mistakenly set a trustline directly to the hot wallet. paths | string | *Optional* The paths of trustlines and orders to use in executing the payment. ### Example @@ -1022,7 +1022,7 @@ options | object | *Optional* Options to filter the resulting transactions. *options.* limit | integer | *Optional* If specified, return at most this many transactions. *options.* maxLedgerVersion | integer | *Optional* Return only transactions in this ledger version or lower. *options.* minLedgerVersion | integer | *Optional* Return only transactions in this ledger verion or higher. -*options.* start | string | *Optional* If specified, this transaction will be the first transaction in the result. +*options.* start | string | *Optional* If specified, this transaction will be the first transaction in the result. You cannot use `start` with `minLedgerVersion` or `maxLedgerVersion`. When `start` is specified, these ledger versions will be determined internally. *options.* types | array\<[transactionType](#transaction-types)\> | *Optional* Only return transactions of the specified [Transaction Types](#transaction-types). ### Return Value diff --git a/src/common/schemas/input/get-transactions.json b/src/common/schemas/input/get-transactions.json index 24a4a52f20..93509683a8 100644 --- a/src/common/schemas/input/get-transactions.json +++ b/src/common/schemas/input/get-transactions.json @@ -13,7 +13,7 @@ "properties": { "start": { "$ref": "hash256", - "description": "If specified, this transaction will be the first transaction in the result." + "description": "If specified, this transaction will be the first transaction in the result. You cannot use `start` with `minLedgerVersion` or `maxLedgerVersion`. When `start` is specified, these ledger versions will be determined internally." }, "limit": { "type": "integer", diff --git a/src/common/schemas/specifications/payment.json b/src/common/schemas/specifications/payment.json index 1c98df4f10..c82a5ff985 100644 --- a/src/common/schemas/specifications/payment.json +++ b/src/common/schemas/specifications/payment.json @@ -22,11 +22,11 @@ "$ref": "hash256" }, "allowPartialPayment": { - "description": "A boolean that, if set to true, indicates that this payment should go through even if the whole amount cannot be delivered because of a lack of liquidity or funds in the source account account", + "description": "If true, this payment should proceed even if the whole amount cannot be delivered due to a lack of liquidity or a lack of funds in the source account.", "type": "boolean" }, "noDirectRipple": { - "description": "A boolean that can be set to true if paths are specified and the sender would like the Ripple Network to disregard any direct paths from the source account to the destination account. This may be used to take advantage of an arbitrage opportunity or by gateways wishing to issue balances from a hot wallet to a user who has mistakenly set a trustline directly to the hot wallet", + "description": "If true and paths are specified, the sender would like the XRP Ledger to disregard any direct paths from the source account to the destination account. This may be used to take advantage of an arbitrage opportunity or by gateways wishing to issue balances from a hot wallet to a user who has mistakenly set a trustline directly to the hot wallet.", "type": "boolean" }, "limitQuality": { From c53db4844ae5902b926bb08effb0fc3c32018be0 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Thu, 1 Mar 2018 17:32:31 -0800 Subject: [PATCH 3/7] Add .travis.yml (#859) --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..223fdf3b3f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: + - 6 + - 8 + - 9 +script: + - yarn compile + - yarn test + - yarn build From 144be08af035a3b25183f4acc532e804e395ae6d Mon Sep 17 00:00:00 2001 From: Elliot Lee Date: Thu, 1 Mar 2018 17:48:28 -0800 Subject: [PATCH 4/7] Export types used by exported variables (#858) Fixes TypeScript compile errors due to generating TS declaration files. See #851 --- src/api.ts | 4 ++-- src/common/connection.ts | 2 +- src/common/types/commands/account_info.ts | 4 ++-- src/common/types/commands/book_offers.ts | 2 +- src/ledger/accountinfo.ts | 4 ++-- src/ledger/balance-sheet.ts | 4 ++-- src/ledger/balances.ts | 4 ++-- src/ledger/ledger.ts | 2 +- src/ledger/orderbook.ts | 9 +++++---- src/ledger/parse/payment-channel.ts | 2 +- src/ledger/settings.ts | 4 ++-- src/ledger/transaction-types.ts | 22 +++++++++++----------- src/ledger/transactions.ts | 4 ++-- src/ledger/utils.ts | 6 +++--- src/transaction/escrow-cancellation.ts | 2 +- src/transaction/escrow-creation.ts | 2 +- src/transaction/escrow-execution.ts | 2 +- src/transaction/payment-channel-claim.ts | 2 +- src/transaction/payment-channel-create.ts | 2 +- src/transaction/payment-channel-fund.ts | 2 +- src/transaction/payment.ts | 2 +- src/transaction/settings.ts | 6 +++--- 22 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/api.ts b/src/api.ts index 58dd3f634a..c288dbe3c4 100644 --- a/src/api.ts +++ b/src/api.ts @@ -53,7 +53,7 @@ import * as ledgerUtils from './ledger/utils' import * as schemaValidator from './common/schema-validator' import {clamp} from './ledger/utils' -type APIOptions = { +export type APIOptions = { server?: string, feeCushion?: number, trace?: boolean, @@ -79,7 +79,7 @@ function getCollectKeyFromCommand(command: string): string|undefined { } // prevent access to non-validated ledger versions -class RestrictedConnection extends Connection { +export class RestrictedConnection extends Connection { request(request: any, timeout?: number) { const ledger_index = request.ledger_index if (ledger_index !== undefined && ledger_index !== 'validated') { diff --git a/src/common/connection.ts b/src/common/connection.ts index ac3ebca771..6c1ba64711 100644 --- a/src/common/connection.ts +++ b/src/common/connection.ts @@ -13,7 +13,7 @@ function isStreamMessageType(type) { type === 'path_find' } -interface ConnectionOptions { +export interface ConnectionOptions { trace?: boolean, proxy?: string proxyAuthorization?: string diff --git a/src/common/types/commands/account_info.ts b/src/common/types/commands/account_info.ts index 17f43904ab..cd4bf0e7b9 100644 --- a/src/common/types/commands/account_info.ts +++ b/src/common/types/commands/account_info.ts @@ -18,7 +18,7 @@ export interface AccountInfoResponse { validated?: boolean } -interface QueueData { +export interface QueueData { txn_count: number, auth_change_queued?: boolean, lowest_sequence?: number, @@ -27,7 +27,7 @@ interface QueueData { transactions?: TransactionData[] } -interface TransactionData { +export interface TransactionData { auth_change?: boolean, fee?: string, fee_level?: string, diff --git a/src/common/types/commands/book_offers.ts b/src/common/types/commands/book_offers.ts index 94504e6351..30e1c9e2ae 100644 --- a/src/common/types/commands/book_offers.ts +++ b/src/common/types/commands/book_offers.ts @@ -22,7 +22,7 @@ export interface BookOffersResponse { marker?: any } -interface OrderBookOffer extends OfferCreateTransaction { +export interface OrderBookOffer extends OfferCreateTransaction { quality?: number owner_funds?: string, taker_gets_funded?: RippledAmount, diff --git a/src/ledger/accountinfo.ts b/src/ledger/accountinfo.ts index a987ef948b..778de00521 100644 --- a/src/ledger/accountinfo.ts +++ b/src/ledger/accountinfo.ts @@ -2,11 +2,11 @@ import {validate, removeUndefined, dropsToXrp} from '../common' import {RippleAPI} from '../api' import {AccountInfoResponse} from '../common/types/commands/account_info' -type GetAccountInfoOptions = { +export type GetAccountInfoOptions = { ledgerVersion?: number } -type FormattedGetAccountInfoResponse = { +export type FormattedGetAccountInfoResponse = { sequence: number, xrpBalance: string, ownerCount: number, diff --git a/src/ledger/balance-sheet.ts b/src/ledger/balance-sheet.ts index 9eb905278b..9f53f9d83b 100644 --- a/src/ledger/balance-sheet.ts +++ b/src/ledger/balance-sheet.ts @@ -4,12 +4,12 @@ import {Amount} from '../common/types/objects' import {ensureLedgerVersion} from './utils' import {RippleAPI} from '../api' -type BalanceSheetOptions = { +export type BalanceSheetOptions = { excludeAddresses?: Array, ledgerVersion?: number } -type GetBalanceSheet = { +export type GetBalanceSheet = { balances?: Array, assets?: Array, obligations?: Array<{ diff --git a/src/ledger/balances.ts b/src/ledger/balances.ts index 4c55929fad..5b8e368082 100644 --- a/src/ledger/balances.ts +++ b/src/ledger/balances.ts @@ -5,13 +5,13 @@ import {GetTrustlinesOptions} from './trustlines' import {FormattedTrustline} from '../common/types/objects/trustlines' -type Balance = { +export type Balance = { value: string, currency: string, counterparty?: string } -type GetBalances = Array +export type GetBalances = Array function getTrustlineBalanceAmount(trustline: FormattedTrustline) { return { diff --git a/src/ledger/ledger.ts b/src/ledger/ledger.ts index 8170be8000..9fc1322be1 100644 --- a/src/ledger/ledger.ts +++ b/src/ledger/ledger.ts @@ -2,7 +2,7 @@ import {validate} from '../common' import parseLedger from './parse/ledger' import {GetLedger} from './types' -type LedgerOptions = { +export type LedgerOptions = { ledgerVersion?: number, includeAllData?: boolean, includeTransactions?: boolean, diff --git a/src/ledger/orderbook.ts b/src/ledger/orderbook.ts index d4abafaedb..c14d309545 100644 --- a/src/ledger/orderbook.ts +++ b/src/ledger/orderbook.ts @@ -12,11 +12,12 @@ export type OrdersOptions = { ledgerVersion?: number } -type Orderbook = { +export type Orderbook = { base: Issue, counter: Issue } -type OrderbookItem = { + +export type OrderbookItem = { specification: OrderSpecification, properties: { maker: string, @@ -29,9 +30,9 @@ type OrderbookItem = { } } -type OrderbookOrders = Array +export type OrderbookOrders = Array -type GetOrderbook = { +export type GetOrderbook = { bids: OrderbookOrders, asks: OrderbookOrders } diff --git a/src/ledger/parse/payment-channel.ts b/src/ledger/parse/payment-channel.ts index 5656226b09..59641ded08 100644 --- a/src/ledger/parse/payment-channel.ts +++ b/src/ledger/parse/payment-channel.ts @@ -29,7 +29,7 @@ export type LedgerEntryResponse = { validated: boolean } -type PaymentChannelResponse = { +export type PaymentChannelResponse = { account: string, balance: string, publicKey: string, diff --git a/src/ledger/settings.ts b/src/ledger/settings.ts index ac7602d40f..ce2362e467 100644 --- a/src/ledger/settings.ts +++ b/src/ledger/settings.ts @@ -3,11 +3,11 @@ import parseFields from './parse/fields' import {validate, constants} from '../common' const AccountFlags = constants.AccountFlags -type SettingsOptions = { +export type SettingsOptions = { ledgerVersion?: number } -type GetSettings = { +export type GetSettings = { passwordSpent?: boolean, requireDestinationTag?: boolean, requireAuthorization?: boolean, diff --git a/src/ledger/transaction-types.ts b/src/ledger/transaction-types.ts index 244638d7e7..10caba57bf 100644 --- a/src/ledger/transaction-types.ts +++ b/src/ledger/transaction-types.ts @@ -1,7 +1,7 @@ import {Amount, Memo} from '../common/types/objects' -type Outcome = { +export type Outcome = { result: string, ledgerVersion: number, indexInLedger: number, @@ -17,7 +17,7 @@ type Outcome = { timestamp?: string } -type Adjustment = { +export type Adjustment = { address: string, amount: { currency: string, @@ -27,7 +27,7 @@ type Adjustment = { tag?: number } -type Trustline = { +export type Trustline = { currency: string, counterparty: string, limit: string, @@ -38,7 +38,7 @@ type Trustline = { frozen?: boolean } -type Settings = { +export type Settings = { passwordSpent?: boolean, requireDestinationTag?: boolean, requireAuthorization?: boolean, @@ -56,11 +56,11 @@ type Settings = { regularKey?: string } -type OrderCancellation = { +export type OrderCancellation = { orderSequence: number } -type Payment = { +export type Payment = { source: Adjustment, destination: Adjustment, paths?: string, @@ -71,7 +71,7 @@ type Payment = { limitQuality?: boolean } -type PaymentTransaction = { +export type PaymentTransaction = { type: string, specification: Payment, outcome: Outcome, @@ -92,7 +92,7 @@ export type Order = { memos?: Memo[] } -type OrderTransaction = { +export type OrderTransaction = { type: string, specification: Order, outcome: Outcome, @@ -101,7 +101,7 @@ type OrderTransaction = { sequence: number } -type OrderCancellationTransaction = { +export type OrderCancellationTransaction = { type: string, specification: OrderCancellation, outcome: Outcome, @@ -110,7 +110,7 @@ type OrderCancellationTransaction = { sequence: number } -type TrustlineTransaction = { +export type TrustlineTransaction = { type: string, specification: Trustline, outcome: Outcome, @@ -119,7 +119,7 @@ type TrustlineTransaction = { sequence: number } -type SettingsTransaction = { +export type SettingsTransaction = { type: string, specification: Settings, outcome: Outcome, diff --git a/src/ledger/transactions.ts b/src/ledger/transactions.ts index 1929ad6d88..9c7e793016 100644 --- a/src/ledger/transactions.ts +++ b/src/ledger/transactions.ts @@ -9,7 +9,7 @@ import {Connection} from '../common' import {TransactionType} from './transaction-types' -type TransactionsOptions = { +export type TransactionsOptions = { start?: string, limit?: number, minLedgerVersion?: number, @@ -23,7 +23,7 @@ type TransactionsOptions = { startTx?: TransactionType } -type GetTransactionsResponse = Array +export type GetTransactionsResponse = Array function parseBinaryTransaction(transaction) { const tx = binary.decode(transaction.tx_blob) diff --git a/src/ledger/utils.ts b/src/ledger/utils.ts index b453ea5b95..85f266143f 100644 --- a/src/ledger/utils.ts +++ b/src/ledger/utils.ts @@ -5,12 +5,12 @@ import {Connection} from '../common' import {TransactionType} from './transaction-types' import {Issue} from '../common/types/objects' -type RecursiveData = { +export type RecursiveData = { marker: string, results: Array } -type Getter = (marker?: string, limit?: number) => Promise +export type Getter = (marker?: string, limit?: number) => Promise function clamp(value: number, min: number, max: number): number { assert(min <= max, 'Illegal clamp bounds') @@ -59,7 +59,7 @@ function renameCounterpartyToIssuer( return withIssuer } -type RequestBookOffersArgs = {taker_gets: Issue, taker_pays: Issue} +export type RequestBookOffersArgs = {taker_gets: Issue, taker_pays: Issue} function renameCounterpartyToIssuerInOrder(order: RequestBookOffersArgs) { const taker_gets = renameCounterpartyToIssuer(order.taker_gets) diff --git a/src/transaction/escrow-cancellation.ts b/src/transaction/escrow-cancellation.ts index 1b9006a184..bc5dd4c0ec 100644 --- a/src/transaction/escrow-cancellation.ts +++ b/src/transaction/escrow-cancellation.ts @@ -4,7 +4,7 @@ const validate = utils.common.validate import {Instructions, Prepare} from './types' import {Memo} from '../common/types/objects' -type EscrowCancellation = { +export type EscrowCancellation = { owner: string, escrowSequence: number, memos?: Array diff --git a/src/transaction/escrow-creation.ts b/src/transaction/escrow-creation.ts index dd0b8b533f..16edb1bce5 100644 --- a/src/transaction/escrow-creation.ts +++ b/src/transaction/escrow-creation.ts @@ -5,7 +5,7 @@ const ValidationError = utils.common.errors.ValidationError import {Instructions, Prepare} from './types' import {Memo} from '../common/types/objects' -type EscrowCreation = { +export type EscrowCreation = { amount: string, destination: string, memos?: Array, diff --git a/src/transaction/escrow-execution.ts b/src/transaction/escrow-execution.ts index ff010233f7..261fa2d1a9 100644 --- a/src/transaction/escrow-execution.ts +++ b/src/transaction/escrow-execution.ts @@ -5,7 +5,7 @@ const ValidationError = utils.common.errors.ValidationError import {Instructions, Prepare} from './types' import {Memo} from '../common/types/objects' -type EscrowExecution = { +export type EscrowExecution = { owner: string, escrowSequence: number, memos?: Array, diff --git a/src/transaction/payment-channel-claim.ts b/src/transaction/payment-channel-claim.ts index 18a46b162a..55025a6a40 100644 --- a/src/transaction/payment-channel-claim.ts +++ b/src/transaction/payment-channel-claim.ts @@ -4,7 +4,7 @@ const claimFlags = utils.common.txFlags.PaymentChannelClaim import {validate, xrpToDrops} from '../common' import {Instructions, Prepare} from './types' -type PaymentChannelClaim = { +export type PaymentChannelClaim = { channel: string, balance?: string, amount?: string, diff --git a/src/transaction/payment-channel-create.ts b/src/transaction/payment-channel-create.ts index bf30116938..508391f3b8 100644 --- a/src/transaction/payment-channel-create.ts +++ b/src/transaction/payment-channel-create.ts @@ -2,7 +2,7 @@ import * as utils from './utils' import {validate, iso8601ToRippleTime, xrpToDrops} from '../common' import {Instructions, Prepare} from './types' -type PaymentChannelCreate = { +export type PaymentChannelCreate = { amount: string, destination: string, settleDelay: number, diff --git a/src/transaction/payment-channel-fund.ts b/src/transaction/payment-channel-fund.ts index 21c6fd73d2..d74320eb38 100644 --- a/src/transaction/payment-channel-fund.ts +++ b/src/transaction/payment-channel-fund.ts @@ -2,7 +2,7 @@ import * as utils from './utils' import {validate, iso8601ToRippleTime, xrpToDrops} from '../common' import {Instructions, Prepare} from './types' -type PaymentChannelFund = { +export type PaymentChannelFund = { channel: string, amount: string, expiration?: string diff --git a/src/transaction/payment.ts b/src/transaction/payment.ts index 06bfd92181..37051d5b67 100644 --- a/src/transaction/payment.ts +++ b/src/transaction/payment.ts @@ -9,7 +9,7 @@ import {Amount, Adjustment, MaxAdjustment, MinAdjustment, Memo} from '../common/types/objects' -type Payment = { + export type Payment = { source: Adjustment & MaxAdjustment, destination: Adjustment & MinAdjustment, paths?: string, diff --git a/src/transaction/settings.ts b/src/transaction/settings.ts index 9e061038e4..f5a9c890df 100644 --- a/src/transaction/settings.ts +++ b/src/transaction/settings.ts @@ -8,12 +8,12 @@ const AccountFields = utils.common.constants.AccountFields import {Instructions, Prepare} from './types' import {Memo} from '../common/types/objects' -type WeightedSigner = {address: string, weight: number} -type SettingsSigners = { +export type WeightedSigner = {address: string, weight: number} +export type SettingsSigners = { threshold?: number, weights: WeightedSigner[] } -type Settings = { +export type Settings = { passwordSpent?: boolean, requireDestinationTag?: boolean, requireAuthorization?: boolean, From df711ecb067e771e0eef913ab2a15c2b73bd0b47 Mon Sep 17 00:00:00 2001 From: Elliot Lee Date: Thu, 1 Mar 2018 21:22:36 -0800 Subject: [PATCH 5/7] Import from 'server' to fix TS4029 --- src/api.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/api.ts b/src/api.ts index c288dbe3c4..b1594be7e0 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,13 +1,15 @@ import * as _ from 'lodash' import {EventEmitter} from 'events' import {Connection, errors, validate} from './common' -import * as server from './server/server' -const connect = server.connect -const disconnect = server.disconnect -const getServerInfo = server.getServerInfo -const getFee = server.getFee -const isConnected = server.isConnected -const getLedgerVersion = server.getLedgerVersion +import { + connect, + disconnect, + isConnected, + getServerInfo, + getFee, + getLedgerVersion, + formatLedgerClose +} from './server/server' import getTransaction from './ledger/transaction' import getTransactions from './ledger/transactions' import getTrustlines from './ledger/trustlines' @@ -114,7 +116,7 @@ class RippleAPI extends EventEmitter { if (serverURL !== undefined) { this.connection = new RestrictedConnection(serverURL, options) this.connection.on('ledgerClosed', message => { - this.emit('ledger', server.formatLedgerClose(message)) + this.emit('ledger', formatLedgerClose(message)) }) this.connection.on('error', (errorCode, errorMessage, data) => { this.emit('error', errorCode, errorMessage, data) From facc513a526efffcf679e53296b69563048077e4 Mon Sep 17 00:00:00 2001 From: Elliot Lee Date: Thu, 1 Mar 2018 21:42:46 -0800 Subject: [PATCH 6/7] Add support for Checks (#853) - See https://github.com/ripple/rippled/pull/2245 * Add support for depositAuth flag * Upgrade ripple-binary-codec to 0.1.13 --- docs/index.md | 250 ++++++++++++++++++ docs/src/index.md.ejs | 3 + docs/src/prepareCheckCancel.md.ejs | 30 +++ docs/src/prepareCheckCash.md.ejs | 30 +++ docs/src/prepareCheckCreate.md.ejs | 30 +++ docs/src/specifications.md.ejs | 30 +++ docs/src/transactions.md.ejs | 6 + package.json | 2 +- src/api.ts | 6 + src/common/errors.ts | 2 +- src/common/schema-validator.ts | 6 + .../schemas/input/prepare-check-cancel.json | 18 ++ .../schemas/input/prepare-check-cash.json | 18 ++ .../schemas/input/prepare-check-create.json | 18 ++ src/common/schemas/objects/tx-type.json | 5 +- .../schemas/output/get-transaction.json | 36 +++ .../schemas/specifications/check-cancel.json | 14 + .../schemas/specifications/check-cash.json | 26 ++ .../schemas/specifications/check-create.json | 31 +++ src/common/validate.ts | 9 + src/ledger/parse/check-cancel.ts | 18 ++ src/ledger/parse/check-cash.ts | 35 +++ src/ledger/parse/check-create.ts | 38 +++ src/ledger/parse/transaction.ts | 9 + src/transaction/check-cancel.ts | 32 +++ src/transaction/check-cash.ts | 50 ++++ src/transaction/check-create.ts | 51 ++++ test/api-test.js | 70 +++++ test/fixtures/requests/index.js | 11 + .../requests/prepare-check-cancel.json | 3 + .../requests/prepare-check-cash-amount.json | 7 + .../prepare-check-cash-delivermin.json | 7 + .../requests/prepare-check-create-full.json | 10 + .../requests/prepare-check-create.json | 7 + .../get-transaction-check-cancel.json | 25 ++ .../responses/get-transaction-check-cash.json | 35 +++ .../get-transaction-check-create.json | 32 +++ ...n => get-transaction-escrow-creation.json} | 0 test/fixtures/responses/index.js | 19 +- .../responses/prepare-check-cancel.json | 8 + .../responses/prepare-check-cash-amount.json | 8 + .../prepare-check-cash-delivermin.json | 8 + .../responses/prepare-check-create-full.json | 8 + .../responses/prepare-check-create.json | 8 + test/fixtures/rippled/index.js | 3 + test/fixtures/rippled/tx/check-cancel.json | 89 +++++++ test/fixtures/rippled/tx/check-cash.json | 108 ++++++++ test/fixtures/rippled/tx/check-create.json | 88 ++++++ test/mock-rippled.js | 23 +- yarn.lock | 37 ++- 50 files changed, 1405 insertions(+), 12 deletions(-) create mode 100644 docs/src/prepareCheckCancel.md.ejs create mode 100644 docs/src/prepareCheckCash.md.ejs create mode 100644 docs/src/prepareCheckCreate.md.ejs create mode 100644 src/common/schemas/input/prepare-check-cancel.json create mode 100644 src/common/schemas/input/prepare-check-cash.json create mode 100644 src/common/schemas/input/prepare-check-create.json create mode 100644 src/common/schemas/specifications/check-cancel.json create mode 100644 src/common/schemas/specifications/check-cash.json create mode 100644 src/common/schemas/specifications/check-create.json create mode 100644 src/ledger/parse/check-cancel.ts create mode 100644 src/ledger/parse/check-cash.ts create mode 100644 src/ledger/parse/check-create.ts create mode 100644 src/transaction/check-cancel.ts create mode 100644 src/transaction/check-cash.ts create mode 100644 src/transaction/check-create.ts create mode 100644 test/fixtures/requests/prepare-check-cancel.json create mode 100644 test/fixtures/requests/prepare-check-cash-amount.json create mode 100644 test/fixtures/requests/prepare-check-cash-delivermin.json create mode 100644 test/fixtures/requests/prepare-check-create-full.json create mode 100644 test/fixtures/requests/prepare-check-create.json create mode 100644 test/fixtures/responses/get-transaction-check-cancel.json create mode 100644 test/fixtures/responses/get-transaction-check-cash.json create mode 100644 test/fixtures/responses/get-transaction-check-create.json rename test/fixtures/responses/{get-transaction-escrow-create.json => get-transaction-escrow-creation.json} (100%) create mode 100644 test/fixtures/responses/prepare-check-cancel.json create mode 100644 test/fixtures/responses/prepare-check-cash-amount.json create mode 100644 test/fixtures/responses/prepare-check-cash-delivermin.json create mode 100644 test/fixtures/responses/prepare-check-create-full.json create mode 100644 test/fixtures/responses/prepare-check-create.json create mode 100644 test/fixtures/rippled/tx/check-cancel.json create mode 100644 test/fixtures/rippled/tx/check-cash.json create mode 100644 test/fixtures/rippled/tx/check-create.json diff --git a/docs/index.md b/docs/index.md index cd5b581e29..2fa42b4d60 100644 --- a/docs/index.md +++ b/docs/index.md @@ -27,6 +27,9 @@ - [Escrow Creation](#escrow-creation) - [Escrow Cancellation](#escrow-cancellation) - [Escrow Execution](#escrow-execution) + - [Check Create](#check-create) + - [Check Cancel](#check-cancel) + - [Check Cash](#check-cash) - [Payment Channel Create](#payment-channel-create) - [Payment Channel Fund](#payment-channel-fund) - [Payment Channel Claim](#payment-channel-claim) @@ -60,6 +63,9 @@ - [preparePaymentChannelCreate](#preparepaymentchannelcreate) - [preparePaymentChannelClaim](#preparepaymentchannelclaim) - [preparePaymentChannelFund](#preparepaymentchannelfund) + - [prepareCheckCreate](#preparecheckcreate) + - [prepareCheckCancel](#preparecheckcancel) + - [prepareCheckCash](#preparecheckcash) - [sign](#sign) - [combine](#combine) - [submit](#submit) @@ -266,6 +272,9 @@ Type | Description [escrowCreation](#escrow-creation) | An `escrowCreation` transaction creates an escrow on the ledger, which locks XRP until a cryptographic condition is met or it expires. It is like an escrow service where the XRP Ledger acts as the escrow agent. [escrowCancellation](#escrow-cancellation) | An `escrowCancellation` transaction unlocks the funds in an escrow and sends them back to the creator of the escrow, but it will only work after the escrow expires. [escrowExecution](#escrow-execution) | An `escrowExecution` transaction unlocks the funds in an escrow and sends them to the destination of the escrow, but it will only work if the cryptographic condition is provided. +[checkCreate](#check-create) | A `checkCreate` transaction creates a check on the ledger, which is a deferred payment that can be cashed by its intended destination. +[checkCancel](#check-cancel) | A `checkCancel` transaction cancels an unreedemed Check, removing it from the ledger without sending any money. +[checkCash](#checkCash) | A `checkCash` transaction redeems a Check to receive up to the amount authorized by the corresponding `checkCreate` transaction. Only the `destination` address of a Check can cash it. ## Transaction Flow @@ -280,6 +289,9 @@ Executing a transaction with `RippleAPI` requires the following four steps: * [prepareEscrowCreation](#prepareescrowcreation) * [prepareEscrowCancellation](#prepareescrowcancellation) * [prepareEscrowExecution](#prepareescrowexecution) + * [prepareCheckCreate](#preparecheckcreate) + * [prepareCheckCancel](#preparecheckcancel) + * [prepareCheckCash](#preparecheckcash) 2. [Sign](#sign) - Cryptographically sign the transaction locally and save the [transaction ID](#transaction-id). Signing is how the owner of an account authorizes a transaction to take place. For multisignature transactions, the `signedTransaction` fields returned by `sign` must be collected and passed to the [combine](#combine) method. 3. [Submit](#submit) - Submit the transaction to the connected server. 4. Verify - Verify that the transaction got validated by querying with [getTransaction](#gettransaction). This is necessary because transactions may fail even if they were successfully submitted. @@ -593,6 +605,74 @@ memos | [memos](#transaction-memos) | *Optional* Array of memos to attach to the ``` +## Check Create + +See [Transaction Types](#transaction-types) for a description. + +Name | Type | Description +---- | ---- | ----------- +destination | [address](#address) | Address of the account that can cash the check. +sendMax | [laxAmount](#amount) | Amount of source currency the check is allowed to debit the sender, including transfer fees on non-XRP currencies. +destinationTag | integer | *Optional* Destination tag that identifies the reason for the check, or a hosted recipient to pay. +expiration | date-time string | *Optional* Time after which the check is no longer valid. +invoiceID | string | *Optional* 256-bit hash, as a 64-character hexadecimal string, representing a specific reason or identifier for this check. + +### Example + + +```json +{ + "destination": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW", + "sendMax": { + "currency": "XRP", + "value": "1" + } +} +``` + + +## Check Cancel + +See [Transaction Types](#transaction-types) for a description. + +Name | Type | Description +---- | ---- | ----------- +checkID | string | The ID of the Check ledger object to cancel, as a 64-character hexadecimal string. + +### Example + + +```json +{ + "checkID": "49647F0D748DC3FE26BDACBC57F251AADEFFF391403EC9BF87C97F67E9977FB0" +} +``` + + +## Check Cash + +See [Transaction Types](#transaction-types) for a description. + +Name | Type | Description +---- | ---- | ----------- +checkID | string | The ID of the Check ledger object to cash, as a 64-character hexadecimal string. +amount | [laxAmount](#amount) | *Optional* Redeem the Check for exactly this amount, if possible. The currency must match that of the sendMax of the corresponding CheckCreate transaction. You must provide either this field or deliverMin. +deliverMin | [laxAmount](#amount) | *Optional* Redeem the Check for at least this amount and for as much as possible. The currency must match that of the sendMax of the corresponding CheckCreate transaction. You must provide either this field or amount. + +### Example + + +```json +{ + "amount": { + "currency": "XRP", + "value": "1" + }, + "checkID": "838766BA2B995C00744175F69A1B11E32C3DBC40E64801A4056FCBD657F57334" +} +``` + + ## Payment Channel Create See [Transaction Types](#transaction-types) for a description. @@ -3592,6 +3672,176 @@ return api.preparePaymentChannelFund(address, paymentChannelFund).then(prepared ``` +## prepareCheckCreate + +`prepareCheckCreate(address: string, checkCreate: Object, instructions: Object): Promise` + +Prepare a Check creation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit). + +### Parameters + +Name | Type | Description +---- | ---- | ----------- +address | [address](#address) | The address of the account that is creating the transaction. +checkCreate | [checkCreate](#check-create) | The specification of the Check create creation to prepare. +instructions | [instructions](#transaction-instructions) | *Optional* Instructions for executing the transaction + +### Return Value + +This method returns a promise that resolves with an object with the following structure: + + + +Name | Type | Description +---- | ---- | ----------- +txJSON | string | The prepared transaction in rippled JSON format. +instructions | object | The instructions for how to execute the transaction after adding automatic defaults. +*instructions.* fee | [value](#value) | An exact fee to pay for the transaction. See [Transaction Fees](#transaction-fees) for more information. +*instructions.* sequence | [sequence](#account-sequence-number) | The initiating account's sequence number for this transaction. +*instructions.* maxLedgerVersion | integer,null | The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum. + +### Example + +```javascript +const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'; +const checkCreate = { + "destination": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW", + "sendMax": { + "currency": "XRP", + "value": "1" + } +}; +return api.prepareCheckCreate(address, checkCreate).then(prepared => + {/* ... */}); +``` + + +```json +{ + "txJSON": "{\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"TransactionType\":\"CheckCreate\",\"Destination\":\"rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW\",\"SendMax\":\"1000000\",\"Flags\":2147483648,\"LastLedgerSequence\":8820051,\"Sequence\":23,\"Fee\":\"12\"}", + "instructions": { + "fee": "0.000012", + "sequence": 23, + "maxLedgerVersion": 8820051 + } +} +``` + + +## prepareCheckCancel + +`prepareCheckCancel(address: string, checkCancel: Object, instructions: Object): Promise` + +Prepare a Check cancellation transaction. This cancels an unredeemed Check, removing it from the ledger without sending any money. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit). + +### Parameters + +Name | Type | Description +---- | ---- | ----------- +address | [address](#address) | The address of the account that is creating the transaction. +checkCancel | [checkCancel](#check-cancel) | The specification of the Check cancellation to prepare. +instructions | [instructions](#transaction-instructions) | *Optional* Instructions for executing the transaction + +### Return Value + +This method returns a promise that resolves with an object with the following structure: + + + +Name | Type | Description +---- | ---- | ----------- +txJSON | string | The prepared transaction in rippled JSON format. +instructions | object | The instructions for how to execute the transaction after adding automatic defaults. +*instructions.* fee | [value](#value) | An exact fee to pay for the transaction. See [Transaction Fees](#transaction-fees) for more information. +*instructions.* sequence | [sequence](#account-sequence-number) | The initiating account's sequence number for this transaction. +*instructions.* maxLedgerVersion | integer,null | The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum. + +### Example + +```javascript +const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'; +const checkCancel = { + "checkID": "49647F0D748DC3FE26BDACBC57F251AADEFFF391403EC9BF87C97F67E9977FB0" +}; +return api.prepareCheckCancel(address, checkCancel).then(prepared => + {/* ... */}); +``` + + +```json +{ + "txJSON": "{\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"TransactionType\":\"CheckCancel\",\"CheckID\":\"49647F0D748DC3FE26BDACBC57F251AADEFFF391403EC9BF87C97F67E9977FB0\",\"Flags\":2147483648,\"LastLedgerSequence\":8819954,\"Fee\":\"12\",\"Sequence\":23}", + "instructions": { + "fee": "0.000012", + "sequence": 23, + "maxLedgerVersion": 8819954 + } +} +``` + + +## prepareCheckCash + +`prepareCheckCash(address: string, checkCash: Object, instructions: Object): Promise` + +Prepare a Check cashing transaction. This redeems a Check to receive up to the amount authorized by the corresponding CheckCreate transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit). + +### Parameters + +Name | Type | Description +---- | ---- | ----------- +address | [address](#address) | The address of the account that is creating the transaction. +checkCash | [checkCash](#check-cash) | The specification of the Check cash to prepare. +instructions | [instructions](#transaction-instructions) | *Optional* Instructions for executing the transaction + +### Return Value + +This method returns a promise that resolves with an object with the following structure: + + + +Name | Type | Description +---- | ---- | ----------- +txJSON | string | The prepared transaction in rippled JSON format. +instructions | object | The instructions for how to execute the transaction after adding automatic defaults. +*instructions.* fee | [value](#value) | An exact fee to pay for the transaction. See [Transaction Fees](#transaction-fees) for more information. +*instructions.* sequence | [sequence](#account-sequence-number) | The initiating account's sequence number for this transaction. +*instructions.* maxLedgerVersion | integer,null | The highest ledger version that the transaction can be included in. Set to `null` if there is no maximum. + +### Example + +```javascript +const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'; +const checkCash = { + "amount": { + "currency": "XRP", + "value": "1" + }, + "checkID": "838766BA2B995C00744175F69A1B11E32C3DBC40E64801A4056FCBD657F57334" +}; +return api.prepareCheckCash(address, checkCash).then(prepared => + {/* ... */}); +``` + + +```json +{ + "txJSON": "{\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"TransactionType\":\"CheckCash\",\"CheckID\":\"838766BA2B995C00744175F69A1B11E32C3DBC40E64801A4056FCBD657F57334\",\"Amount\":\"1000000\",\"Flags\":2147483648,\"LastLedgerSequence\":8819954,\"Sequence\":23,\"Fee\":\"12\"}", + "instructions": { + "fee": "0.000012", + "sequence": 23, + "maxLedgerVersion": 8819954 + } +} +``` + + ## sign `sign(txJSON: string, secret: string, options: Object): {signedTransaction: string, id: string}` diff --git a/docs/src/index.md.ejs b/docs/src/index.md.ejs index 8017c549ef..5ba59633ec 100644 --- a/docs/src/index.md.ejs +++ b/docs/src/index.md.ejs @@ -34,6 +34,9 @@ <% include preparePaymentChannelCreate.md.ejs %> <% include preparePaymentChannelClaim.md.ejs %> <% include preparePaymentChannelFund.md.ejs %> +<% include prepareCheckCreate.md.ejs %> +<% include prepareCheckCancel.md.ejs %> +<% include prepareCheckCash.md.ejs %> <% include sign.md.ejs %> <% include combine.md.ejs %> <% include submit.md.ejs %> diff --git a/docs/src/prepareCheckCancel.md.ejs b/docs/src/prepareCheckCancel.md.ejs new file mode 100644 index 0000000000..b1dc279114 --- /dev/null +++ b/docs/src/prepareCheckCancel.md.ejs @@ -0,0 +1,30 @@ +## prepareCheckCancel + +`prepareCheckCancel(address: string, checkCancel: Object, instructions: Object): Promise` + +Prepare a Check cancellation transaction. This cancels an unredeemed Check, removing it from the ledger without sending any money. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit). + +### Parameters + +<%- renderSchema('input/prepare-check-cancel.json') %> + +### Return Value + +This method returns a promise that resolves with an object with the following structure: + + + +<%- renderSchema('output/prepare.json') %> + +### Example + +```javascript +const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'; +const checkCancel = <%- importFile('test/fixtures/requests/prepare-check-cancel.json') %>; +return api.prepareCheckCancel(address, checkCancel).then(prepared => + {/* ... */}); +``` + +<%- renderFixture('responses/prepare-check-cancel.json') %> diff --git a/docs/src/prepareCheckCash.md.ejs b/docs/src/prepareCheckCash.md.ejs new file mode 100644 index 0000000000..5a646042bf --- /dev/null +++ b/docs/src/prepareCheckCash.md.ejs @@ -0,0 +1,30 @@ +## prepareCheckCash + +`prepareCheckCash(address: string, checkCash: Object, instructions: Object): Promise` + +Prepare a Check cashing transaction. This redeems a Check to receive up to the amount authorized by the corresponding CheckCreate transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit). + +### Parameters + +<%- renderSchema('input/prepare-check-cash.json') %> + +### Return Value + +This method returns a promise that resolves with an object with the following structure: + + + +<%- renderSchema('output/prepare.json') %> + +### Example + +```javascript +const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'; +const checkCash = <%- importFile('test/fixtures/requests/prepare-check-cash-amount.json') %>; +return api.prepareCheckCash(address, checkCash).then(prepared => + {/* ... */}); +``` + +<%- renderFixture('responses/prepare-check-cash-amount.json') %> diff --git a/docs/src/prepareCheckCreate.md.ejs b/docs/src/prepareCheckCreate.md.ejs new file mode 100644 index 0000000000..6b776d8808 --- /dev/null +++ b/docs/src/prepareCheckCreate.md.ejs @@ -0,0 +1,30 @@ +## prepareCheckCreate + +`prepareCheckCreate(address: string, checkCreate: Object, instructions: Object): Promise` + +Prepare a Check creation transaction. The prepared transaction must subsequently be [signed](#sign) and [submitted](#submit). + +### Parameters + +<%- renderSchema('input/prepare-check-create.json') %> + +### Return Value + +This method returns a promise that resolves with an object with the following structure: + + + +<%- renderSchema('output/prepare.json') %> + +### Example + +```javascript +const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59'; +const checkCreate = <%- importFile('test/fixtures/requests/prepare-check-create.json') %>; +return api.prepareCheckCreate(address, checkCreate).then(prepared => + {/* ... */}); +``` + +<%- renderFixture('responses/prepare-check-create.json') %> diff --git a/docs/src/specifications.md.ejs b/docs/src/specifications.md.ejs index d4f4638bf2..0ab1cb0d7f 100644 --- a/docs/src/specifications.md.ejs +++ b/docs/src/specifications.md.ejs @@ -82,6 +82,36 @@ See [Transaction Types](#transaction-types) for a description. <%- renderFixture('requests/prepare-escrow-execution.json') %> +## Check Create + +See [Transaction Types](#transaction-types) for a description. + +<%- renderSchema('specifications/check-create.json') %> + +### Example + +<%- renderFixture('requests/prepare-check-create.json') %> + +## Check Cancel + +See [Transaction Types](#transaction-types) for a description. + +<%- renderSchema('specifications/check-cancel.json') %> + +### Example + +<%- renderFixture('requests/prepare-check-cancel.json') %> + +## Check Cash + +See [Transaction Types](#transaction-types) for a description. + +<%- renderSchema('specifications/check-cash.json') %> + +### Example + +<%- renderFixture('requests/prepare-check-cash-amount.json') %> + ## Payment Channel Create See [Transaction Types](#transaction-types) for a description. diff --git a/docs/src/transactions.md.ejs b/docs/src/transactions.md.ejs index 1df5c2c602..4689b258dc 100644 --- a/docs/src/transactions.md.ejs +++ b/docs/src/transactions.md.ejs @@ -14,6 +14,9 @@ Type | Description [escrowCreation](#escrow-creation) | An `escrowCreation` transaction creates an escrow on the ledger, which locks XRP until a cryptographic condition is met or it expires. It is like an escrow service where the XRP Ledger acts as the escrow agent. [escrowCancellation](#escrow-cancellation) | An `escrowCancellation` transaction unlocks the funds in an escrow and sends them back to the creator of the escrow, but it will only work after the escrow expires. [escrowExecution](#escrow-execution) | An `escrowExecution` transaction unlocks the funds in an escrow and sends them to the destination of the escrow, but it will only work if the cryptographic condition is provided. +[checkCreate](#check-create) | A `checkCreate` transaction creates a check on the ledger, which is a deferred payment that can be cashed by its intended destination. +[checkCancel](#check-cancel) | A `checkCancel` transaction cancels an unreedemed Check, removing it from the ledger without sending any money. +[checkCash](#checkCash) | A `checkCash` transaction redeems a Check to receive up to the amount authorized by the corresponding `checkCreate` transaction. Only the `destination` address of a Check can cash it. ## Transaction Flow @@ -28,6 +31,9 @@ Executing a transaction with `RippleAPI` requires the following four steps: * [prepareEscrowCreation](#prepareescrowcreation) * [prepareEscrowCancellation](#prepareescrowcancellation) * [prepareEscrowExecution](#prepareescrowexecution) + * [prepareCheckCreate](#preparecheckcreate) + * [prepareCheckCancel](#preparecheckcancel) + * [prepareCheckCash](#preparecheckcash) 2. [Sign](#sign) - Cryptographically sign the transaction locally and save the [transaction ID](#transaction-id). Signing is how the owner of an account authorizes a transaction to take place. For multisignature transactions, the `signedTransaction` fields returned by `sign` must be collected and passed to the [combine](#combine) method. 3. [Submit](#submit) - Submit the transaction to the connected server. 4. Verify - Verify that the transaction got validated by querying with [getTransaction](#gettransaction). This is necessary because transactions may fail even if they were successfully submitted. diff --git a/package.json b/package.json index 187bc83a0b..af92ffa3b6 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "jsonschema": "^1.1.1", "lodash": "^4.17.4", "ripple-address-codec": "^2.0.1", - "ripple-binary-codec": "^0.1.10", + "ripple-binary-codec": "^0.1.13", "ripple-hashes": "^0.3.1", "ripple-keypairs": "^0.10.1", "ripple-lib-transactionparser": "^0.6.2", diff --git a/src/api.ts b/src/api.ts index b1594be7e0..82be4f69db 100644 --- a/src/api.ts +++ b/src/api.ts @@ -31,6 +31,9 @@ import prepareEscrowCancellation from './transaction/escrow-cancellation' import preparePaymentChannelCreate from './transaction/payment-channel-create' import preparePaymentChannelFund from './transaction/payment-channel-fund' import preparePaymentChannelClaim from './transaction/payment-channel-claim' +import prepareCheckCreate from './transaction/check-create' +import prepareCheckCancel from './transaction/check-cancel' +import prepareCheckCash from './transaction/check-cash' import prepareSettings from './transaction/settings' import sign from './transaction/sign' import combine from './transaction/combine' @@ -250,6 +253,9 @@ class RippleAPI extends EventEmitter { preparePaymentChannelCreate = preparePaymentChannelCreate preparePaymentChannelFund = preparePaymentChannelFund preparePaymentChannelClaim = preparePaymentChannelClaim + prepareCheckCreate = prepareCheckCreate + prepareCheckCash = prepareCheckCash + prepareCheckCancel = prepareCheckCancel prepareSettings = prepareSettings sign = sign combine = combine diff --git a/src/common/errors.ts b/src/common/errors.ts index 46ec21b30d..7cf8a1df7e 100644 --- a/src/common/errors.ts +++ b/src/common/errors.ts @@ -29,7 +29,7 @@ class RippleError extends Error { } /* console.log in node uses util.inspect on object, and util.inspect allows - us to cutomize its output: + us to customize its output: https://nodejs.org/api/util.html#util_custom_inspect_function_on_objects */ inspect() { return this.toString() diff --git a/src/common/schema-validator.ts b/src/common/schema-validator.ts index 51161fb303..b48bd8664e 100644 --- a/src/common/schema-validator.ts +++ b/src/common/schema-validator.ts @@ -53,6 +53,9 @@ function loadSchemas() { require('./schemas/specifications/payment-channel-create.json'), require('./schemas/specifications/payment-channel-fund.json'), require('./schemas/specifications/payment-channel-claim.json'), + require('./schemas/specifications/check-create.json'), + require('./schemas/specifications/check-cash.json'), + require('./schemas/specifications/check-cancel.json'), require('./schemas/specifications/trustline.json'), require('./schemas/output/sign.json'), require('./schemas/output/submit.json'), @@ -100,6 +103,9 @@ function loadSchemas() { require('./schemas/input/prepare-payment-channel-create.json'), require('./schemas/input/prepare-payment-channel-fund.json'), require('./schemas/input/prepare-payment-channel-claim.json'), + require('./schemas/input/prepare-check-create.json'), + require('./schemas/input/prepare-check-cash.json'), + require('./schemas/input/prepare-check-cancel.json'), require('./schemas/input/compute-ledger-hash.json'), require('./schemas/input/sign.json'), require('./schemas/input/submit.json'), diff --git a/src/common/schemas/input/prepare-check-cancel.json b/src/common/schemas/input/prepare-check-cancel.json new file mode 100644 index 0000000000..430e47ffe0 --- /dev/null +++ b/src/common/schemas/input/prepare-check-cancel.json @@ -0,0 +1,18 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "prepareCheckCancelParameters", + "type": "object", + "properties": { + "address": { + "$ref": "address", + "description": "The address of the account that is creating the transaction." + }, + "checkCancel": { + "$ref": "checkCancel", + "description": "The specification of the Check cancellation to prepare." + }, + "instructions": {"$ref": "instructions"} + }, + "additionalProperties": false, + "required": ["address", "checkCancel"] +} diff --git a/src/common/schemas/input/prepare-check-cash.json b/src/common/schemas/input/prepare-check-cash.json new file mode 100644 index 0000000000..16d491bf75 --- /dev/null +++ b/src/common/schemas/input/prepare-check-cash.json @@ -0,0 +1,18 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "prepareCheckCashParameters", + "type": "object", + "properties": { + "address": { + "$ref": "address", + "description": "The address of the account that is creating the transaction." + }, + "checkCash": { + "$ref": "checkCash", + "description": "The specification of the Check cash to prepare." + }, + "instructions": {"$ref": "instructions"} + }, + "additionalProperties": false, + "required": ["address", "checkCash"] +} diff --git a/src/common/schemas/input/prepare-check-create.json b/src/common/schemas/input/prepare-check-create.json new file mode 100644 index 0000000000..180281b80e --- /dev/null +++ b/src/common/schemas/input/prepare-check-create.json @@ -0,0 +1,18 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "prepareCheckCreateParameters", + "type": "object", + "properties": { + "address": { + "$ref": "address", + "description": "The address of the account that is creating the transaction." + }, + "checkCreate": { + "$ref": "checkCreate", + "description": "The specification of the Check create creation to prepare." + }, + "instructions": {"$ref": "instructions"} + }, + "additionalProperties": false, + "required": ["address", "checkCreate"] +} diff --git a/src/common/schemas/objects/tx-type.json b/src/common/schemas/objects/tx-type.json index 0200ff6776..0b120cf9e1 100644 --- a/src/common/schemas/objects/tx-type.json +++ b/src/common/schemas/objects/tx-type.json @@ -15,6 +15,9 @@ "escrowExecution", "paymentChannelCreate", "paymentChannelFund", - "paymentChannelClaim" + "paymentChannelClaim", + "checkCreate", + "checkCancel", + "checkCash" ] } diff --git a/src/common/schemas/output/get-transaction.json b/src/common/schemas/output/get-transaction.json index 9665b1b3ab..0f860110b6 100644 --- a/src/common/schemas/output/get-transaction.json +++ b/src/common/schemas/output/get-transaction.json @@ -96,6 +96,42 @@ } } }, + { + "properties": { + "type": { + "enum": [ + "checkCreate" + ] + }, + "specification": { + "$ref": "checkCreate" + } + } + }, + { + "properties": { + "type": { + "enum": [ + "checkCancel" + ] + }, + "specification": { + "$ref": "checkCancel" + } + } + }, + { + "properties": { + "type": { + "enum": [ + "checkCash" + ] + }, + "specification": { + "$ref": "checkCash" + } + } + }, { "properties": { "type": { diff --git a/src/common/schemas/specifications/check-cancel.json b/src/common/schemas/specifications/check-cancel.json new file mode 100644 index 0000000000..a3558a18c7 --- /dev/null +++ b/src/common/schemas/specifications/check-cancel.json @@ -0,0 +1,14 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "checkCancel", + "link": "check-cancel", + "type": "object", + "properties": { + "checkID": { + "$ref": "hash256", + "description": "The ID of the Check ledger object to cancel, as a 64-character hexadecimal string." + } + }, + "required": ["checkID"], + "additionalProperties": false +} diff --git a/src/common/schemas/specifications/check-cash.json b/src/common/schemas/specifications/check-cash.json new file mode 100644 index 0000000000..9895f31828 --- /dev/null +++ b/src/common/schemas/specifications/check-cash.json @@ -0,0 +1,26 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "checkCash", + "link": "check-cash", + "type": "object", + "properties": { + "checkID": { + "$ref": "hash256", + "description": "The ID of the Check ledger object to cash, as a 64-character hexadecimal string." + }, + "amount": { + "$ref": "laxAmount", + "description": "Redeem the Check for exactly this amount, if possible. The currency must match that of the sendMax of the corresponding CheckCreate transaction. You must provide either this field or deliverMin." + }, + "deliverMin": { + "$ref": "laxAmount", + "description": "Redeem the Check for at least this amount and for as much as possible. The currency must match that of the sendMax of the corresponding CheckCreate transaction. You must provide either this field or amount." + } + }, + "required": ["checkID"], + "oneOf": [ + {"required": ["amount"]}, + {"required": ["deliverMin"]} + ], + "additionalProperties": false +} diff --git a/src/common/schemas/specifications/check-create.json b/src/common/schemas/specifications/check-create.json new file mode 100644 index 0000000000..b8bb228b34 --- /dev/null +++ b/src/common/schemas/specifications/check-create.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "checkCreate", + "link": "check-create", + "type": "object", + "properties": { + "destination": { + "$ref": "address", + "description": "Address of the account that can cash the check." + }, + "sendMax": { + "$ref": "laxAmount", + "description": "Amount of source currency the check is allowed to debit the sender, including transfer fees on non-XRP currencies." + }, + "destinationTag": { + "$ref": "tag", + "description": "Destination tag that identifies the reason for the check, or a hosted recipient to pay." + }, + "expiration": { + "type": "string", + "format": "date-time", + "description": "Time after which the check is no longer valid." + }, + "invoiceID": { + "$ref": "hash256", + "description": "256-bit hash, as a 64-character hexadecimal string, representing a specific reason or identifier for this check." + } + }, + "required": ["destination", "sendMax"], + "additionalProperties": false +} diff --git a/src/common/validate.ts b/src/common/validate.ts index 3ffac66747..3b229c3f3a 100644 --- a/src/common/validate.ts +++ b/src/common/validate.ts @@ -89,6 +89,15 @@ _.partial(schemaValidate, 'preparePaymentChannelFundParameters') export const preparePaymentChannelClaim = _.partial(schemaValidate, 'preparePaymentChannelClaimParameters') +export const prepareCheckCreate = +_.partial(schemaValidate, 'prepareCheckCreateParameters') + +export const prepareCheckCash = +_.partial(schemaValidate, 'prepareCheckCashParameters') + +export const prepareCheckCancel = +_.partial(schemaValidate, 'prepareCheckCancelParameters') + export const sign = _.partial(schemaValidate, 'signParameters') diff --git a/src/ledger/parse/check-cancel.ts b/src/ledger/parse/check-cancel.ts new file mode 100644 index 0000000000..437944bb6e --- /dev/null +++ b/src/ledger/parse/check-cancel.ts @@ -0,0 +1,18 @@ +import * as assert from 'assert' +import {removeUndefined} from '../../common' + +export type FormattedCheckCancel = { + + // ID of the Check ledger object to cancel. + checkID: string +} + +function parseCheckCancel(tx: any): FormattedCheckCancel { + assert(tx.TransactionType === 'CheckCancel') + + return removeUndefined({ + checkID: tx.CheckID + }) +} + +export default parseCheckCancel diff --git a/src/ledger/parse/check-cash.ts b/src/ledger/parse/check-cash.ts new file mode 100644 index 0000000000..211bf04603 --- /dev/null +++ b/src/ledger/parse/check-cash.ts @@ -0,0 +1,35 @@ +import * as assert from 'assert' +import {removeUndefined} from '../../common' +import parseAmount from './amount' +import {Amount} from '../../common/types/objects' + +export type FormattedCheckCash = { + + // ID of the Check ledger object to cash. + checkID: string, + + // (Optional) redeem the Check for exactly this amount, if possible. + // The currency must match that of the `SendMax` of the corresponding + // `CheckCreate` transaction. + amount: Amount, + + // (Optional) redeem the Check for at least this amount and + // for as much as possible. + // The currency must match that of the `SendMax` of the corresponding + // `CheckCreate` transaction. + deliverMin: Amount + + // *must* include either Amount or DeliverMin, but not both. +} + +function parseCheckCash(tx: any): FormattedCheckCash { + assert(tx.TransactionType === 'CheckCash') + + return removeUndefined({ + checkID: tx.CheckID, + amount: tx.Amount && parseAmount(tx.Amount), + deliverMin: tx.DeliverMin && parseAmount(tx.DeliverMin) + }) +} + +export default parseCheckCash diff --git a/src/ledger/parse/check-create.ts b/src/ledger/parse/check-create.ts new file mode 100644 index 0000000000..e468add95b --- /dev/null +++ b/src/ledger/parse/check-create.ts @@ -0,0 +1,38 @@ +import * as assert from 'assert' +import {parseTimestamp} from './utils' +import {removeUndefined} from '../../common' +import parseAmount from './amount' +import {Amount} from '../../common/types/objects' + +export type FormattedCheckCreate = { + + // account that can cash the check. + destination: string, + + // amount the check is allowed to debit the sender, + // including transfer fees on non-XRP currencies. + sendMax: Amount, + + // (Optional) identifies the reason for the check, or a hosted recipient. + destinationTag?: string, + + // (Optional) time in seconds since the Ripple Epoch. + expiration?: string, + + // (Optional) 256-bit hash representing a specific reason or identifier. + invoiceID?: string +} + +function parseCheckCreate(tx: any): FormattedCheckCreate { + assert(tx.TransactionType === 'CheckCreate') + + return removeUndefined({ + destination: tx.Destination, + sendMax: parseAmount(tx.SendMax), + destinationTag: tx.DestinationTag, + expiration: tx.Expiration && parseTimestamp(tx.Expiration), + invoiceID: tx.InvoiceID + }) +} + +export default parseCheckCreate diff --git a/src/ledger/parse/transaction.ts b/src/ledger/parse/transaction.ts index f5a0c082f7..7d19d3baba 100644 --- a/src/ledger/parse/transaction.ts +++ b/src/ledger/parse/transaction.ts @@ -9,6 +9,9 @@ import parseSettings from './settings' import parseEscrowCreation from './escrow-creation' import parseEscrowExecution from './escrow-execution' import parseEscrowCancellation from './escrow-cancellation' +import parseCheckCreate from './check-create' +import parseCheckCash from './check-cash' +import parseCheckCancel from './check-cancel' import parsePaymentChannelCreate from './payment-channel-create' import parsePaymentChannelFund from './payment-channel-fund' import parsePaymentChannelClaim from './payment-channel-claim' @@ -26,6 +29,9 @@ function parseTransactionType(type) { EscrowCreate: 'escrowCreation', EscrowFinish: 'escrowExecution', EscrowCancel: 'escrowCancellation', + CheckCreate: 'checkCreate', + CheckCash: 'checkCash', + CheckCancel: 'checkCancel', PaymentChannelCreate: 'paymentChannelCreate', PaymentChannelFund: 'paymentChannelFund', PaymentChannelClaim: 'paymentChannelClaim', @@ -47,6 +53,9 @@ function parseTransaction(tx: any): any { 'escrowCreation': parseEscrowCreation, 'escrowExecution': parseEscrowExecution, 'escrowCancellation': parseEscrowCancellation, + 'checkCreate': parseCheckCreate, + 'checkCash': parseCheckCash, + 'checkCancel': parseCheckCancel, 'paymentChannelCreate': parsePaymentChannelCreate, 'paymentChannelFund': parsePaymentChannelFund, 'paymentChannelClaim': parsePaymentChannelClaim, diff --git a/src/transaction/check-cancel.ts b/src/transaction/check-cancel.ts new file mode 100644 index 0000000000..9a694672f1 --- /dev/null +++ b/src/transaction/check-cancel.ts @@ -0,0 +1,32 @@ +import * as utils from './utils' +import {validate} from '../common' +import {Instructions, Prepare} from './types' + +type CheckCancel = { + checkID: string +} + +function createCheckCancelTransaction(account: string, + cancel: CheckCancel +): object { + const txJSON = { + Account: account, + TransactionType: 'CheckCancel', + CheckID: cancel.checkID + } + + return txJSON +} + +function prepareCheckCancel(address: string, + checkCancel: CheckCancel, + instructions: Instructions = {} +): Promise { + validate.prepareCheckCancel( + {address, checkCancel, instructions}) + const txJSON = createCheckCancelTransaction( + address, checkCancel) + return utils.prepareTransaction(txJSON, this, instructions) +} + +export default prepareCheckCancel diff --git a/src/transaction/check-cash.ts b/src/transaction/check-cash.ts new file mode 100644 index 0000000000..67686bf44e --- /dev/null +++ b/src/transaction/check-cash.ts @@ -0,0 +1,50 @@ +import * as utils from './utils' +const ValidationError = utils.common.errors.ValidationError +const toRippledAmount = utils.common.toRippledAmount +import {validate} from '../common' +import {Instructions, Prepare} from './types' +import {Amount} from '../common/types/objects' + +type CheckCash = { + checkID: string, + amount?: Amount, + deliverMin?: Amount +} + +function createCheckCashTransaction(account: string, + checkCash: CheckCash +): object { + if (checkCash.amount && checkCash.deliverMin) { + throw new ValidationError('"amount" and "deliverMin" properties on ' + + 'CheckCash are mutually exclusive') + } + + const txJSON: any = { + Account: account, + TransactionType: 'CheckCash', + CheckID: checkCash.checkID + } + + if (checkCash.amount !== undefined) { + txJSON.Amount = toRippledAmount(checkCash.amount) + } + + if (checkCash.deliverMin !== undefined) { + txJSON.DeliverMin = toRippledAmount(checkCash.deliverMin) + } + + return txJSON +} + +function prepareCheckCash(address: string, + checkCash: CheckCash, + instructions: Instructions = {} +): Promise { + validate.prepareCheckCash( + {address, checkCash, instructions}) + const txJSON = createCheckCashTransaction( + address, checkCash) + return utils.prepareTransaction(txJSON, this, instructions) +} + +export default prepareCheckCash diff --git a/src/transaction/check-create.ts b/src/transaction/check-create.ts new file mode 100644 index 0000000000..8fce9ef0d1 --- /dev/null +++ b/src/transaction/check-create.ts @@ -0,0 +1,51 @@ +import * as utils from './utils' +const toRippledAmount = utils.common.toRippledAmount +import {validate, iso8601ToRippleTime} from '../common' +import {Instructions, Prepare} from './types' +import {Amount} from '../common/types/objects' + +type CheckCreate = { + destination: string, + sendMax: Amount, + destinationTag?: number, + expiration?: string, + invoiceID?: string +} + +function createCheckCreateTransaction(account: string, + check: CheckCreate +): object { + const txJSON: any = { + Account: account, + TransactionType: 'CheckCreate', + Destination: check.destination, + SendMax: toRippledAmount(check.sendMax) + } + + if (check.destinationTag !== undefined) { + txJSON.DestinationTag = check.destinationTag + } + + if (check.expiration !== undefined) { + txJSON.Expiration = iso8601ToRippleTime(check.expiration) + } + + if (check.invoiceID !== undefined) { + txJSON.InvoiceID = check.invoiceID + } + + return txJSON +} + +function prepareCheckCreate(address: string, + checkCreate: CheckCreate, + instructions: Instructions = {} +): Promise { + validate.prepareCheckCreate( + {address, checkCreate, instructions}) + const txJSON = createCheckCreateTransaction( + address, checkCreate) + return utils.prepareTransaction(txJSON, this, instructions) +} + +export default prepareCheckCreate diff --git a/test/api-test.js b/test/api-test.js index 3bd4aa4f92..968c34230d 100644 --- a/test/api-test.js +++ b/test/api-test.js @@ -346,6 +346,45 @@ describe('RippleAPI', function () { 'prepare')); }); + it('prepareCheckCreate', function () { + const localInstructions = _.defaults({ + maxFee: '0.000012' + }, instructions); + return this.api.prepareCheckCreate( + address, requests.prepareCheckCreate.normal, + localInstructions).then( + _.partial(checkResult, responses.prepareCheckCreate.normal, + 'prepare')); + }); + + it('prepareCheckCreate full', function () { + return this.api.prepareCheckCreate( + address, requests.prepareCheckCreate.full).then( + _.partial(checkResult, responses.prepareCheckCreate.full, + 'prepare')); + }); + + it('prepareCheckCash amount', function () { + return this.api.prepareCheckCash( + address, requests.prepareCheckCash.amount).then( + _.partial(checkResult, responses.prepareCheckCash.amount, + 'prepare')); + }); + + it('prepareCheckCash deliverMin', function () { + return this.api.prepareCheckCash( + address, requests.prepareCheckCash.deliverMin).then( + _.partial(checkResult, responses.prepareCheckCash.deliverMin, + 'prepare')); + }); + + it('prepareCheckCancel', function () { + return this.api.prepareCheckCancel( + address, requests.prepareCheckCancel.normal).then( + _.partial(checkResult, responses.prepareCheckCancel.normal, + 'prepare')); + }); + it('preparePaymentChannelCreate', function () { const localInstructions = _.defaults({ maxFee: '0.000012' @@ -786,6 +825,37 @@ describe('RippleAPI', function () { }); }); + // Checks + + it('getTransaction - CheckCreate', function () { + const hash = + '605A2E2C8E48AECAF5C56085D1AEAA0348DC838CE122C9188F94EB19DA05C2FE'; + return this.api.getTransaction(hash).then( + _.partial(checkResult, + responses.getTransaction.checkCreate, + 'getTransaction')); + }); + + it('getTransaction - CheckCancel', function () { + const hash = + 'B4105D1B2D83819647E4692B7C5843D674283F669524BD50C9614182E3A12CD4'; + return this.api.getTransaction(hash).then( + _.partial(checkResult, + responses.getTransaction.checkCancel, + 'getTransaction')); + }); + + it('getTransaction - CheckCash', function () { + const hash = + '8321208465F70BA52C28BCC4F646BAF3B012BA13B57576C0336F42D77E3E0749'; + return this.api.getTransaction(hash/*, options*/).then( + _.partial(checkResult, + responses.getTransaction.checkCash, + 'getTransaction')); + }); + + // Escrows + it('getTransaction - EscrowCreation', function () { const hash = '144F272380BDB4F1BD92329A2178BABB70C20F59042C495E10BF72EBFB408EE1'; diff --git a/test/fixtures/requests/index.js b/test/fixtures/requests/index.js index 2e337711a4..14deb4d107 100644 --- a/test/fixtures/requests/index.js +++ b/test/fixtures/requests/index.js @@ -38,6 +38,17 @@ module.exports = { normal: require('./prepare-escrow-cancellation'), memos: require('./prepare-escrow-cancellation-memos') }, + prepareCheckCreate: { + normal: require('./prepare-check-create'), + full: require('./prepare-check-create-full') + }, + prepareCheckCash: { + amount: require('./prepare-check-cash-amount'), + deliverMin: require('./prepare-check-cash-delivermin') + }, + prepareCheckCancel: { + normal: require('./prepare-check-cancel') + }, preparePaymentChannelCreate: { normal: require('./prepare-payment-channel-create'), full: require('./prepare-payment-channel-create-full') diff --git a/test/fixtures/requests/prepare-check-cancel.json b/test/fixtures/requests/prepare-check-cancel.json new file mode 100644 index 0000000000..f1e6240059 --- /dev/null +++ b/test/fixtures/requests/prepare-check-cancel.json @@ -0,0 +1,3 @@ +{ + "checkID": "49647F0D748DC3FE26BDACBC57F251AADEFFF391403EC9BF87C97F67E9977FB0" +} diff --git a/test/fixtures/requests/prepare-check-cash-amount.json b/test/fixtures/requests/prepare-check-cash-amount.json new file mode 100644 index 0000000000..a02ab588f3 --- /dev/null +++ b/test/fixtures/requests/prepare-check-cash-amount.json @@ -0,0 +1,7 @@ +{ + "amount": { + "currency": "XRP", + "value": "1" + }, + "checkID": "838766BA2B995C00744175F69A1B11E32C3DBC40E64801A4056FCBD657F57334" +} diff --git a/test/fixtures/requests/prepare-check-cash-delivermin.json b/test/fixtures/requests/prepare-check-cash-delivermin.json new file mode 100644 index 0000000000..92c455efd5 --- /dev/null +++ b/test/fixtures/requests/prepare-check-cash-delivermin.json @@ -0,0 +1,7 @@ +{ + "deliverMin": { + "currency": "XRP", + "value": "0.8" + }, + "checkID": "838766BA2B995C00744175F69A1B11E32C3DBC40E64801A4056FCBD657F57334" +} diff --git a/test/fixtures/requests/prepare-check-create-full.json b/test/fixtures/requests/prepare-check-create-full.json new file mode 100644 index 0000000000..a1d70b472b --- /dev/null +++ b/test/fixtures/requests/prepare-check-create-full.json @@ -0,0 +1,10 @@ +{ + "destination": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW", + "sendMax": { + "currency": "XRP", + "value": "1" + }, + "destinationTag": 2, + "expiration": "2018-09-24T21:21:50.000Z", + "invoiceID": "1F40FC92DA241694750979EE6CF582F2D5D7D28E18335DE05ABC54D0560E0F53" +} diff --git a/test/fixtures/requests/prepare-check-create.json b/test/fixtures/requests/prepare-check-create.json new file mode 100644 index 0000000000..4edfd38b17 --- /dev/null +++ b/test/fixtures/requests/prepare-check-create.json @@ -0,0 +1,7 @@ +{ + "destination": "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW", + "sendMax": { + "currency": "XRP", + "value": "1" + } +} diff --git a/test/fixtures/responses/get-transaction-check-cancel.json b/test/fixtures/responses/get-transaction-check-cancel.json new file mode 100644 index 0000000000..e1720381b3 --- /dev/null +++ b/test/fixtures/responses/get-transaction-check-cancel.json @@ -0,0 +1,25 @@ +{ + "type": "checkCancel", + "address": "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE", + "sequence": 6, + "id": "B4105D1B2D83819647E4692B7C5843D674283F669524BD50C9614182E3A12CD4", + "specification": { + "checkID": "6EE1727598693635183A3D967342A46C739FC06F973CA6A3277A92E8D997E7A8" + }, + "outcome": { + "result": "tesSUCCESS", + "timestamp": "2018-02-23T22:45:41.000Z", + "fee": "0.000012", + "balanceChanges": { + "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE": [ + { + "currency": "XRP", + "value": "-0.000012" + } + ] + }, + "orderbookChanges": {}, + "ledgerVersion": 6967970, + "indexInLedger": 4 + } +} diff --git a/test/fixtures/responses/get-transaction-check-cash.json b/test/fixtures/responses/get-transaction-check-cash.json new file mode 100644 index 0000000000..7b449783a2 --- /dev/null +++ b/test/fixtures/responses/get-transaction-check-cash.json @@ -0,0 +1,35 @@ +{ + "type": "checkCash", + "address": "raLHvSZXacoGiCoWrdBhVGstZm6GhF7oRr", + "sequence": 3, + "id": "8321208465F70BA52C28BCC4F646BAF3B012BA13B57576C0336F42D77E3E0749", + "specification": { + "checkID": "4F6DDA7972A5E8C8F2AA3D2A475E56475FA573C65B935E26EABDA5F06A982C70", + "amount": { + "currency": "XRP", + "value": "2.5" + } + }, + "outcome": { + "result": "tesSUCCESS", + "timestamp": "2018-02-23T22:26:52.000Z", + "fee": "0.000012", + "balanceChanges": { + "raLHvSZXacoGiCoWrdBhVGstZm6GhF7oRr": [ + { + "currency": "XRP", + "value": "2.499988" + } + ], + "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE": [ + { + "currency": "XRP", + "value": "-2.5" + } + ] + }, + "orderbookChanges": {}, + "ledgerVersion": 6967596, + "indexInLedger": 0 + } +} diff --git a/test/fixtures/responses/get-transaction-check-create.json b/test/fixtures/responses/get-transaction-check-create.json new file mode 100644 index 0000000000..177f2c754e --- /dev/null +++ b/test/fixtures/responses/get-transaction-check-create.json @@ -0,0 +1,32 @@ +{ + "type": "checkCreate", + "address": "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE", + "sequence": 3, + "id": "605A2E2C8E48AECAF5C56085D1AEAA0348DC838CE122C9188F94EB19DA05C2FE", + "specification": { + "destination": "raLHvSZXacoGiCoWrdBhVGstZm6GhF7oRr", + "sendMax": { + "currency": "XRP", + "value": "3" + }, + "destinationTag": 1235, + "expiration": "2018-02-25T21:22:47.000Z", + "invoiceID": "DEADBEEF2FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B" + }, + "outcome": { + "result": "tesSUCCESS", + "timestamp": "2018-02-23T22:20:01.000Z", + "fee": "0.000012", + "balanceChanges": { + "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE": [ + { + "currency": "XRP", + "value": "-0.000012" + } + ] + }, + "orderbookChanges": {}, + "ledgerVersion": 6967458, + "indexInLedger": 1 + } +} diff --git a/test/fixtures/responses/get-transaction-escrow-create.json b/test/fixtures/responses/get-transaction-escrow-creation.json similarity index 100% rename from test/fixtures/responses/get-transaction-escrow-create.json rename to test/fixtures/responses/get-transaction-escrow-creation.json diff --git a/test/fixtures/responses/index.js b/test/fixtures/responses/index.js index c2e66a58e9..d4facacc96 100644 --- a/test/fixtures/responses/index.js +++ b/test/fixtures/responses/index.js @@ -42,8 +42,14 @@ module.exports = { trustlineFrozenOff: require('./get-transaction-trust-set-frozen-off.json'), trustlineNoQuality: require('./get-transaction-trust-no-quality.json'), notValidated: require('./get-transaction-not-validated.json'), + checkCreate: + require('./get-transaction-check-create.json'), + checkCancel: + require('./get-transaction-check-cancel.json'), + checkCash: + require('./get-transaction-check-cash.json'), escrowCreation: - require('./get-transaction-escrow-create.json'), + require('./get-transaction-escrow-creation.json'), escrowCancellation: require('./get-transaction-escrow-cancellation.json'), escrowExecution: @@ -113,6 +119,17 @@ module.exports = { noMaxLedgerVersion: require('./prepare-settings-no-maxledgerversion.json'), signers: require('./prepare-settings-signers.json') }, + prepareCheckCreate: { + normal: require('./prepare-check-create'), + full: require('./prepare-check-create-full') + }, + prepareCheckCash: { + amount: require('./prepare-check-cash-amount'), + deliverMin: require('./prepare-check-cash-delivermin') + }, + prepareCheckCancel: { + normal: require('./prepare-check-cancel') + }, prepareEscrowCreation: { normal: require('./prepare-escrow-creation'), full: require('./prepare-escrow-creation-full') diff --git a/test/fixtures/responses/prepare-check-cancel.json b/test/fixtures/responses/prepare-check-cancel.json new file mode 100644 index 0000000000..493fe250bf --- /dev/null +++ b/test/fixtures/responses/prepare-check-cancel.json @@ -0,0 +1,8 @@ +{ + "txJSON": "{\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"TransactionType\":\"CheckCancel\",\"CheckID\":\"49647F0D748DC3FE26BDACBC57F251AADEFFF391403EC9BF87C97F67E9977FB0\",\"Flags\":2147483648,\"LastLedgerSequence\":8819954,\"Fee\":\"12\",\"Sequence\":23}", + "instructions": { + "fee": "0.000012", + "sequence": 23, + "maxLedgerVersion": 8819954 + } +} diff --git a/test/fixtures/responses/prepare-check-cash-amount.json b/test/fixtures/responses/prepare-check-cash-amount.json new file mode 100644 index 0000000000..a344cdf422 --- /dev/null +++ b/test/fixtures/responses/prepare-check-cash-amount.json @@ -0,0 +1,8 @@ +{ + "txJSON": "{\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"TransactionType\":\"CheckCash\",\"CheckID\":\"838766BA2B995C00744175F69A1B11E32C3DBC40E64801A4056FCBD657F57334\",\"Amount\":\"1000000\",\"Flags\":2147483648,\"LastLedgerSequence\":8819954,\"Sequence\":23,\"Fee\":\"12\"}", + "instructions": { + "fee": "0.000012", + "sequence": 23, + "maxLedgerVersion": 8819954 + } +} diff --git a/test/fixtures/responses/prepare-check-cash-delivermin.json b/test/fixtures/responses/prepare-check-cash-delivermin.json new file mode 100644 index 0000000000..524515fbfa --- /dev/null +++ b/test/fixtures/responses/prepare-check-cash-delivermin.json @@ -0,0 +1,8 @@ +{ + "txJSON": "{\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"TransactionType\":\"CheckCash\",\"CheckID\":\"838766BA2B995C00744175F69A1B11E32C3DBC40E64801A4056FCBD657F57334\",\"DeliverMin\":\"800000\",\"Flags\":2147483648,\"LastLedgerSequence\":8819954,\"Sequence\":23,\"Fee\":\"12\"}", + "instructions": { + "fee": "0.000012", + "sequence": 23, + "maxLedgerVersion": 8819954 + } +} diff --git a/test/fixtures/responses/prepare-check-create-full.json b/test/fixtures/responses/prepare-check-create-full.json new file mode 100644 index 0000000000..a43e7d5715 --- /dev/null +++ b/test/fixtures/responses/prepare-check-create-full.json @@ -0,0 +1,8 @@ +{ + "txJSON": "{\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"TransactionType\":\"CheckCreate\",\"Destination\":\"rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW\",\"SendMax\":\"1000000\",\"DestinationTag\":2,\"Expiration\":591139310,\"InvoiceID\":\"1F40FC92DA241694750979EE6CF582F2D5D7D28E18335DE05ABC54D0560E0F53\",\"Flags\":2147483648,\"LastLedgerSequence\":8819954,\"Sequence\":23,\"Fee\":\"12\"}", + "instructions": { + "fee": "0.000012", + "sequence": 23, + "maxLedgerVersion": 8819954 + } +} diff --git a/test/fixtures/responses/prepare-check-create.json b/test/fixtures/responses/prepare-check-create.json new file mode 100644 index 0000000000..355b16f172 --- /dev/null +++ b/test/fixtures/responses/prepare-check-create.json @@ -0,0 +1,8 @@ +{ + "txJSON": "{\"Account\":\"r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59\",\"TransactionType\":\"CheckCreate\",\"Destination\":\"rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW\",\"SendMax\":\"1000000\",\"Flags\":2147483648,\"LastLedgerSequence\":8820051,\"Sequence\":23,\"Fee\":\"12\"}", + "instructions": { + "fee": "0.000012", + "sequence": 23, + "maxLedgerVersion": 8820051 + } +} diff --git a/test/fixtures/rippled/index.js b/test/fixtures/rippled/index.js index 94ca6890ff..bc5073e4b6 100644 --- a/test/fixtures/rippled/index.js +++ b/test/fixtures/rippled/index.js @@ -72,6 +72,9 @@ module.exports = { LedgerWithoutTime: require('./tx/ledger-without-time.json'), NotValidated: require('./tx/not-validated.json'), OfferWithExpiration: require('./tx/order-with-expiration.json'), + CheckCreate: require('./tx/check-create.json'), + CheckCancel: require('./tx/check-cancel.json'), + CheckCash: require('./tx/check-cash.json'), EscrowCreation: require('./tx/escrow-creation.json'), EscrowCancellation: require('./tx/escrow-cancellation.json'), diff --git a/test/fixtures/rippled/tx/check-cancel.json b/test/fixtures/rippled/tx/check-cancel.json new file mode 100644 index 0000000000..5e1664046e --- /dev/null +++ b/test/fixtures/rippled/tx/check-cancel.json @@ -0,0 +1,89 @@ +{ + "id": 0, + "result": { + "Account": "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE", + "CheckID": "6EE1727598693635183A3D967342A46C739FC06F973CA6A3277A92E8D997E7A8", + "Fee": "12", + "Flags": 2147483648, + "LastLedgerSequence": 6968242, + "Sequence": 6, + "SigningPubKey": "03C1B24925182F5B881D34E07993FAAD90B918EF3D6661963A3E9EE402B6F87659", + "TransactionType": "CheckCancel", + "TxnSignature": "3045022100B3BC49F917E408DB5FFE1570CDE69E28AA4BD99AABAC7043EE71BDC346BF76F902200F8E4E059B1AF33BBD595CEDB86A556C40E40ADFB86F1B4451F447E88DD01A0B", + "date": 572741141, + "hash": "B4105D1B2D83819647E4692B7C5843D674283F669524BD50C9614182E3A12CD4", + "inLedger": 6967970, + "ledger_index": 6967970, + "meta": { + "AffectedNodes": [ + { + "ModifiedNode": { + "FinalFields": { + "Flags": 0, + "Owner": "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE", + "RootIndex": "46B6FD7D2C937D6A5D2832CAC94F424300B3FE72B5D1D460C20E6FADAD2FF7C7" + }, + "LedgerEntryType": "DirectoryNode", + "LedgerIndex": "46B6FD7D2C937D6A5D2832CAC94F424300B3FE72B5D1D460C20E6FADAD2FF7C7" + } + }, + { + "DeletedNode": { + "FinalFields": { + "Account": "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE", + "Destination": "raLHvSZXacoGiCoWrdBhVGstZm6GhF7oRr", + "DestinationNode": "0000000000000000", + "DestinationTag": 1236, + "Expiration": 572908967, + "Flags": 0, + "InvoiceID": "DEADBEEF3FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B", + "OwnerNode": "0000000000000000", + "PreviousTxnID": "FCE773D30272546ADD1ADF1763AE8C69B857C7AD0B4A13B9B524991D5611740E", + "PreviousTxnLgrSeq": 6967917, + "SendMax": "4000000", + "Sequence": 5 + }, + "LedgerEntryType": "Check", + "LedgerIndex": "6EE1727598693635183A3D967342A46C739FC06F973CA6A3277A92E8D997E7A8" + } + }, + { + "ModifiedNode": { + "FinalFields": { + "Account": "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE", + "Balance": "9996499928", + "Flags": 0, + "OwnerCount": 0, + "Sequence": 7 + }, + "LedgerEntryType": "AccountRoot", + "LedgerIndex": "8FD7FBA4C35956B4964015D938AD50A939458E8CD13FA24A58F40A07ABE47E52", + "PreviousFields": { + "Balance": "9996499940", + "OwnerCount": 1, + "Sequence": 6 + }, + "PreviousTxnID": "FCE773D30272546ADD1ADF1763AE8C69B857C7AD0B4A13B9B524991D5611740E", + "PreviousTxnLgrSeq": 6967917 + } + }, + { + "ModifiedNode": { + "FinalFields": { + "Flags": 0, + "Owner": "raLHvSZXacoGiCoWrdBhVGstZm6GhF7oRr", + "RootIndex": "A33DF86647D19B7868A6FAD1E65F753837F8CFEF8F1C4F34717FD5CC7E6EA2E3" + }, + "LedgerEntryType": "DirectoryNode", + "LedgerIndex": "A33DF86647D19B7868A6FAD1E65F753837F8CFEF8F1C4F34717FD5CC7E6EA2E3" + } + } + ], + "TransactionIndex": 4, + "TransactionResult": "tesSUCCESS" + }, + "validated": true + }, + "status": "success", + "type": "response" +} \ No newline at end of file diff --git a/test/fixtures/rippled/tx/check-cash.json b/test/fixtures/rippled/tx/check-cash.json new file mode 100644 index 0000000000..f941570ebd --- /dev/null +++ b/test/fixtures/rippled/tx/check-cash.json @@ -0,0 +1,108 @@ +{ + "id": 0, + "result": { + "Account": "raLHvSZXacoGiCoWrdBhVGstZm6GhF7oRr", + "Amount": "2500000", + "CheckID": "4F6DDA7972A5E8C8F2AA3D2A475E56475FA573C65B935E26EABDA5F06A982C70", + "Fee": "12", + "Flags": 2147483648, + "LastLedgerSequence": 6967889, + "Sequence": 3, + "SigningPubKey": "02ACB1C22D68E01414D2F527B4666E119F36E5B996D1CE6C8DBDE03769E5B2B95B", + "TransactionType": "CheckCash", + "TxnSignature": "304402205CA374B304F5D595E930489D70D5EDD062142D6D231D55AC0123F2AA02C8F10202206B5B9AA6A8560382053FF628662D42E74BB79B84B4A507719180823A720A261F", + "date": 572740012, + "hash": "8321208465F70BA52C28BCC4F646BAF3B012BA13B57576C0336F42D77E3E0749", + "inLedger": 6967596, + "ledger_index": 6967596, + "meta": { + "AffectedNodes": [ + { + "ModifiedNode": { + "FinalFields": { + "Account": "raLHvSZXacoGiCoWrdBhVGstZm6GhF7oRr", + "Balance": "10003499964", + "Flags": 0, + "OwnerCount": 0, + "Sequence": 4 + }, + "LedgerEntryType": "AccountRoot", + "LedgerIndex": "1F5CCAAAAE908C0F449ADB267084DFFD3E4432921E64A020EEBC59D95BD4940A", + "PreviousFields": { + "Balance": "10000999976", + "Sequence": 3 + }, + "PreviousTxnID": "7D1400825FD25D17B0283B71B0CC2ACC921F32D057B66BB7331F1B43483BC3DA", + "PreviousTxnLgrSeq": 6967427 + } + }, + { + "ModifiedNode": { + "FinalFields": { + "Flags": 0, + "Owner": "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE", + "RootIndex": "46B6FD7D2C937D6A5D2832CAC94F424300B3FE72B5D1D460C20E6FADAD2FF7C7" + }, + "LedgerEntryType": "DirectoryNode", + "LedgerIndex": "46B6FD7D2C937D6A5D2832CAC94F424300B3FE72B5D1D460C20E6FADAD2FF7C7" + } + }, + { + "DeletedNode": { + "FinalFields": { + "Account": "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE", + "Destination": "raLHvSZXacoGiCoWrdBhVGstZm6GhF7oRr", + "DestinationNode": "0000000000000000", + "DestinationTag": 1235, + "Expiration": 572908967, + "Flags": 0, + "InvoiceID": "DEADBEEF2FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B", + "OwnerNode": "0000000000000000", + "PreviousTxnID": "605A2E2C8E48AECAF5C56085D1AEAA0348DC838CE122C9188F94EB19DA05C2FE", + "PreviousTxnLgrSeq": 6967458, + "SendMax": "3000000", + "Sequence": 3 + }, + "LedgerEntryType": "Check", + "LedgerIndex": "4F6DDA7972A5E8C8F2AA3D2A475E56475FA573C65B935E26EABDA5F06A982C70" + } + }, + { + "ModifiedNode": { + "FinalFields": { + "Account": "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE", + "Balance": "9996499952", + "Flags": 0, + "OwnerCount": 0, + "Sequence": 5 + }, + "LedgerEntryType": "AccountRoot", + "LedgerIndex": "8FD7FBA4C35956B4964015D938AD50A939458E8CD13FA24A58F40A07ABE47E52", + "PreviousFields": { + "Balance": "9998999952", + "OwnerCount": 1 + }, + "PreviousTxnID": "4FE09BCC476230E75A45014CD8F77E91C7FF95C07BB8E55923EB55741911C85D", + "PreviousTxnLgrSeq": 6967586 + } + }, + { + "ModifiedNode": { + "FinalFields": { + "Flags": 0, + "Owner": "raLHvSZXacoGiCoWrdBhVGstZm6GhF7oRr", + "RootIndex": "A33DF86647D19B7868A6FAD1E65F753837F8CFEF8F1C4F34717FD5CC7E6EA2E3" + }, + "LedgerEntryType": "DirectoryNode", + "LedgerIndex": "A33DF86647D19B7868A6FAD1E65F753837F8CFEF8F1C4F34717FD5CC7E6EA2E3" + } + } + ], + "TransactionIndex": 0, + "TransactionResult": "tesSUCCESS" + }, + "validated": true + }, + "status": "success", + "type": "response" +} \ No newline at end of file diff --git a/test/fixtures/rippled/tx/check-create.json b/test/fixtures/rippled/tx/check-create.json new file mode 100644 index 0000000000..2a0caa1b29 --- /dev/null +++ b/test/fixtures/rippled/tx/check-create.json @@ -0,0 +1,88 @@ +{ + "id": 0, + "result": { + "Account": "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE", + "Destination": "raLHvSZXacoGiCoWrdBhVGstZm6GhF7oRr", + "DestinationTag": 1235, + "Expiration": 572908967, + "Fee": "12", + "Flags": 2147483648, + "InvoiceID": "DEADBEEF2FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B", + "LastLedgerSequence": 6967747, + "SendMax": "3000000", + "Sequence": 3, + "SigningPubKey": "03C1B24925182F5B881D34E07993FAAD90B918EF3D6661963A3E9EE402B6F87659", + "TransactionType": "CheckCreate", + "TxnSignature": "3044022058FD0FBB7486D84DBEFE6C10BE0D43C3344E6B175BED19C1FF514C379A4FB344022021DE0087152FCDD6EB7ED14E057BBA94CAF70B920AA79CB82AAD4B82E7AFF760", + "date": 572739601, + "hash": "605A2E2C8E48AECAF5C56085D1AEAA0348DC838CE122C9188F94EB19DA05C2FE", + "inLedger": 6967458, + "ledger_index": 6967458, + "meta": { + "AffectedNodes": [ + { + "ModifiedNode": { + "FinalFields": { + "Flags": 0, + "Owner": "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE", + "RootIndex": "46B6FD7D2C937D6A5D2832CAC94F424300B3FE72B5D1D460C20E6FADAD2FF7C7" + }, + "LedgerEntryType": "DirectoryNode", + "LedgerIndex": "46B6FD7D2C937D6A5D2832CAC94F424300B3FE72B5D1D460C20E6FADAD2FF7C7" + } + }, + { + "CreatedNode": { + "LedgerEntryType": "Check", + "LedgerIndex": "4F6DDA7972A5E8C8F2AA3D2A475E56475FA573C65B935E26EABDA5F06A982C70", + "NewFields": { + "Account": "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE", + "Destination": "raLHvSZXacoGiCoWrdBhVGstZm6GhF7oRr", + "DestinationTag": 1235, + "Expiration": 572908967, + "InvoiceID": "DEADBEEF2FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B", + "SendMax": "3000000", + "Sequence": 3 + } + } + }, + { + "ModifiedNode": { + "FinalFields": { + "Account": "rNpdNFXNMvEcaXDqMypi48gdSABZkYuyQE", + "Balance": "9998999964", + "Flags": 0, + "OwnerCount": 1, + "Sequence": 4 + }, + "LedgerEntryType": "AccountRoot", + "LedgerIndex": "8FD7FBA4C35956B4964015D938AD50A939458E8CD13FA24A58F40A07ABE47E52", + "PreviousFields": { + "Balance": "9998999976", + "OwnerCount": 0, + "Sequence": 3 + }, + "PreviousTxnID": "7D1400825FD25D17B0283B71B0CC2ACC921F32D057B66BB7331F1B43483BC3DA", + "PreviousTxnLgrSeq": 6967427 + } + }, + { + "ModifiedNode": { + "FinalFields": { + "Flags": 0, + "Owner": "raLHvSZXacoGiCoWrdBhVGstZm6GhF7oRr", + "RootIndex": "A33DF86647D19B7868A6FAD1E65F753837F8CFEF8F1C4F34717FD5CC7E6EA2E3" + }, + "LedgerEntryType": "DirectoryNode", + "LedgerIndex": "A33DF86647D19B7868A6FAD1E65F753837F8CFEF8F1C4F34717FD5CC7E6EA2E3" + } + } + ], + "TransactionIndex": 1, + "TransactionResult": "tesSUCCESS" + }, + "validated": true + }, + "status": "success", + "type": "response" +} \ No newline at end of file diff --git a/test/mock-rippled.js b/test/mock-rippled.js index bcef9d93ec..db6ebe7e34 100644 --- a/test/mock-rippled.js +++ b/test/mock-rippled.js @@ -289,7 +289,24 @@ module.exports = function createMockRippled(port) { } else if (request.transaction === '097B9491CC76B64831F1FEA82EAA93BCD728106D90B65A072C933888E946C40B') { conn.send(createResponse(request, fixtures.tx.OfferWithExpiration)); + } + + // Checks + + else if (request.transaction === + '605A2E2C8E48AECAF5C56085D1AEAA0348DC838CE122C9188F94EB19DA05C2FE') { + conn.send(createResponse(request, fixtures.tx.CheckCreate)); } else if (request.transaction === + 'B4105D1B2D83819647E4692B7C5843D674283F669524BD50C9614182E3A12CD4') { + conn.send(createResponse(request, fixtures.tx.CheckCancel)); + } else if (request.transaction === + '8321208465F70BA52C28BCC4F646BAF3B012BA13B57576C0336F42D77E3E0749') { + conn.send(createResponse(request, fixtures.tx.CheckCash)); + } + + // Escrows + + else if (request.transaction === '144F272380BDB4F1BD92329A2178BABB70C20F59042C495E10BF72EBFB408EE1') { conn.send(createResponse(request, fixtures.tx.EscrowCreation)); } else if (request.transaction === @@ -302,7 +319,11 @@ module.exports = function createMockRippled(port) { 'CC5277137B3F25EE8B86259C83CB0EAADE818505E4E9BCBF19B1AC6FD1369931') { conn.send(createResponse(request, fixtures.tx.EscrowExecutionSimple)); - } else if (request.transaction === + } + + // Payment Channels + + else if (request.transaction === '0E9CA3AB1053FC0C1CBAA75F636FE1EC92F118C7056BBEF5D63E4C116458A16D') { conn.send(createResponse(request, fixtures.tx.PaymentChannelCreate)); } else if (request.transaction === diff --git a/yarn.lock b/yarn.lock index 4d6cf2683b..f9e8df9b0e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -803,8 +803,8 @@ core-js@^1.0.0: resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636" core-js@^2.4.0: - version "2.5.1" - resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.1.tgz#ae6874dc66937789b80754ff5428df66819ca50b" + version "2.5.3" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.3.tgz#8acc38345824f16d8365b7c9b4259168e8ed603e" core-util-is@1.0.2, core-util-is@~1.0.0: version "1.0.2" @@ -2590,7 +2590,11 @@ lodash@3.6.0: version "3.6.0" resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.6.0.tgz#5266a8f49dd989be4f9f681b6f2a0c55285d0d9a" -lodash@^4.12.0, lodash@^4.14.0, lodash@^4.17.4: +lodash@^4.12.0: + version "4.17.5" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511" + +lodash@^4.14.0, lodash@^4.17.4: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" @@ -3502,8 +3506,8 @@ rechoir@^0.6.2: resolve "^1.1.6" regenerator-runtime@^0.11.0: - version "0.11.0" - resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz#7e54fe5b5ccd5d6624ea6255c3473be090b802e1" + version "0.11.1" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" regex-cache@^0.4.2: version "0.4.4" @@ -3696,7 +3700,7 @@ ripple-address-codec@^2.0.1: hash.js "^1.0.3" x-address-codec "^0.7.0" -ripple-binary-codec@^0.1.0, ripple-binary-codec@^0.1.10: +ripple-binary-codec@^0.1.0: version "0.1.12" resolved "https://registry.yarnpkg.com/ripple-binary-codec/-/ripple-binary-codec-0.1.12.tgz#30fb61a8d5bf61301899616c6f842e393082e385" dependencies: @@ -3708,6 +3712,18 @@ ripple-binary-codec@^0.1.0, ripple-binary-codec@^0.1.10: lodash "^4.12.0" ripple-address-codec "^2.0.1" +ripple-binary-codec@^0.1.13: + version "0.1.13" + resolved "https://registry.yarnpkg.com/ripple-binary-codec/-/ripple-binary-codec-0.1.13.tgz#c68951405a17a71695551e789966ff376da552e4" + dependencies: + babel-runtime "^6.6.1" + bn.js "^4.11.3" + create-hash "^1.1.2" + decimal.js "^5.0.8" + inherits "^2.0.1" + lodash "^4.12.0" + ripple-address-codec "^2.0.1" + ripple-hashes@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/ripple-hashes/-/ripple-hashes-0.3.1.tgz#f2f46f1ff05e6487500a99839019114cd2482411" @@ -3796,7 +3812,14 @@ setimmediate@^1.0.4: version "1.0.5" resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285" -sha.js@^2.4.0, sha.js@^2.4.8: +sha.js@^2.4.0: + version "2.4.10" + resolved "https://registry.yarnpkg.com/sha.js/-/sha.js-2.4.10.tgz#b1fde5cd7d11a5626638a07c604ab909cfa31f9b" + dependencies: + inherits "^2.0.1" + safe-buffer "^5.0.1" + +sha.js@^2.4.8: version "2.4.9" resolved "https://registry.yarnpkg.com/sha.js/-/sha.js-2.4.9.tgz#98f64880474b74f4a38b8da9d3c0f2d104633e7d" dependencies: From 0ad8c577c043a745d97d081cc5677ef077119aa9 Mon Sep 17 00:00:00 2001 From: Elliot Lee Date: Thu, 1 Mar 2018 21:46:20 -0800 Subject: [PATCH 7/7] Export Check* transaction param types --- src/transaction/check-cancel.ts | 2 +- src/transaction/check-cash.ts | 2 +- src/transaction/check-create.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/transaction/check-cancel.ts b/src/transaction/check-cancel.ts index 9a694672f1..5a262e2f28 100644 --- a/src/transaction/check-cancel.ts +++ b/src/transaction/check-cancel.ts @@ -2,7 +2,7 @@ import * as utils from './utils' import {validate} from '../common' import {Instructions, Prepare} from './types' -type CheckCancel = { +export type CheckCancel = { checkID: string } diff --git a/src/transaction/check-cash.ts b/src/transaction/check-cash.ts index 67686bf44e..97fdd1a769 100644 --- a/src/transaction/check-cash.ts +++ b/src/transaction/check-cash.ts @@ -5,7 +5,7 @@ import {validate} from '../common' import {Instructions, Prepare} from './types' import {Amount} from '../common/types/objects' -type CheckCash = { +export type CheckCash = { checkID: string, amount?: Amount, deliverMin?: Amount diff --git a/src/transaction/check-create.ts b/src/transaction/check-create.ts index 8fce9ef0d1..e720d5e057 100644 --- a/src/transaction/check-create.ts +++ b/src/transaction/check-create.ts @@ -4,7 +4,7 @@ import {validate, iso8601ToRippleTime} from '../common' import {Instructions, Prepare} from './types' import {Amount} from '../common/types/objects' -type CheckCreate = { +export type CheckCreate = { destination: string, sendMax: Amount, destinationTag?: number,