Comments (2)
Pierre-Marie [email protected] writes:
Hello,
This is just a matter of reversing the array, but the comment is a bit misleading
message open_anchor { // Transaction ID of anchor. required sha256_hash txid = 1;
See https://github.com/ElementsProject/lightning/blob/master/bitcoin/tx.c#L232
We always encode hashes as big-endian. That's the normal encoding for SHA.
Unfortunately, bitcoind uses little-endian for transaction hashes for
reasons unknown. It uses big-endian for block hashes though!
It's wrong. I keep this script around to fix it up to paste into block:
( cat > hex_rev.c; chmod a+x hex_rev.c )
// 2>/dev/null; set -e; OUT=/tmp/basename $0 .c
; if [ ! -f "$OUT" ] || [ "$OUT" -ot "$0" ]; then gcc -Wall -g -o "$OUT".$$ $0 && mv "$OUT".$$ "$OUT"; fi; exec "$OUT" "$@"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <err.h>
#include <stdbool.h>
static char hexchar(unsigned int x)
{
if (x < 10)
return '0' + x;
else
return 'a' - 10 + x;
}
static void print_hex(const unsigned char *val, size_t len)
{
size_t i;
for (i = 0; i < len; i++)
printf("%c%c", hexchar(val[i] >> 4), hexchar(val[i] % 16));
printf("\n");
}
static bool char_to_hex(unsigned char *val, char c)
{
if (c >= '0' && c <= '9') {
*val = c - '0';
return true;
}
if (c >= 'a' && c <= 'f') {
*val = c - 'a' + 10;
return true;
}
if (c >= 'A' && c <= 'F') {
*val = c - 'A' + 10;
return true;
}
return false;
}
static bool from_hex(const char *str, size_t slen, void *buf, size_t bufsize)
{
unsigned char v1, v2;
unsigned char *p = buf;
while (slen > 1) {
if (!char_to_hex(&v1, str[0]) || !char_to_hex(&v2, str[1]))
return false;
if (!bufsize)
return false;
*(p++) = (v1 << 4) | v2;
str += 2;
slen -= 2;
bufsize--;
}
return slen == 0 && bufsize == 0;
}
static void reverse_hash(unsigned char *hex, size_t len)
{
unsigned int i;
for (i = 0; i < len / 2; i++) {
unsigned char tmp = hex[i];
hex[i] = hex[len - 1 - i];
hex[len - 1 - i] = tmp;
}
}
int main(int argc, char *argv[])
{
int i;
for (i = 1; i < argc; i++) {
unsigned char hex[strlen(argv[i]) / 2];
if (!from_hex(argv[i], strlen(argv[i]), hex, sizeof(hex)))
errx(1, "Bad hex '%s'", argv[i]);
reverse_hash(hex, sizeof(hex));
print_hex(hex, sizeof(hex));
}
return 0;
}
from lightning.
Fair enough!
Cheers
from lightning.
Related Issues (20)
- BOLT12 - lightningd resolves the incorrect invoice_label due to case insensitivity in offer description HOT 4
- logging: DEBUG level causes too much output
- Build: Skip contrib/pyln-grpc-proto ? HOT 5
- Add an API-Method which returns the emergency.recover file HOT 1
- Feature request: add start_time parameter to listforwards HOT 6
- API: Listfunds does not list incoming unconfirmed transactions HOT 1
- Channel funds stuck "ONCHAIN" after close HOT 2
- Invalid JSON Format bitcoin plugin estimated fee RPC HOT 3
- min-emergency-msat requirement even with zero channels open HOT 2
- (24.02.2) make "ERROR: git is required for generating version information"
- testnet4 support HOT 3
- HTLC timeout transaction sweep is never run due to integer underflow HOT 3
- Rune restrictions per unit of time and rune UX HOT 1
- gossipd crash in v24.02 HOT 6
- ci: Flaky tests are slowing down the process of merging HOT 3
- Closing transaction stuck in mempool with low fee HOT 9
- nix: build broken in a nix shell HOT 3
- Rune restriction not being enforced on pnamedescription or pnamelabel when issuing invoice HOT 1
- gossipd: gossip_store: get delete entry offset HOT 2
- Missing dependency lopsq.co HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lightning.