-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from resilientdb/utxo
Utxo
- Loading branch information
Showing
64 changed files
with
2,883 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
build --cxxopt='-std=c++17' --copt=-O3 --jobs=40 | ||
build --action_env=PYTHON_BIN_PATH="/usr/bin/python3.10" | ||
build --action_env=PYTHON_LIB_PATH="/usr/include/python3.10" | ||
#build --action_env=PYTHON_BIN_PATH="/usr/bin/python3.10" | ||
#build --action_env=PYTHON_LIB_PATH="/usr/include/python3.10" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
cc_library( | ||
name = "utxo_client", | ||
srcs = ["utxo_client.cpp"], | ||
hdrs = ["utxo_client.h"], | ||
deps = [ | ||
"//application/utxo/proto:rpc_cc_proto", | ||
"//application/utxo/proto:utxo_cc_proto", | ||
"//client:resdb_user_client", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright (c) 2019-2022 ExpoLab, UC Davis | ||
* | ||
* Permission is hereby granted, free of charge, to any person | ||
* obtaining a copy of this software and associated documentation | ||
* files (the "Software"), to deal in the Software without | ||
* restriction, including without limitation the rights to use, | ||
* copy, modify, merge, publish, distribute, sublicense, and/or | ||
* sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
#include "application/utxo/client/utxo_client.h" | ||
|
||
#include <glog/logging.h> | ||
|
||
#include "application/utxo/proto/rpc.pb.h" | ||
|
||
namespace resdb { | ||
namespace utxo { | ||
|
||
UTXOClient::UTXOClient(const ResDBConfig& config) : ResDBUserClient(config) {} | ||
|
||
int UTXOClient::Transfer(const UTXO& utxo) { | ||
UTXORequest request; | ||
UTXOResponse response; | ||
*request.mutable_utxo() = utxo; | ||
|
||
int ret = SendRequest(request, &response); | ||
if (ret != 0 || response.ret() < 0) { | ||
return -1; | ||
} | ||
return response.ret(); | ||
} | ||
|
||
std::vector<UTXO> UTXOClient::GetList(int64_t end_id, int num) { | ||
UTXOQuery query; | ||
query.set_query_transaction(true); | ||
query.set_end_id(end_id); | ||
query.set_num(num); | ||
|
||
CustomQueryResponse response; | ||
|
||
int ret = SendRequest(query, Request::TYPE_CUSTOM_QUERY); | ||
if (ret) { | ||
LOG(ERROR) << "send request fail"; | ||
return std::vector<UTXO>(); | ||
} | ||
|
||
ret = RecvRawMessage(&response); | ||
if (ret) { | ||
LOG(ERROR) << "recv response fail"; | ||
return std::vector<UTXO>(); | ||
} | ||
|
||
UTXOQueryResponse utxo_response; | ||
utxo_response.ParseFromString(response.resp_str()); | ||
std::vector<UTXO> utxo_list; | ||
for (const auto utxo : utxo_response.utxos()) { | ||
utxo_list.push_back(utxo); | ||
} | ||
return utxo_list; | ||
} | ||
|
||
int64_t UTXOClient::GetWallet(const std::string& address) { | ||
UTXOQuery query; | ||
query.set_query_transaction(false); | ||
query.set_address(address); | ||
|
||
CustomQueryResponse response; | ||
|
||
int ret = SendRequest(query, Request::TYPE_CUSTOM_QUERY); | ||
if (ret) { | ||
LOG(ERROR) << "send request fail"; | ||
return -1; | ||
} | ||
|
||
ret = RecvRawMessage(&response); | ||
if (ret) { | ||
LOG(ERROR) << "recv response fail"; | ||
return -1; | ||
} | ||
|
||
UTXOQueryResponse utxo_response; | ||
utxo_response.ParseFromString(response.resp_str()); | ||
return utxo_response.value(); | ||
} | ||
|
||
} // namespace utxo | ||
} // namespace resdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2019-2022 ExpoLab, UC Davis | ||
* | ||
* Permission is hereby granted, free of charge, to any person | ||
* obtaining a copy of this software and associated documentation | ||
* files (the "Software"), to deal in the Software without | ||
* restriction, including without limitation the rights to use, | ||
* copy, modify, merge, publish, distribute, sublicense, and/or | ||
* sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "application/utxo/proto/utxo.pb.h" | ||
#include "client/resdb_user_client.h" | ||
|
||
namespace resdb { | ||
namespace utxo { | ||
|
||
class UTXOClient : public ResDBUserClient { | ||
public: | ||
UTXOClient(const ResDBConfig& config); | ||
|
||
int Transfer(const UTXO& utxo); | ||
|
||
std::vector<UTXO> GetList(int64_t end_id, int num); | ||
|
||
int64_t GetWallet(const std::string& address); | ||
}; | ||
|
||
} // namespace utxo | ||
} // namespace resdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("@rules_cc//cc:defs.bzl", "cc_proto_library") | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
|
||
proto_library( | ||
name = "utxo_proto", | ||
srcs = ["utxo.proto"], | ||
) | ||
|
||
cc_proto_library( | ||
name = "utxo_cc_proto", | ||
deps = [":utxo_proto"], | ||
) | ||
|
||
proto_library( | ||
name = "config_proto", | ||
srcs = ["config.proto"], | ||
deps = ["utxo_proto"], | ||
) | ||
|
||
cc_proto_library( | ||
name = "config_cc_proto", | ||
deps = [":config_proto"], | ||
) | ||
|
||
proto_library( | ||
name = "rpc_proto", | ||
srcs = ["rpc.proto"], | ||
deps = ["utxo_proto"], | ||
) | ||
|
||
cc_proto_library( | ||
name = "rpc_cc_proto", | ||
deps = [":rpc_proto"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
syntax = "proto3"; | ||
|
||
package resdb.utxo; | ||
|
||
import "application/utxo/proto/utxo.proto"; | ||
|
||
message GenesisUTXO { | ||
repeated UTXO transactions = 1; | ||
} | ||
|
||
message Config { | ||
GenesisUTXO genesis_transactions = 1; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
syntax = "proto3"; | ||
|
||
package resdb.utxo; | ||
|
||
import "application/utxo/proto/utxo.proto"; | ||
|
||
message UTXORequest { | ||
UTXO utxo = 1; | ||
} | ||
|
||
message UTXOResponse { | ||
int64 ret = 1; | ||
} | ||
|
||
message UTXOQuery { | ||
bool query_transaction = 1; | ||
int64 end_id = 2; | ||
int32 num = 3; | ||
string address = 4; | ||
} | ||
|
||
message UTXOQueryResponse { | ||
repeated UTXO utxos = 1; | ||
int64 value = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
syntax = "proto3"; | ||
|
||
package resdb.utxo; | ||
|
||
message UTXOIn { | ||
int64 prev_id = 1; | ||
int32 out_idx = 2; | ||
} | ||
|
||
message UTXOOut{ | ||
string address = 1; | ||
int64 value = 2; | ||
bool spent = 3; | ||
string pub_key = 4; | ||
} | ||
|
||
message UTXO { | ||
repeated UTXOIn in = 1; | ||
repeated UTXOOut out = 2; | ||
string sig = 3; // signed by the owner. | ||
string address = 4; | ||
int64 transaction_id = 5; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
cc_binary( | ||
name = "utxo_server", | ||
srcs = ["utxo_server.cpp"], | ||
deps = [ | ||
"//application/utils:server_factory", | ||
"//application/utxo/service:utxo_executor", | ||
"//config:resdb_config_utils", | ||
"//ordering/pbft:consensus_service_pbft", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
region : { | ||
replica_info : { | ||
id:1, | ||
ip:"127.0.0.1", | ||
port: 10001, | ||
}, | ||
replica_info : { | ||
id:2, | ||
ip:"127.0.0.1", | ||
port: 10002, | ||
}, | ||
replica_info : { | ||
id:3, | ||
ip:"127.0.0.1", | ||
port: 10003, | ||
}, | ||
replica_info : { | ||
id:4, | ||
ip:"127.0.0.1", | ||
port: 10004, | ||
}, | ||
region_id: 1, | ||
}, | ||
self_region_id:1, | ||
} | ||
|
||
|
Oops, something went wrong.