mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-09 03:36:49 +00:00
Address reviewer's feedback.
This commit is contained in:
@@ -47,8 +47,9 @@ STIssue::STIssue(SerialIter& sit, SField const& name) : STBase{name}
|
||||
{
|
||||
MPTID mptID;
|
||||
std::uint32_t sequence = sit.get32();
|
||||
// Preserve the existing LE memcpy result on every host endian.
|
||||
// Wire 04 03 02 01 becomes MPTID bytes 01 02 03 04 on both.
|
||||
// MPTID stores the sequence in canonical big-endian bytes. STIssue
|
||||
// ledger bytes are the legacy LE-host encoding, so convert the
|
||||
// native get32() value to LE bytes before copying into the MPTID.
|
||||
sequence = boost::endian::native_to_little(sequence);
|
||||
static_assert(MPTID::size() == sizeof(sequence) + sizeof(currencyOrAccount));
|
||||
memcpy(mptID.data(), &sequence, sizeof(sequence));
|
||||
@@ -105,9 +106,10 @@ STIssue::add(Serializer& s) const
|
||||
s.addBitString(noAccount());
|
||||
std::uint32_t sequence = 0;
|
||||
memcpy(&sequence, issue.getMptID().data(), sizeof(sequence));
|
||||
// Preserve the existing LE ledger bytes on every host endian.
|
||||
// MPTID bytes 01 02 03 04 become wire bytes 04 03 02 01 on both.
|
||||
sequence = boost::endian::native_to_little(sequence);
|
||||
// The MPTID bytes are canonical big-endian. Interpret those bytes
|
||||
// as the legacy LE-host value so add32() writes the preserved
|
||||
// STIssue wire bytes on every host endian.
|
||||
sequence = boost::endian::little_to_native(sequence);
|
||||
s.add32(sequence);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <xrpl/protocol/Serializer.h>
|
||||
#include <xrpl/protocol/UintTypes.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
namespace xrpl::test {
|
||||
@@ -149,23 +150,13 @@ public:
|
||||
using namespace jtx;
|
||||
Account const alice{"alice"};
|
||||
|
||||
struct Vector
|
||||
{
|
||||
std::uint32_t sequence;
|
||||
std::uint32_t legacySequence;
|
||||
};
|
||||
|
||||
// 0x01020304 pins canonical MPTID bytes 01 02 03 04 and
|
||||
// preserved STIssue wire bytes 04 03 02 01 on BE and LE.
|
||||
Vector const vectors[] = {
|
||||
{.sequence = 0x00000001, .legacySequence = 0x01000000},
|
||||
{.sequence = 0x01020304, .legacySequence = 0x04030201},
|
||||
{.sequence = 0xa1b2c3d4, .legacySequence = 0xd4c3b2a1},
|
||||
};
|
||||
std::array<std::uint32_t, 3> const vectors = {0x00000001, 0x01020304, 0xa1b2c3d4};
|
||||
|
||||
for (auto const& vector : vectors)
|
||||
for (auto const vector : vectors)
|
||||
{
|
||||
MPTID const mptID = makeMptID(vector.sequence, alice);
|
||||
MPTID const mptID = makeMptID(vector, alice);
|
||||
MPTIssue const issue{mptID};
|
||||
STIssue const stIssue(sfAsset, Asset{issue});
|
||||
|
||||
@@ -177,9 +168,11 @@ public:
|
||||
expected.addBitString(alice.id());
|
||||
expected.addBitString(noAccount());
|
||||
{
|
||||
std::array<unsigned char, 4> bytes;
|
||||
auto const seq = boost::endian::native_to_little(vector.sequence);
|
||||
memcpy(bytes.data(), &seq, 4);
|
||||
std::array<unsigned char, 4> const bytes{
|
||||
static_cast<unsigned char>(vector),
|
||||
static_cast<unsigned char>(vector >> 8),
|
||||
static_cast<unsigned char>(vector >> 16),
|
||||
static_cast<unsigned char>(vector >> 24)};
|
||||
expected.addRaw(bytes.data(), bytes.size());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user