Skip to content

Commit

Permalink
fix build_chain.sh bug and remove excess errorCode (FISCO-BCOS#4115)
Browse files Browse the repository at this point in the history
  • Loading branch information
wenlinlee authored Dec 18, 2023
1 parent 01485f6 commit eae66ae
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 29 deletions.
14 changes: 0 additions & 14 deletions bcos-executor/src/precompiled/common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,6 @@ enum PrecompiledErrorCode : int
CODE_UNKNOW_FUNCTION_CALL = -50101,
CODE_TABLE_NOT_EXIST = -50100,

// AccountPrecompiled -50299 ~ -50200
CODE_ACCOUNT_BALANCE_NOT_ENOUGH = -50202,
CODE_ACCOUNT_NOT_EXIST = -50201,
CODE_ACCOUNT_SUB_BALANCE_FAILED = -50200,

// BalancePrecompiled -50099 ~ -50000
CODE_REGISTER_CALLER_FAILED = -50006,
CODE_REGISTER_CALLER_ALREADY_EXIST = -50005,
CODE_REGISTER_CALLER_NOT_EXIST = -50004,
CODE_UNREGISTER_CALLER_FAILED = -50003,
CODE_CHECK_CALLER_FAILED = -50002,
CODE_TRANSFER_FAILED = -50001,
CODE_CALLER_TABLE_NOT_EXIST = -50000,

// correct return: code great or equal 0
CODE_SUCCESS = 0
};
Expand Down
16 changes: 1 addition & 15 deletions bcos-executor/src/precompiled/extension/BalancePrecompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ void BalancePrecompiled::getBalance(
auto appsTable = _executive->storage().openTable(appsTableName);
if (!usrTable && !appsTable)
{
_callParameters->setExecResult(codec.encode(int32_t(CODE_ACCOUNT_NOT_EXIST)));
BOOST_THROW_EXCEPTION(protocol::PrecompiledError(
"account appsTable and usrTable not exist, getBalance failed"));
return;
Expand Down Expand Up @@ -188,14 +187,12 @@ void BalancePrecompiled::addBalance(
<< LOG_BADGE("BalancePrecompiled") << LOG_DESC("addBalance")
<< LOG_KV("account", accountStr) << LOG_KV("value", value)
<< LOG_KV("caller", caller) << LOG_KV("callerTableNotExist", "true");
_callParameters->setExecResult(codec.encode(int32_t(CODE_CALLER_TABLE_NOT_EXIST)));
BOOST_THROW_EXCEPTION(
protocol::PrecompiledError("caller table not exist, addBalance failed"));
}
auto entry = _executive->storage().getRow(SYS_BALANCE_CALLER, caller);
if (!entry.has_value() || entry->get() == "0")
{
_callParameters->setExecResult(codec.encode(int32_t(CODE_CHECK_CALLER_FAILED)));
BOOST_THROW_EXCEPTION(
protocol::PrecompiledError("the request's sender not caller, addBalance failed"));
return;
Expand Down Expand Up @@ -257,15 +254,13 @@ void BalancePrecompiled::subBalance(
<< LOG_KV("account", accountStr) << LOG_KV("value", value)
<< LOG_KV("caller", caller)
<< LOG_KV("callerTableNotExist", "true");
_callParameters->setExecResult(codec.encode(int32_t(CODE_CALLER_TABLE_NOT_EXIST)));
BOOST_THROW_EXCEPTION(
protocol::PrecompiledError("the request's sender not caller, subBalance failed"));
return;
}
auto entry = table->getRow(caller);
if (!entry.has_value() || entry->get() == "0")
{
_callParameters->setExecResult(codec.encode(int32_t(CODE_CHECK_CALLER_FAILED)));
BOOST_THROW_EXCEPTION(protocol::PrecompiledError("caller not exist, subBalance failed"));
}

Expand Down Expand Up @@ -326,15 +321,13 @@ void BalancePrecompiled::transfer(const std::shared_ptr<executor::TransactionExe
<< LOG_KV("from", fromStr) << LOG_KV("to", toStr)
<< LOG_KV("value", value) << LOG_KV("caller", caller)
<< LOG_KV("callerTableNotExist", "true");
_callParameters->setExecResult(codec.encode(int32_t(CODE_CALLER_TABLE_NOT_EXIST)));
BOOST_THROW_EXCEPTION(
protocol::PrecompiledError("caller table not exist, transfer failed"));
return;
}
auto entry = table->getRow(caller);
if (!entry || entry->get() == "0")
{
_callParameters->setExecResult(codec.encode(int32_t(CODE_CHECK_CALLER_FAILED)));
BOOST_THROW_EXCEPTION(protocol::PrecompiledError("caller not exist"));
}

Expand Down Expand Up @@ -408,13 +401,12 @@ void BalancePrecompiled::transfer(const std::shared_ptr<executor::TransactionExe
_callParameters->m_create, _callParameters->m_gasLeft, true);
if (addBalanceResult1->status == int32_t(CODE_SUCCESS))
{
_callParameters->setExecResult(codec.encode(int32_t(CODE_TRANSFER_FAILED)));
BOOST_THROW_EXCEPTION(PrecompiledError("transfer failed"));
}
}
}
else
{
_callParameters->setExecResult(codec.encode(int32_t(CODE_TRANSFER_FAILED)));
BOOST_THROW_EXCEPTION(protocol::PrecompiledError(
"transfer failed, account subBalance failed, please check the account balance"));
PRECOMPILED_LOG(WARNING) << BLOCK_NUMBER(blockContext.number())
Expand Down Expand Up @@ -446,7 +438,6 @@ void BalancePrecompiled::registerCaller(

if (RANGES::find(governors, Address(origin)) == governors.end())
{
_callParameters->setExecResult(codec.encode(int32_t(CODE_REGISTER_CALLER_FAILED)));
PRECOMPILED_LOG(TRACE) << BLOCK_NUMBER(blockContext.number()) << LOG_BADGE("registerCaller")
<< LOG_DESC("failed to register, only governor can register caller");
BOOST_THROW_EXCEPTION(protocol::PrecompiledError("only governor can register caller"));
Expand Down Expand Up @@ -474,8 +465,6 @@ void BalancePrecompiled::registerCaller(
auto callerEntry = table->getRow(accountStr);
if (callerEntry && callerEntry->get() == "1")
{
_callParameters->setExecResult(
codec.encode(int32_t(CODE_REGISTER_CALLER_ALREADY_EXIST)));
BOOST_THROW_EXCEPTION(protocol::PrecompiledError("caller already exist"));
return;
}
Expand Down Expand Up @@ -508,7 +497,6 @@ void BalancePrecompiled::unregisterCaller(
<< LOG_KV("account address", accountStr);
if (RANGES::find(governors, Address(origin)) == governors.end())
{
_callParameters->setExecResult(codec.encode(int32_t(CODE_REGISTER_CALLER_FAILED)));
PRECOMPILED_LOG(TRACE) << BLOCK_NUMBER(blockContext.number()) << LOG_BADGE("registerCaller")
<< LOG_DESC("failed to register, only governor can register caller");
BOOST_THROW_EXCEPTION(protocol::PrecompiledError("only governor can register caller"));
Expand All @@ -520,15 +508,13 @@ void BalancePrecompiled::unregisterCaller(
{
std::string tableStr(SYS_BALANCE_CALLER);
_executive->storage().createTable(tableStr, "caller_address");
_callParameters->setExecResult(codec.encode(int32_t(CODE_UNREGISTER_CALLER_FAILED)));
PRECOMPILED_LOG(WARNING) << BLOCK_NUMBER(blockContext.number())
<< LOG_BADGE("BalancePrecompiled") << LOG_DESC("unregisterCaller")
<< LOG_KV("account", accountStr);
}
auto entry = table->getRow(accountStr);
if (!entry.has_value())
{
_callParameters->setExecResult(codec.encode(int32_t(CODE_REGISTER_CALLER_NOT_EXIST)));
BOOST_THROW_EXCEPTION(protocol::PrecompiledError("caller not exist"));
}

Expand Down
5 changes: 5 additions & 0 deletions bcos-utilities/bcos-utilities/DataConvertUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ bool bcos::isHexString(string const& _string)

bool bcos::isHexStringV2(string const& _string)
{
// if string is null, default return true
if (_string.length() == 0)
{
return true;
}
if (_string.length() % 2 == 0)
{
std::regex pattern("0x[0-9a-fA-F]*");
Expand Down
5 changes: 5 additions & 0 deletions tools/BcosAirBuilder/build_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2280,6 +2280,11 @@ check_auth_account()
if [ -z "${auth_admin_account}" ]; then
# get account string to auth_admin_account
generate_auth_account
else
if ! [[ ${auth_admin_account} =~ ^0x[0-9a-fA-F]{40}$ ]]; then
LOG_FATAL "auth_admin_account must be a valid, please check it!"
exit 1
fi
fi
}

Expand Down

0 comments on commit eae66ae

Please sign in to comment.