From 8d37da0952af59e7f7e4f4b89fb0167373e3f39c Mon Sep 17 00:00:00 2001 From: Alexandru Chiriac Date: Tue, 4 Dec 2018 23:35:07 +0000 Subject: [PATCH] Update Submit Response (#978) * update submit output schema * update submit response object --- docs/index.md | 31 ++++++++++++++++++++++++--- src/common/schemas/output/submit.json | 26 +++++++++++++++++++--- src/transaction/submit.ts | 9 +++++++- test/api-test.js | 11 +++++++--- test/fixtures/responses/submit.json | 22 ++++++++++++++++++- test/fixtures/rippled/submit.json | 19 ++++++++++++++-- 6 files changed, 105 insertions(+), 13 deletions(-) diff --git a/docs/index.md b/docs/index.md index 41faa646..0e14c987 100644 --- a/docs/index.md +++ b/docs/index.md @@ -5481,8 +5481,13 @@ This method returns an object with the following structure: Name | Type | Description ---- | ---- | ----------- -resultCode | string | The result code returned by rippled. [List of transaction responses](https://ripple.com/build/transactions/#full-transaction-response-list) -resultMessage | string | Human-readable explanation of the status of the transaction. +resultCode | string | Deprecated: Use `engine_result` instead. +resultMessage | string | Deprecated: Use `engine_result_message` instead. +engine_result | string | Code indicating the preliminary result of the transaction, for example tesSUCCESS. [List of transaction responses](https://ripple.com/build/transactions/#full-transaction-response-list) +engine_result_code | integer | Numeric code indicating the preliminary result of the transaction, directly correlated to `engine_result` +engine_result_message | string | Human-readable explanation of the transaction's preliminary result. +tx_blob | string | The complete transaction in hex string format. +tx_json | [tx](https://ripple.com/build/transactions/) | The complete transaction in JSON format. ### Example @@ -5496,7 +5501,27 @@ return api.submit(signedTransaction) ```json { "resultCode": "tesSUCCESS", - "resultMessage": "The transaction was applied. Only final in a validated ledger." + "resultMessage": "The transaction was applied. Only final in a validated ledger.", + "engine_result": "tesSUCCESS", + "engine_result_code": 0, + "engine_result_message": "The transaction was applied. Only final in a validated ledger.", + "tx_blob": "1200002280000000240000016861D4838D7EA4C6800000000000000000000000000055534400000000004B4E9C06F24296074F7BC48F92A97916C6DC5EA9684000000000002710732103AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB7446304402200E5C2DD81FDF0BE9AB2A8D797885ED49E804DBF28E806604D878756410CA98B102203349581946B0DDA06B36B35DBC20EDA27552C1F167BCF5C6ECFF49C6A46F858081144B4E9C06F24296074F7BC48F92A97916C6DC5EA983143E9D4A2B8AA0780F682D136F7A56D6724EF53754", + "tx_json": { + "Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "Amount": { + "currency": "USD", + "issuer": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "value": "1" + }, + "Destination": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "Fee": "10000", + "Flags": 2147483648, + "Sequence": 360, + "SigningPubKey": "03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB", + "TransactionType": "Payment", + "TxnSignature": "304402200E5C2DD81FDF0BE9AB2A8D797885ED49E804DBF28E806604D878756410CA98B102203349581946B0DDA06B36B35DBC20EDA27552C1F167BCF5C6ECFF49C6A46F8580", + "hash": "4D5D90890F8D49519E4151938601EF3D0B30B16CD6A519D9C99102C9FA77F7E0" + } } ``` diff --git a/src/common/schemas/output/submit.json b/src/common/schemas/output/submit.json index ef975973..31e5f10d 100644 --- a/src/common/schemas/output/submit.json +++ b/src/common/schemas/output/submit.json @@ -5,13 +5,33 @@ "properties": { "resultCode": { "type": "string", - "description": "The result code returned by rippled. [List of transaction responses](https://ripple.com/build/transactions/#full-transaction-response-list)" + "description": "Deprecated: Use `engine_result` instead." }, "resultMessage": { "type": "string", - "description": "Human-readable explanation of the status of the transaction." + "description": "Deprecated: Use `engine_result_message` instead." + }, + "engine_result": { + "type": "string", + "description": "Code indicating the preliminary result of the transaction, for example tesSUCCESS. [List of transaction responses](https://ripple.com/build/transactions/#full-transaction-response-list)" + }, + "engine_result_code": { + "type": "integer", + "description": "Numeric code indicating the preliminary result of the transaction, directly correlated to `engine_result`" + }, + "engine_result_message": { + "type": "string", + "description": "Human-readable explanation of the transaction's preliminary result." + }, + "tx_blob": { + "type": "string", + "description": "The complete transaction in hex string format." + }, + "tx_json": { + "$ref": "tx", + "description": "The complete transaction in JSON format." } }, - "required": ["resultCode", "resultMessage"], + "required": ["resultCode", "resultMessage", "engine_result", "engine_result_code", "engine_result_message", "tx_blob", "tx_json"], "additionalProperties": false } diff --git a/src/transaction/submit.ts b/src/transaction/submit.ts index 9e7d13a9..1e39850a 100644 --- a/src/transaction/submit.ts +++ b/src/transaction/submit.ts @@ -20,8 +20,15 @@ function isImmediateRejection(engineResult: string): boolean { function formatSubmitResponse(response): FormattedSubmitResponse { const data = { + // @deprecated resultCode: response.engine_result, - resultMessage: response.engine_result_message + // @deprecated + resultMessage: response.engine_result_message, + engine_result: response.engine_result, + engine_result_code: response.engine_result_code, + engine_result_message: response.engine_result_message, + tx_blob: response.tx_blob, + tx_json: response.tx_json } if (isImmediateRejection(response.engine_result)) { throw new utils.common.errors.RippledError('Submit failed', data) diff --git a/test/api-test.js b/test/api-test.js index 82b97f6a..5a29efe2 100644 --- a/test/api-test.js +++ b/test/api-test.js @@ -33,7 +33,11 @@ function checkResult(expected, schemaName, response) { assert(response.txJSON); assert.deepEqual(JSON.parse(response.txJSON), JSON.parse(expected.txJSON)); } - assert.deepEqual(_.omit(response, 'txJSON'), _.omit(expected, 'txJSON')); + if (expected.tx_json) { + assert(response.tx_json); + assert.deepEqual(response.tx_json, expected.tx_json); + } + assert.deepEqual(_.omit(response, 'txJSON'), _.omit(expected, 'txJSON'), _.omit(response, 'tx_json'), _.omit(response, 'tx_json')); if (schemaName) { schemaValidator.schemaValidate(schemaName, response); } @@ -1536,8 +1540,9 @@ describe('RippleAPI', function () { }); it('submit', function () { - return this.api.submit(responses.sign.normal.signedTransaction).then( - _.partial(checkResult, responses.submit, 'submit')); + return this.api.submit(responses.sign.normal.signedTransaction).then(response => { + checkResult(responses.submit, 'submit', response); + }); }); it('submit - failure', function () { diff --git a/test/fixtures/responses/submit.json b/test/fixtures/responses/submit.json index 4d8f03d7..fc15575f 100644 --- a/test/fixtures/responses/submit.json +++ b/test/fixtures/responses/submit.json @@ -1,4 +1,24 @@ { "resultCode": "tesSUCCESS", - "resultMessage": "The transaction was applied. Only final in a validated ledger." + "resultMessage": "The transaction was applied. Only final in a validated ledger.", + "engine_result": "tesSUCCESS", + "engine_result_code": 0, + "engine_result_message": "The transaction was applied. Only final in a validated ledger.", + "tx_blob": "1200002280000000240000016861D4838D7EA4C6800000000000000000000000000055534400000000004B4E9C06F24296074F7BC48F92A97916C6DC5EA9684000000000002710732103AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB7446304402200E5C2DD81FDF0BE9AB2A8D797885ED49E804DBF28E806604D878756410CA98B102203349581946B0DDA06B36B35DBC20EDA27552C1F167BCF5C6ECFF49C6A46F858081144B4E9C06F24296074F7BC48F92A97916C6DC5EA983143E9D4A2B8AA0780F682D136F7A56D6724EF53754", + "tx_json": { + "Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "Amount": { + "currency": "USD", + "issuer": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "value": "1" + }, + "Destination": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "Fee": "10000", + "Flags": 2147483648, + "Sequence": 360, + "SigningPubKey": "03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB", + "TransactionType": "Payment", + "TxnSignature": "304402200E5C2DD81FDF0BE9AB2A8D797885ED49E804DBF28E806604D878756410CA98B102203349581946B0DDA06B36B35DBC20EDA27552C1F167BCF5C6ECFF49C6A46F8580", + "hash": "4D5D90890F8D49519E4151938601EF3D0B30B16CD6A519D9C99102C9FA77F7E0" + } } diff --git a/test/fixtures/rippled/submit.json b/test/fixtures/rippled/submit.json index a02e05c7..e2fc5680 100644 --- a/test/fixtures/rippled/submit.json +++ b/test/fixtures/rippled/submit.json @@ -7,7 +7,22 @@ "engine_result": "tesSUCCESS", "engine_result_code": 0, "engine_result_message": "The transaction was applied. Only final in a validated ledger.", - "tx_blob": "12000322000000002400000017201B0086955468400000000000000C732102F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D87446304402207660BDEF67105CE1EBA9AD35DC7156BAB43FF1D47633199EE257D70B6B9AAFBF02207F5517BC8AEF2ADC1325897ECDBA8C673838048BCA62F4E98B252F19BE88796D770A726970706C652E636F6D81144FBFF73DA4ECF9B701940F27341FA8020C313443", - "tx_json": {} + "tx_blob": "1200002280000000240000016861D4838D7EA4C6800000000000000000000000000055534400000000004B4E9C06F24296074F7BC48F92A97916C6DC5EA9684000000000002710732103AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB7446304402200E5C2DD81FDF0BE9AB2A8D797885ED49E804DBF28E806604D878756410CA98B102203349581946B0DDA06B36B35DBC20EDA27552C1F167BCF5C6ECFF49C6A46F858081144B4E9C06F24296074F7BC48F92A97916C6DC5EA983143E9D4A2B8AA0780F682D136F7A56D6724EF53754", + "tx_json": { + "Account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "Amount": { + "currency": "USD", + "issuer": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "value": "1" + }, + "Destination": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "Fee": "10000", + "Flags": 2147483648, + "Sequence": 360, + "SigningPubKey": "03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB", + "TransactionType": "Payment", + "TxnSignature": "304402200E5C2DD81FDF0BE9AB2A8D797885ED49E804DBF28E806604D878756410CA98B102203349581946B0DDA06B36B35DBC20EDA27552C1F167BCF5C6ECFF49C6A46F8580", + "hash": "4D5D90890F8D49519E4151938601EF3D0B30B16CD6A519D9C99102C9FA77F7E0" + } } }