Skip to content

Commit

Permalink
Apply Account
Browse files Browse the repository at this point in the history
  • Loading branch information
MizukiSonoko committed Dec 16, 2016
1 parent 00028cc commit c7a52da
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 45 deletions.
9 changes: 9 additions & 0 deletions core/consensus/consensus_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ limitations under the License.
#include "../util/logger.hpp"
#include "../model/transaction.hpp"

#include "../model/commands/add.hpp"
#include "../model/commands/transfer.hpp"
#include "../model/commands/update.hpp"

#include "../model/objects/account.hpp"
#include "../model/objects/asset.hpp"
#include "../model/objects/domain.hpp"


namespace event {

template <typename T>
Expand Down
6 changes: 6 additions & 0 deletions core/consensus/sumeragi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ namespace sumeragi {
unsigned long maxFaulty; // f
unsigned long proxyTailNdx;
int panicCount;

long long int commitedCount = 0;

unsigned long numValidatingPeers;
std::string myPublicKey;

Expand Down Expand Up @@ -292,6 +295,9 @@ namespace sumeragi {

// Commit locally
logger::explore("sumeragi", "commit");
context->commitedCount++;
logger::explore("sumeragi", "commit count:"+std::to_string(context->commitedCount));

merkle_transaction_repository::commit(event); //TODO: add error handling in case not saved

// Write exec code smart contract
Expand Down
8 changes: 8 additions & 0 deletions core/consensus/sumeragi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ limitations under the License.
#include "../service/peer_service.hpp"
#include "../infra/protobuf/event.grpc.pb.h"

#include "../model/commands/add.hpp"
#include "../model/commands/transfer.hpp"
#include "../model/commands/update.hpp"

#include "../model/objects/account.hpp"
#include "../model/objects/asset.hpp"
#include "../model/objects/domain.hpp"

namespace sumeragi {

void initializeSumeragi(
Expand Down
8 changes: 8 additions & 0 deletions core/infra/connection/connection_with_grpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ limitations under the License.

#include "../protobuf/event.grpc.pb.h"

#include "../../model/commands/add.hpp"
#include "../../model/commands/transfer.hpp"
#include "../../model/commands/update.hpp"

#include "../../model/objects/asset.hpp"
#include "../../model/objects/domain.hpp"
#include "../../model/objects/account.hpp"

#include <string>
#include <vector>
#include <memory>
Expand Down
9 changes: 9 additions & 0 deletions core/infra/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,14 @@ target_link_libraries(http_server_with_cappuccino
ssl
crypto
logger
datetime
peer_service_with_json

objects
base64
signature
convertor
connection_with_grpc
peer_service_with_json
)

99 changes: 58 additions & 41 deletions core/infra/server/http_server_with_cappuccino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ limitations under the License.
#include "../../server/http_server.hpp"
#include "../../vendor/Cappuccino/cappuccino.hpp"
#include "../../util/logger.hpp"
#include "../../service/peer_service.hpp"
#include "../../infra/protobuf/convertor.hpp"

#include "../../consensus/connection/connection.hpp"


namespace http {

const auto assetName = "PointDemo";

using nlohmann::json;
using Request = Cappuccino::Request;
using Response = Cappuccino::Response;


template<typename T>
using Transaction = transaction::Transaction<T>;
template<typename T>
using ConsensusEvent = event::ConsensusEvent<T>;
template<typename T>
using Add = command::Add<T>;
template<typename T>
using Transfer = command::Transfer<T>;
using namespace transaction;
using namespace command;
using namespace event;
using namespace object;

json responseError(std::string message){
return json({
Expand All @@ -57,61 +57,69 @@ namespace http {
logger::info("server", "initialize server!");
Cappuccino::Cappuccino( 0, nullptr);


Cappuccino::route<Cappuccino::Method::POST>( "/account/register",[](std::shared_ptr<Request> request) -> Response{
auto res = Response(request);
auto data = request->json();
/*
if(!data.empty()){
try{
auto publicKey = data["publicKey"].get<std::string>();
auto alias = data["alias"].get<std::string>();
auto timestamp = data["timestamp"].get<int>();

// ToDo make transaction
auto event = ConsensusEvent<Transaction<Add<object::Account>>>(
publicKey.c_str(),
publicKey.c_str(),
alias.c_str()
);
event.addTxSignature(
peer::getMyPublicKey(),
signature::sign(event.getHash(), peer::getMyPublicKey(), peer::getPrivateKey()).c_str()
);
connection::send(peer::getMyIp(), convertor::encode(event));

}catch(...) {
res.json(json({
{"status", 400},
{"message", "Invalied json type or value"}
}));
{"status", 400},
{"message", "Invalied json type or value"}
}));
return res;
}
}else{
res.json(json({
{"status", 400},
{"message", "Invalied json"}
}));
{"status", 400},
{"message", "Invalied json"}
}));
return res;
}
res.json(json({
{"status", 200},
{"message", "successful"},
{"uuid", ""}
}));
*/

return res;
});

Cappuccino::route<Cappuccino::Method::GET>( "/account",[](std::shared_ptr<Request> request) -> Response{
std::string uuid = request->params("uuid");
auto res = Response(request);
/*
auto data = // ToDo repository user data.

auto rdata = "";//repository::account::find("uuid");
auto data = json::parse(rdata);

res.json(json({
{"status", 200},
{"alias", data["alias"]},
{"assets", data["assets"]}
}));
*/

return res;
});


Cappuccino::route<Cappuccino::Method::POST>( "/asset/operation",[](std::shared_ptr<Request> request) -> Response{
auto res = Response(request);
auto data = request->json();
/*
if(!data.empty()){
try{
auto assetUuid = data["asset-uuid"].get<std::string>();
Expand All @@ -122,48 +130,57 @@ namespace http {
auto sender = data["params"]["sender"].get<std::string>();
auto receiver = data["params"]["receiver"].get<std::string>();

// ToDo make transaction
auto event = ConsensusEvent<Transaction<Transfer<Asset>>>(
sender.c_str(),
sender.c_str(),
receiver.c_str(),
assetName,
std::atoi(value.c_str())
);
event.addTxSignature(
peer::getMyPublicKey(),
signature::sign(event.getHash(), peer::getMyPublicKey(), peer::getPrivateKey()).c_str()
);
connection::send(peer::getMyIp(), convertor::encode(event));


}catch(...) {
res.json(json({
{"status", 400},
{"message", "Invalied json type or value"}
}));
{"status", 400},
{"message", "Invalied json type or value"}
}));
return res;
}
}else{
res.json(json({
{"status", 400},
{"message", "Invalied json"}
}));
{"status", 400},
{"message", "Invalied json"}
}));
return res;
}

res.json(json({
{"status", 200},
{"alias", data["alias"]},
{"assets": data["assets"]}
}));
*/
{"status", 200},
{"message", "Ok"}
}));
return res;
});

Cappuccino::route<Cappuccino::Method::GET>( "/history/transaction",[](std::shared_ptr<Request> request) -> Response{
std::string uuid = request->params("uuid");
auto res = Response(request);
/*
auto transaction_data = // ToDo repository user data.

auto transaction_data = "";//repository::transaction::findAll();

auto tx_json = json::array();
for(auto tx: transaction_data){
for(auto tx: json::parse(transaction_data)){
tx_json.push_back(tx);
}

res.json(json({
{"status", 200},
{"history", tx_json}
}));
*/
{"status", 200},
{"history", tx_json}
}));
return res;
});

Expand Down
4 changes: 0 additions & 4 deletions core/model/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ limitations under the License.
#ifndef CORE_DOMAIN_TRANSACTIONS_TRANSACTION_HPP_
#define CORE_DOMAIN_TRANSACTIONS_TRANSACTION_HPP_

#include "commands/add.hpp"
#include "commands/transfer.hpp"
#include "commands/update.hpp"

#include "../crypto/signature.hpp"
#include "../util/datetime.hpp"
#include "../crypto/hash.hpp"
Expand Down
9 changes: 9 additions & 0 deletions core/validation/transaction_validator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ limitations under the License.
#include "../consensus/consensus_event.hpp"
#include "../infra/protobuf/event.grpc.pb.h"

#include "../model/commands/add.hpp"
#include "../model/commands/transfer.hpp"
#include "../model/commands/update.hpp"

#include "../model/objects/account.hpp"
#include "../model/objects/asset.hpp"
#include "../model/objects/domain.hpp"


#include <memory>
#include <type_traits>

Expand Down

0 comments on commit c7a52da

Please sign in to comment.