MCPcopy Create free account
hub / github.com/ElementsProject/lightning / do_decode

Function do_decode

devtools/onion.c:135–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135static void do_decode(int argc, char **argv, const u8 *assocdata)
136{
137 const tal_t *ctx = talz(NULL, tal_t);
138 u8 *serialized;
139 struct route_step *step;
140
141 if (argc != 4)
142 opt_usage_exit_fail("Expect an filename and privkey with 'decode' method");
143
144 /* "-" means stdin, which is NULL for grab_file */
145 char *hextemp = grab_file(ctx, streq(argv[2], "-") ? NULL : argv[2]);
146 size_t hexlen = strlen(hextemp);
147
148 // trim trailing whitespace
149 while (isspace(hextemp[hexlen-1]))
150 hexlen--;
151
152 serialized = tal_hexdata(hextemp, hextemp, hexlen);
153 if (!serialized) {
154 errx(1, "Invalid onion hex '%s'", hextemp);
155 }
156
157 step = decode_with_privkey(ctx, serialized, tal_strdup(ctx, argv[3]), assocdata);
158
159 if (!step || !step->next)
160 errx(1, "Error processing message.");
161
162 printf("payload=%s\n", tal_hex(ctx, step->raw_payload));
163 if (step->nextcase == ONION_FORWARD) {
164 u8 *ser = serialize_onionpacket(ctx, step->next);
165 if (!ser)
166 errx(1, "Error serializing message.");
167 printf("next=%s\n", tal_hex(ctx, ser));
168 }
169 tal_free(ctx);
170}
171
172static char *opt_set_ad(const char *arg, u8 **assocdata)
173{

Callers 1

mainFunction · 0.85

Calls 8

opt_usage_exit_failFunction · 0.85
grab_fileFunction · 0.85
tal_hexdataFunction · 0.85
errxFunction · 0.85
decode_with_privkeyFunction · 0.85
tal_hexFunction · 0.85
tal_freeFunction · 0.85
serialize_onionpacketFunction · 0.50

Tested by

no test coverage detected