mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 02:55:50 +00:00
Fix and improve offer taking and trust setting.
This commit is contained in:
@@ -1147,15 +1147,15 @@ STAmount LedgerEntrySet::rippleTransferFee(const uint160& uSenderID, const uint1
|
|||||||
}
|
}
|
||||||
|
|
||||||
TER LedgerEntrySet::trustCreate(
|
TER LedgerEntrySet::trustCreate(
|
||||||
const bool bSrcHigh, // Who to charge with reserve.
|
const bool bSrcHigh,
|
||||||
const uint160& uSrcAccountID,
|
const uint160& uSrcAccountID,
|
||||||
SLE::ref sleSrcAccount,
|
|
||||||
const uint160& uDstAccountID,
|
const uint160& uDstAccountID,
|
||||||
const uint256& uIndex,
|
const uint256& uIndex, // --> ripple state entry
|
||||||
const STAmount& saSrcBalance, // Issuer should be ACCOUNT_ONE
|
SLE::ref sleAccount, // --> the account being set.
|
||||||
const STAmount& saSrcLimit,
|
const STAmount& saBalance, // --> balance of account being set. Issuer should be ACCOUNT_ONE
|
||||||
const uint32 uSrcQualityIn,
|
const STAmount& saLimit, // --> limit for account being set. Issuer should be the account being set.
|
||||||
const uint32 uSrcQualityOut)
|
const uint32 uQualityIn,
|
||||||
|
const uint32 uQualityOut)
|
||||||
{
|
{
|
||||||
const uint160& uLowAccountID = !bSrcHigh ? uSrcAccountID : uDstAccountID;
|
const uint160& uLowAccountID = !bSrcHigh ? uSrcAccountID : uDstAccountID;
|
||||||
const uint160& uHighAccountID = bSrcHigh ? uSrcAccountID : uDstAccountID;
|
const uint160& uHighAccountID = bSrcHigh ? uSrcAccountID : uDstAccountID;
|
||||||
@@ -1182,23 +1182,26 @@ TER LedgerEntrySet::trustCreate(
|
|||||||
|
|
||||||
if (tesSUCCESS == terResult)
|
if (tesSUCCESS == terResult)
|
||||||
{
|
{
|
||||||
sleRippleState->setFieldU64(sfLowNode, uLowNode);
|
const bool bSetDst = saLimit.getIssuer() == uDstAccountID;
|
||||||
|
const bool bSetHigh = bSrcHigh ^ bSetDst;
|
||||||
|
|
||||||
|
sleRippleState->setFieldU64(sfLowNode, uLowNode); // Remember deletion hints.
|
||||||
sleRippleState->setFieldU64(sfHighNode, uHighNode);
|
sleRippleState->setFieldU64(sfHighNode, uHighNode);
|
||||||
|
|
||||||
sleRippleState->setFieldAmount(!bSrcHigh ? sfLowLimit : sfHighLimit, saSrcLimit);
|
sleRippleState->setFieldAmount(!bSetHigh ? sfLowLimit : sfHighLimit, saLimit);
|
||||||
sleRippleState->setFieldAmount( bSrcHigh ? sfLowLimit : sfHighLimit, STAmount(saSrcBalance.getCurrency(), uDstAccountID));
|
sleRippleState->setFieldAmount( bSetHigh ? sfLowLimit : sfHighLimit, STAmount(saBalance.getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID));
|
||||||
|
|
||||||
if (uSrcQualityIn)
|
if (uQualityIn)
|
||||||
sleRippleState->setFieldU32(bSrcHigh ? sfHighQualityIn : sfLowQualityIn, uSrcQualityIn);
|
sleRippleState->setFieldU32(!bSetHigh ? sfLowQualityIn : sfHighQualityIn, uQualityIn);
|
||||||
|
|
||||||
if (uSrcQualityOut)
|
if (uQualityOut)
|
||||||
sleRippleState->setFieldU32(bSrcHigh ? sfHighQualityOut : sfLowQualityOut, uSrcQualityIn);
|
sleRippleState->setFieldU32(!bSetHigh ? sfLowQualityOut : sfHighQualityOut, uQualityOut);
|
||||||
|
|
||||||
sleRippleState->setFieldU32(sfFlags, !bSrcHigh ? lsfLowReserve : lsfHighReserve);
|
sleRippleState->setFieldU32(sfFlags, !bSetHigh ? lsfLowReserve : lsfHighReserve);
|
||||||
|
|
||||||
ownerCountAdjust(uSrcAccountID, 1, sleSrcAccount);
|
ownerCountAdjust(!bSetDst ? uSrcAccountID : uDstAccountID, 1, sleAccount);
|
||||||
|
|
||||||
sleRippleState->setFieldAmount(sfBalance, bSrcHigh ? -saSrcBalance: saSrcBalance);
|
sleRippleState->setFieldAmount(sfBalance, bSetHigh ? -saBalance : saBalance);
|
||||||
}
|
}
|
||||||
|
|
||||||
return terResult;
|
return terResult;
|
||||||
@@ -1223,25 +1226,24 @@ TER LedgerEntrySet::rippleCredit(const uint160& uSenderID, const uint160& uRecei
|
|||||||
|
|
||||||
if (!sleRippleState)
|
if (!sleRippleState)
|
||||||
{
|
{
|
||||||
STAmount saSrcLimit = STAmount(uCurrencyID, uSenderID);
|
STAmount saReceiverLimit = STAmount(uCurrencyID, uReceiverID);
|
||||||
STAmount saBalance = saAmount;
|
STAmount saBalance = saAmount;
|
||||||
|
|
||||||
saBalance.setIssuer(ACCOUNT_ONE);
|
saBalance.setIssuer(ACCOUNT_ONE);
|
||||||
|
|
||||||
cLog(lsDEBUG) << boost::str(boost::format("rippleCredit: create line: %s (%s) -> %s : %s")
|
cLog(lsDEBUG) << boost::str(boost::format("rippleCredit: create line: %s (0) -> %s : %s")
|
||||||
% RippleAddress::createHumanAccountID(uSenderID)
|
% RippleAddress::createHumanAccountID(uSenderID)
|
||||||
% saBalance.getFullText()
|
|
||||||
% RippleAddress::createHumanAccountID(uReceiverID)
|
% RippleAddress::createHumanAccountID(uReceiverID)
|
||||||
% saAmount.getFullText());
|
% saAmount.getFullText());
|
||||||
|
|
||||||
terResult = trustCreate(
|
terResult = trustCreate(
|
||||||
bSenderHigh,
|
bSenderHigh,
|
||||||
uSenderID,
|
uSenderID,
|
||||||
entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(uSenderID)),
|
|
||||||
uReceiverID,
|
uReceiverID,
|
||||||
uIndex,
|
uIndex,
|
||||||
|
entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(uReceiverID)),
|
||||||
saBalance,
|
saBalance,
|
||||||
saSrcLimit);
|
saReceiverLimit);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -132,9 +132,9 @@ public:
|
|||||||
TER trustCreate(
|
TER trustCreate(
|
||||||
const bool bSrcHigh,
|
const bool bSrcHigh,
|
||||||
const uint160& uSrcAccountID,
|
const uint160& uSrcAccountID,
|
||||||
SLE::ref sleSrcAccount,
|
|
||||||
const uint160& uDstAccountID,
|
const uint160& uDstAccountID,
|
||||||
const uint256& uIndex,
|
const uint256& uIndex,
|
||||||
|
SLE::ref sleAccount,
|
||||||
const STAmount& saSrcBalance,
|
const STAmount& saSrcBalance,
|
||||||
const STAmount& saSrcLimit,
|
const STAmount& saSrcLimit,
|
||||||
const uint32 uSrcQualityIn = 0,
|
const uint32 uSrcQualityIn = 0,
|
||||||
|
|||||||
@@ -287,13 +287,13 @@ TER TrustSetTransactor::doApply()
|
|||||||
|
|
||||||
// Create a new ripple line.
|
// Create a new ripple line.
|
||||||
terResult = mEngine->getNodes().trustCreate(
|
terResult = mEngine->getNodes().trustCreate(
|
||||||
bHigh, // Who to charge with reserve.
|
bHigh,
|
||||||
mTxnAccountID,
|
mTxnAccountID,
|
||||||
mTxnAccount,
|
|
||||||
uDstAccountID,
|
uDstAccountID,
|
||||||
Ledger::getRippleStateIndex(mTxnAccountID, uDstAccountID, uCurrencyID),
|
Ledger::getRippleStateIndex(mTxnAccountID, uDstAccountID, uCurrencyID),
|
||||||
|
mTxnAccount,
|
||||||
saBalance,
|
saBalance,
|
||||||
saLimitAllow,
|
saLimitAllow, // Limit for who is being charged.
|
||||||
uQualityIn,
|
uQualityIn,
|
||||||
uQualityOut);
|
uQualityOut);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ buster.testCase("Offer tests", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
"offer create then crossing offer, no trust lines" :
|
"offer create then crossing offer, no trust lines with self" :
|
||||||
function (done) {
|
function (done) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
@@ -108,6 +108,261 @@ buster.testCase("Offer tests", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// rippled broken: Balances are wrong.
|
||||||
|
"Offer create then crossing offer with XRP. Reverse order." :
|
||||||
|
function (done) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Create accounts.";
|
||||||
|
|
||||||
|
testutils.create_accounts(self.remote, "root", "100000.0", ["alice", "bob", "mtgox"], callback);
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Set limits.";
|
||||||
|
|
||||||
|
testutils.credit_limits(self.remote,
|
||||||
|
{
|
||||||
|
"alice" : "1000/USD/mtgox",
|
||||||
|
"bob" : "1000/USD/mtgox"
|
||||||
|
},
|
||||||
|
callback);
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Distribute funds.";
|
||||||
|
|
||||||
|
testutils.payments(self.remote,
|
||||||
|
{
|
||||||
|
"mtgox" : "500/USD/alice"
|
||||||
|
},
|
||||||
|
callback);
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Create first offer.";
|
||||||
|
|
||||||
|
self.remote.transaction()
|
||||||
|
.offer_create("bob", "1/USD/mtgox", "4000.0")
|
||||||
|
.on('proposed', function (m) {
|
||||||
|
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
||||||
|
|
||||||
|
callback(m.result !== 'tesSUCCESS');
|
||||||
|
})
|
||||||
|
.submit();
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Create crossing offer.";
|
||||||
|
|
||||||
|
self.remote.transaction()
|
||||||
|
.offer_create("alice", "150000.0", "50/USD/mtgox")
|
||||||
|
.on('proposed', function (m) {
|
||||||
|
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
||||||
|
|
||||||
|
callback(m.result !== 'tesSUCCESS');
|
||||||
|
})
|
||||||
|
.submit();
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Verify balances.";
|
||||||
|
|
||||||
|
testutils.verify_balances(self.remote,
|
||||||
|
{
|
||||||
|
"alice" : [ "499/USD/mtgox", String(100000000000+4000000000-2*(Remote.fees['default'].to_number())) ],
|
||||||
|
"bob" : [ "1/USD/mtgox", String(100000000000-4000000000-2*(Remote.fees['default'].to_number())) ],
|
||||||
|
},
|
||||||
|
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 (error) {
|
||||||
|
// console.log("result: error=%s", error);
|
||||||
|
buster.refute(error, self.what);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
"Offer create then crossing offer with XRP." :
|
||||||
|
function (done) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Create accounts.";
|
||||||
|
|
||||||
|
testutils.create_accounts(self.remote, "root", "100000.0", ["alice", "bob", "mtgox"], callback);
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Set limits.";
|
||||||
|
|
||||||
|
testutils.credit_limits(self.remote,
|
||||||
|
{
|
||||||
|
"alice" : "1000/USD/mtgox",
|
||||||
|
"bob" : "1000/USD/mtgox"
|
||||||
|
},
|
||||||
|
callback);
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Distribute funds.";
|
||||||
|
|
||||||
|
testutils.payments(self.remote,
|
||||||
|
{
|
||||||
|
"mtgox" : "500/USD/alice"
|
||||||
|
},
|
||||||
|
callback);
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Create first offer.";
|
||||||
|
|
||||||
|
self.remote.transaction()
|
||||||
|
.offer_create("alice", "150000.0", "50/USD/mtgox")
|
||||||
|
.on('proposed', function (m) {
|
||||||
|
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
||||||
|
|
||||||
|
callback(m.result !== 'tesSUCCESS');
|
||||||
|
})
|
||||||
|
.submit();
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Create crossing offer.";
|
||||||
|
|
||||||
|
self.remote.transaction()
|
||||||
|
.offer_create("bob", "1/USD/mtgox", "4000.0")
|
||||||
|
.on('proposed', function (m) {
|
||||||
|
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
||||||
|
|
||||||
|
callback(m.result !== 'tesSUCCESS');
|
||||||
|
})
|
||||||
|
.submit();
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Verify balances.";
|
||||||
|
|
||||||
|
testutils.verify_balances(self.remote,
|
||||||
|
{
|
||||||
|
"alice" : [ "499/USD/mtgox", String(100000000000+4000000000-2*(Remote.fees['default'].to_number())) ],
|
||||||
|
"bob" : [ "1/USD/mtgox", String(100000000000-4000000000-2*(Remote.fees['default'].to_number())) ],
|
||||||
|
},
|
||||||
|
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 (error) {
|
||||||
|
// console.log("result: error=%s", error);
|
||||||
|
buster.refute(error, self.what);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
"Offer create then crossing offer with XRP with limit override." :
|
||||||
|
function (done) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Create accounts.";
|
||||||
|
|
||||||
|
testutils.create_accounts(self.remote, "root", "100000.0", ["alice", "bob", "mtgox"], callback);
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Set limits.";
|
||||||
|
|
||||||
|
testutils.credit_limits(self.remote,
|
||||||
|
{
|
||||||
|
"alice" : "1000/USD/mtgox",
|
||||||
|
// "bob" : "1000/USD/mtgox"
|
||||||
|
},
|
||||||
|
callback);
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Distribute funds.";
|
||||||
|
|
||||||
|
testutils.payments(self.remote,
|
||||||
|
{
|
||||||
|
"mtgox" : "500/USD/alice"
|
||||||
|
},
|
||||||
|
callback);
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Create first offer.";
|
||||||
|
|
||||||
|
self.remote.transaction()
|
||||||
|
.offer_create("alice", "150000.0", "50/USD/mtgox")
|
||||||
|
.on('proposed', function (m) {
|
||||||
|
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
||||||
|
|
||||||
|
callback(m.result !== 'tesSUCCESS');
|
||||||
|
})
|
||||||
|
.submit();
|
||||||
|
},
|
||||||
|
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 = "Create crossing offer.";
|
||||||
|
|
||||||
|
self.remote.transaction()
|
||||||
|
.offer_create("bob", "1/USD/mtgox", "4000.0")
|
||||||
|
.on('proposed', function (m) {
|
||||||
|
// console.log("PROPOSED: offer_create: %s", JSON.stringify(m));
|
||||||
|
|
||||||
|
callback(m.result !== 'tesSUCCESS');
|
||||||
|
})
|
||||||
|
.submit();
|
||||||
|
},
|
||||||
|
function (callback) {
|
||||||
|
self.what = "Verify balances.";
|
||||||
|
|
||||||
|
testutils.verify_balances(self.remote,
|
||||||
|
{
|
||||||
|
"alice" : [ "499/USD/mtgox", String(100000000000+4000000000-2*(Remote.fees['default'].to_number())) ],
|
||||||
|
"bob" : [ "1/USD/mtgox", String(100000000000-4000000000-1*(Remote.fees['default'].to_number())) ],
|
||||||
|
},
|
||||||
|
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 (error) {
|
||||||
|
// console.log("result: error=%s", error);
|
||||||
|
buster.refute(error, self.what);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
"offer_create then ledger_accept then offer_cancel then ledger_accept." :
|
"offer_create then ledger_accept then offer_cancel then ledger_accept." :
|
||||||
function (done) {
|
function (done) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|||||||
Reference in New Issue
Block a user