From b3c1a562690ce34f2c9dd668a5b18da2255afcb1 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 20 Aug 2024 13:23:28 -0300 Subject: nip13: remove section about pow prefix querying. prefix searching was removed from the spec. --- 13.md | 10 ---------- 1 file changed, 10 deletions(-) (limited to '13.md') diff --git a/13.md b/13.md index 99289c2..0900d2d 100644 --- a/13.md +++ b/13.md @@ -103,16 +103,6 @@ function countLeadingZeroes(hex) { } ``` -Querying relays for PoW notes ------------------------------ - -If relays allow searching on prefixes, you can use this as a way to filter notes of a certain difficulty: - -``` -$ echo '["REQ", "subid", {"ids": ["000000000"]}]' | websocat wss://some-relay.com | jq -c '.[2]' -{"id":"000000000121637feeb68a06c8fa7abd25774bdedfa9b6ef648386fb3b70c387", ...} -``` - Delegated Proof of Work ----------------------- -- cgit v1.2.3 From e7eb776288b424e8cd43080b33b21506942f91e0 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Mon, 9 Sep 2024 12:38:51 -0700 Subject: Revert example code update --- 13.md | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) (limited to '13.md') diff --git a/13.md b/13.md index 0900d2d..cf5b1ac 100644 --- a/13.md +++ b/13.md @@ -48,37 +48,30 @@ Validating Here is some reference C code for calculating the difficulty (aka number of leading zero bits) in a nostr event id: ```c -#include -#include -#include - -int countLeadingZeroes(const char *hex) { - int count = 0; - - for (int i = 0; i < strlen(hex); i++) { - int nibble = (int)strtol((char[]){hex[i], '\0'}, NULL, 16); - if (nibble == 0) { - count += 4; - } else { - count += __builtin_clz(nibble) - 28; - break; - } - } +int zero_bits(unsigned char b) +{ + int n = 0; - return count; -} + if (b == 0) + return 8; -int main(int argc, char *argv[]) { - if (argc != 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); - return 1; - } + while (b >>= 1) + n++; - const char *hex_string = argv[1]; - int result = countLeadingZeroes(hex_string); - printf("Leading zeroes in hex string %s: %d\n", hex_string, result); + return 7-n; +} - return 0; +/* find the number of leading zero bits in a hash */ +int count_leading_zero_bits(unsigned char *hash) +{ + int bits, total, i; + for (i = 0, total = 0; i < 32; i++) { + bits = zero_bits(hash[i]); + total += bits; + if (bits != 8) + break; + } + return total; } ``` -- cgit v1.2.3