mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-26 22:15:52 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin
This commit is contained in:
@@ -268,7 +268,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
|
|||||||
}
|
}
|
||||||
else if (!speEnd.mCurrencyID)
|
else if (!speEnd.mCurrencyID)
|
||||||
{
|
{
|
||||||
// Last element is for XRP continue with qualifying books.
|
// Last element is for XRP, continue with qualifying books.
|
||||||
BOOST_FOREACH(OrderBook::ref book, mOrderBook.getXRPInBooks())
|
BOOST_FOREACH(OrderBook::ref book, mOrderBook.getXRPInBooks())
|
||||||
{
|
{
|
||||||
// XXX Don't allow looping through same order books.
|
// XXX Don't allow looping through same order books.
|
||||||
@@ -298,19 +298,42 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Last element is for non-XRP continue by adding ripple lines and order books.
|
// Last element is for non-XRP, continue by adding ripple lines and order books.
|
||||||
|
|
||||||
// Create new paths for each outbound account not already in the path.
|
// Create new paths for each outbound account not already in the path.
|
||||||
AccountItems rippleLines(speEnd.mAccountID, mLedger, AccountItem::pointer(new RippleState()));
|
AccountItems rippleLines(speEnd.mAccountID, mLedger, AccountItem::pointer(new RippleState()));
|
||||||
|
|
||||||
BOOST_FOREACH(AccountItem::ref item, rippleLines.getItems())
|
BOOST_FOREACH(AccountItem::ref item, rippleLines.getItems())
|
||||||
{
|
{
|
||||||
RippleState* line=(RippleState*)item.get();
|
RippleState* rspEntry = (RippleState*) item.get();
|
||||||
|
|
||||||
if (!spPath.hasSeen(line->getAccountIDPeer().getAccountID()))
|
if (spPath.hasSeen(rspEntry->getAccountIDPeer().getAccountID()))
|
||||||
{
|
{
|
||||||
|
// Peer is in path already. Ignore it to avoid a loop.
|
||||||
|
cLog(lsDEBUG) <<
|
||||||
|
boost::str(boost::format("findPaths: SEEN: %s/%s --> %s/%s")
|
||||||
|
% RippleAddress::createHumanAccountID(speEnd.mAccountID)
|
||||||
|
% STAmount::createHumanCurrency(speEnd.mCurrencyID)
|
||||||
|
% RippleAddress::createHumanAccountID(rspEntry->getAccountIDPeer().getAccountID())
|
||||||
|
% STAmount::createHumanCurrency(speEnd.mCurrencyID));
|
||||||
|
}
|
||||||
|
else if (!rspEntry->getBalance().isPositive() // Have IOUs to send.
|
||||||
|
&& (!rspEntry->getLimitPeer() // Peer does not extend credit.
|
||||||
|
|| *rspEntry->getBalance().negate() >= rspEntry->getLimitPeer())) // No credit left.
|
||||||
|
{
|
||||||
|
// Path has no credit left. Ignore it.
|
||||||
|
cLog(lsDEBUG) <<
|
||||||
|
boost::str(boost::format("findPaths: No credit: %s/%s --> %s/%s")
|
||||||
|
% RippleAddress::createHumanAccountID(speEnd.mAccountID)
|
||||||
|
% STAmount::createHumanCurrency(speEnd.mCurrencyID)
|
||||||
|
% RippleAddress::createHumanAccountID(rspEntry->getAccountIDPeer().getAccountID())
|
||||||
|
% STAmount::createHumanCurrency(speEnd.mCurrencyID));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Can transmit IOUs.
|
||||||
STPath new_path(spPath);
|
STPath new_path(spPath);
|
||||||
STPathElement new_ele(line->getAccountIDPeer().getAccountID(),
|
STPathElement new_ele(rspEntry->getAccountIDPeer().getAccountID(),
|
||||||
speEnd.mCurrencyID,
|
speEnd.mCurrencyID,
|
||||||
uint160());
|
uint160());
|
||||||
|
|
||||||
@@ -318,7 +341,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
|
|||||||
boost::str(boost::format("findPaths: %s/%s --> %s/%s")
|
boost::str(boost::format("findPaths: %s/%s --> %s/%s")
|
||||||
% RippleAddress::createHumanAccountID(speEnd.mAccountID)
|
% RippleAddress::createHumanAccountID(speEnd.mAccountID)
|
||||||
% STAmount::createHumanCurrency(speEnd.mCurrencyID)
|
% STAmount::createHumanCurrency(speEnd.mCurrencyID)
|
||||||
% RippleAddress::createHumanAccountID(line->getAccountIDPeer().getAccountID())
|
% RippleAddress::createHumanAccountID(rspEntry->getAccountIDPeer().getAccountID())
|
||||||
% STAmount::createHumanCurrency(speEnd.mCurrencyID));
|
% STAmount::createHumanCurrency(speEnd.mCurrencyID));
|
||||||
|
|
||||||
new_path.mPath.push_back(new_ele);
|
new_path.mPath.push_back(new_ele);
|
||||||
@@ -326,15 +349,6 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
|
|||||||
|
|
||||||
bContinued = true;
|
bContinued = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
cLog(lsDEBUG) <<
|
|
||||||
boost::str(boost::format("findPaths: SEEN: %s/%s --> %s/%s")
|
|
||||||
% RippleAddress::createHumanAccountID(speEnd.mAccountID)
|
|
||||||
% STAmount::createHumanCurrency(speEnd.mCurrencyID)
|
|
||||||
% RippleAddress::createHumanAccountID(line->getAccountIDPeer().getAccountID())
|
|
||||||
% STAmount::createHumanCurrency(speEnd.mCurrencyID));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every book that wants the source currency.
|
// Every book that wants the source currency.
|
||||||
@@ -448,6 +462,8 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax
|
|||||||
cLog(lsDEBUG) << boost::str(boost::format("findPaths: no ledger"));
|
cLog(lsDEBUG) << boost::str(boost::format("findPaths: no ledger"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cLog(lsDEBUG) << boost::str(boost::format("findPaths< bFound=%d") % bFound);
|
||||||
|
|
||||||
return bFound;
|
return bFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -660,4 +660,110 @@ buster.testCase("More Path finding", {
|
|||||||
|
|
||||||
// Test alternative paths with qualities.
|
// Test alternative paths with qualities.
|
||||||
});
|
});
|
||||||
|
|
||||||
|
buster.testCase("Path negatives", {
|
||||||
|
// 'setUp' : testutils.build_setup({ verbose: true, no_server: true }),
|
||||||
|
// 'setUp' : testutils.build_setup({ verbose: true }),
|
||||||
|
'setUp' : testutils.build_setup(),
|
||||||
|
'tearDown' : testutils.build_teardown(),
|
||||||
|
|
||||||
|
"Issue #5" :
|
||||||
|
function (done) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Create accounts.";
|
||||||
|
|
||||||
|
testutils.create_accounts(self.remote, "root", "10000.0", ["alice", "bob", "carol", "dan"], callback);
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Set credit limits.";
|
||||||
|
|
||||||
|
testutils.credit_limits(self.remote,
|
||||||
|
{
|
||||||
|
// 2. acct 4 trusted all the other accts for 100 usd
|
||||||
|
"dan" : [ "100/USD/alice", "100/USD/bob", "100/USD/carol" ],
|
||||||
|
// 3. acct 2 acted as a nexus for acct 1 and 3, was trusted by 1 and 3 for 100 usd
|
||||||
|
"alice" : [ "100/USD/bob" ],
|
||||||
|
"carol" : [ "100/USD/bob" ],
|
||||||
|
},
|
||||||
|
callback);
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Distribute funds.";
|
||||||
|
|
||||||
|
testutils.payments(self.remote,
|
||||||
|
{
|
||||||
|
// 4. acct 2 sent acct 3 a 75 iou
|
||||||
|
"bob" : "75/USD/carol",
|
||||||
|
},
|
||||||
|
callback);
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Verify balances.";
|
||||||
|
|
||||||
|
testutils.verify_balances(self.remote,
|
||||||
|
{
|
||||||
|
"bob" : [ "-75/USD/carol" ],
|
||||||
|
"carol" : "75/USD/bob",
|
||||||
|
},
|
||||||
|
callback);
|
||||||
|
},
|
||||||
|
// function (callback) {
|
||||||
|
// self.what = "Display ledger";
|
||||||
|
//
|
||||||
|
// self.remote.request_ledger('current', true)
|
||||||
|
// .on('success', function (m) {
|
||||||
|
// console.log("Ledger: %s", JSON.stringify(m, undefined, 2));
|
||||||
|
//
|
||||||
|
// callback();
|
||||||
|
// })
|
||||||
|
// .request();
|
||||||
|
// },
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Find path from alice to bob";
|
||||||
|
|
||||||
|
// 5. acct 1 sent a 25 usd iou to acct 2
|
||||||
|
self.remote.request_ripple_path_find("alice", "bob", "25/USD/bob",
|
||||||
|
[ { 'currency' : "USD" } ])
|
||||||
|
.on('success', function (m) {
|
||||||
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
|
|
||||||
|
// 0 alternatives.
|
||||||
|
buster.assert.equals(0, m.alternatives.length)
|
||||||
|
|
||||||
|
callback();
|
||||||
|
})
|
||||||
|
.request();
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "alice fails to send to bob.";
|
||||||
|
|
||||||
|
self.remote.transaction()
|
||||||
|
.payment('alice', 'bob', "25/USD/alice")
|
||||||
|
.once('proposed', function (m) {
|
||||||
|
// console.log("proposed: %s", JSON.stringify(m));
|
||||||
|
callback(m.result !== 'tecPATH_DRY');
|
||||||
|
})
|
||||||
|
.submit();
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Verify balances final.";
|
||||||
|
|
||||||
|
testutils.verify_balances(self.remote,
|
||||||
|
{
|
||||||
|
"alice" : [ "0/USD/bob", "0/USD/dan"],
|
||||||
|
"bob" : [ "0/USD/alice", "-75/USD/carol", "0/USD/dan" ],
|
||||||
|
"carol" : [ "75/USD/bob", "0/USD/dan" ],
|
||||||
|
"dan" : [ "0/USD/alice", "0/USD/bob", "0/USD/carol" ],
|
||||||
|
},
|
||||||
|
callback);
|
||||||
|
},
|
||||||
|
], function (error) {
|
||||||
|
buster.refute(error, self.what);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
// vim:sw=2:sts=2:ts=8:et
|
// vim:sw=2:sts=2:ts=8:et
|
||||||
|
|||||||
Reference in New Issue
Block a user