Skip to content

Commit

Permalink
Merge pull request hyperledger-iroha#179 from hyperledger/feature/api
Browse files Browse the repository at this point in the history
Feature/api

Notice: I found **bug in attach Accout to Asset**. Protobuf outputs below error:
```
[libprotobuf ERROR google/protobuf/wire_format_lite.cc:534] String field 'Api.Account.assets' contains invalid UTF-8 data when parsing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes.
```
It cannot be detected by gTest tests. It is caused in *smart_contract/instances/sample_rating/WeightedRateAttach.java*.
  • Loading branch information
motxx authored Mar 3, 2017
2 parents 6188aae + 99d244c commit bff6929
Show file tree
Hide file tree
Showing 102 changed files with 7,601 additions and 604 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ config/sumeragi.json
cmake-build-debu/*
docker/build/iroha.tar
cmake-build-debug/*
external/
external/*
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 2.8)
PROJECT(iroha C CXX)

SET(CMAKE_CXX_FLAGS "-g -Wall -std=c++1y")
SET(CMAKE_CXX_FLAGS "-g -std=c++1y -Wall -fPIC")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3")
SET(CMAKE_CXX_FLAGS_DEBUG "-Wextra -O0")
SET(CMAKE_SHARED_LINKER_FLAGS "-lpthread -lssl")
Expand All @@ -24,6 +24,7 @@ include("dependencies.cmake")
add_subdirectory(core)
add_subdirectory(peer)
add_subdirectory(tools)
add_subdirectory(smart_contract)


if(TESTING)
Expand Down
5 changes: 5 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"database_path":"/tmp/iroha_ledger",
"java_class_path":"java_tests",
"java_class_path_local":"smart_contract/java_tests",
"java_library_path":"lib",
"java_library_path_local":"build/lib",
"java_policy_path":"jvm/java.policy.txt",
"concurrency": 0,
"max_faulty_peers" : 1,
"pool_worker_queue_size": 1024,
Expand Down
1 change: 1 addition & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ add_subdirectory(infra)
add_subdirectory(util)
add_subdirectory(crypto)
add_subdirectory(validation)
add_subdirectory(transaction_builder)
7 changes: 7 additions & 0 deletions core/consensus/consensus_event.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


#include "consensus_event.hpp"

namespace event{

};
13 changes: 7 additions & 6 deletions core/consensus/sumeragi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ limitations under the License.
#include <infra/config/peer_service_with_json.hpp>
#include <infra/config/iroha_config_with_json.hpp>

#include "connection/connection.hpp"

/**
* |ーーー| |ーーー| |ーーー| |ーーー|
* | ス |ー| メ |ー| ラ |ー| ギ |
Expand All @@ -56,7 +58,6 @@ namespace sumeragi {

std::map<std::string, std::string> txCache;

//thread pool and a storage of events
static ThreadPool pool(
ThreadPoolOptions{
.threads_count = config::IrohaConfigManager::getInstance()
Expand Down Expand Up @@ -135,7 +136,7 @@ namespace sumeragi {
std::string line;
for (int i=0; i<numValidationPeer; i++) line += "=====";
logger::explore("sumeragi") << line;

logger::explore("sumeragi") << "numValidSignatures:"
<< numValidSignatures
<< " faulty:"
Expand Down Expand Up @@ -271,7 +272,7 @@ namespace sumeragi {
return 0l;
//return merkle_transaction_repository::getLastLeafOrder() + 1;
}


void processTransaction(ConsensusEvent& event) {

Expand Down Expand Up @@ -399,7 +400,7 @@ namespace sumeragi {
if (broadcastEnd > context->numValidatingPeers - 1) {
broadcastEnd = context->numValidatingPeers - 1;
}

logger::info("sumeragi") << "broadcastEnd:" << broadcastEnd;
logger::info("sumeragi") << "broadcastStart:" << broadcastStart;
// WIP issue hash event
Expand Down Expand Up @@ -429,8 +430,8 @@ namespace sumeragi {
tmp_deq.push_back(std::move(context->validatingPeers[0]));
context->validatingPeers.clear();
context->validatingPeers = std::move(tmp_deq);
std::sort(context->validatingPeers.begin(), context->validatingPeers.end(),
[](const std::unique_ptr<peer::Node> &lhs,
const std::unique_ptr<peer::Node> &rhs) {
Expand Down
2 changes: 1 addition & 1 deletion core/infra/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#add_subdirectory(smart_contract)
add_subdirectory(virtual_machine)
add_subdirectory(crypto)
add_subdirectory(repository)
add_subdirectory(server)
Expand Down
20 changes: 20 additions & 0 deletions core/infra/config/iroha_config_with_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ std::string IrohaConfigManager::getDatabasePath(
return this->getParam<std::string>("database_path", defaultValue);
}

std::string IrohaConfigManager::getJavaClassPath(const std::string& defaultValue) {
return this->getParam<std::string>("java_class_path", defaultValue);
}

std::string IrohaConfigManager::getJavaClassPathLocal(const std::string& defaultValue) {
return this->getParam<std::string>("java_class_path_local", defaultValue);
}

std::string IrohaConfigManager::getJavaLibraryPath(const std::string& defaultValue) {
return this->getParam<std::string>("java_library_path", defaultValue);
}

std::string IrohaConfigManager::getJavaLibraryPathLocal(const std::string& defaultValue) {
return this->getParam<std::string>("java_library_path_local", defaultValue);
}

std::string IrohaConfigManager::getJavaPolicyPath(const std::string& defaultValue) {
return this->getParam<std::string>("java_policy_path", defaultValue);
}

size_t IrohaConfigManager::getConcurrency(size_t defaultValue) {
return this->getParam<size_t>("concurrency", defaultValue);
}
Expand Down
6 changes: 6 additions & 0 deletions core/infra/config/iroha_config_with_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class IrohaConfigManager : config::AbstractConfigManager {
std::string getConfigName();

std::string getDatabasePath(const std::string& defaultValue);
std::string getJavaClassPath(const std::string& defaultValue);
std::string getJavaClassPathLocal(const std::string& defaultValue);
std::string getJavaLibraryPath(const std::string& defaultValue);
std::string getJavaLibraryPathLocal(const std::string& defaultValue);

std::string getJavaPolicyPath(const std::string& defaultValue);
size_t getConcurrency(size_t defaultValue);
size_t getMaxFaultyPeers(size_t defaultValue);
size_t getPoolWorkerQueueSize(size_t defaultValue);
Expand Down
29 changes: 29 additions & 0 deletions core/infra/crypto/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
all: libhash.a

CC = g++
KECCAK_PATH = ../../vendor/KeccakCodePackage

DEFINE = -DKeccakP200_excluded -DKeccakP400_excluded -DKeccakP800_excluded

CFLAGS := $(CFLAGS) -g -std=c++1y -Wall -fPIC
CFLAGS := $(CFLAGS) $(DEFINE)
CFLAGS := $(CFLAGS) -I$(KECCAK_PATH)/bin/generic64/libkeccak.a.headers

KeccakP-1600-opt64.o: $(KECCAK_PATH)/SnP/KeccakP-1600/Optimized64/KeccakP-1600-opt64.c
$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
OBJECTS := $(OBJECTS) KeccakP-1600-opt64.o

KeccakSponge.o: $(KECCAK_PATH)/Constructions/KeccakSponge.c
$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
OBJECTS := $(OBJECTS) KeccakSponge.o

SimpleFIPS202.o: $(KECCAK_PATH)/Modes/SimpleFIPS202.c
$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
OBJECTS := $(OBJECTS) SimpleFIPS202.o

libhash.a: $(OBJECTS)
$(CC) $(CFLAGS) hash.cpp -c
ar rcs libhash.a hash.o $(OBJECTS)

clean:
rm -rf libhash.a *.o
5 changes: 3 additions & 2 deletions core/infra/protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
SET(CMAKE_CXX_FLAGS "-std=c++14 -L/usr/local/lib `pkg-config --libs grpc++ grpc` -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed -lprotobuf -lpthread -ldl")
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

SET(CMAKE_CXX_FLAGS "-g -std=c++1y -Wall -fPIC -L/usr/local/lib `pkg-config --libs grpc++ grpc` -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed -lprotobuf -lpthread -ldl")

include_directories(
${PROJECT_SOURCE_DIR}/core
Expand All @@ -13,7 +15,6 @@ ADD_LIBRARY(event_with_grpc STATIC
api.grpc.pb.cc
api.pb.cc
)

target_link_libraries(event_with_grpc
grpc++
grpc++_reflection
Expand Down
6 changes: 5 additions & 1 deletion core/infra/repository/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

SET(LEVELDB_PATH ${PROJECT_SOURCE_DIR}/core/vendor/leveldb)

SET(CMAKE_CXX_FLAGS "-g -Wall -std=c++1y -fPIC")

include_directories(
${LEVELDB_PATH}/include
${PROJECT_SOURCE_DIR}/core
${LEVELDB_PATH}/include
)

link_directories(
${LEVELDB_PATH}/out-shared
${LEVELDB_PATH}/out-static
)

Expand All @@ -16,6 +19,7 @@ target_link_libraries(world_state_repo_with_level_db
snappy
leveldb
logger
config_manager
exception
json
)
14 changes: 7 additions & 7 deletions core/infra/repository/world_state_repository_with_level_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace repository {

std::string readData;
detail::loggerStatus(detail::db->Get(leveldb::ReadOptions(), key, &readData));
if (readData != "") {
if (!readData.empty()) {
return readData;
} else {
return "";
Expand All @@ -173,12 +173,12 @@ namespace repository {
detail::loadDb();
}

std::string result = "";
std::string result;
detail::loggerStatus(detail::db->Get(leveldb::ReadOptions(), key, &result));
if (result == "") {
return defaultValue;
} else {
if (!result.empty()) {
return result;
} else {
return defaultValue;
}
}

Expand All @@ -187,9 +187,9 @@ namespace repository {
detail::loadDb();
}

std::string result = "";
std::string result;
detail::loggerStatus(detail::db->Get(leveldb::ReadOptions(), key, &result));
return result == "";
return !result.empty();
}
};
};
1 change: 0 additions & 1 deletion core/infra/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ target_link_libraries(http_server_with_cappuccino
connection_with_grpc
cappuccino
)

4 changes: 2 additions & 2 deletions core/infra/server/http_server_with_cappuccino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ limitations under the License.

#include <transaction_builder/transaction_builder.hpp>
#include <consensus/connection/connection.hpp>

#include <infra/protobuf/api.pb.h>

// -- WIP --
Expand All @@ -39,7 +40,6 @@ using grpc::Status;
// -------

namespace http {

using namespace Api;

using txbuilder::TransactionBuilder;
Expand Down Expand Up @@ -186,4 +186,4 @@ namespace http {
Cappuccino::run();

}
}; // namespace http
}; // namespace http
27 changes: 0 additions & 27 deletions core/infra/smart_contract/CMakeLists.txt

This file was deleted.

33 changes: 0 additions & 33 deletions core/infra/smart_contract/jvm/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit bff6929

Please sign in to comment.