From 7a928804ecf3b7511f1b6bfd63c88c58460ef7a9 Mon Sep 17 00:00:00 2001 From: Elliot Lee Date: Tue, 17 Jul 2018 22:22:07 -0700 Subject: [PATCH] feat: add payment channel details to tx (2) (#920) * Bump transactionparser to v0.7.1 and update output schema * yarn docgen for required `threshold` and `weights` --- docs/index.md | 13 +++++++------ package.json | 2 +- src/common/schemas/output/outcome.json | 8 ++++++-- src/ledger/parse/utils.ts | 4 ++-- .../get-transaction-payment-channel-claim.json | 12 +++++++++++- .../get-transaction-payment-channel-create.json | 10 +++++++++- .../get-transaction-payment-channel-fund.json | 12 +++++++++++- yarn.lock | 6 +++--- 8 files changed, 50 insertions(+), 17 deletions(-) diff --git a/docs/index.md b/docs/index.md index b632995b..74fc22bb 100644 --- a/docs/index.md +++ b/docs/index.md @@ -516,8 +516,8 @@ regularKey | [address](#address),null | *Optional* The public key of a new keypa requireAuthorization | boolean | *Optional* If set, this account must individually approve other users in order for those users to hold this account’s issuances. requireDestinationTag | boolean | *Optional* Requires incoming payments to specify a destination tag. signers | object | *Optional* Settings that determine what sets of accounts can be used to sign a transaction on behalf of this account using multisigning. -*signers.* threshold | integer | *Optional* A target number for the signer weights. A multi-signature from this list is valid only if the sum weights of the signatures provided is equal or greater than this value. To delete the signers setting, use the value `0`. -*signers.* weights | array | *Optional* Weights of signatures for each signer. +*signers.* threshold | integer | A target number for the signer weights. A multi-signature from this list is valid only if the sum weights of the signatures provided is equal or greater than this value. To delete the signers setting, use the value `0`. +*signers.* weights | array | Weights of signatures for each signer. *signers.* weights[] | object | An association of an address and a weight. *signers.weights[].* address | [address](#address) | A Ripple account address *signers.weights[].* weight | integer | The weight that the signature of this account counts as towards the threshold. @@ -1153,8 +1153,8 @@ specification | object | A specification that would produce the same outcome as outcome | object | The outcome of the transaction (what effects it had). *outcome.* result | string | Result code returned by rippled. See [Transaction Results](https://ripple.com/build/transactions/#full-transaction-response-list) for a complete list. *outcome.* fee | [value](#value) | The XRP fee that was charged for the transaction. -*outcome.balanceChanges.* \* | array\<[balance](#amount)\> | Key is the ripple address; value is an array of signed amounts representing changes of balances for that address. -*outcome.orderbookChanges.* \* | array | Key is the maker's ripple address; value is an array of changes +*outcome.balanceChanges.* \* | array\<[balance](#amount)\> | Key is the XRP Ledger address; value is an array of signed amounts representing changes of balances for that address. +*outcome.orderbookChanges.* \* | array | Key is the maker's XRP Ledger address; value is an array of changes *outcome.orderbookChanges.* \*[] | object | A change to an order. *outcome.orderbookChanges.\*[].* direction | string | Equal to "buy" for buy orders and "sell" for sell orders. *outcome.orderbookChanges.\*[].* quantity | [amount](#amount) | The amount to be bought or sold by the maker. @@ -1166,6 +1166,7 @@ outcome | object | The outcome of the transaction (what effects it had). *outcome.* ledgerVersion | integer | The ledger version that the transaction was validated in. *outcome.* ledgerVersion | string | The ledger version that the transaction was validated in. *outcome.* indexInLedger | integer | The ordering index of the transaction in the ledger. +*outcome.* channelChanges | object | *Optional* Properties reflecting the details of the payment channel. *outcome.* deliveredAmount | [amount](#amount) | *Optional* For payment transactions, it is impossible to reliably compute the actual delivered amount from the balanceChanges due to fixed precision. If the payment is not a partial payment and the transaction succeeded, the deliveredAmount should always be considered to be the amount specified in the transaction. *outcome.* timestamp | date-time string | *Optional* The timestamp when the transaction was validated. (May be missing when requesting transactions in binary mode.) @@ -3566,8 +3567,8 @@ regularKey | [address](#address),null | *Optional* The public key of a new keypa requireAuthorization | boolean | *Optional* If set, this account must individually approve other users in order for those users to hold this account’s issuances. requireDestinationTag | boolean | *Optional* Requires incoming payments to specify a destination tag. signers | object | *Optional* Settings that determine what sets of accounts can be used to sign a transaction on behalf of this account using multisigning. -*signers.* threshold | integer | *Optional* A target number for the signer weights. A multi-signature from this list is valid only if the sum weights of the signatures provided is equal or greater than this value. To delete the signers setting, use the value `0`. -*signers.* weights | array | *Optional* Weights of signatures for each signer. +*signers.* threshold | integer | A target number for the signer weights. A multi-signature from this list is valid only if the sum weights of the signatures provided is equal or greater than this value. To delete the signers setting, use the value `0`. +*signers.* weights | array | Weights of signatures for each signer. *signers.* weights[] | object | An association of an address and a weight. *signers.weights[].* address | [address](#address) | A Ripple account address *signers.weights[].* weight | integer | The weight that the signature of this account counts as towards the threshold. diff --git a/package.json b/package.json index 6e0964ff..e52ec3cb 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "ripple-binary-codec": "^0.1.13", "ripple-hashes": "^0.3.1", "ripple-keypairs": "^0.10.1", - "ripple-lib-transactionparser": "^0.6.2", + "ripple-lib-transactionparser": "0.7.1", "ws": "^3.3.1" }, "devDependencies": { diff --git a/src/common/schemas/output/outcome.json b/src/common/schemas/output/outcome.json index bb45749b..85c82c30 100644 --- a/src/common/schemas/output/outcome.json +++ b/src/common/schemas/output/outcome.json @@ -25,7 +25,7 @@ "type": "object", "additionalProperties": { "type": "array", - "description": "Key is the ripple address; value is an array of signed amounts representing changes of balances for that address.", + "description": "Key is the XRP Ledger address; value is an array of signed amounts representing changes of balances for that address.", "items": {"$ref": "balance"} } }, @@ -33,10 +33,14 @@ "type": "object", "additionalProperties": { "type": "array", - "description": "Key is the maker's ripple address; value is an array of changes", + "description": "Key is the maker's XRP Ledger address; value is an array of changes", "items": {"$ref": "orderChange"} } }, + "channelChanges": { + "type": "object", + "description": "Properties reflecting the details of the payment channel." + }, "ledgerVersion": { "$ref": "ledgerVersion", "description": "The ledger version that the transaction was validated in." diff --git a/src/ledger/parse/utils.ts b/src/ledger/parse/utils.ts index 00fad074..55bcce9f 100644 --- a/src/ledger/parse/utils.ts +++ b/src/ledger/parse/utils.ts @@ -103,7 +103,7 @@ function parseOutcome(tx: any): any|undefined { } const balanceChanges = transactionParser.parseBalanceChanges(metadata) const orderbookChanges = transactionParser.parseOrderbookChanges(metadata) - const channel = transactionParser.parseChannelDetails(metadata) + const channelChanges = transactionParser.parseChannelChanges(metadata) removeEmptyCounterpartyInBalanceChanges(balanceChanges) removeEmptyCounterpartyInOrderbookChanges(orderbookChanges) @@ -114,7 +114,7 @@ function parseOutcome(tx: any): any|undefined { fee: common.dropsToXrp(tx.Fee), balanceChanges: balanceChanges, orderbookChanges: orderbookChanges, - channel: channel, + channelChanges: channelChanges, ledgerVersion: tx.ledger_index, indexInLedger: tx.meta.TransactionIndex, deliveredAmount: parseDeliveredAmount(tx) diff --git a/test/fixtures/responses/get-transaction-payment-channel-claim.json b/test/fixtures/responses/get-transaction-payment-channel-claim.json index 3fe46372..fe0cf18c 100644 --- a/test/fixtures/responses/get-transaction-payment-channel-claim.json +++ b/test/fixtures/responses/get-transaction-payment-channel-claim.json @@ -23,6 +23,16 @@ }, "orderbookChanges": {}, "ledgerVersion": 786310, - "indexInLedger": 0 + "indexInLedger": 0, + "channelChanges": { + "status": "modified", + "channelId": "43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1", + "source": "rfAuMkVuZQnQhvdMcUKg4ndBb9SPDhzNmK", + "destination": "rBmNDZ7vbTCwakKXsX3pDAwDdQuxM7yBRa", + "channelBalanceChangeDrops": "801000", + "channelAmountDrops": "1000000", + "channelBalanceDrops": "801000", + "previousTxnId": "0E9CA3AB1053FC0C1CBAA75F636FE1EC92F118C7056BBEF5D63E4C116458A16D" + } } } diff --git a/test/fixtures/responses/get-transaction-payment-channel-create.json b/test/fixtures/responses/get-transaction-payment-channel-create.json index 55d4d54f..aa6bce30 100644 --- a/test/fixtures/responses/get-transaction-payment-channel-create.json +++ b/test/fixtures/responses/get-transaction-payment-channel-create.json @@ -24,6 +24,14 @@ }, "orderbookChanges": {}, "ledgerVersion": 786309, - "indexInLedger": 0 + "indexInLedger": 0, + "channelChanges": { + "status": "created", + "channelId": "43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1", + "source": "rfAuMkVuZQnQhvdMcUKg4ndBb9SPDhzNmK", + "destination": "rBmNDZ7vbTCwakKXsX3pDAwDdQuxM7yBRa", + "channelAmountDrops": "1000000", + "channelBalanceDrops": "0" + } } } diff --git a/test/fixtures/responses/get-transaction-payment-channel-fund.json b/test/fixtures/responses/get-transaction-payment-channel-fund.json index da5ed1c6..925ad887 100644 --- a/test/fixtures/responses/get-transaction-payment-channel-fund.json +++ b/test/fixtures/responses/get-transaction-payment-channel-fund.json @@ -21,6 +21,16 @@ }, "orderbookChanges": {}, "ledgerVersion": 786310, - "indexInLedger": 1 + "indexInLedger": 1, + "channelChanges": { + "status": "modified", + "channelId": "43904CBFCDCEC530B4037871F86EE90BF799DF8D2E0EA564BC8A3F332E4F5FB1", + "source": "rfAuMkVuZQnQhvdMcUKg4ndBb9SPDhzNmK", + "destination": "rBmNDZ7vbTCwakKXsX3pDAwDdQuxM7yBRa", + "channelAmountChangeDrops": "1000000", + "channelAmountDrops": "2000000", + "channelBalanceDrops": "801000", + "previousTxnId": "81B9ECAE7195EB6E8034AEDF44D8415A7A803E14513FDBB34FA984AB37D59563" + } } } diff --git a/yarn.lock b/yarn.lock index e654cd58..4c2eab3d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4164,9 +4164,9 @@ ripple-keypairs@^0.10.1: hash.js "^1.0.3" ripple-address-codec "^2.0.1" -ripple-lib-transactionparser@^0.6.2: - version "0.6.2" - resolved "https://registry.yarnpkg.com/ripple-lib-transactionparser/-/ripple-lib-transactionparser-0.6.2.tgz#eb117834816cab3398445a74ec3cacec95b6b5fa" +ripple-lib-transactionparser@0.7.1: + version "0.7.1" + resolved "https://registry.yarnpkg.com/ripple-lib-transactionparser/-/ripple-lib-transactionparser-0.7.1.tgz#5ececb1e03d65d05605343f4b9dbb76d1089145b" dependencies: bignumber.js "^4.1.0" lodash "^4.17.4"