Skip to content

Commit

Permalink
Use ripple-hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Clark committed Oct 14, 2015
1 parent 462e440 commit 0dc0008
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 562 deletions.
28 changes: 28 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"lru-cache": "~2.5.0",
"ripple-address-codec": "^2.0.1",
"ripple-binary-codec": "^0.0.6",
"ripple-hashes": "^0.0.1",
"ripple-keypairs": "^0.10.0",
"ripple-lib-transactionparser": "^0.5.1",
"ripple-lib-value": "0.1.0",
Expand Down
13 changes: 6 additions & 7 deletions src/api/offline/ledgerhash.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';
const _ = require('lodash');
const common = require('../common');
const hashes = require('ripple-hashes');

function convertLedgerHeader(header) {
return {
Expand All @@ -25,7 +26,7 @@ function convertLedgerHeader(header) {

function hashLedgerHeader(ledgerHeader) {
const header = convertLedgerHeader(ledgerHeader);
return common.core.Ledger.calculateLedgerHash(header);
return hashes.computeLedgerHash(header);
}

function computeTransactionHash(ledger) {
Expand All @@ -39,8 +40,7 @@ function computeTransactionHash(ledger) {
tx.meta ? {metaData: tx.meta} : {});
return renameMeta;
});
const ledgerObject = common.core.Ledger.from_json({transactions: txs});
const transactionHash = ledgerObject.calc_tx_hash();
const transactionHash = hashes.computeTransactionTreeHash(txs);
if (ledger.transactionHash !== undefined
&& ledger.transactionHash !== transactionHash) {
throw new common.errors.ValidationError('transactionHash in header'
Expand All @@ -54,8 +54,7 @@ function computeStateHash(ledger) {
return ledger.stateHash;
}
const state = JSON.parse(ledger.rawState);
const ledgerObject = common.core.Ledger.from_json({accountState: state});
const stateHash = ledgerObject.calc_account_hash();
const stateHash = hashes.computeStateTreeHash(state);
if (ledger.stateHash !== undefined && ledger.stateHash !== stateHash) {
throw new common.errors.ValidationError('stateHash in header'
+ ' does not match computed hash of state');
Expand All @@ -64,11 +63,11 @@ function computeStateHash(ledger) {
}

function computeLedgerHash(ledger: Object): string {
const hashes = {
const subhashes = {
transactionHash: computeTransactionHash(ledger),
stateHash: computeStateHash(ledger)
};
return hashLedgerHeader(_.assign({}, ledger, hashes));
return hashLedgerHeader(_.assign({}, ledger, subhashes));
}

module.exports = computeLedgerHash;
38 changes: 0 additions & 38 deletions src/core/hashprefixes.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ exports.Meta = require('./meta').Meta;
exports.RippleError = require('./rippleerror').RippleError;
exports.utils = require('./utils');
exports.Server = require('./server').Server;
exports.Ledger = require('./ledger').Ledger;

exports._test = {
Log: require('./log'),
PathFind: require('./pathfind').PathFind,
TransactionManager: require('./transactionmanager').TransactionManager,
TransactionQueue: require('./transactionqueue').TransactionQueue,
RangeSet: require('./rangeset').RangeSet,
HashPrefixes: require('./hashprefixes'),
OrderbookUtils: require('./orderbookutils'),
constants: require('./constants')
};
186 changes: 0 additions & 186 deletions src/core/ledger.js

This file was deleted.

22 changes: 0 additions & 22 deletions src/core/ledgerspaces.js

This file was deleted.

0 comments on commit 0dc0008

Please sign in to comment.