mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-22 14:50:54 +00:00
progress
This commit is contained in:
committed by
Bronek Kozicki
parent
ebc97aee25
commit
286612cf19
@@ -20,8 +20,8 @@
|
||||
#ifndef RIPPLE_PROTOCOL_ASSET_H_INCLUDED
|
||||
#define RIPPLE_PROTOCOL_ASSET_H_INCLUDED
|
||||
|
||||
#include <xrpl/basics/base_uint.h>
|
||||
#include <xrpl/basics/Number.h>
|
||||
#include <xrpl/basics/base_uint.h>
|
||||
#include <xrpl/protocol/Issue.h>
|
||||
#include <xrpl/protocol/MPTIssue.h>
|
||||
|
||||
@@ -94,7 +94,8 @@ public:
|
||||
void
|
||||
setJson(Json::Value& jv) const;
|
||||
|
||||
STAmount operator() (Number const&) const;
|
||||
STAmount
|
||||
operator()(Number const&) const;
|
||||
|
||||
bool
|
||||
native() const
|
||||
|
||||
@@ -155,8 +155,9 @@ public:
|
||||
|
||||
template <AssetType A>
|
||||
STAmount(A const& asset, Number const& number)
|
||||
: STAmount(asset, number.mantissa(), number.exponent())
|
||||
{}
|
||||
: STAmount(asset, number.mantissa(), number.exponent())
|
||||
{
|
||||
}
|
||||
|
||||
// Legacy support for new-style amounts
|
||||
STAmount(IOUAmount const& amount, Issue const& issue);
|
||||
|
||||
@@ -43,7 +43,8 @@ Asset::setJson(Json::Value& jv) const
|
||||
std::visit([&](auto&& issue) { issue.setJson(jv); }, issue_);
|
||||
}
|
||||
|
||||
STAmount Asset::operator() (Number const& number) const
|
||||
STAmount
|
||||
Asset::operator()(Number const& number) const
|
||||
{
|
||||
return STAmount{*this, number};
|
||||
}
|
||||
|
||||
@@ -206,25 +206,63 @@ class Vault_test : public beast::unit_test::suite
|
||||
env(tx, ter(tecLOCKED));
|
||||
}
|
||||
|
||||
SUBCASE("transfer IOU")
|
||||
SUBCASE("transfer XRP")
|
||||
{
|
||||
Asset asset = issuer["IOU"];
|
||||
// Construct asset.
|
||||
Asset asset{xrpIssue()};
|
||||
// Depositor already holds asset.
|
||||
// Create vault.
|
||||
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)});
|
||||
auto tx = vault.deposit(
|
||||
{.depositor = depositor,
|
||||
.id = keylet.key,
|
||||
.amount = asset(123)});
|
||||
env(tx);
|
||||
env.close();
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("transfer IOU")
|
||||
{
|
||||
// Construct asset.
|
||||
Asset asset = issuer["IOU"];
|
||||
// Fund depositor with asset.
|
||||
env.trust(asset(1000), depositor);
|
||||
env(pay(issuer, depositor, asset(1000)));
|
||||
// Create vault.
|
||||
auto [tx, keylet] = vault.create({.owner = owner, .asset = asset});
|
||||
env(tx);
|
||||
env.close();
|
||||
|
||||
{
|
||||
auto tx = vault.deposit(
|
||||
{.depositor = depositor,
|
||||
.id = keylet.key,
|
||||
.amount = asset(123)});
|
||||
env(tx);
|
||||
env.close();
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("transfer MPT")
|
||||
{
|
||||
// Construct asset.
|
||||
MPTTester mptt{env, issuer, {.fund = false}};
|
||||
mptt.create({.flags = tfMPTCanTransfer | tfMPTCanLock});
|
||||
Asset asset = mptt.issuanceID();
|
||||
// Fund depositor with asset.
|
||||
mptt.authorize({ .account = depositor });
|
||||
env(pay(issuer, depositor, asset(1000)));
|
||||
// Create vault.
|
||||
auto [tx, keylet] = vault.create({.owner = owner, .asset = asset});
|
||||
env(tx);
|
||||
env.close();
|
||||
}
|
||||
|
||||
// TODO: VaultSet (update) succeed
|
||||
// TODO: VaultSet (update) fail: wrong owner
|
||||
// TODO: VaultSet (update) fail: Data too large
|
||||
|
||||
@@ -75,6 +75,17 @@ Vault::deposit(DepositArgs const& args)
|
||||
return jv;
|
||||
}
|
||||
|
||||
Json::Value
|
||||
Vault::withdraw(WithdrawArgs const& args)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[jss::TransactionType] = jss::VaultWithdraw;
|
||||
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 test
|
||||
} // namespace ripple
|
||||
|
||||
@@ -80,6 +80,15 @@ struct Vault
|
||||
Json::Value
|
||||
deposit(DepositArgs const& args);
|
||||
|
||||
struct WithdrawArgs
|
||||
{
|
||||
Account depositor;
|
||||
uint256 id;
|
||||
STAmount amount;
|
||||
};
|
||||
|
||||
Json::Value
|
||||
withdraw(WithdrawArgs const& args);
|
||||
};
|
||||
|
||||
} // namespace jtx
|
||||
|
||||
Reference in New Issue
Block a user