Fix txpooldetail command not working, add missing commands to list, fix connect command for ipv6
This commit is contained in:
@@ -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;
|
||||
|
||||
+9
-8
@@ -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 <x>, send <address> <amount> [fee], txpooldetail <txhash>, balance [address], connect <ipv4>, sync (requires nodes), flushchain, fullverify, blockdetail <block number>, wipechain, genaddr, exit\n");
|
||||
printf("Commands: mine <x>, send <address> <amount> [fee], txpooldetail <txhash>, balance [address], connect <ipv4> [port], peers, sync (requires nodes), flushchain, fullverify, blockdetail <block number>, wipechain, genaddr, exit\n");
|
||||
|
||||
char line[1024];
|
||||
while (true) {
|
||||
@@ -1308,9 +1308,12 @@ int main(int argc, char* argv[]) {
|
||||
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;
|
||||
}
|
||||
|
||||
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 <ipv4> [port]\n");
|
||||
printf("usage: connect <ipv4/ipv6> [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 <ipv4> [port]\n");
|
||||
printf("usage: connect <ipv4/ipv6> [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);
|
||||
|
||||
Reference in New Issue
Block a user