|
| 1 | +/** |
| 2 | + * nimbus_verified_proxy |
| 3 | + * Copyright (c) 2025 Status Research & Development GmbH |
| 4 | + * Licensed and distributed under either of |
| 5 | + * * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). |
| 6 | + * * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). |
| 7 | + * at your option. This file may not be copied, modified, or distributed except according to those terms. |
| 8 | + */ |
| 9 | + |
| 10 | +#include "./verifproxy.h" |
| 11 | +#include <stdio.h> |
| 12 | +#include <stdlib.h> |
| 13 | +#include <string.h> |
| 14 | +#include <unistd.h> |
| 15 | +#include <time.h> |
| 16 | +#include <stdbool.h> |
| 17 | + |
| 18 | +char filterId[67]; |
| 19 | +bool filterCreated = false; |
| 20 | + |
| 21 | +void onBlockNumber(Context *ctx, int status, char *res) { |
| 22 | + printf("Blocknumber: %s\n", res); |
| 23 | + freeResponse(res); |
| 24 | +} |
| 25 | + |
| 26 | +void onStart(Context *ctx, int status, char *res) { |
| 27 | + if (status < 0){ // callback onStart is called only for errors |
| 28 | + printf("Problem while starting verified proxy\n"); |
| 29 | + stopVerifProxy(ctx); |
| 30 | + freeContext(ctx); |
| 31 | + exit(EXIT_FAILURE); |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +void onStorage(Context *ctx, int status, char *res) { |
| 36 | + printf("Storage: %s\n", res); |
| 37 | + freeResponse(res); |
| 38 | +} |
| 39 | + |
| 40 | +void onBalance(Context *ctx, int status, char *res) { |
| 41 | + printf("Balance: %s\n", res); |
| 42 | + freeResponse(res); |
| 43 | +} |
| 44 | + |
| 45 | +void onNonce(Context *ctx, int status, char *res) { |
| 46 | + printf("Nonce: %s\n", res); |
| 47 | + freeResponse(res); |
| 48 | +} |
| 49 | + |
| 50 | +void onCode(Context *ctx, int status, char *res) { |
| 51 | + printf("Code: %s\n", res); |
| 52 | + freeResponse(res); |
| 53 | +} |
| 54 | + |
| 55 | +void genericCallback(Context *ctx, int status, char *res) { |
| 56 | + printf("Status: %d\n", status); |
| 57 | + if (status < 0) printf("Error: %s\n", res); |
| 58 | + freeResponse(res); |
| 59 | +} |
| 60 | + |
| 61 | +void onFilterCreate(Context *ctx, int status, char *res) { |
| 62 | + if (status == RET_SUCCESS) { |
| 63 | + strncpy(filterId, &res[1], strlen(res) - 2); // remove quotes |
| 64 | + filterId[strlen(res) - 2] = '\0'; |
| 65 | + filterCreated = true; |
| 66 | + } |
| 67 | + freeResponse(res); |
| 68 | +} |
| 69 | + |
| 70 | +void onCallComplete(Context *ctx, int status, char *res) { |
| 71 | + if (status == RET_SUCCESS) { |
| 72 | + printf("Call Complete: %s\n", res); |
| 73 | + } else { |
| 74 | + printf("Call Error: %s\n", res); |
| 75 | + } |
| 76 | + freeResponse(res); |
| 77 | +} |
| 78 | + |
| 79 | +void onLogs(Context *ctx, int status, char *res) { |
| 80 | + if (status == RET_SUCCESS) { |
| 81 | + printf("Logs fetch successful\n"); |
| 82 | + } else { |
| 83 | + printf("Logs Fetch Error: %s\n", res); |
| 84 | + } |
| 85 | + freeResponse(res); |
| 86 | +} |
| 87 | + |
| 88 | +void makeCalls(Context *ctx) { |
| 89 | + char *BLOCK_HASH = "0xc62fa4cbdd48175b1171d8b7cede250ac1bea47ace4d19db344b922cd1e63111"; |
| 90 | + char *TX_HASH = "0xbbcd3d9bc70874c03453caa19fd91239abb0eef84dc61ca33e2110df81df330c"; |
| 91 | + char *CALL_ARGS = "{\"to\": \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\",\"data\": \"0x70a08231000000000000000000000000De5ae63A348C4d63343C8E20Fb6286909418c8A4\"}"; |
| 92 | + char *FILTER_OPTIONS = "{\"fromBlock\": \"latest\", \"toBlock\": \"latest\", \"topics\":[\"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\"]}"; |
| 93 | + |
| 94 | + eth_blockNumber(ctx, onBlockNumber); |
| 95 | + eth_getBalance(ctx, "0x954a86C613fd1fBaC9C7A43a071A68254C75E4AC", "latest", onBalance); |
| 96 | + eth_getStorageAt(ctx, "0x954a86C613fd1fBaC9C7A43a071A68254C75E4AC", "0x0", "latest", onStorage); |
| 97 | + eth_getTransactionCount(ctx, "0x954a86C613fd1fBaC9C7A43a071A68254C75E4AC", "latest", onNonce); |
| 98 | + eth_getCode(ctx, "0x954a86C613fd1fBaC9C7A43a071A68254C75E4AC", "latest", onCode); |
| 99 | + |
| 100 | + /* -------- Blocks & Uncles -------- */ |
| 101 | + |
| 102 | + eth_getBlockByHash(ctx, BLOCK_HASH, false, genericCallback); |
| 103 | + eth_getBlockByNumber(ctx, "latest", false, genericCallback); |
| 104 | + eth_getUncleCountByBlockNumber(ctx, "latest", genericCallback); |
| 105 | + eth_getUncleCountByBlockHash(ctx, BLOCK_HASH, genericCallback); |
| 106 | + |
| 107 | + eth_getBlockTransactionCountByNumber(ctx, "latest", genericCallback); |
| 108 | + eth_getBlockTransactionCountByHash(ctx, BLOCK_HASH, genericCallback); |
| 109 | + |
| 110 | + /* -------- Transactions -------- */ |
| 111 | + eth_getTransactionByBlockNumberAndIndex(ctx, "latest", 0ULL, genericCallback); |
| 112 | + eth_getTransactionByBlockHashAndIndex(ctx, BLOCK_HASH, 0ULL, genericCallback); |
| 113 | + |
| 114 | + eth_getTransactionByHash(ctx, TX_HASH, genericCallback); |
| 115 | + eth_getTransactionReceipt(ctx, TX_HASH, genericCallback); |
| 116 | + |
| 117 | + eth_getBlockReceipts(ctx, "latest", genericCallback); |
| 118 | + |
| 119 | + /* -------- Calls, Access Lists, Gas Estimation -------- */ |
| 120 | + eth_call(ctx, CALL_ARGS, "latest", true, onCallComplete); |
| 121 | + eth_createAccessList(ctx, CALL_ARGS, "latest", false, onCallComplete); |
| 122 | + eth_estimateGas(ctx, CALL_ARGS, "latest", false, onCallComplete); |
| 123 | + |
| 124 | + /* -------- Logs & Filters -------- */ |
| 125 | + eth_getLogs(ctx, FILTER_OPTIONS, onLogs); |
| 126 | + if (filterCreated) { |
| 127 | + eth_getFilterLogs(ctx, filterId, onLogs); |
| 128 | + eth_getFilterChanges(ctx, filterId, onLogs); |
| 129 | + } else { |
| 130 | + eth_newFilter(ctx, FILTER_OPTIONS, onFilterCreate); |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +int main() { |
| 135 | + NimMain(); |
| 136 | + |
| 137 | + char* jsonConfig = |
| 138 | + "{" |
| 139 | + "\"eth2Network\": \"mainnet\"," |
| 140 | + "\"trustedBlockRoot\": \"0x2558d82e8b29c4151a0683e4f9d480d229d84b27b51a976f56722e014227e723\"," |
| 141 | + "\"backendUrl\": \"https://eth.blockrazor.xyz\"," |
| 142 | + "\"beaconApiUrls\": \"http://testing.mainnet.beacon-api.nimbus.team,http://www.lightclientdata.org\"," |
| 143 | + "\"logLevel\": \"FATAL\"," |
| 144 | + "\"logStdout\": \"None\"" |
| 145 | + "}"; |
| 146 | + |
| 147 | + Context *ctx = startVerifProxy(jsonConfig, onStart); |
| 148 | + |
| 149 | + time_t start = time(NULL); |
| 150 | + |
| 151 | + makeCalls(ctx); |
| 152 | + |
| 153 | + while(true) { |
| 154 | + if ((time(NULL) - start) > 12) { //all 24 methods should return |
| 155 | + printf("\n\n Executing all eth api methods\n\n"); |
| 156 | + makeCalls(ctx); |
| 157 | + start = time(NULL); |
| 158 | + } |
| 159 | + processVerifProxyTasks(ctx); |
| 160 | + } |
| 161 | + printf("it is here and this is the problem"); |
| 162 | + stopVerifProxy(ctx); |
| 163 | + freeContext(ctx); |
| 164 | +} |
0 commit comments