mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 07:25:51 +00:00
progress
This commit is contained in:
committed by
Bronek Kozicki
parent
1680477e39
commit
ebc97aee25
@@ -21,12 +21,14 @@
|
|||||||
#define RIPPLE_PROTOCOL_ASSET_H_INCLUDED
|
#define RIPPLE_PROTOCOL_ASSET_H_INCLUDED
|
||||||
|
|
||||||
#include <xrpl/basics/base_uint.h>
|
#include <xrpl/basics/base_uint.h>
|
||||||
|
#include <xrpl/basics/Number.h>
|
||||||
#include <xrpl/protocol/Issue.h>
|
#include <xrpl/protocol/Issue.h>
|
||||||
#include <xrpl/protocol/MPTIssue.h>
|
#include <xrpl/protocol/MPTIssue.h>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|
||||||
class Asset;
|
class Asset;
|
||||||
|
class STAmount;
|
||||||
|
|
||||||
template <typename TIss>
|
template <typename TIss>
|
||||||
concept ValidIssueType =
|
concept ValidIssueType =
|
||||||
@@ -92,6 +94,8 @@ public:
|
|||||||
void
|
void
|
||||||
setJson(Json::Value& jv) const;
|
setJson(Json::Value& jv) const;
|
||||||
|
|
||||||
|
STAmount operator() (Number const&) const;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
native() const
|
native() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -153,6 +153,11 @@ public:
|
|||||||
template <AssetType A>
|
template <AssetType A>
|
||||||
STAmount(A const& asset, int mantissa, int exponent = 0);
|
STAmount(A const& asset, int mantissa, int exponent = 0);
|
||||||
|
|
||||||
|
template <AssetType A>
|
||||||
|
STAmount(A const& asset, Number const& number)
|
||||||
|
: STAmount(asset, number.mantissa(), number.exponent())
|
||||||
|
{}
|
||||||
|
|
||||||
// Legacy support for new-style amounts
|
// Legacy support for new-style amounts
|
||||||
STAmount(IOUAmount const& amount, Issue const& issue);
|
STAmount(IOUAmount const& amount, Issue const& issue);
|
||||||
STAmount(XRPAmount const& amount);
|
STAmount(XRPAmount const& amount);
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ Asset::setJson(Json::Value& jv) const
|
|||||||
std::visit([&](auto&& issue) { issue.setJson(jv); }, issue_);
|
std::visit([&](auto&& issue) { issue.setJson(jv); }, issue_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STAmount Asset::operator() (Number const& number) const
|
||||||
|
{
|
||||||
|
return STAmount{*this, number};
|
||||||
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
to_string(Asset const& asset)
|
to_string(Asset const& asset)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ transResults()
|
|||||||
MAKE_ERROR(tecLOCKED, "Fund is locked."),
|
MAKE_ERROR(tecLOCKED, "Fund is locked."),
|
||||||
MAKE_ERROR(tecBAD_CREDENTIALS, "Bad credentials."),
|
MAKE_ERROR(tecBAD_CREDENTIALS, "Bad credentials."),
|
||||||
MAKE_ERROR(tecWRONG_ASSET, "Wrong asset given."),
|
MAKE_ERROR(tecWRONG_ASSET, "Wrong asset given."),
|
||||||
|
MAKE_ERROR(tecLIMIT_EXCEEDED, "Limit exceeded."),
|
||||||
|
|
||||||
MAKE_ERROR(tefALREADY, "The exact transaction was already in this ledger."),
|
MAKE_ERROR(tefALREADY, "The exact transaction was already in this ledger."),
|
||||||
MAKE_ERROR(tefBAD_ADD_AUTH, "Not authorized to add account."),
|
MAKE_ERROR(tefBAD_ADD_AUTH, "Not authorized to add account."),
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ class Vault_test : public beast::unit_test::suite
|
|||||||
|
|
||||||
Account issuer{"issuer"};
|
Account issuer{"issuer"};
|
||||||
Account owner{"owner"};
|
Account owner{"owner"};
|
||||||
env.fund(XRP(1000), issuer, owner);
|
Account depositor{"depositor"};
|
||||||
|
env.fund(XRP(1000), issuer, owner, depositor);
|
||||||
env.close();
|
env.close();
|
||||||
auto vault = env.vault();
|
auto vault = env.vault();
|
||||||
|
|
||||||
@@ -205,6 +206,25 @@ class Vault_test : public beast::unit_test::suite
|
|||||||
env(tx, ter(tecLOCKED));
|
env(tx, ter(tecLOCKED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SUBCASE("transfer IOU")
|
||||||
|
{
|
||||||
|
Asset asset = issuer["IOU"];
|
||||||
|
auto [tx, keylet] = vault.create({.owner = owner, .asset = asset});
|
||||||
|
env.trust(asset(1000), depositor);
|
||||||
|
env(pay(issuer, depositor, asset(1000)));
|
||||||
|
env(tx);
|
||||||
|
env.close();
|
||||||
|
|
||||||
|
{
|
||||||
|
auto tx = vault.deposit({
|
||||||
|
.depositor = depositor,
|
||||||
|
.id = keylet.key,
|
||||||
|
.amount = asset(123)});
|
||||||
|
env(tx);
|
||||||
|
env.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: VaultSet (update) succeed
|
// TODO: VaultSet (update) succeed
|
||||||
// TODO: VaultSet (update) fail: wrong owner
|
// TODO: VaultSet (update) fail: wrong owner
|
||||||
// TODO: VaultSet (update) fail: Data too large
|
// TODO: VaultSet (update) fail: Data too large
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
#define RIPPLE_TEST_JTX_AMOUNT_H_INCLUDED
|
#define RIPPLE_TEST_JTX_AMOUNT_H_INCLUDED
|
||||||
|
|
||||||
#include <test/jtx/Account.h>
|
#include <test/jtx/Account.h>
|
||||||
#include <test/jtx/amount.h>
|
|
||||||
#include <test/jtx/tags.h>
|
#include <test/jtx/tags.h>
|
||||||
#include <xrpl/basics/contract.h>
|
#include <xrpl/basics/contract.h>
|
||||||
#include <xrpl/protocol/FeeUnits.h>
|
#include <xrpl/protocol/FeeUnits.h>
|
||||||
|
|||||||
@@ -64,6 +64,17 @@ Vault::del(DeleteArgs const& args)
|
|||||||
return jv;
|
return jv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Json::Value
|
||||||
|
Vault::deposit(DepositArgs const& args)
|
||||||
|
{
|
||||||
|
Json::Value jv;
|
||||||
|
jv[jss::TransactionType] = jss::VaultDeposit;
|
||||||
|
jv[jss::Account] = args.depositor.human();
|
||||||
|
jv[jss::VaultID] = to_string(args.id);
|
||||||
|
jv[jss::Amount] = to_json(args.amount);
|
||||||
|
return jv;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace jtx
|
} // namespace jtx
|
||||||
} // namespace test
|
} // namespace test
|
||||||
} // namespace ripple
|
} // namespace ripple
|
||||||
|
|||||||
@@ -21,9 +21,10 @@
|
|||||||
#define RIPPLE_TEST_JTX_VAULT_H_INCLUDED
|
#define RIPPLE_TEST_JTX_VAULT_H_INCLUDED
|
||||||
|
|
||||||
#include <test/jtx/Account.h>
|
#include <test/jtx/Account.h>
|
||||||
#include <xrpl/json/json_value.h>
|
#include <test/jtx/amount.h>
|
||||||
|
|
||||||
#include <xrpl/basics/base_uint.h>
|
#include <xrpl/basics/base_uint.h>
|
||||||
|
#include <xrpl/json/json_value.h>
|
||||||
#include <xrpl/protocol/Asset.h>
|
#include <xrpl/protocol/Asset.h>
|
||||||
#include <xrpl/protocol/Keylet.h>
|
#include <xrpl/protocol/Keylet.h>
|
||||||
|
|
||||||
@@ -68,6 +69,17 @@ struct Vault
|
|||||||
|
|
||||||
Json::Value
|
Json::Value
|
||||||
del(DeleteArgs const& args);
|
del(DeleteArgs const& args);
|
||||||
|
|
||||||
|
struct DepositArgs
|
||||||
|
{
|
||||||
|
Account depositor;
|
||||||
|
uint256 id;
|
||||||
|
STAmount amount;
|
||||||
|
};
|
||||||
|
|
||||||
|
Json::Value
|
||||||
|
deposit(DepositArgs const& args);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace jtx
|
} // namespace jtx
|
||||||
|
|||||||
@@ -74,8 +74,11 @@ VaultDeposit::doApply()
|
|||||||
return tecINSUFFICIENT_FUNDS;
|
return tecINSUFFICIENT_FUNDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
Number assetTotalNew = vault->at(sfAssetTotal) + amount;
|
vault->at(sfAssetTotal) += amount;
|
||||||
if (assetTotalNew > vault->at(sfAssetMaximum))
|
vault->at(sfAssetAvailable) += amount;
|
||||||
|
|
||||||
|
auto maximum = *vault->at(sfAssetMaximum);
|
||||||
|
if (maximum != 0 && *vault->at(sfAssetTotal) > maximum)
|
||||||
return tecLIMIT_EXCEEDED;
|
return tecLIMIT_EXCEEDED;
|
||||||
|
|
||||||
// TODO: Check credentials.
|
// TODO: Check credentials.
|
||||||
@@ -87,9 +90,6 @@ VaultDeposit::doApply()
|
|||||||
if (auto ter = accountSend(view(), account_, vaultAccount, amount, j_))
|
if (auto ter = accountSend(view(), account_, vaultAccount, amount, j_))
|
||||||
return ter;
|
return ter;
|
||||||
|
|
||||||
vault->at(sfAssetTotal) += amount;
|
|
||||||
vault->at(sfAssetAvailable) += amount;
|
|
||||||
|
|
||||||
auto shares = assetsToSharesDeposit(view(), vault, amount);
|
auto shares = assetsToSharesDeposit(view(), vault, amount);
|
||||||
if (!shares)
|
if (!shares)
|
||||||
return shares.error();
|
return shares.error();
|
||||||
|
|||||||
@@ -2247,7 +2247,7 @@ assetsToSharesDeposit(
|
|||||||
return assets;
|
return assets;
|
||||||
Number shareTotal = getShareTotal(view, vault);
|
Number shareTotal = getShareTotal(view, vault);
|
||||||
auto shares = shareTotal * (assets / assetTotal);
|
auto shares = shareTotal * (assets / assetTotal);
|
||||||
STAmount amount{MPTAmount{shares}, MPTIssue{vault->at(sfMPTokenIssuanceID)}};
|
STAmount amount{vault->at(sfMPTokenIssuanceID), shares};
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user