From fa0ba1f74fa1a5746990d64f30409b0a31f5b753 Mon Sep 17 00:00:00 2001 From: cjcchen Date: Thu, 9 Nov 2023 22:04:12 +0000 Subject: [PATCH 1/2] support transfer to multi address --- .../utxo/service_tools/start_utxo_service.sh | 2 +- .../wallet_tool/cpp/utxo_client_tools.cpp | 63 ++++++++++++++----- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/service/tools/utxo/service_tools/start_utxo_service.sh b/service/tools/utxo/service_tools/start_utxo_service.sh index c0ffc9d32..75b394f37 100755 --- a/service/tools/utxo/service_tools/start_utxo_service.sh +++ b/service/tools/utxo/service_tools/start_utxo_service.sh @@ -1,4 +1,4 @@ -killall -9 utxo_server +killall -9 utxo_service SERVER_PATH=./bazel-bin/service/utxo/utxo_service SERVER_CONFIG=service/tools/config/server/server.config diff --git a/service/tools/utxo/wallet_tool/cpp/utxo_client_tools.cpp b/service/tools/utxo/wallet_tool/cpp/utxo_client_tools.cpp index 207b9233c..e98344e28 100644 --- a/service/tools/utxo/wallet_tool/cpp/utxo_client_tools.cpp +++ b/service/tools/utxo/wallet_tool/cpp/utxo_client_tools.cpp @@ -46,9 +46,10 @@ void ShowUsage() { } void Transfer(UTXOClient* client, int64_t transaction_id, - const std::string& address, const std::string& to_address, - const int value, const std::string& private_key, - const std::string& to_pub_key) { + const std::string& address, + const std::vector& to_address, + const std::vector& values, const std::string& private_key, + const std::vector& to_pub_key) { if (private_key.empty() || to_pub_key.empty()) { printf("no private key or public key\n"); return; @@ -60,13 +61,16 @@ void Transfer(UTXOClient* client, int64_t transaction_id, in->set_out_idx(0); nonce += transaction_id; - UTXOOut* out = utxo.add_out(); - out->set_address(to_address); - out->set_value(value); - out->set_pub_key(to_pub_key); - utxo.set_address(address); - utxo.set_sig(resdb::utils::ECDSASignString(private_key, - address + std::to_string(nonce))); + for(int i = 0; i < to_address.size();++i){ + UTXOOut* out = utxo.add_out(); + out->set_address(to_address[i]); + out->set_value(values[i]); + out->set_pub_key(to_pub_key[i]); + utxo.set_address(address); + utxo.set_sig(resdb::utils::ECDSASignString(private_key, + address + std::to_string(nonce))); + LOG(ERROR)<<"transfer from:"<Transfer(utxo); LOG(ERROR) << "execute result:\n" << output; @@ -87,6 +91,35 @@ void GetWallet(UTXOClient* client, const std::string& address) { LOG(ERROR) << "address:" << address << " get wallet value:" << ret; } +std::vector ParseString(std::string str){ + std::vector ret; + while(true){ + size_t pos = str.find(","); + if(pos == std::string::npos){ + ret.push_back(str); + break; + } + ret.push_back(str.substr(0,pos)); + str = str.substr(pos+1); + } + return ret; +} + +std::vector ParseValue(std::string str){ + std::vector ret; + while(true){ + size_t pos = str.find(","); + if(pos == std::string::npos){ + ret.push_back(strtoull(str.c_str(), NULL, 10)); + break; + } + ret.push_back(strtoull(str.substr(0,pos).c_str(), NULL, 10)); + str = str.substr(pos+1); + } + return ret; +} + + int main(int argc, char** argv) { if (argc < 3) { printf("-d -c [config]\n"); @@ -100,7 +133,7 @@ int main(int argc, char** argv) { int num = 10; int c; std::string cmd; - int64_t value = 0; + std::string value; std::string client_config_file; while ((c = getopt(argc, argv, "c:d:t:x:m:h:e:v:n:p:b:")) != -1) { switch (c) { @@ -126,7 +159,7 @@ int main(int argc, char** argv) { num = strtoull(optarg, NULL, 10); break; case 'v': - value = strtoull(optarg, NULL, 10); + value = optarg; break; case 'p': private_key = optarg; @@ -142,11 +175,11 @@ int main(int argc, char** argv) { ResDBConfig config = GenerateResDBConfig(client_config_file); config.SetClientTimeoutMs(100000); - + printf("???\n"); UTXOClient client(config); if (cmd == "transfer") { - Transfer(&client, transaction_id, address, to_address, value, private_key, - to_pub_key); + Transfer(&client, transaction_id, address, ParseString(to_address), ParseValue(value), private_key, + ParseString(to_pub_key)); } else if (cmd == "list") { GetList(&client, end_id, num); } else if (cmd == "wallet") { From 04870ea62738ede3741329dcd86acc2ff6f86f58 Mon Sep 17 00:00:00 2001 From: cjcchen Date: Thu, 9 Nov 2023 22:05:51 +0000 Subject: [PATCH 2/2] end --- service/tools/utxo/wallet_tool/cpp/utxo_client_tools.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/service/tools/utxo/wallet_tool/cpp/utxo_client_tools.cpp b/service/tools/utxo/wallet_tool/cpp/utxo_client_tools.cpp index e98344e28..f6adf0628 100644 --- a/service/tools/utxo/wallet_tool/cpp/utxo_client_tools.cpp +++ b/service/tools/utxo/wallet_tool/cpp/utxo_client_tools.cpp @@ -175,7 +175,6 @@ int main(int argc, char** argv) { ResDBConfig config = GenerateResDBConfig(client_config_file); config.SetClientTimeoutMs(100000); - printf("???\n"); UTXOClient client(config); if (cmd == "transfer") { Transfer(&client, transaction_id, address, ParseString(to_address), ParseValue(value), private_key,