MCPcopy Create free account
hub / github.com/QuipNetwork/cpp-sdk / depositToWinternitz

Method depositToWinternitz

src/quip_factory.cpp:34–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32 ~Impl() { curl_global_cleanup(); }
33
34 Address depositToWinternitz(const VaultId &vaultId, const Address &to,
35 const WinternitzAddress &pqTo,
36 const PrivateKey &private_key,
37 const Amount &amount) {
38 // Encode the function call using the ABI encoding script
39 nlohmann::json params = {
40 toHex(vaultId),
41 to,
42 {toHex(pqTo.publicSeed), toHex(pqTo.publicKeyHash)}};
43
44 std::string params_json = params.dump();
45 std::string data = abiEncode("depositToWinternitz", abi_json, params_json);
46
47 // Get the nonce for the account
48 const char *env_private_key = std::getenv("PRIVATE_KEY");
49 if (!env_private_key) {
50 throw std::runtime_error("PRIVATE_KEY environment variable not set");
51 }
52
53 // Get account address from private key using ethers.js
54 std::string command =
55 std::string("cd ./ethereum-sdk && node -e \"console.log(new "
56 "(require('ethers').Wallet)('") +
57 env_private_key + "').address)\"";
58
59 FILE *pipe = popen(command.c_str(), "r");
60 if (!pipe) {
61 throw std::runtime_error("Failed to execute ethers.js command");
62 }
63
64 std::string from_address;
65 char buffer[128];
66 while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
67 from_address += buffer;
68 }
69 int status = pclose(pipe);
70 if (status != 0) {
71 throw std::runtime_error("ethers.js command failed: " + from_address);
72 }
73
74 // Remove newline
75 if (!from_address.empty() &&
76 from_address[from_address.length() - 1] == '\n') {
77 from_address.erase(from_address.length() - 1);
78 }
79
80 // Get nonce
81 nlohmann::json nonce_params = {from_address, "latest"};
82 auto nonce_response = sendJsonRpc("eth_getTransactionCount", nonce_params);
83 std::string nonce_hex = nonce_response["result"];
84 uint64_t nonce = std::stoull(nonce_hex.substr(2), nullptr, 16);
85
86 // Get gas price and convert to EIP-1559 format
87 auto gas_price_response =
88 sendJsonRpc("eth_gasPrice", nlohmann::json::array());
89 std::string gas_price_hex = gas_price_response["result"];
90 uint64_t gas_price = std::stoull(gas_price_hex.substr(2), nullptr, 16);
91

Callers

nothing calls this directly

Calls 4

toHexFunction · 0.85
abiEncodeFunction · 0.85
ensure0xFunction · 0.85
getChainIdFunction · 0.85

Tested by

no test coverage detected