| 1992 | } |
| 1993 | |
| 1994 | void TransactionExecutor::getCode( |
| 1995 | std::string_view contract, std::function<void(bcos::Error::Ptr, bcos::bytes)> callback) |
| 1996 | { |
| 1997 | EXECUTOR_NAME_LOG(INFO) << "Get code request" << LOG_KV("Contract", contract); |
| 1998 | |
| 1999 | if (!m_isRunning) |
| 2000 | { |
| 2001 | EXECUTOR_NAME_LOG(ERROR) << "TransactionExecutor is not running"; |
| 2002 | callback( |
| 2003 | BCOS_ERROR_UNIQUE_PTR(ExecuteError::STOPPED, "TransactionExecutor is not running"), {}); |
| 2004 | return; |
| 2005 | } |
| 2006 | |
| 2007 | storage::StateStorageInterface::Ptr stateStorage; |
| 2008 | |
| 2009 | { |
| 2010 | std::unique_lock<std::shared_mutex> lock(m_stateStoragesMutex); |
| 2011 | if (!m_stateStorages.empty()) |
| 2012 | { |
| 2013 | stateStorage = createStateStorage(m_stateStorages.back().storage, true, false); |
| 2014 | } |
| 2015 | } |
| 2016 | // create temp state storage |
| 2017 | if (!stateStorage) |
| 2018 | { |
| 2019 | if (m_cachedStorage) |
| 2020 | { |
| 2021 | stateStorage = createStateStorage(m_cachedStorage, true, false); |
| 2022 | } |
| 2023 | else |
| 2024 | { |
| 2025 | stateStorage = createStateStorage(m_backendStorage, true, false); |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | std::string contractTableName = getContractTableName(executor::USER_APPS_PREFIX, contract); |
| 2030 | |
| 2031 | auto getCodeFromContractTable = [stateStorage, this](std::string_view contractTableName, |
| 2032 | decltype(callback) _callback) { |
| 2033 | stateStorage->asyncGetRow(contractTableName, ACCOUNT_CODE, |
| 2034 | [this, callback = std::move(_callback)]( |
| 2035 | Error::UniquePtr error, std::optional<Entry> entry) { |
| 2036 | if (!m_isRunning) |
| 2037 | { |
| 2038 | callback(BCOS_ERROR_UNIQUE_PTR( |
| 2039 | ExecuteError::STOPPED, "TransactionExecutor is not running"), |
| 2040 | {}); |
| 2041 | return; |
| 2042 | } |
| 2043 | |
| 2044 | if (error) |
| 2045 | { |
| 2046 | EXECUTOR_NAME_LOG(INFO) << "Get code failed: " << error->errorMessage(); |
| 2047 | |
| 2048 | callback(BCOS_ERROR_WITH_PREV_UNIQUE_PTR(-1, "Get code failed", *error), {}); |
| 2049 | return; |
| 2050 | } |
| 2051 | |