Skip to content

Commit

Permalink
support deploy with value
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyShi22 committed Jan 25, 2024
1 parent 8b429c6 commit 164e9c0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
34 changes: 24 additions & 10 deletions bcos-executor/src/executive/TransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,16 +562,30 @@ std::tuple<std::unique_ptr<HostContext>, CallParameters::UniquePtr> TransactionE
// Create table
try
{
m_storageWrapper->createTable(tableName, std::string(STORAGE_VALUE));
EXECUTIVE_LOG(DEBUG) << "create contract table " << LOG_KV("table", tableName)
<< LOG_KV("sender", callParameters->senderAddress);
if (m_blockContext.isAuthCheck() ||
(!m_blockContext.isWasm() &&
m_blockContext.blockVersion() >= BlockVersion::V3_3_VERSION))
if (callParameters->value == 0)
{
// only create table when value is 0 need to create table, if value > 0, table is
// created in accountPrecompiled addBalance()
m_storageWrapper->createTable(tableName, std::string(STORAGE_VALUE));


EXECUTIVE_LOG(DEBUG) << "create contract table " << LOG_KV("table", tableName)
<< LOG_KV("sender", callParameters->senderAddress);
if (m_blockContext.isAuthCheck() ||
(!m_blockContext.isWasm() &&
m_blockContext.blockVersion() >= BlockVersion::V3_3_VERSION))
{
// Create auth table, always create auth table when version >= 3.3.0
creatAuthTable(tableName, callParameters->origin, callParameters->senderAddress,
m_blockContext.blockVersion());
}
}
else
{
// Create auth table, always create auth table when version >= 3.3.0
creatAuthTable(tableName, callParameters->origin, callParameters->senderAddress,
m_blockContext.blockVersion());
EXECUTIVE_LOG(DEBUG) << "no need create contract table when deploy with value "
<< LOG_KV("table", tableName)
<< LOG_KV("sender", callParameters->senderAddress)
<< LOG_KV("value", callParameters->value);
}

if (m_blockContext.features().get(ledger::Features::Flag::feature_sharding))
Expand Down Expand Up @@ -769,7 +783,7 @@ CallParameters::UniquePtr TransactionExecutive::go(
evmcMessage.flags = flags;
evmcMessage.depth = 0; // depth own by scheduler
evmcMessage.gas = leftGas;
evmcMessage.value = toEvmC(h256(0));
evmcMessage.value = toEvmC(hostContext.value());
evmcMessage.create2_salt = toEvmC(0x0_cppui256);

if (blockContext.isWasm())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void AccountPrecompiled::addAccountBalance(const std::string& accountTableName,

if (response->status != (int32_t)TransactionStatus::None)
{
PRECOMPILED_LOG(INFO) << LOG_BADGE("AccountManagerPrecompiled")
PRECOMPILED_LOG(INFO) << LOG_BADGE("AccountPrecompiled")
<< LOG_DESC("createAccount failed")
<< LOG_KV("accountTableName", accountTableName)
<< LOG_KV("status", response->status);
Expand Down
8 changes: 8 additions & 0 deletions bcos-executor/src/vm/HostContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ bool HostContext::setCode(bytes code)

// dry code hash in account table
m_executive->storage().setRow(m_tableName, ACCOUNT_CODE_HASH, std::move(codeHashEntry));

if (features().get(ledger::Features::Flag::feature_balance))
{
// update account's special code
Entry entryToDelete;
entryToDelete.setStatus(Entry::DELETED);
m_executive->storage().setRow(m_tableName, ACCOUNT_CODE, std::move(entryToDelete));
}
return true;
}
return false;
Expand Down
1 change: 1 addition & 0 deletions bcos-executor/src/vm/HostContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class HostContext : public evmc_host_context
bool isCreate() const { return m_callParameters->create; }
bool staticCall() const { return m_callParameters->staticCall; }
int64_t gas() const { return m_callParameters->gas; }
u256 value() const { return m_callParameters->value; }
void suicide()
{
m_executive->setContractTableChanged();
Expand Down

0 comments on commit 164e9c0

Please sign in to comment.