add uritoken helpers

This commit is contained in:
Denis Angell
2023-11-21 12:20:34 +01:00
parent fac568c949
commit aa3a402f09
2 changed files with 108 additions and 5 deletions

View File

@@ -17,11 +17,10 @@
*/
//==============================================================================
#include <test/jtx/flags.h>
#include <test/jtx/uritoken.h>
#include <ripple/protocol/SField.h>
#include <ripple/protocol/jss.h>
#include <test/jtx/flags.h>
#include <test/jtx/uritoken.h>
namespace ripple {
namespace test {
@@ -46,6 +45,67 @@ mint(jtx::Account const& account, std::string const& uri)
return jv;
}
void
dest::operator()(Env& env, JTx& jt) const
{
jt.jv[sfDestination.jsonName] = dest_.human();
}
void
amt::operator()(Env& env, JTx& jt) const
{
jt.jv[sfAmount.jsonName] = amt_.getJson(JsonOptions::none);
}
Json::Value
burn(jtx::Account const& account, std::string const& id)
{
using namespace jtx;
Json::Value jv;
jv[jss::TransactionType] = jss::URITokenBurn;
jv[jss::Account] = account.human();
jv[sfURITokenID.jsonName] = id;
return jv;
}
Json::Value
sell(
jtx::Account const& account,
std::string const& id)
{
using namespace jtx;
Json::Value jv;
jv[jss::TransactionType] = jss::URITokenCreateSellOffer;
jv[jss::Account] = account.human();
jv[sfURITokenID.jsonName] = id;
return jv;
}
Json::Value
cancel(
jtx::Account const& account,
std::string const& id)
{
using namespace jtx;
Json::Value jv;
jv[jss::TransactionType] = jss::URITokenCancelSellOffer;
jv[jss::Account] = account.human();
jv[sfURITokenID.jsonName] = id;
return jv;
}
Json::Value
buy(jtx::Account const& account,
std::string const& id)
{
using namespace jtx;
Json::Value jv;
jv[jss::TransactionType] = jss::URITokenBuy;
jv[jss::Account] = account.human();
jv[sfURITokenID.jsonName] = id;
return jv;
}
} // namespace uritoken
} // namespace jtx
} // namespace test

View File

@@ -20,11 +20,12 @@
#ifndef RIPPLE_TEST_JTX_URITOKEN_H_INCLUDED
#define RIPPLE_TEST_JTX_URITOKEN_H_INCLUDED
#include <ripple/basics/strHex.h>
#include <ripple/protocol/STAmount.h>
#include <initializer_list>
#include <test/jtx/Account.h>
#include <test/jtx/Env.h>
#include <test/jtx/owners.h>
#include <ripple/basics/strHex.h>
#include <initializer_list>
namespace ripple {
namespace test {
@@ -38,6 +39,48 @@ tokenid(jtx::Account const& account, std::string const& uri);
Json::Value
mint(jtx::Account const& account, std::string const& uri);
/** Sets the optional Destination on an URITokenMint. */
class dest
{
private:
jtx::Account dest_;
public:
explicit dest(jtx::Account const& dest) : dest_(dest)
{
}
void
operator()(Env&, JTx& jtx) const;
};
/** Sets the optional Amount on an URITokenMint. */
class amt
{
private:
STAmount amt_;
public:
explicit amt(STAmount const& amt) : amt_(amt)
{
}
void
operator()(Env&, JTx& jtx) const;
};
Json::Value
burn(jtx::Account const& account, std::string const& id);
Json::Value
sell(jtx::Account const& account, std::string const& id);
Json::Value
cancel(jtx::Account const& account, std::string const& id);
Json::Value
buy(jtx::Account const& account, std::string const& id);
} // namespace uritoken
} // namespace jtx