'balance all' command
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <khash/khash.h>
|
||||
#include <crypto/crypto.h>
|
||||
#include <string.h>
|
||||
#include <utils.h>
|
||||
#include <uint256.h>
|
||||
|
||||
typedef struct {
|
||||
|
||||
16
include/utils.h
Normal file
16
include/utils.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
static inline void AddressToHexString(const uint8_t address[32], char out[65]) {
|
||||
if (!address || !out) {
|
||||
return;
|
||||
}
|
||||
to_hex(address, out);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -90,7 +90,6 @@ void BalanceSheet_Print() {
|
||||
|
||||
// Iterate through every entry
|
||||
khiter_t k;
|
||||
size_t iter = 0;
|
||||
for (k = kh_begin(sheetMap); k != kh_end(sheetMap); ++k) {
|
||||
if (kh_exist(sheetMap, k)) {
|
||||
key32_t key = kh_key(sheetMap, k);
|
||||
@@ -99,12 +98,13 @@ void BalanceSheet_Print() {
|
||||
char balanceStr[80];
|
||||
uint256_serialize(&val.balance, balanceStr);
|
||||
|
||||
printf("Sheet entry %llu: mapkey=%02x%02x%02x%02x... address=%02x%02x%02x%02x... balance=%s\n",
|
||||
(unsigned long long)(iter),
|
||||
key.bytes[0], key.bytes[1], key.bytes[2], key.bytes[3],
|
||||
val.address[0], val.address[1], val.address[2], val.address[3],
|
||||
balanceStr,
|
||||
iter++);
|
||||
char addrHex[65];
|
||||
AddressToHexString(key.bytes, addrHex);
|
||||
|
||||
// Print full address
|
||||
printf("Address %s: balance=%s pebble(s)\n",
|
||||
addrHex,
|
||||
balanceStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
14
src/main.c
14
src/main.c
@@ -11,6 +11,7 @@
|
||||
#include <signal.h>
|
||||
#include <balance_sheet.h>
|
||||
|
||||
|
||||
#include <constants.h>
|
||||
#include <autolykos2/autolykos2.h>
|
||||
|
||||
@@ -181,13 +182,6 @@ static bool ParseHexAddress32(const char* in, uint8_t outAddress[32]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static void AddressToHexString(const uint8_t address[32], char out[65]) {
|
||||
if (!address || !out) {
|
||||
return;
|
||||
}
|
||||
to_hex(address, out);
|
||||
}
|
||||
|
||||
static bool FlushChainAndSheet(blockchain_t* chain,
|
||||
const char* chainDataDir,
|
||||
uint256_t currentSupply,
|
||||
@@ -653,6 +647,12 @@ int main(int argc, char* argv[]) {
|
||||
uint8_t* effectiveAddress = minerAddress;
|
||||
|
||||
if (addressStr) {
|
||||
if (strcmp(addressStr, "all") == 0) {
|
||||
printf("All balances:\n");
|
||||
BalanceSheet_Print();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ParseHexAddress32(addressStr, queryAddress)) {
|
||||
printf("invalid address: expected 64 hex chars (optionally prefixed with 0x)\n");
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user