Ledger owner fund (#753)

Fixes #754
This commit is contained in:
cyan317
2023-07-11 12:36:48 +01:00
committed by GitHub
parent 210d7fdbc8
commit 7710468f37
5 changed files with 562 additions and 17 deletions

View File

@@ -161,7 +161,8 @@ CreateCreateOfferTransactionObject(
std::string_view currency,
std::string_view issuer,
int takerGets,
int takerPays)
int takerPays,
bool reverse)
{
ripple::STObject obj(ripple::sfTransaction);
obj.setFieldU16(ripple::sfTransactionType, ripple::ttOFFER_CREATE);
@@ -173,8 +174,16 @@ CreateCreateOfferTransactionObject(
// add amount
ripple::Issue issue1(
ripple::Currency{currency}, ripple::parseBase58<ripple::AccountID>(std::string(issuer)).value());
obj.setFieldAmount(ripple::sfTakerGets, ripple::STAmount(issue1, takerGets));
obj.setFieldAmount(ripple::sfTakerPays, ripple::STAmount(takerPays, false));
if (reverse)
{
obj.setFieldAmount(ripple::sfTakerPays, ripple::STAmount(issue1, takerGets));
obj.setFieldAmount(ripple::sfTakerGets, ripple::STAmount(takerPays, false));
}
else
{
obj.setFieldAmount(ripple::sfTakerGets, ripple::STAmount(issue1, takerGets));
obj.setFieldAmount(ripple::sfTakerPays, ripple::STAmount(takerPays, false));
}
auto key = "test";
ripple::Slice slice(key, 4);
@@ -230,12 +239,21 @@ CreateMetaDataForCreateOffer(
std::string_view issueId,
uint32_t transactionIndex,
int finalTakerGets,
int finalTakerPays)
int finalTakerPays,
bool reverse)
{
ripple::STObject finalFields(ripple::sfNewFields);
ripple::Issue issue1 = GetIssue(currency, issueId);
finalFields.setFieldAmount(ripple::sfTakerPays, ripple::STAmount(issue1, finalTakerPays));
finalFields.setFieldAmount(ripple::sfTakerGets, ripple::STAmount(finalTakerGets, false));
if (reverse)
{
finalFields.setFieldAmount(ripple::sfTakerGets, ripple::STAmount(issue1, finalTakerPays));
finalFields.setFieldAmount(ripple::sfTakerPays, ripple::STAmount(finalTakerGets, false));
}
else
{
finalFields.setFieldAmount(ripple::sfTakerPays, ripple::STAmount(issue1, finalTakerPays));
finalFields.setFieldAmount(ripple::sfTakerGets, ripple::STAmount(finalTakerGets, false));
}
ripple::STObject metaObj(ripple::sfTransactionMetaData);
ripple::STArray metaArray{1};
ripple::STObject node(ripple::sfCreatedNode);

View File

@@ -90,6 +90,7 @@ CreateAccountRootObject(
/*
* Create a createoffer treansaction
* Taker pay is XRP
* If reverse is true, taker gets is XRP
*/
[[nodiscard]] ripple::STObject
CreateCreateOfferTransactionObject(
@@ -99,7 +100,8 @@ CreateCreateOfferTransactionObject(
std::string_view currency,
std::string_view issuer,
int takerGets,
int takerPays);
int takerPays,
bool reverse = false);
/*
* Return an issue object with given currency and issue account
@@ -122,6 +124,8 @@ CreateMetaDataForBookChange(
/*
* Meta data for adding a offer object
* finalTakerGets is XRP
* If reverse is true, finalTakerPays is XRP
*/
[[nodiscard]] ripple::STObject
CreateMetaDataForCreateOffer(
@@ -129,7 +133,8 @@ CreateMetaDataForCreateOffer(
std::string_view issueId,
uint32_t transactionIndex,
int finalTakerGets,
int finalTakerPays);
int finalTakerPays,
bool reverse = false);
/*
* Meta data for removing a offer object