Skip to content

Commit

Permalink
modify errorCode of rpc and precompiled
Browse files Browse the repository at this point in the history
  • Loading branch information
bxq2011hust committed Mar 4, 2019
1 parent 323cbb6 commit 3d7d093
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 29 deletions.
20 changes: 10 additions & 10 deletions libprecompiled/Common.h
Expand Up @@ -46,21 +46,21 @@ namespace precompiled
/// note: abi.abiOut will return a positive number related to the negative number.
/// It maybe coincide with the positive number that should have been returned.

const int CODE_NO_AUTHORIZED = -1;
const int CODE_NO_AUTHORIZED = 50000;

/// AuthorityPrecompiled -30 ~ -39
const int CODE_TABLE_AND_ADDRESS_EXIST = -30;
const int CODE_TABLE_AND_ADDRESS_NOT_EXIST = -31;
/// AuthorityPrecompiled 51000 ~ 51099
const int CODE_TABLE_AND_ADDRESS_EXIST = 51000;
const int CODE_TABLE_AND_ADDRESS_NOT_EXIST = 51001;

/// ConsensusPrecompiled
const int CODE_INVALID_NODEID = -40;
const int CODE_LAST_SEALER = -41;
const int CODE_INVALID_NODEID = 51100;
const int CODE_LAST_SEALER = 51101;

/// CNSPrecompiled -50 ~ -59
const int CODE_ADDRESS_AND_VERSION_EXIST = -50;
/// CNSPrecompiled
const int CODE_ADDRESS_AND_VERSION_EXIST = 51200;

/// SystemConfigPrecompiled -60 ~ -69
const int CODE_INVALID_CONFIGURATION_VALUES = -60;
/// SystemConfigPrecompiled
const int CODE_INVALID_CONFIGURATION_VALUES = 51300;

} // namespace precompiled
} // namespace dev
11 changes: 4 additions & 7 deletions librpc/Common.h
Expand Up @@ -21,8 +21,8 @@

#pragma once

#include <map>
#include <string>

#define INVALIDNUMBER -1
#define RPC_LOG(LEVEL) LOG(LEVEL) << "[RPC]"

Expand All @@ -34,7 +34,7 @@ namespace rpc
enum RPCExceptionType
{
Success = 0,
GroupID,
GroupID = 40001,
JsonParse,
BlockHash,
BlockNumberT,
Expand All @@ -45,11 +45,8 @@ enum RPCExceptionType
InvalidRequest
};

const std::string RPCMsg[] = {"Success", "GroupID does not exist", "Response json parse error",
"BlockHash does not exist", "BlockNumber does not exist", "TransactionIndex is out of range",
"Call needs a 'from' field", "Only pbft consensus supports the view property",
"Invalid System Config",
"Don't send request to this node, the node doesn't belong to the group of this request"};
extern std::map<int, std::string> RPCMsg;


} // namespace rpc
} // namespace dev
11 changes: 11 additions & 0 deletions librpc/Rpc.cpp
Expand Up @@ -44,6 +44,17 @@ using namespace dev::ledger;
static const int64_t maxTransactionGasLimit = 0x7fffffffffffffff;
static const int64_t gasPrice = 1;

std::map<int, std::string> dev::rpc::RPCMsg{{RPCExceptionType::Success, "Success"},
{RPCExceptionType::GroupID, "GroupID does not exist"},
{RPCExceptionType::JsonParse, "Response json parse error"},
{RPCExceptionType::BlockHash, "BlockHash does not exist"},
{RPCExceptionType::BlockNumberT, "BlockNumber does not exist"},
{RPCExceptionType::TransactionIndex, "TransactionIndex is out of range"},
{RPCExceptionType::CallFrom, "Call needs a 'from' field"},
{RPCExceptionType::NoView, "Only pbft consensus supports the view property"},
{RPCExceptionType::InvalidSystemConfig, "Invalid System Config"},
{RPCExceptionType::InvalidRequest,
"Don't send request to this node who doesn't belong to the group"}};

Rpc::Rpc(std::shared_ptr<dev::ledger::LedgerManager> _ledgerManager,
std::shared_ptr<dev::p2p::P2PInterface> _service)
Expand Down
6 changes: 3 additions & 3 deletions libstorage/MemoryTableFactory.cpp
Expand Up @@ -119,13 +119,13 @@ Table::Ptr MemoryTableFactory::openTable(const string& tableName, bool authority
}

Table::Ptr MemoryTableFactory::createTable(const string& tableName, const string& keyField,
const std::string& valueField, bool authorigytFlag, Address const& _origin)
const std::string& valueField, bool authorityFlag, Address const& _origin)
{
STORAGE_LOG(DEBUG) << LOG_BADGE("MemoryTableFactory") << LOG_DESC("create table")
<< LOG_KV("table name", tableName) << LOG_KV("blockHash", m_blockHash)
<< LOG_KV("blockNum", m_blockNum);

auto sysTable = openTable(SYS_TABLES, authorigytFlag);
auto sysTable = openTable(SYS_TABLES, authorityFlag);

// To make sure the table exists
auto tableEntries = sysTable->select(tableName, sysTable->newCondition());
Expand All @@ -143,7 +143,7 @@ Table::Ptr MemoryTableFactory::createTable(const string& tableName, const string
tableEntry->setField("key_field", keyField);
tableEntry->setField("value_field", valueField);
createTableCode = sysTable->insert(
tableName, tableEntry, std::make_shared<AccessOptions>(_origin, authorigytFlag));
tableName, tableEntry, std::make_shared<AccessOptions>(_origin, authorityFlag));
if (createTableCode == -1)
{
STORAGE_LOG(WARNING) << LOG_BADGE("MemoryTableFactory")
Expand Down
2 changes: 1 addition & 1 deletion libstorage/MemoryTableFactory.h
Expand Up @@ -40,7 +40,7 @@ class MemoryTableFactory : public StateDBFactory

Table::Ptr openTable(const std::string& table, bool authorityFlag = true) override;
Table::Ptr createTable(const std::string& tableName, const std::string& keyField,
const std::string& valueField, bool authorigytFlag = true,
const std::string& valueField, bool authorityFlag = true,
Address const& _origin = Address()) override;

virtual Storage::Ptr stateStorage() { return m_stateStorage; }
Expand Down
2 changes: 1 addition & 1 deletion libstorage/Table.h
Expand Up @@ -210,7 +210,7 @@ class StateDBFactory : public std::enable_shared_from_this<StateDBFactory>

virtual Table::Ptr openTable(const std::string& table, bool authorityFlag = true) = 0;
virtual Table::Ptr createTable(const std::string& tableName, const std::string& keyField,
const std::string& valueField, bool authorigytFlag, Address const& _origin = Address()) = 0;
const std::string& valueField, bool authorityFlag, Address const& _origin = Address()) = 0;
};

} // namespace storage
Expand Down
10 changes: 5 additions & 5 deletions test/unittests/libstorage/test_ConsensusPrecompiled.cpp
Expand Up @@ -186,17 +186,17 @@ BOOST_AUTO_TEST_CASE(TestErrorNodeID)
bytes out = consensusPrecompiled->call(context, bytesConstRef(&in));
u256 count = 1;
abi.abiOut(bytesConstRef(&out), count);
BOOST_TEST(count == 216u);
BOOST_TEST(count == 156u);
in = abi.abiIn("addObserver(string)", nodeID);
out = consensusPrecompiled->call(context, bytesConstRef(&in));
count = 1;
abi.abiOut(bytesConstRef(&out), count);
BOOST_TEST(count == 216u);
BOOST_TEST(count == 156u);
in = abi.abiIn("remove(string)", nodeID);
out = consensusPrecompiled->call(context, bytesConstRef(&in));
count = 1;
abi.abiOut(bytesConstRef(&out), count);
BOOST_TEST(count == 216u);
BOOST_TEST(count == 156u);
}

BOOST_AUTO_TEST_CASE(TestRemoveLastSealer)
Expand Down Expand Up @@ -227,13 +227,13 @@ BOOST_AUTO_TEST_CASE(TestRemoveLastSealer)
out = consensusPrecompiled->call(context, bytesConstRef(&in));
count = 1;
abi.abiOut(bytesConstRef(&out), count);
BOOST_TEST(count == 215u);
BOOST_TEST(count == 157u);

in = abi.abiIn("addObserver(string)", nodeID1);
out = consensusPrecompiled->call(context, bytesConstRef(&in));
count = 1;
abi.abiOut(bytesConstRef(&out), count);
BOOST_TEST(count == 215u);
BOOST_TEST(count == 157u);
}

BOOST_AUTO_TEST_CASE(errFunc)
Expand Down
4 changes: 2 additions & 2 deletions test/unittests/libstorage/test_SystemConfigPrecompiled.cpp
Expand Up @@ -97,13 +97,13 @@ BOOST_AUTO_TEST_CASE(InvalidValue)
bytes out = systemConfigPrecompiled->call(context, bytesConstRef(&in));
u256 count = 1;
abi.abiOut(bytesConstRef(&out), count);
BOOST_TEST(count == 196u);
BOOST_TEST(count == 100u);

in = abi.abiIn("setValueByKey(string,string)", "tx_count_limit", "0");
out = systemConfigPrecompiled->call(context, bytesConstRef(&in));
count = 1;
abi.abiOut(bytesConstRef(&out), count);
BOOST_TEST(count == 196u);
BOOST_TEST(count == 100u);
}

BOOST_AUTO_TEST_SUITE_END()
Expand Down

0 comments on commit 3d7d093

Please sign in to comment.