mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 20:55:48 +00:00
Add support for parsing SetFee and EnableAmendment pseudo-transactions
This commit is contained in:
@@ -5,6 +5,7 @@ machine:
|
|||||||
testripple.circleci.com: 127.0.0.1
|
testripple.circleci.com: 127.0.0.1
|
||||||
dependencies:
|
dependencies:
|
||||||
pre:
|
pre:
|
||||||
|
- npm -g install npm@latest-2
|
||||||
- wget https://s3-us-west-2.amazonaws.com/ripple-debs/rippled_0.30.1-b11-1.deb
|
- wget https://s3-us-west-2.amazonaws.com/ripple-debs/rippled_0.30.1-b11-1.deb
|
||||||
- sudo dpkg -i rippled_0.30.1-b11-1.deb
|
- sudo dpkg -i rippled_0.30.1-b11-1.deb
|
||||||
test:
|
test:
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
"assert-diff": "^1.0.1",
|
"assert-diff": "^1.0.1",
|
||||||
"babel-cli": "^6.4.0",
|
"babel-cli": "^6.4.0",
|
||||||
"babel-core": "^6.4.0",
|
"babel-core": "^6.4.0",
|
||||||
"babel-eslint": "^4.1.8",
|
"babel-eslint": "^6.0.4",
|
||||||
"babel-loader": "^6.2.1",
|
"babel-loader": "^6.2.1",
|
||||||
"babel-plugin-syntax-flow": "^6.3.13",
|
"babel-plugin-syntax-flow": "^6.3.13",
|
||||||
"babel-plugin-transform-flow-strip-types": "^6.4.0",
|
"babel-plugin-transform-flow-strip-types": "^6.4.0",
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
"coveralls": "^2.10.0",
|
"coveralls": "^2.10.0",
|
||||||
"doctoc": "^0.15.0",
|
"doctoc": "^0.15.0",
|
||||||
"ejs": "^2.3.4",
|
"ejs": "^2.3.4",
|
||||||
"eslint": "^2.1.0",
|
"eslint": "^2.9.0",
|
||||||
"eventemitter2": "^0.4.14",
|
"eventemitter2": "^0.4.14",
|
||||||
"flow-bin": "^0.14",
|
"flow-bin": "^0.14",
|
||||||
"gulp": "^3.8.10",
|
"gulp": "^3.8.10",
|
||||||
|
|||||||
9
src/ledger/parse/amendment.js
Normal file
9
src/ledger/parse/amendment.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
'use strict'; // eslint-disable-line strict
|
||||||
|
|
||||||
|
function parseAmendment(tx: Object) {
|
||||||
|
return {
|
||||||
|
amendment: tx.Amendment
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = parseAmendment;
|
||||||
15
src/ledger/parse/fee-update.js
Normal file
15
src/ledger/parse/fee-update.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
'use strict'; // eslint-disable-line strict
|
||||||
|
const BigNumber = require('bignumber.js');
|
||||||
|
const {dropsToXrp} = require('./utils');
|
||||||
|
|
||||||
|
function parseFeeUpdate(tx: Object) {
|
||||||
|
const baseFeeDrops = (new BigNumber(tx.BaseFee, 16)).toString();
|
||||||
|
return {
|
||||||
|
baseFeeXRP: dropsToXrp(baseFeeDrops),
|
||||||
|
referenceFeeUnits: tx.ReferenceFeeUnits,
|
||||||
|
reserveBaseXRP: dropsToXrp(tx.ReserveBase),
|
||||||
|
reserveIncrementXRP: dropsToXrp(tx.ReserveIncrement)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = parseFeeUpdate;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
'use strict';
|
'use strict'; // eslint-disable-line strict
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const parsePayment = require('./payment');
|
const parsePayment = require('./payment');
|
||||||
@@ -11,6 +11,8 @@ const parseSuspendedPaymentCreation = require('./suspended-payment-creation');
|
|||||||
const parseSuspendedPaymentExecution = require('./suspended-payment-execution');
|
const parseSuspendedPaymentExecution = require('./suspended-payment-execution');
|
||||||
const parseSuspendedPaymentCancellation =
|
const parseSuspendedPaymentCancellation =
|
||||||
require('./suspended-payment-cancellation');
|
require('./suspended-payment-cancellation');
|
||||||
|
const parseFeeUpdate = require('./fee-update');
|
||||||
|
const parseAmendment = require('./amendment');
|
||||||
|
|
||||||
function parseTransactionType(type) {
|
function parseTransactionType(type) {
|
||||||
const mapping = {
|
const mapping = {
|
||||||
@@ -23,7 +25,9 @@ function parseTransactionType(type) {
|
|||||||
SuspendedPaymentCreate: 'suspendedPaymentCreation',
|
SuspendedPaymentCreate: 'suspendedPaymentCreation',
|
||||||
SuspendedPaymentFinish: 'suspendedPaymentExecution',
|
SuspendedPaymentFinish: 'suspendedPaymentExecution',
|
||||||
SuspendedPaymentCancel: 'suspendedPaymentCancellation',
|
SuspendedPaymentCancel: 'suspendedPaymentCancellation',
|
||||||
SignerListSet: 'settings'
|
SignerListSet: 'settings',
|
||||||
|
SetFee: 'feeUpdate', // pseudo-transaction
|
||||||
|
EnableAmendment: 'amendment' // pseudo-transaction
|
||||||
};
|
};
|
||||||
return mapping[type] || null;
|
return mapping[type] || null;
|
||||||
}
|
}
|
||||||
@@ -38,7 +42,9 @@ function parseTransaction(tx: Object): Object {
|
|||||||
'settings': parseSettings,
|
'settings': parseSettings,
|
||||||
'suspendedPaymentCreation': parseSuspendedPaymentCreation,
|
'suspendedPaymentCreation': parseSuspendedPaymentCreation,
|
||||||
'suspendedPaymentExecution': parseSuspendedPaymentExecution,
|
'suspendedPaymentExecution': parseSuspendedPaymentExecution,
|
||||||
'suspendedPaymentCancellation': parseSuspendedPaymentCancellation
|
'suspendedPaymentCancellation': parseSuspendedPaymentCancellation,
|
||||||
|
'feeUpdate': parseFeeUpdate,
|
||||||
|
'amendment': parseAmendment
|
||||||
};
|
};
|
||||||
const parser = mapping[type];
|
const parser = mapping[type];
|
||||||
assert(parser !== undefined, 'Unrecognized transaction type');
|
assert(parser !== undefined, 'Unrecognized transaction type');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
'use strict';
|
'use strict'; // eslint-disable-line strict
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const parseTransaction = require('./parse/transaction');
|
const parseTransaction = require('./parse/transaction');
|
||||||
@@ -13,15 +13,18 @@ function attachTransactionDate(connection: Connection, tx: Object
|
|||||||
return Promise.resolve(tx);
|
return Promise.resolve(tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tx.ledger_index) {
|
const ledgerVersion = tx.ledger_index || tx.LedgerSequence;
|
||||||
|
|
||||||
|
if (!ledgerVersion) {
|
||||||
return new Promise(() => {
|
return new Promise(() => {
|
||||||
throw new errors.NotFoundError('ledger_index not found in tx');
|
throw new errors.NotFoundError(
|
||||||
|
'ledger_index and LedgerSequence not found in tx');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const request = {
|
const request = {
|
||||||
command: 'ledger',
|
command: 'ledger',
|
||||||
ledger_index: tx.ledger_index
|
ledger_index: ledgerVersion
|
||||||
};
|
};
|
||||||
|
|
||||||
return connection.request(request).then(data => {
|
return connection.request(request).then(data => {
|
||||||
|
|||||||
@@ -708,6 +708,21 @@ describe('RippleAPI', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getTransaction - amendment', function() {
|
||||||
|
const hash =
|
||||||
|
'A971B83ABED51D83749B73F3C1AAA627CD965AFF74BE8CD98299512D6FB0658F';
|
||||||
|
return this.api.getTransaction(hash).then(result => {
|
||||||
|
assert.deepEqual(result, responses.getTransaction.amendment);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getTransaction - feeUpdate', function() {
|
||||||
|
const hash =
|
||||||
|
'C6A40F56127436DCD830B1B35FF939FD05B5747D30D6542572B7A835239817AF';
|
||||||
|
return this.api.getTransaction(hash).then(result => {
|
||||||
|
assert.deepEqual(result, responses.getTransaction.feeUpdate);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getTransactions', function() {
|
it('getTransactions', function() {
|
||||||
|
|||||||
17
test/fixtures/responses/get-transaction-amendment.json
vendored
Normal file
17
test/fixtures/responses/get-transaction-amendment.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"type": "amendment",
|
||||||
|
"address": "rrrrrrrrrrrrrrrrrrrrrhoLvTp",
|
||||||
|
"sequence": 0,
|
||||||
|
"id": "A971B83ABED51D83749B73F3C1AAA627CD965AFF74BE8CD98299512D6FB0658F",
|
||||||
|
"specification": {
|
||||||
|
"amendment": "42426C4D4F1009EE67080A9B7965B44656D7714D104A72F9B4369F97ABF044EE"
|
||||||
|
},
|
||||||
|
"outcome": {
|
||||||
|
"result": "tesSUCCESS",
|
||||||
|
"timestamp": "2016-05-05T16:33:30.000Z",
|
||||||
|
"fee": "0",
|
||||||
|
"balanceChanges": {},
|
||||||
|
"orderbookChanges": {},
|
||||||
|
"indexInLedger": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
21
test/fixtures/responses/get-transaction-fee-update.json
vendored
Normal file
21
test/fixtures/responses/get-transaction-fee-update.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"type": "feeUpdate",
|
||||||
|
"address": "rrrrrrrrrrrrrrrrrrrrrhoLvTp",
|
||||||
|
"sequence": 0,
|
||||||
|
"id": "C6A40F56127436DCD830B1B35FF939FD05B5747D30D6542572B7A835239817AF",
|
||||||
|
"specification": {
|
||||||
|
"baseFeeXRP": "0.00001",
|
||||||
|
"referenceFeeUnits": 10,
|
||||||
|
"reserveBaseXRP": "50",
|
||||||
|
"reserveIncrementXRP": "12.5"
|
||||||
|
},
|
||||||
|
"outcome": {
|
||||||
|
"result": "tesSUCCESS",
|
||||||
|
"timestamp": "2014-08-08T16:57:50.000Z",
|
||||||
|
"fee": "0",
|
||||||
|
"balanceChanges": {},
|
||||||
|
"orderbookChanges": {},
|
||||||
|
"ledgerVersion": 3717633,
|
||||||
|
"indexInLedger": 3
|
||||||
|
}
|
||||||
|
}
|
||||||
6
test/fixtures/responses/index.js
vendored
6
test/fixtures/responses/index.js
vendored
@@ -1,4 +1,4 @@
|
|||||||
'use strict';
|
'use strict'; // eslint-disable-line strict
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
generateAddress: require('./generate-address.json'),
|
generateAddress: require('./generate-address.json'),
|
||||||
@@ -43,7 +43,9 @@ module.exports = {
|
|||||||
suspendedPaymentExecution:
|
suspendedPaymentExecution:
|
||||||
require('./get-transaction-suspended-payment-execution.json'),
|
require('./get-transaction-suspended-payment-execution.json'),
|
||||||
suspendedPaymentExecutionSimple:
|
suspendedPaymentExecutionSimple:
|
||||||
require('./get-transaction-suspended-payment-execution-simple.json')
|
require('./get-transaction-suspended-payment-execution-simple.json'),
|
||||||
|
amendment: require('./get-transaction-amendment.json'),
|
||||||
|
feeUpdate: require('./get-transaction-fee-update.json')
|
||||||
},
|
},
|
||||||
getTransactions: {
|
getTransactions: {
|
||||||
normal: require('./get-transactions.json'),
|
normal: require('./get-transactions.json'),
|
||||||
|
|||||||
4
test/fixtures/rippled/index.js
vendored
4
test/fixtures/rippled/index.js
vendored
@@ -72,6 +72,8 @@ module.exports = {
|
|||||||
require('./tx/suspended-payment-execution-simple.json'),
|
require('./tx/suspended-payment-execution-simple.json'),
|
||||||
Unrecognized: require('./tx/unrecognized.json'),
|
Unrecognized: require('./tx/unrecognized.json'),
|
||||||
NoMeta: require('./tx/no-meta.json'),
|
NoMeta: require('./tx/no-meta.json'),
|
||||||
LedgerZero: require('./tx/ledger-zero.json')
|
LedgerZero: require('./tx/ledger-zero.json'),
|
||||||
|
Amendment: require('./tx/amendment.json'),
|
||||||
|
SetFee: require('./tx/set-fee.json')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
40
test/fixtures/rippled/tx/amendment.json
vendored
Normal file
40
test/fixtures/rippled/tx/amendment.json
vendored
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"id": 0,
|
||||||
|
"status": "success",
|
||||||
|
"type": "response",
|
||||||
|
"result": {
|
||||||
|
"Account": "rrrrrrrrrrrrrrrrrrrrrhoLvTp",
|
||||||
|
"Amendment": "42426C4D4F1009EE67080A9B7965B44656D7714D104A72F9B4369F97ABF044EE",
|
||||||
|
"Fee": "0",
|
||||||
|
"Flags": 65536,
|
||||||
|
"date": 515781210,
|
||||||
|
"LedgerSequence": 20889601,
|
||||||
|
"Sequence": 0,
|
||||||
|
"SigningPubKey": "",
|
||||||
|
"TransactionType": "EnableAmendment",
|
||||||
|
"hash": "A971B83ABED51D83749B73F3C1AAA627CD965AFF74BE8CD98299512D6FB0658F",
|
||||||
|
"meta": {
|
||||||
|
"AffectedNodes": [
|
||||||
|
{
|
||||||
|
"CreatedNode": {
|
||||||
|
"LedgerEntryType": "Amendments",
|
||||||
|
"LedgerIndex": "7DB0788C020F02780A673DC74757F23823FA3014C1866E72CC4CD8B226CD6EF4",
|
||||||
|
"NewFields": {
|
||||||
|
"Majorities": [
|
||||||
|
{
|
||||||
|
"Majority": {
|
||||||
|
"Amendment": "42426C4D4F1009EE67080A9B7965B44656D7714D104A72F9B4369F97ABF044EE",
|
||||||
|
"CloseTime": 515781202
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"TransactionIndex": 0,
|
||||||
|
"TransactionResult": "tesSUCCESS"
|
||||||
|
},
|
||||||
|
"validated": true
|
||||||
|
}
|
||||||
|
}
|
||||||
43
test/fixtures/rippled/tx/set-fee.json
vendored
Normal file
43
test/fixtures/rippled/tx/set-fee.json
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
"id": 0,
|
||||||
|
"status": "success",
|
||||||
|
"type": "response",
|
||||||
|
"result": {
|
||||||
|
"hash": "C6A40F56127436DCD830B1B35FF939FD05B5747D30D6542572B7A835239817AF",
|
||||||
|
"ledger_index": 3717633,
|
||||||
|
"date": 460832270,
|
||||||
|
"TransactionType": "SetFee",
|
||||||
|
"Sequence": 0,
|
||||||
|
"ReferenceFeeUnits": 10,
|
||||||
|
"ReserveBase": 50000000,
|
||||||
|
"ReserveIncrement": 12500000,
|
||||||
|
"BaseFee": "000000000000000A",
|
||||||
|
"Fee": "0",
|
||||||
|
"SigningPubKey": "",
|
||||||
|
"Account": "rrrrrrrrrrrrrrrrrrrrrhoLvTp",
|
||||||
|
"meta": {
|
||||||
|
"TransactionIndex": 3,
|
||||||
|
"AffectedNodes": [
|
||||||
|
{
|
||||||
|
"ModifiedNode": {
|
||||||
|
"LedgerEntryType": "FeeSettings",
|
||||||
|
"LedgerIndex": "4BC50C9B0D8515D3EAAE1E74B29A95804346C491EE1A95BF25E4AAB854A6A651",
|
||||||
|
"PreviousFields": {
|
||||||
|
"ReserveBase": 20000000,
|
||||||
|
"ReserveIncrement": 5000000
|
||||||
|
},
|
||||||
|
"FinalFields": {
|
||||||
|
"Flags": 0,
|
||||||
|
"ReferenceFeeUnits": 10,
|
||||||
|
"ReserveBase": 50000000,
|
||||||
|
"ReserveIncrement": 12500000,
|
||||||
|
"BaseFee": "000000000000000A"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"TransactionResult": "tesSUCCESS"
|
||||||
|
},
|
||||||
|
"validated": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -292,6 +292,12 @@ module.exports = function createMockRippled(port) {
|
|||||||
} else if (request.transaction ===
|
} else if (request.transaction ===
|
||||||
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA13') {
|
'4FB3ADF22F3C605E23FAEFAA185F3BD763C4692CAC490D9819D117CD33BFAA13') {
|
||||||
conn.send(createResponse(request, fixtures.tx.LedgerZero));
|
conn.send(createResponse(request, fixtures.tx.LedgerZero));
|
||||||
|
} else if (request.transaction ===
|
||||||
|
'A971B83ABED51D83749B73F3C1AAA627CD965AFF74BE8CD98299512D6FB0658F') {
|
||||||
|
conn.send(createResponse(request, fixtures.tx.Amendment));
|
||||||
|
} else if (request.transaction ===
|
||||||
|
'C6A40F56127436DCD830B1B35FF939FD05B5747D30D6542572B7A835239817AF') {
|
||||||
|
conn.send(createResponse(request, fixtures.tx.SetFee));
|
||||||
} else {
|
} else {
|
||||||
assert(false, 'Unrecognized transaction hash: ' + request.transaction);
|
assert(false, 'Unrecognized transaction hash: ' + request.transaction);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user