From c4e28df46f368eaca8cffe66443a0ae88fbdd098 Mon Sep 17 00:00:00 2001 From: DcruBro Date: Mon, 27 Jul 2026 12:22:43 +0200 Subject: [PATCH] Fix txpooldetail command not working, add missing commands to list, fix connect command for ipv6 --- include/utils.h | 43 +++++++++++++++++++++++++++++++++++++++++++ src/main.c | 23 ++++++++++++----------- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/include/utils.h b/include/utils.h index 35747ee..efd5498 100644 --- a/include/utils.h +++ b/include/utils.h @@ -301,6 +301,49 @@ static inline bool IsValidIPv4(const char* ip) { return octetCount == 4; } +static inline bool IsValidIPv6(const char* ip) { + if (!ip || *ip == '\0') { + return false; + } + + int colonCount = 0; + const char* p = ip; + + while (*p != '\0') { + if (colonCount > 7) { + return false; + } + + int hexDigits = 0; + while ((*p >= '0' && *p <= '9') || + (*p >= 'a' && *p <= 'f') || + (*p >= 'A' && *p <= 'F')) { + ++hexDigits; + if (hexDigits > 4) { + return false; + } + ++p; + } + + if (hexDigits == 0) { + return false; + } + + ++colonCount; + if (colonCount < 8) { + if (*p != ':') { + return false; + } + ++p; + if (*p == '\0') { + return false; + } + } + } + + return colonCount == 8; +} + static inline void Uint256ToDecimal(const uint256_t* value, char* out, size_t outSize) { if (!value || !out || outSize == 0) { return; diff --git a/src/main.c b/src/main.c index 7c235b1..7e6a101 100644 --- a/src/main.c +++ b/src/main.c @@ -839,7 +839,7 @@ int main(int argc, char* argv[]) { char supplyStr[80]; Uint256ToDecimal(¤tSupply, supplyStr, sizeof(supplyStr)); printf("Current chain has %zu blocks, total supply %s\n", Chain_Size(chain), supplyStr); - printf("Commands: mine , send
[fee], txpooldetail , balance [address], connect , sync (requires nodes), flushchain, fullverify, blockdetail , wipechain, genaddr, exit\n"); + printf("Commands: mine , send
[fee], txpooldetail , balance [address], connect [port], peers, sync (requires nodes), flushchain, fullverify, blockdetail , wipechain, genaddr, exit\n"); char line[1024]; while (true) { @@ -1307,10 +1307,13 @@ int main(int argc, char* argv[]) { // Re-evaluate loop condition: continue while local < peerHeight if ((uint64_t)Chain_Size(chain) >= peerHeight) break; continue; + } + + // Sync loop finished with this peer; release the pin taken by Node_GetBestOutboundPeer so + // the reaper may reclaim the slot if the peer has since disconnected. + TcpConnection_Unpin(peerConn); + continue; } - // Sync loop finished with this peer; release the pin taken by Node_GetBestOutboundPeer so - // the reaper may reclaim the slot if the peer has since disconnected. - TcpConnection_Unpin(peerConn); if (strcmp(cmd, "txpooldetail") == 0) { char* hashStr = strtok(NULL, " \t"); @@ -1352,8 +1355,6 @@ int main(int argc, char* argv[]) { continue; } - } - if (strcmp(cmd, "blockdetail") == 0) { char* blockNumberStr = strtok(NULL, " \t"); char* extra = strtok(NULL, " \t"); @@ -1435,12 +1436,12 @@ int main(int argc, char* argv[]) { char* portStr = strtok(NULL, " \t"); char* extra = strtok(NULL, " \t"); if (!ipStr || extra) { - printf("usage: connect [port]\n"); + printf("usage: connect [port]\n"); continue; } - if (!IsValidIPv4(ipStr)) { - printf("invalid IPv4 address\n"); + if (!IsValidIPv4(ipStr) && !IsValidIPv6(ipStr)) { + printf("invalid IPv4 or IPv6 address\n"); continue; } @@ -1454,7 +1455,7 @@ int main(int argc, char* argv[]) { } peerPort = (unsigned short)parsedPort; if (strtok(NULL, " \t")) { - printf("usage: connect [port]\n"); + printf("usage: connect [port]\n"); continue; } } @@ -1554,7 +1555,7 @@ int main(int argc, char* argv[]) { break; } - printf("Unknown command. Available: mine, send, balance, connect, flushchain, fullverify, blockdetail, wipechain, genaddr, exit\n"); + printf("Unknown command. Available: mine, send, sync, txpooldetail, blockdetail, balance, connect, peers, flushchain, fullverify, wipechain, genaddr, exit\n"); } (void)FlushChainAndSheet(chain, chainDataDir, currentSupply, currentReward);