diff --git a/src/cpp/ripple/LedgerEntrySet.cpp b/src/cpp/ripple/LedgerEntrySet.cpp index d47be76c94..4d560750da 100644 --- a/src/cpp/ripple/LedgerEntrySet.cpp +++ b/src/cpp/ripple/LedgerEntrySet.cpp @@ -19,9 +19,9 @@ DECLARE_INSTANCE(LedgerEntrySet) void LedgerEntrySet::init(Ledger::ref ledger, const uint256& transactionID, uint32 ledgerID) { mEntries.clear(); - mLedger = ledger; + mLedger = ledger; mSet.init(transactionID, ledgerID); - mSeq = 0; + mSeq = 0; } void LedgerEntrySet::clear() @@ -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) diff --git a/test/offer-test.js b/test/offer-test.js index d7949bc268..8cb0332863 100644 --- a/test/offer-test.js +++ b/test/offer-test.js @@ -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();