Merge branch 'develop' of github.com:jedmccaleb/NewCoin into develop

This commit is contained in:
JoelKatz
2013-04-21 12:55:34 -07:00
6 changed files with 54 additions and 30 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "ripple-lib", "name": "ripple-lib",
"version": "0.7.5", "version": "0.7.6",
"description": "Ripple JavaScript client library", "description": "Ripple JavaScript client library",
"files": [ "files": [

View File

@@ -1972,8 +1972,8 @@ void NetworkOPs::getBookPage(Ledger::pointer lpLedger, const uint160& uTakerPays
// Only provide, if not fully funded. // Only provide, if not fully funded.
jvOffer["taker_gets_funded"] = saTakerGetsFunded.getJson(0); jvOffer["taker_gets_funded"] = saTakerGetsFunded.getJson(0);
jvOffer["taker_pays_funded"] = saTakerPaysFunded.getJson(0); jvOffer["taker_pays_funded"] = saTakerPaysFunded.getJson(0);
} }
STAmount saOwnerPays = QUALITY_ONE == uOfferRate STAmount saOwnerPays = QUALITY_ONE == uOfferRate
? saTakerGetsFunded ? saTakerGetsFunded
: std::min(saOwnerFunds, STAmount::multiply(saTakerGetsFunded, STAmount(CURRENCY_ONE, ACCOUNT_ONE, uOfferRate, -9))); : std::min(saOwnerFunds, STAmount::multiply(saTakerGetsFunded, STAmount(CURRENCY_ONE, ACCOUNT_ONE, uOfferRate, -9)));
@@ -1985,6 +1985,8 @@ void NetworkOPs::getBookPage(Ledger::pointer lpLedger, const uint160& uTakerPays
if (!saOwnerFunds.isZero() || uOfferOwnerID == uTakerID) if (!saOwnerFunds.isZero() || uOfferOwnerID == uTakerID)
{ {
// Only provide funded offers and offers of the taker. // Only provide funded offers and offers of the taker.
jvOffer["quality"] = saDirRate.getText();
jvOffers.append(jvOffer); jvOffers.append(jvOffer);
} }

View File

@@ -69,6 +69,10 @@ Amount.from_json = function (j) {
return (new Amount()).parse_json(j); return (new Amount()).parse_json(j);
}; };
Amount.from_quality = function (q, c, i) {
return (new Amount()).parse_quality(q, c, i);
};
Amount.from_human = function (j) { Amount.from_human = function (j) {
return (new Amount()).parse_human(j); return (new Amount()).parse_human(j);
}; };
@@ -103,6 +107,16 @@ Amount.prototype.add = function (v) {
if (!this.is_comparable(v)) { if (!this.is_comparable(v)) {
result = Amount.NaN(); result = Amount.NaN();
} }
else if (v.is_zero()) {
result = this;
}
else if (this.is_zero()) {
result = v.clone();
result._is_negative = false;
result._is_native = this._is_native;
result._currency = this._currency;
result._issuer = this._issuer;
}
else if (this._is_native) { else if (this._is_native) {
result = new Amount(); result = new Amount();
@@ -112,13 +126,6 @@ Amount.prototype.add = function (v) {
result._is_negative = s.compareTo(BigInteger.ZERO) < 0; result._is_negative = s.compareTo(BigInteger.ZERO) < 0;
result._value = result._is_negative ? s.negate() : s; result._value = result._is_negative ? s.negate() : s;
}
else if (v.is_zero()) {
result = this;
}
else if (this.is_zero()) {
result = v.clone();
// YYY Why are these cloned? We never modify them.
result._currency = this._currency; result._currency = this._currency;
result._issuer = this._issuer; result._issuer = this._issuer;
} }
@@ -258,7 +265,8 @@ Amount.prototype.compareTo = function (v) {
return result; return result;
}; };
// Returns copy. // Make d a copy of this. Returns d.
// Modification of objects internally refered to is not allowed.
Amount.prototype.copyTo = function (d, negate) { Amount.prototype.copyTo = function (d, negate) {
if ('object' === typeof this._value) if ('object' === typeof this._value)
{ {
@@ -275,8 +283,8 @@ Amount.prototype.copyTo = function (d, negate) {
? !this._is_negative // Negating. ? !this._is_negative // Negating.
: this._is_negative; // Just copying. : this._is_negative; // Just copying.
this._currency.copyTo(d._currency); d._currency = this._currency;
this._issuer.copyTo(d._issuer); d._issuer = this._issuer;
// Prevent negative zero // Prevent negative zero
if (d.is_zero()) d._is_negative = false; if (d.is_zero()) d._is_negative = false;
@@ -606,11 +614,25 @@ Amount.prototype.parse_human = function (j) {
}; };
Amount.prototype.parse_issuer = function (issuer) { Amount.prototype.parse_issuer = function (issuer) {
this._issuer.parse_json(issuer); this._issuer = UInt160.from_json(issuer);
return this; return this;
}; };
// --> h: 8 hex bytes quality or 32 hex bytes directory index.
Amount.prototype.parse_quality = function (q, c, i) {
this._is_negative = false;
this._value = new BigInteger(q.substring(q.length-14), 16);
this._offset = parseInt(q.substring(q.length-16, q.length-14), 16)-100;
this._currency = Currency.from_json(c);
this._issuer = UInt160.from_json(i);
this._is_native = this._currency.is_native();
this.canonicalize();
return this;
}
// <-> j // <-> j
Amount.prototype.parse_json = function (j) { Amount.prototype.parse_json = function (j) {
if ('string' === typeof j) { if ('string' === typeof j) {
@@ -628,8 +650,8 @@ Amount.prototype.parse_json = function (j) {
} }
else { else {
this.parse_native(j); this.parse_native(j);
this._currency = new Currency(); this._currency = Currency.from_json("0");
this._issuer = new UInt160(); this._issuer = UInt160.from_json("0");
} }
} }
else if ('number' === typeof j) { else if ('number' === typeof j) {
@@ -757,11 +779,11 @@ Amount.prototype.parse_value = function (j) {
Amount.prototype.set_currency = function (c) { Amount.prototype.set_currency = function (c) {
if ('string' === typeof c) { if ('string' === typeof c) {
this._currency.parse_json(c); this._currency = Currency.from_json(c);
} }
else else
{ {
c.copyTo(this._currency); this._currency = c;
} }
this._is_native = this._currency.is_native(); this._is_native = this._currency.is_native();
@@ -770,9 +792,9 @@ Amount.prototype.set_currency = function (c) {
Amount.prototype.set_issuer = function (issuer) { Amount.prototype.set_issuer = function (issuer) {
if (issuer instanceof UInt160) { if (issuer instanceof UInt160) {
issuer.copyTo(this._issuer); this._issuer = issuer;
} else { } else {
this._issuer.parse_json(issuer); this._issuer = UInt160.from_json(issuer);
} }
return this; return this;
@@ -975,7 +997,7 @@ Amount.prototype.not_equals_why = function (d, ignore_issuer) {
if (!this._is_native) { if (!this._is_native) {
if (!this._currency.equals(d._currency)) return "Non-XRP currency differs."; if (!this._currency.equals(d._currency)) return "Non-XRP currency differs.";
if (!ignore_issuer && !this._issuer.equals(d._issuer)) { if (!ignore_issuer && !this._issuer.equals(d._issuer)) {
return "Non-XRP issuer differs."; return "Non-XRP issuer differs: " + d._issuer.to_json() + "/" + this._issuer.to_json();
} }
} }
return false; return false;

View File

@@ -1164,11 +1164,11 @@ Remote.prototype.request_ripple_balance = function (account, issuer, currency, c
var accountHigh = UInt160.from_json(account).equals(highLimit.issuer()); var accountHigh = UInt160.from_json(account).equals(highLimit.issuer());
request.emit('ripple_state', { request.emit('ripple_state', {
'account_balance' : ( accountHigh ? balance.negate() : balance).parse_issuer(account), 'account_balance' : ( accountHigh ? balance.negate() : balance.clone()).parse_issuer(account),
'peer_balance' : (!accountHigh ? balance.negate() : balance).parse_issuer(issuer), 'peer_balance' : (!accountHigh ? balance.negate() : balance.clone()).parse_issuer(issuer),
'account_limit' : ( accountHigh ? highLimit : lowLimit).parse_issuer(issuer), 'account_limit' : ( accountHigh ? highLimit : lowLimit).clone().parse_issuer(issuer),
'peer_limit' : (!accountHigh ? highLimit : lowLimit).parse_issuer(account), 'peer_limit' : (!accountHigh ? highLimit : lowLimit).clone().parse_issuer(account),
'account_quality_in' : ( accountHigh ? node.HighQualityIn : node.LowQualityIn), 'account_quality_in' : ( accountHigh ? node.HighQualityIn : node.LowQualityIn),
'peer_quality_in' : (!accountHigh ? node.HighQualityIn : node.LowQualityIn), 'peer_quality_in' : (!accountHigh ? node.HighQualityIn : node.LowQualityIn),

View File

@@ -329,7 +329,7 @@ buster.testCase("Amount", {
var a = Amount.from_json("1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL"); var a = Amount.from_json("1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
var b = Amount.from_json("1/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP"); var b = Amount.from_json("1/USD/rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP");
buster.refute(a.equals(b)); buster.refute(a.equals(b));
buster.assert.equals(a.not_equals_why(b), "Non-XRP issuer differs."); buster.assert.equals(a.not_equals_why(b), "Non-XRP issuer differs: rH5aWQJ4R7v4Mpyf4kDBUvDFT5cbpFq3XP/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");
}, },
"1 USD != 1 EUR" : function () { "1 USD != 1 EUR" : function () {
var a = Amount.from_json("1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL"); var a = Amount.from_json("1/USD/rNDKeo9RrCiRdfsMG8AdoZvNZxHASGzbZL");

View File

@@ -372,7 +372,7 @@ buster.testCase("Sending future", {
.submit(); .submit();
}, },
function (callback) { function (callback) {
self.what = "Verify balance from alice's pov."; self.what = "Verify balance from alice's pov: 1";
self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT')
.once('ripple_state', function (m) { .once('ripple_state', function (m) {
@@ -397,7 +397,7 @@ buster.testCase("Sending future", {
.submit(); .submit();
}, },
function (callback) { function (callback) {
self.what = "Verify balance from alice's pov."; self.what = "Verify balance from alice's pov: 2";
self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT')
.once('ripple_state', function (m) { .once('ripple_state', function (m) {
@@ -422,7 +422,7 @@ buster.testCase("Sending future", {
.submit(); .submit();
}, },
function (callback) { function (callback) {
self.what = "Verify balance from alice's pov."; self.what = "Verify balance from alice's pov: 3";
self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT')
.once('ripple_state', function (m) { .once('ripple_state', function (m) {
@@ -445,7 +445,7 @@ buster.testCase("Sending future", {
.submit(); .submit();
}, },
function (callback) { function (callback) {
self.what = "Verify balance from alice's pov."; self.what = "Verify balance from alice's pov: 4";
self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT')
.once('ripple_state', function (m) { .once('ripple_state', function (m) {
@@ -467,7 +467,7 @@ buster.testCase("Sending future", {
// .ledger_accept(); // .ledger_accept();
// }, // },
// function (callback) { // function (callback) {
// self.what = "Verify balance from alice's pov."; // self.what = "Verify balance from alice's pov: 5";
// //
// self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT') // self.remote.request_ripple_balance("alice", "bob", "USD", 'CURRENT')
// .once('ripple_state', function (m) { // .once('ripple_state', function (m) {