Express transferRate as a float

This commit is contained in:
Chris Clark
2015-07-23 14:02:57 -07:00
parent a383bd7e52
commit 34a4dd3077
5 changed files with 14 additions and 5 deletions

View File

@@ -33,7 +33,7 @@ const AccountFields = {
WalletSize: {name: 'walletSize', defaults: 0},
MessageKey: {name: 'messageKey'},
Domain: {name: 'domain', encoding: 'hex'},
TransferRate: {name: 'transferRate', defaults: 0},
TransferRate: {name: 'transferRate', defaults: 0, shift: 9},
Signers: {name: 'signers'}
};

View File

@@ -27,7 +27,12 @@
"walletSize": {"type": ["integer", "null"]},
"messageKey": {"type": "string"},
"domain": {"type": "string"},
"transferRate": {"type": ["integer", "null"]},
"transferRate": {
"oneOf": [
{"type": "null"},
{"type": "number", "minimum": 1, "maximum": 4.294967295}
]
},
"signers": {"type": "string"},
"regularKey": {"$ref": "address"}
},

View File

@@ -1,11 +1,15 @@
/* @flow */
'use strict';
const BigNumber = require('bignumber.js');
const AccountFields = require('./utils').constants.AccountFields;
function parseField(info, value) {
if (info.encoding === 'hex' && !info.length) {
return new Buffer(value, 'hex').toString('ascii');
}
if (info.shift) {
return (new BigNumber(value)).shift(-info.shift).toNumber();
}
return value;
}

View File

@@ -1,7 +1,7 @@
/* @flow */
'use strict';
const _ = require('lodash');
const assert = require('assert');
const BigNumber = require('bignumber.js');
const utils = require('./utils');
const validate = utils.common.validate;
const AccountFlagIndices = utils.common.constants.AccountFlagIndices;
@@ -64,7 +64,7 @@ function setTransactionFields(transaction, input) {
*/
function convertTransferRate(transferRate) {
return _.isNumber(transferRate) ? transferRate * 1e9 : transferRate;
return (new BigNumber(transferRate)).shift(9).toNumber();
}
function createSettingsTransaction(account, settings) {

View File

@@ -4,5 +4,5 @@
"emailHash": "23463B99B62A72F26ED677CC556C44E8",
"walletLocator": "00000000000000000000000000000000000000000000000000000000DEADBEEF",
"domain": "example.com",
"transferRate": 1002000000
"transferRate": 1.002
}