Skip to content

Commit

Permalink
更新transferBalance中合约调用的同时也能转账,发送方改为sender,以及接收方地址添加预编译合约地址过滤 (FISCO-B…
Browse files Browse the repository at this point in the history
…COS#4156)

Co-authored-by: binliu21 <[email protected]>
Co-authored-by: jimmyshi <[email protected]>
  • Loading branch information
3 people authored Jan 3, 2024
1 parent 446db45 commit fe07833
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions bcos-executor/src/executive/TransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,22 @@ bool TransactionExecutive::transferBalance(std::string_view origin, std::string_
// sender 是合约地址
// receiver 是转账接收方
EXECUTIVE_LOG(TRACE) << LOG_BADGE("Execute") << "now to transferBalance"
<< LOG_KV("subAccount", origin) << LOG_KV("addAccount", receiver)
<< LOG_KV("receiveAddress", ACCOUNT_ADDRESS) << LOG_KV("value", value)
<< LOG_KV("origin", origin)
<< LOG_KV("subAccount", sender)
<< LOG_KV("addAccount", receiver)
<< LOG_KV("receiveAddress", ACCOUNT_ADDRESS)
<< LOG_KV("value", value)
<< LOG_KV("gas", gas);

if (isPrecompiled(std::string(receiver)))
{
EXECUTIVE_LOG(DEBUG) << LOG_BADGE("Execute") << "transferBalance, receiverAddress is precompiled address";
return false;
}
// first subAccountBalance, then addAccountBalance
// origin = origin - value
// sender = sender - value
auto codec = CodecWrapper(m_blockContext.hashHandler(), m_blockContext.isWasm());
auto params = codec.encodeWithSig("subAccountBalance(uint256)", value);
auto formTableName = bcos::getContractTableName(executor::USER_APPS_PREFIX, origin);
auto formTableName = bcos::getContractTableName(executor::USER_APPS_PREFIX, sender);
std::vector<std::string> fromTableNameVector = {formTableName};
auto inputParams = codec.encode(fromTableNameVector, params);
auto subParams = codec.encode(std::string(ACCOUNT_ADDRESS), inputParams);
Expand Down Expand Up @@ -341,7 +348,7 @@ bool TransactionExecutive::transferBalance(std::string_view origin, std::string_
{
EXECUTIVE_LOG(DEBUG) << LOG_BADGE("Execute")
<< LOG_DESC("transferBalance add failed, need to restore")
<< LOG_KV("addAccount", receiver) << LOG_KV("tablename", toTableName);
<< LOG_KV("tableName", formTableName) << LOG_KV("will add balance", value);

// if receiver add failed, sender need to restore
// sender = sender + value
Expand All @@ -364,7 +371,7 @@ bool TransactionExecutive::transferBalance(std::string_view origin, std::string_
return false;
}
EXECUTIVE_LOG(DEBUG) << LOG_BADGE("Execute") << "transferBalance finished."
<< LOG_KV("subAccount", origin) << LOG_KV("addAccount", receiver)
<< LOG_KV("subAccount", sender) << LOG_KV("addAccount", receiver)
<< LOG_KV("receiveAddress", ACCOUNT_ADDRESS) << LOG_KV("value", value)
<< LOG_KV("gas", gas);
return true;
Expand Down

0 comments on commit fe07833

Please sign in to comment.