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

Function abiEncode

src/common.cpp:13–60  ·  view source on GitHub ↗

Shared ABI encoding function implementation

Source from the content-addressed store, hash-verified

11
12// Shared ABI encoding function implementation
13std::string abiEncode(const std::string &function_name,
14 const std::string &abi_json,
15 const std::string &params_json) {
16 // Escape quotes in the JSON strings for shell command
17 std::string escaped_abi = abi_json;
18 std::string escaped_params = params_json;
19
20 // Replace " with \" for shell safety
21 size_t pos = 0;
22 while ((pos = escaped_abi.find("\"", pos)) != std::string::npos) {
23 escaped_abi.replace(pos, 1, "\\\"");
24 pos += 2;
25 }
26 pos = 0;
27 while ((pos = escaped_params.find("\"", pos)) != std::string::npos) {
28 escaped_params.replace(pos, 1, "\\\"");
29 pos += 2;
30 }
31
32 std::string command =
33 "npx ts-node " + std::string(getenv("PWD") ? getenv("PWD") : ".") +
34 "/ethereum-sdk/scripts/abiEncode.ts \"" + escaped_abi + "\" \"" +
35 function_name + "\" \"" + escaped_params + "\"";
36
37 FILE *pipe = popen(command.c_str(), "r");
38 if (!pipe) {
39 throw std::runtime_error("Failed to execute ABI encoding script");
40 }
41
42 std::string result;
43 char buffer[128];
44 while (fgets(buffer, sizeof(buffer), pipe) != nullptr) {
45 result += buffer;
46 }
47
48 int status = pclose(pipe);
49 if (status != 0) {
50 throw std::runtime_error("ABI encoding script failed with status " +
51 std::to_string(status));
52 }
53
54 // Remove trailing newline
55 if (!result.empty() && result.back() == '\n') {
56 result.pop_back();
57 }
58
59 return result;
60}
61
62// Helper function for curl write callback
63static size_t WriteCallback(void *contents, size_t size, size_t nmemb,

Callers 10

changePqOwnerMethod · 0.85
getPqOwnerMethod · 0.85
depositToWinternitzMethod · 0.85
getQuipWalletAddressMethod · 0.85
getCreationFeeMethod · 0.85
getTransferFeeMethod · 0.85
getExecuteFeeMethod · 0.85
getVaultIdMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected