Skip to content

Commit

Permalink
VG-4573: Ripple - fix destinationTag set to 1 (#867)
Browse files Browse the repository at this point in the history
* ripple: uniform int64 type for destinationTag
* ci: bump patch version
  • Loading branch information
jcoatelen-ledger committed May 4, 2022
1 parent 84a5ea8 commit 95a7bd5
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ include_what_you_use() # add cmake conf option IWYU=ON to activate
# The project version number.
set(VERSION_MAJOR 4 CACHE STRING "Project major version number.")
set(VERSION_MINOR 1 CACHE STRING "Project minor version number.")
set(VERSION_PATCH 11 CACHE STRING "Project patch version number.")
set(VERSION_PATCH 12 CACHE STRING "Project patch version number.")
mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build)
Expand Down
11 changes: 9 additions & 2 deletions core/src/wallet/ripple/api_impl/RippleLikeTransactionApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,14 @@ namespace ledger {
//1 byte Destination tag: Type Code = 2, Field Code = 14
writer.writeByte(0x2E);
//4 bytes Destination tag
writer.writeBeValue<uint32_t>(static_cast<const uint32_t>(_destinationTag.getValue()));
const int64_t& destinationTagValue = _destinationTag.getValue();
if(destinationTagValue > static_cast<int64_t>(std::numeric_limits<uint32_t>::max()) ||
destinationTagValue < static_cast<int64_t>(std::numeric_limits<uint32_t>::min()))
{
throw make_exception(api::ErrorCode::RUNTIME_ERROR,
"RippleLikeTransactionApi::serialize: destinationTag value does not fit in uint32");
}
writer.writeBeValue<uint32_t>(static_cast<const uint32_t>(destinationTagValue));
}

//2 bytes LastLedgerSequence Field ID: Type Code = 2, Field Code = 27
Expand Down Expand Up @@ -361,7 +368,7 @@ namespace ledger {
return *this;
}

RippleLikeTransactionApi &RippleLikeTransactionApi::setDestinationTag(uint32_t tag) {
RippleLikeTransactionApi &RippleLikeTransactionApi::setDestinationTag(int64_t tag) {
_destinationTag = tag;
return *this;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/wallet/ripple/api_impl/RippleLikeTransactionApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace ledger {
RippleLikeTransactionApi & setReceiver(const std::shared_ptr<api::RippleLikeAddress> &receiver);
RippleLikeTransactionApi & setSigningPubKey(const std::vector<uint8_t> &pubKey);
RippleLikeTransactionApi & setHash(const std::string &hash);
RippleLikeTransactionApi & setDestinationTag(uint32_t tag);
RippleLikeTransactionApi & setDestinationTag(int64_t tag);
std::vector<api::RippleLikeMemo> getMemos() override;
void addMemo(api::RippleLikeMemo const& memo) override;
std::experimental::optional<int64_t> getDestinationTag() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace {
std::vector<std::string> fees;
std::vector<uint64_t> confirmations;
std::vector<BigInt> sequence;
std::vector<Option<uint64_t>> tag;
std::vector<Option<int64_t>> tag;
std::vector<int32_t> status;

void update(const std::string& txUid, const Option<std::string>& bUid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace ledger {

tx.sequence = BigInt(static_cast<unsigned long long>(get_number<uint64_t>(row, 14)));
if (row.get_indicator(15) != i_null) {
tx.destinationTag = get_number<uint64_t>(row, 15);
tx.destinationTag = get_number<int64_t>(row, 15);
}

if (row.get_indicator(16) != i_null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace ledger {
std::string sender;
Option<Block> block;
uint64_t confirmations;
Option<uint64_t> destinationTag;
Option<int64_t> destinationTag;
std::vector<api::RippleLikeMemo> memos;
int32_t status;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace ledger {
block.hash = number;
_transaction->block = block;
} else if (_lastKey == "DestinationTag") {
_transaction->destinationTag = Option<uint64_t>(value.toUint64());
_transaction->destinationTag = Option<int64_t>(value.toInt64());
} else if (_lastKey == "date" && currentObject != "transaction") {
_transaction->receivedAt = xrp_utils::toTimePoint<std::chrono::system_clock>(value.toUint64());
if (_transaction->block.hasValue()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ namespace ledger {
//1 byte Destination tag: Type Code = 2, Field Code = 14
reader.readNextByte();
auto bigIntTag = BigInt::fromHex(hex::toString(reader.read(4)));
tx->setDestinationTag(static_cast<const uint32_t>(bigIntTag.toUint64()));
tx->setDestinationTag(bigIntTag.toInt64());
}

//2 bytes LastLedgerSequence Field ID: Type Code = 2, Field Code = 27
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ TEST_F(RippleLikeWalletSynchronization, VaultAccountSynchronization) {
std::dynamic_pointer_cast<OperationQuery>(account->queryOperations()->complete())->execute());
std::cout << "Ops: " << ops.size() << std::endl;

uint32_t destinationTag = 0;
int64_t destinationTag = 0;
for (auto const& op : ops) {
auto xrpOp = op->asRippleLikeOperation();

Expand Down

0 comments on commit 95a7bd5

Please sign in to comment.