20#include <glog/logging.h>
21#include <google/protobuf/util/json_util.h>
27using google::protobuf::util::MessageToJsonString;
30using resdb::utxo::UTXO;
32using resdb::utxo::UTXOIn;
33using resdb::utxo::UTXOOut;
37 "<cmd> -c <config> -m <caller address> -n <contract name> -p <contact "
38 "path> -a <params> \n");
43 const std::string& address,
44 const std::vector<std::string>& to_address,
45 const std::vector<int64_t>& values,
46 const std::string& private_key,
47 const std::vector<std::string>& to_pub_key) {
48 if (private_key.empty() || to_pub_key.empty()) {
49 printf(
"no private key or public key\n");
54 UTXOIn* in = utxo.add_in();
55 in->set_prev_id(transaction_id);
57 nonce += transaction_id;
59 for (
size_t i = 0; i < to_address.size(); ++i) {
60 UTXOOut* out = utxo.add_out();
61 out->set_address(to_address[i]);
62 out->set_value(values[i]);
63 out->set_pub_key(to_pub_key[i]);
64 utxo.set_address(address);
66 private_key, address + std::to_string(nonce)));
67 LOG(ERROR) <<
"transfer from:" << address <<
" to:" << to_address[i]
68 <<
" value:" << values[i];
71 auto output = client->
Transfer(utxo);
72 LOG(ERROR) <<
"execute result:\n" << output;
76 std::vector<UTXO> list = client->
GetList(end_id, num);
77 LOG(ERROR) <<
"get utxo:";
78 for (
const UTXO& utxo : list) {
80 MessageToJsonString(utxo, &str);
81 printf(
"%s\n", str.c_str());
87 LOG(ERROR) <<
"address:" << address <<
" get wallet value:" << ret;
91 std::vector<std::string> ret;
93 size_t pos = str.find(
",");
94 if (pos == std::string::npos) {
98 ret.push_back(str.substr(0, pos));
99 str = str.substr(pos + 1);
105 std::vector<int64_t> ret;
107 size_t pos = str.find(
",");
108 if (pos == std::string::npos) {
109 ret.push_back(strtoull(str.c_str(), NULL, 10));
112 ret.push_back(strtoull(str.substr(0, pos).c_str(), NULL, 10));
113 str = str.substr(pos + 1);
118int main(
int argc,
char** argv) {
120 printf(
"-d <cmd> -c [config]\n");
124 int64_t transaction_id = 0;
125 std::string address, to_address, params, contract_address, func_name,
126 private_key, to_pub_key;
132 std::string client_config_file;
133 while ((c = getopt(argc, argv,
"c:d:t:x:m:h:e:v:n:p:b:")) != -1) {
136 client_config_file = optarg;
145 transaction_id = strtoull(optarg, NULL, 10);
151 end_id = strtoull(optarg, NULL, 10);
154 num = strtoull(optarg, NULL, 10);
160 private_key = optarg;
171 ResDBConfig config = GenerateResDBConfig(client_config_file);
174 if (cmd ==
"transfer") {
177 }
else if (cmd ==
"list") {
179 }
else if (cmd ==
"wallet") {
void SetClientTimeoutMs(int timeout_ms)
std::vector< UTXO > GetList(int64_t end_id, int num)
int Transfer(const UTXO &utxo)
int64_t GetWallet(const std::string &address)
std::string ECDSASignString(const std::string &private_key, const std::string &message)
std::unique_ptr< ResDBConfig > GenerateResDBConfig(const std::string &config_file, const std::string &private_key_file, const std::string &cert_file, std::optional< ReplicaInfo > self_info, std::optional< ConfigGenFunc > gen_func)