Skip to content

Commit

Permalink
* Fix pb command factory with respect to amount;
Browse files Browse the repository at this point in the history
* Add eq operator for Amount
  • Loading branch information
muratovv authored and lebdron committed Jul 19, 2017
1 parent f675e32 commit 5bcb7b1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
24 changes: 18 additions & 6 deletions irohad/model/converters/impl/pb_command_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ namespace iroha {
protocol::AddAssetQuantity pb_add_asset_quantity;
pb_add_asset_quantity.set_account_id(add_asset_quantity.account_id);
pb_add_asset_quantity.set_asset_id(add_asset_quantity.asset_id);
pb_add_asset_quantity.set_amount(add_asset_quantity.amount);
auto amount = pb_add_asset_quantity.mutable_amount();
amount->set_integer_part(add_asset_quantity.amount.int_part);
amount->set_fractial_part(add_asset_quantity.amount.frac_part);
}

model::AddAssetQuantity
Expand All @@ -39,7 +41,10 @@ namespace iroha {
model::AddAssetQuantity add_asset_quantity;
add_asset_quantity.account_id = pb_add_asset_quantity.account_id();
add_asset_quantity.asset_id = pb_add_asset_quantity.asset_id();
add_asset_quantity.amount = pb_add_asset_quantity.amount();
add_asset_quantity.amount.int_part =
pb_add_asset_quantity.amount().integer_part();
add_asset_quantity.amount.frac_part =
pb_add_asset_quantity.amount().fractial_part();
return add_asset_quantity;
}

Expand Down Expand Up @@ -239,16 +244,23 @@ namespace iroha {
pb_transfer_asset.set_src_account_id(transfer_asset.src_account_id);
pb_transfer_asset.set_dest_account_id(transfer_asset.dest_account_id);
pb_transfer_asset.set_asset_id(transfer_asset.asset_id);
pb_transfer_asset.set_ammount(transfer_asset.amount);
auto amount = pb_transfer_asset.mutable_amount();
amount->set_integer_part(transfer_asset.amount.int_part);
amount->set_fractial_part(transfer_asset.amount.frac_part);
return pb_transfer_asset;
}
model::TransferAsset
PbCommandFactory::deserializeTransferAsset(protocol::TransferAsset &pb_subtract_asset_quantity) {
model::TransferAsset transfer_asset;
transfer_asset.src_account_id = pb_subtract_asset_quantity.src_account_id();
transfer_asset.dest_account_id = pb_subtract_asset_quantity.dest_account_id();
transfer_asset.src_account_id =
pb_subtract_asset_quantity.src_account_id();
transfer_asset.dest_account_id =
pb_subtract_asset_quantity.dest_account_id();
transfer_asset.asset_id = pb_subtract_asset_quantity.asset_id();
transfer_asset.amount = pb_subtract_asset_quantity.asset_id();
transfer_asset.amount.int_part =
pb_subtract_asset_quantity.amount().integer_part();
transfer_asset.amount.frac_part =
pb_subtract_asset_quantity.amount().fractial_part();
return transfer_asset;
}

Expand Down
13 changes: 9 additions & 4 deletions libs/common/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace iroha {
/**
* Base type which represents blob of fixed size.
*/
template <size_t size_>
template<size_t size_>
class blob_t : public std::array<byte_t, size_> {
/**
* Dark magic of C++, do not touch pls :)
Expand Down Expand Up @@ -76,16 +76,16 @@ namespace iroha {
uint8_t front, back;
auto ptr = this->data();
for (uint32_t i = 0, k = 0; i < size_; i++) {
front = (uint8_t)(ptr[i] & 0xF0) >> 4;
back = (uint8_t)(ptr[i] & 0xF);
front = (uint8_t) (ptr[i] & 0xF0) >> 4;
back = (uint8_t) (ptr[i] & 0xF);
res[k++] = code[front];
res[k++] = code[back];
}
return res;
}
};

template <size_t size>
template<size_t size>
using hash_t = blob_t<size>;

// fixed-size hashes
Expand Down Expand Up @@ -120,6 +120,11 @@ namespace iroha {
return int_part * coef + frac_part;
}

bool operator==(const Amount &rhs) {
return this->int_part == rhs.int_part &&
this->frac_part == rhs.frac_part;
}

private:
int ipow(int base, int exp) {
int result = 1;
Expand Down

0 comments on commit 5bcb7b1

Please sign in to comment.