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

Function do_decode

devtools/onion.c:134–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.85

Calls 9

opt_usage_exit_failFunction · 0.85
grab_file_strFunction · 0.85
cisspaceFunction · 0.85
tal_hexdataFunction · 0.85
errxFunction · 0.85
decode_with_privkeyFunction · 0.85
tal_hexFunction · 0.85
serialize_onionpacketFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected