Rename ledger "account" to "state"

This commit is contained in:
Chris Clark
2015-08-17 18:37:05 -07:00
parent 2f8655dc23
commit 1f54b3a0cf
11 changed files with 34 additions and 33 deletions

View File

@@ -5,7 +5,7 @@
"properties": {
"accepted": {"type": "boolean"},
"closed": {"type": "boolean"},
"accountHash": {"$ref": "hash256"},
"stateHash": {"$ref": "hash256"},
"closeTime": {"type": "integer", "minimum": 0},
"closeTimeResolution": {"type": "integer", "minimum": 1},
"closeFlags": {"type": "integer", "minimum": 0},
@@ -18,13 +18,13 @@
"transactions": {"type": "array", "items": {"type": "object"}},
"rawTransactions": {"type": "string"},
"transactionHashes": {"type": "array", "items": {"$ref": "hash256"}},
"rawAccounts": {"type": "string"},
"accountHashes": {"type": "array", "items": {"$ref": "hash256"}}
"rawState": {"type": "string"},
"stateHashes": {"type": "array", "items": {"$ref": "hash256"}}
},
"required": [
"accepted",
"closed",
"accountHash",
"stateHash",
"closeTime",
"closeTimeResolution",
"closeFlags",

View File

@@ -7,7 +7,7 @@
"ledgerVersion": {"$ref": "ledgerVersion"},
"includeAllData": {"type": "boolean"},
"includeTransactions": {"type": "boolean"},
"includeAccounts": {"type": "boolean"}
"includeState": {"type": "boolean"}
},
"additionalProperties": false
}

View File

@@ -9,7 +9,8 @@ function error(text) {
return new ValidationError(text);
}
function validateAddressAndSecret(obj: {address: string, secret: string}): void {
function validateAddressAndSecret(obj: {address: string, secret: string}
): void {
const address = obj.address;
const secret = obj.secret;
schemaValidate('address', address);

View File

@@ -12,7 +12,7 @@ function getLedgerAsync(options, callback) {
ledger: options.ledgerVersion || 'validated',
expand: options.includeAllData,
transactions: options.includeTransactions,
accounts: options.includeAccounts
accounts: options.includeState
};
this.remote.requestLedger(request,

View File

@@ -17,21 +17,21 @@ function parseTransactions(transactions) {
};
}
function parseAccounts(accounts) {
if (_.isEmpty(accounts)) {
function parseState(state) {
if (_.isEmpty(state)) {
return {};
}
if (_.isString(accounts[0])) {
return {accountHashes: accounts};
if (_.isString(state[0])) {
return {stateHashes: state};
}
return {rawAccounts: JSON.stringify(accounts)};
return {rawState: JSON.stringify(state)};
}
function parseLedger(ledger: Object): Object {
return removeUndefined(_.assign({
accepted: ledger.accepted,
closed: ledger.closed,
accountHash: ledger.account_hash,
stateHash: ledger.account_hash,
closeTime: ledger.close_time,
closeTimeResolution: ledger.close_time_resolution,
closeFlags: ledger.close_flags,
@@ -43,7 +43,7 @@ function parseLedger(ledger: Object): Object {
transactionHash: ledger.transaction_hash
},
parseTransactions(ledger.transactions),
parseAccounts(ledger.accountState)
parseState(ledger.accountState)
));
}

View File

@@ -32,7 +32,8 @@ function getAccountLines(remote, address, ledgerVersion, options, marker, limit,
function getTrustlinesAsync(account: string, options: {currency: string,
counterparty: string, limit: number, ledgerVersion: number},
callback: () => void): void {
callback: () => void
): void {
validate.address(account);
validate.getTrustlinesOptions(options);

View File

@@ -7,7 +7,7 @@ function convertLedgerHeader(header) {
return {
accepted: header.accepted,
closed: header.closed,
account_hash: header.accountHash,
account_hash: header.stateHash,
close_time: header.closeTime,
close_time_resolution: header.closeTimeResolution,
close_flags: header.closeFlags,
@@ -49,25 +49,24 @@ function computeTransactionHash(ledger) {
return transactionHash;
}
function computeAccountHash(ledger) {
if (ledger.rawAccounts === undefined) {
return ledger.accountHash;
function computeStateHash(ledger) {
if (ledger.rawState === undefined) {
return ledger.stateHash;
}
const accounts = JSON.parse(ledger.rawAccounts);
const ledgerObject = common.core.Ledger.from_json({accountState: accounts});
const accountHash = ledgerObject.calc_account_hash().to_hex();
if (ledger.accountHash !== undefined
&& ledger.accountHash !== accountHash) {
throw new common.errors.ValidationError('accountHash in header'
+ ' does not match computed hash of accounts');
const state = JSON.parse(ledger.rawState);
const ledgerObject = common.core.Ledger.from_json({accountState: state});
const stateHash = ledgerObject.calc_account_hash().to_hex();
if (ledger.stateHash !== undefined && ledger.stateHash !== stateHash) {
throw new common.errors.ValidationError('stateHash in header'
+ ' does not match computed hash of state');
}
return accountHash;
return stateHash;
}
function computeLedgerHash(ledger: Object): string {
const hashes = {
transactionHash: computeTransactionHash(ledger),
accountHash: computeAccountHash(ledger)
stateHash: computeStateHash(ledger)
};
return hashLedgerHeader(_.assign({}, ledger, hashes));
}

View File

@@ -556,7 +556,7 @@ describe('RippleAPI', function() {
it('getLedger - full, then computeLedgerHash', function() {
const request = {
includeTransactions: true,
includeAccounts: true,
includeState: true,
includeAllData: true,
ledgerVersion: 38129
};

View File

@@ -1,6 +1,6 @@
{
"accepted": true,
"accountHash": "D9ABF622DA26EEEE48203085D4BC23B0F77DC6F8724AC33D975DA3CA492D2E44",
"stateHash": "D9ABF622DA26EEEE48203085D4BC23B0F77DC6F8724AC33D975DA3CA492D2E44",
"closeTime": 492656470,
"parentCloseTime": 492656460,
"closeFlags": 0,

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
{
"accepted": true,
"closed": true,
"accountHash": "EC028EC32896D537ECCA18D18BEBE6AE99709FEFF9EF72DBD3A7819E918D8B96",
"stateHash": "EC028EC32896D537ECCA18D18BEBE6AE99709FEFF9EF72DBD3A7819E918D8B96",
"closeTime": 464908910,
"closeTimeResolution": 10,
"closeFlags": 0,