Prevent offers spending from XRP reserve.

This commit is contained in:
Arthur Britto
2012-12-20 22:23:10 -08:00
parent 37c073a79b
commit fadf9aa442
2 changed files with 39 additions and 40 deletions

View File

@@ -1013,7 +1013,7 @@ STAmount LedgerEntrySet::rippleHolds(const uint160& uAccountID, const uint160& u
}
else if (uAccountID > uIssuerID)
{
if (bAvail)
if (false && bAvail)
{
saBalance = sleRippleState->getFieldAmount(sfLowLimit);
saBalance -= sleRippleState->getFieldAmount(sfBalance);
@@ -1028,7 +1028,7 @@ STAmount LedgerEntrySet::rippleHolds(const uint160& uAccountID, const uint160& u
}
else
{
if (bAvail)
if (false && bAvail)
{
saBalance = sleRippleState->getFieldAmount(sfHighLimit);
saBalance += sleRippleState->getFieldAmount(sfBalance);
@@ -1052,8 +1052,18 @@ STAmount LedgerEntrySet::accountHolds(const uint160& uAccountID, const uint160&
if (!uCurrencyID)
{
SLE::pointer sleAccount = entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(uAccountID));
uint64 uReserve = mLedger->getReserve(sleAccount->getFieldU32(sfOwnerCount));
saAmount = sleAccount->getFieldAmount(sfBalance);
saAmount = sleAccount->getFieldAmount(sfBalance)-uReserve;
if (saAmount < uReserve)
{
saAmount.zero();
}
else
{
saAmount -= uReserve;
}
}
else
{
@@ -1070,7 +1080,9 @@ STAmount LedgerEntrySet::accountHolds(const uint160& uAccountID, const uint160&
// Returns the funds available for uAccountID for a currency/issuer.
// Use when you need a default for rippling uAccountID's currency.
// XXX Should take into account quality?
// --> saDefault/currency/issuer
// --> bAvail: true to include going into debt.
// <-- saFunds: Funds available. May be negative.
// If the issuer is the same as uAccountID, funds are unlimited, use result is saDefault.
STAmount LedgerEntrySet::accountFunds(const uint160& uAccountID, const STAmount& saDefault, bool bAvail)

View File

@@ -481,54 +481,41 @@ buster.testCase("Offer tests", {
.offer_create("bob", "50/USD/alice", "200/EUR/carol")
.on('proposed', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS');
callback(m.result !== 'terUNFUNDED');
seq = m.tx_json.Sequence;
})
.submit();
},
// function (callback) {
// self.what = "Alice converts USD to EUR via ripple.";
// self.what = "Alice converts USD to EUR via offer.";
//
// self.remote.transaction()
// .payment("alice", "alice", "10/EUR/carol")
// .send_max("50/USD/alice")
// .offer_create("alice", "200/EUR/carol", "50/USD/alice")
// .on('proposed', function (m) {
// // console.log("proposed: %s", JSON.stringify(m));
//
// // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
// callback(m.result !== 'tesSUCCESS');
//
// seq = m.tx_json.Sequence;
// })
// .submit();
// },
function (callback) {
self.what = "Alice converts USD to EUR via offer.";
self.remote.transaction()
.offer_create("alice", "200/EUR/carol", "50/USD/alice")
.on('proposed', function (m) {
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
callback(m.result !== 'tesSUCCESS');
seq = m.tx_json.Sequence;
})
.submit();
},
function (callback) {
self.what = "Verify balances.";
testutils.verify_balances(self.remote,
{
"alice" : [ "-50/USD/bob", "200/EUR/carol" ],
"bob" : [ "50/USD/alice", "-200/EUR/carol" ],
"carol" : [ "-200/EUR/alice", "200/EUR/bob" ],
},
callback);
},
function (callback) {
self.what = "Verify offer consumed.";
testutils.verify_offer_not_found(self.remote, "bob", seq, callback);
},
// function (callback) {
// self.what = "Verify balances.";
//
// testutils.verify_balances(self.remote,
// {
// "alice" : [ "-50/USD/bob", "200/EUR/carol" ],
// "bob" : [ "50/USD/alice", "-200/EUR/carol" ],
// "carol" : [ "-200/EUR/alice", "200/EUR/bob" ],
// },
// callback);
// },
// function (callback) {
// self.what = "Verify offer consumed.";
//
// testutils.verify_offer_not_found(self.remote, "bob", seq, callback);
// },
], function (error) {
buster.refute(error, self.what);
done();