| 208 | } |
| 209 | |
| 210 | bool executeWithWinternitzValue(const WinternitzAddress &winternitz_address, |
| 211 | const Signature &pq_sig, |
| 212 | const Address &target_address, |
| 213 | const std::vector<uint8_t> &opdata, |
| 214 | Amount eth_value) { |
| 215 | try { |
| 216 | // Get private key from environment |
| 217 | const char *env_private_key = std::getenv("PRIVATE_KEY"); |
| 218 | if (!env_private_key) { |
| 219 | throw std::runtime_error("PRIVATE_KEY environment variable not set"); |
| 220 | } |
| 221 | PrivateKey private_key = env_private_key; |
| 222 | |
| 223 | // Convert C++ types to the format expected by the ABI encoder |
| 224 | nlohmann::json nextPqOwner = { |
| 225 | {"publicSeed", toHex(winternitz_address.publicSeed)}, |
| 226 | {"publicKeyHash", toHex(winternitz_address.publicKeyHash)}}; |
| 227 | |
| 228 | // Convert signature elements to hex strings array (ABI expects bytes32[67]) |
| 229 | nlohmann::json elements = nlohmann::json::array(); |
| 230 | for (const auto &element : pq_sig) { |
| 231 | elements.push_back(toHex(element)); |
| 232 | } |
| 233 | nlohmann::json pqSig = {{"elements", elements}}; |
| 234 | |
| 235 | // Convert opdata to hex string |
| 236 | std::string opdata_hex = toHex(opdata); |
| 237 | |
| 238 | // Create parameters for ABI encoding |
| 239 | nlohmann::json params = {nextPqOwner, pqSig, target_address, opdata_hex}; |
| 240 | |
| 241 | // Encode the function call using shared abiEncode function |
| 242 | std::string params_json = params.dump(); |
| 243 | std::string data = |
| 244 | abiEncode("executeWithWinternitz", abi_json, params_json); |
| 245 | |
| 246 | // Get the execute fee (use passed value) |
| 247 | Amount executeFee = getExecuteFee(); |
| 248 | Amount totalValue = eth_value; // Use the passed ETH value instead of just the fee |
| 249 | |
| 250 | // Get account address from private key |
| 251 | std::string from_address = deriveClassicalPublicKey(private_key); |
| 252 | |
| 253 | // Get nonce |
| 254 | nlohmann::json nonce_params = {from_address, "latest"}; |
| 255 | auto nonce_response = |
| 256 | sendJsonRpc("eth_getTransactionCount", nonce_params); |
| 257 | std::string nonce_hex = nonce_response["result"]; |
| 258 | uint64_t nonce = std::stoull(nonce_hex.substr(2), nullptr, 16); |
| 259 | |
| 260 | // Get gas price and convert to EIP-1559 format |
| 261 | auto gas_price_response = |
| 262 | sendJsonRpc("eth_gasPrice", nlohmann::json::array()); |
| 263 | std::string gas_price_hex = gas_price_response["result"]; |
| 264 | uint64_t gas_price = std::stoull(gas_price_hex.substr(2), nullptr, 16); |
| 265 | |
| 266 | uint64_t max_fee_per_gas = gas_price * 2; |
| 267 | uint64_t max_priority_fee_per_gas = gas_price; |
nothing calls this directly
no test coverage detected