mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Prevent offers spending from XRP reserve.
This commit is contained in:
@@ -1013,7 +1013,7 @@ STAmount LedgerEntrySet::rippleHolds(const uint160& uAccountID, const uint160& u
|
|||||||
}
|
}
|
||||||
else if (uAccountID > uIssuerID)
|
else if (uAccountID > uIssuerID)
|
||||||
{
|
{
|
||||||
if (bAvail)
|
if (false && bAvail)
|
||||||
{
|
{
|
||||||
saBalance = sleRippleState->getFieldAmount(sfLowLimit);
|
saBalance = sleRippleState->getFieldAmount(sfLowLimit);
|
||||||
saBalance -= sleRippleState->getFieldAmount(sfBalance);
|
saBalance -= sleRippleState->getFieldAmount(sfBalance);
|
||||||
@@ -1028,7 +1028,7 @@ STAmount LedgerEntrySet::rippleHolds(const uint160& uAccountID, const uint160& u
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (bAvail)
|
if (false && bAvail)
|
||||||
{
|
{
|
||||||
saBalance = sleRippleState->getFieldAmount(sfHighLimit);
|
saBalance = sleRippleState->getFieldAmount(sfHighLimit);
|
||||||
saBalance += sleRippleState->getFieldAmount(sfBalance);
|
saBalance += sleRippleState->getFieldAmount(sfBalance);
|
||||||
@@ -1052,8 +1052,18 @@ STAmount LedgerEntrySet::accountHolds(const uint160& uAccountID, const uint160&
|
|||||||
if (!uCurrencyID)
|
if (!uCurrencyID)
|
||||||
{
|
{
|
||||||
SLE::pointer sleAccount = entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(uAccountID));
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -1070,7 +1080,9 @@ STAmount LedgerEntrySet::accountHolds(const uint160& uAccountID, const uint160&
|
|||||||
|
|
||||||
// Returns the funds available for uAccountID for a currency/issuer.
|
// Returns the funds available for uAccountID for a currency/issuer.
|
||||||
// Use when you need a default for rippling uAccountID's currency.
|
// Use when you need a default for rippling uAccountID's currency.
|
||||||
|
// XXX Should take into account quality?
|
||||||
// --> saDefault/currency/issuer
|
// --> saDefault/currency/issuer
|
||||||
|
// --> bAvail: true to include going into debt.
|
||||||
// <-- saFunds: Funds available. May be negative.
|
// <-- saFunds: Funds available. May be negative.
|
||||||
// If the issuer is the same as uAccountID, funds are unlimited, use result is saDefault.
|
// 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)
|
STAmount LedgerEntrySet::accountFunds(const uint160& uAccountID, const STAmount& saDefault, bool bAvail)
|
||||||
|
|||||||
@@ -481,54 +481,41 @@ buster.testCase("Offer tests", {
|
|||||||
.offer_create("bob", "50/USD/alice", "200/EUR/carol")
|
.offer_create("bob", "50/USD/alice", "200/EUR/carol")
|
||||||
.on('proposed', function (m) {
|
.on('proposed', function (m) {
|
||||||
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
||||||
callback(m.result !== 'tesSUCCESS');
|
callback(m.result !== 'terUNFUNDED');
|
||||||
|
|
||||||
seq = m.tx_json.Sequence;
|
seq = m.tx_json.Sequence;
|
||||||
})
|
})
|
||||||
.submit();
|
.submit();
|
||||||
},
|
},
|
||||||
// function (callback) {
|
// function (callback) {
|
||||||
// self.what = "Alice converts USD to EUR via ripple.";
|
// self.what = "Alice converts USD to EUR via offer.";
|
||||||
//
|
//
|
||||||
// self.remote.transaction()
|
// self.remote.transaction()
|
||||||
// .payment("alice", "alice", "10/EUR/carol")
|
// .offer_create("alice", "200/EUR/carol", "50/USD/alice")
|
||||||
// .send_max("50/USD/alice")
|
|
||||||
// .on('proposed', function (m) {
|
// .on('proposed', function (m) {
|
||||||
// // console.log("proposed: %s", JSON.stringify(m));
|
// // console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
||||||
//
|
|
||||||
// callback(m.result !== 'tesSUCCESS');
|
// callback(m.result !== 'tesSUCCESS');
|
||||||
|
//
|
||||||
|
// seq = m.tx_json.Sequence;
|
||||||
// })
|
// })
|
||||||
// .submit();
|
// .submit();
|
||||||
// },
|
// },
|
||||||
function (callback) {
|
// function (callback) {
|
||||||
self.what = "Alice converts USD to EUR via offer.";
|
// self.what = "Verify balances.";
|
||||||
|
//
|
||||||
self.remote.transaction()
|
// testutils.verify_balances(self.remote,
|
||||||
.offer_create("alice", "200/EUR/carol", "50/USD/alice")
|
// {
|
||||||
.on('proposed', function (m) {
|
// "alice" : [ "-50/USD/bob", "200/EUR/carol" ],
|
||||||
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
// "bob" : [ "50/USD/alice", "-200/EUR/carol" ],
|
||||||
callback(m.result !== 'tesSUCCESS');
|
// "carol" : [ "-200/EUR/alice", "200/EUR/bob" ],
|
||||||
|
// },
|
||||||
seq = m.tx_json.Sequence;
|
// callback);
|
||||||
})
|
// },
|
||||||
.submit();
|
// function (callback) {
|
||||||
},
|
// self.what = "Verify offer consumed.";
|
||||||
function (callback) {
|
//
|
||||||
self.what = "Verify balances.";
|
// testutils.verify_offer_not_found(self.remote, "bob", seq, callback);
|
||||||
|
// },
|
||||||
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) {
|
], function (error) {
|
||||||
buster.refute(error, self.what);
|
buster.refute(error, self.what);
|
||||||
done();
|
done();
|
||||||
|
|||||||
Reference in New Issue
Block a user