Skip to content

Commit

Permalink
Fix issuer bugs
Browse files Browse the repository at this point in the history
* Fix a balance comparison bug
* Fix a bug with self transfers

Signed-off-by: Mic Bowman <mic.bowman@intel.com>
  • Loading branch information
cmickeyb committed May 14, 2024
1 parent af3e8ff commit 8cc427d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion exchange-contract/exchange/contracts/issuer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,18 @@ bool ww::exchange::issuer::transfer(const Message& msg, const Environment& env,
const std::string new_owner(msg.get_string("new_owner_identity"));
ASSERT_SUCCESS(rsp, new_owner.size() > 0, "invalid transfer request, invalid owner identity parameter");

// if the old and new accounts are the same, then there is nothing to be done
if (old_owner == new_owner)
return rsp.success(false);

const int count = (int) msg.get_number("count");
ASSERT_SUCCESS(rsp, count > 0, "invalid transfer request, invalid asset count");

// if there is no issuance for this identity, we treat it as a 0 balance
ww::exchange::LedgerEntry old_entry;
ASSERT_SUCCESS(rsp, ledger_store.get_entry(old_owner, old_entry),
"transfer failed, insufficient balance for transfer");
ASSERT_SUCCESS(rsp, count < old_entry.asset_.count_,
ASSERT_SUCCESS(rsp, count <= old_entry.asset_.count_,
"transfer failed, insufficient balance for transfer");

if (! ledger_store.exists(new_owner))
Expand Down

0 comments on commit 8cc427d

Please sign in to comment.