Skip to content

Commit

Permalink
[VG-3785] [VG-3957] Fix Tezos delegation amount and receiver (#861)
Browse files Browse the repository at this point in the history
* fix: non-null Tezos (un)delegation operation amount
* fix: set receiver to empty for Tezos undelegate operations
* ci: bump patch version
* test: update a reference in stella unit test
  • Loading branch information
jcoatelen-ledger authored Mar 17, 2022
1 parent 54db1d6 commit b7a61ac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 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 6 CACHE STRING "Project patch version number.")
set(VERSION_PATCH 7 CACHE STRING "Project patch version number.")
mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build)
Expand Down
3 changes: 3 additions & 0 deletions core/src/tezos/TezosLikeAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ namespace ledger {
}

std::string TezosLikeAddress::toBase58() {
if(_hash160.empty()) {
return std::string();
}
auto config = std::make_shared<DynamicObject>();
config->putString("networkIdentifier", _params.Identifier);
return Base58::encodeWithChecksum(vector::concat(getVersion(), _hash160), config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ namespace ledger {
&& _transaction->block.hasValue()) {
_transaction->block.getValue().height = BigInt::fromString(number).toUint64();
} else if (_lastKey == "amount" || _lastKey == "volume") {
_transaction->value = toValue(number, _lastKey == "volume");
if(_transaction->type != api::TezosOperationTag::OPERATION_TAG_DELEGATION) {
_transaction->value = toValue(number, _lastKey == "volume");
}
} else if (_lastKey == "fee") {
_transaction->fees = _transaction->fees + toValue(number, false);
} else if (_lastKey == "gas_limit") {
Expand Down Expand Up @@ -193,6 +195,11 @@ namespace ledger {
} else if (_lastKey == "sender" ||
(currentObject == "src" && _lastKey == "tz")) {
_transaction->sender = value;
} else if(_lastKey == "receiver" && _transaction->type == api::TezosOperationTag::OPERATION_TAG_DELEGATION) {
// For undelegation, the API returns type=delegation & receiver attribute is defined
// For delegation, the API returns type=delegation but receiver is not defined ('delegate' used instead)
// Receiver should be empty to differentiate delegate from undelegate in db
_transaction->receiver = "";
} else if (_lastKey == "receiver" || _lastKey == "delegate" ||
((currentObject == "destination" || currentObject == "delegate") && _lastKey == "tz")) {
_transaction->receiver = value;
Expand Down Expand Up @@ -222,6 +229,9 @@ namespace ledger {
if (_lastKey == "type" &&
_transaction->type == api::TezosOperationTag::OPERATION_TAG_ORIGINATION) {
_transaction->originatedAccount = TezosLikeBlockchainExplorerOriginatedAccount();
} else if(_lastKey == "type" &&
_transaction->type == api::TezosOperationTag::OPERATION_TAG_DELEGATION) {
_transaction->value = BigInt(0);
}

} else if (_lastKey == "public_key" ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ TEST_F(StellarFixture, GetLastLedger) {
auto ledger = uv::wait(explorer->getLastLedger());
auto t = DateUtils::toJSON(ledger->time);
EXPECT_TRUE(!ledger->hash.empty());
EXPECT_TRUE(ledger->height > 69859L);
EXPECT_TRUE(ledger->height > 21153L);
EXPECT_TRUE(ledger->time > DateUtils::fromJSON("2015-07-16T23:49:00Z"));
}

Expand Down

0 comments on commit b7a61ac

Please sign in to comment.