Skip to content

Commit

Permalink
MaxAmt
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnxie999 committed Jan 9, 2024
1 parent 22909fc commit f959d15
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/ripple/app/tx/impl/MPTokenIssuanceCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ MPTokenIssuanceCreate::preflight(PreflightContext const& ctx)
return temMALFORMED;
}

// TODO: check if maximumAmount is within 63 bit range

// Check if maximumAmount is within 63 bit range
if (auto const maxAmt = ctx.tx[~sfMaximumAmount])
{
if (maxAmt == 0)
return temMALFORMED;

// TODO: Improve this check and move the constant elsewhere (STAmount?)
if (maxAmt > 0x7FFFFFFFFFFFFFFFull)
return temMALFORMED;
}
return preflight2(ctx);
}

Expand Down
8 changes: 8 additions & 0 deletions src/test/app/MPToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ class MPToken_test : public beast::unit_test::suite
// empty metadata returns error
env(mpt::create(alice, 100, 0, 0, ""), ter(temMALFORMED));
env.close();

// MaximumAmout of 0 returns error
env(mpt::create(alice, 0, 1, 1, "test"), ter(temMALFORMED));
env.close();

// MaximumAmount larger than 63 bit returns errpr
env(mpt::create(alice, 0xFFFFFFFFFFFFFFF0ull, 0, 0, "test"), ter(temMALFORMED));
env.close();
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/test/jtx/impl/mpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ namespace jtx {

namespace mpt {

static std::array<std::uint8_t, 8>
uint64ToByteArray(std::uint64_t value) {
std::array<std::uint8_t, 8> result;
std::memcpy(result.data(), &value, sizeof(value));
return result;
}

Json::Value
create(jtx::Account const& account)
{
Expand All @@ -39,18 +46,20 @@ create(jtx::Account const& account)
Json::Value
create(
jtx::Account const& account,
std::uint32_t const maxAmt,
std::uint64_t const maxAmt,
std::uint8_t const assetScale,
std::uint16_t transferFee,
std::string metadata)
{
Json::Value jv;
jv[sfAccount.jsonName] = account.human();
jv[sfTransactionType.jsonName] = jss::MPTokenIssuanceCreate;
jv[sfMaximumAmount.jsonName] = maxAmt;
jv[sfAssetScale.jsonName] = assetScale;
jv[sfTransferFee.jsonName] = transferFee;
jv[sfMPTokenMetadata.jsonName] = strHex(metadata);

// convert maxAmt to hex string, since json doesn't accept 64-bit int
jv[sfMaximumAmount.jsonName] = strHex(uint64ToByteArray(maxAmt));
return jv;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/jtx/mpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ create(jtx::Account const& account);
Json::Value
create(
jtx::Account const& account,
std::uint32_t const maxAmt,
std::uint64_t const maxAmt,
std::uint8_t const assetScale,
std::uint16_t transferFee,
std::string metadata);
Expand Down

0 comments on commit f959d15

Please sign in to comment.