2.0 KiB
Developer Docs for SDL
Random stuff that is useful for devs.
Checking return values from litelib
There are 3 functions written in Rust that live in lib/src/lib.rs :
litelib_initialize_new
- create a new client/connection and brand new wallet
litelib_initialize_new_from_phrase
- create a new client/connection from a seedphrase (restoring from seedphrase)
litelib_initialize_existing
- create a new client/connection with an already existing wallet
The Rust code calls it a "LightClient" while the C++ of SDL calls it a "Connection".
When litelib_initialize_existing
or litelib_initialize_new_from_phrase
return successfully, they return the string "OK" (which is not JSON).
When litelib_initialize_new
returns successfully it returns JSON that looks like :
{"seed":"seed","birthday":birthday}
where "seed" is a 24 word seed and birthday is an integer block height.
So when calling these 3 functions, which looks almost the same in the calling code, the code which checks if they worked will be different, depending on what each returns on success.
When checking the return value of litelib_initialize_existing
or litelib_initialize_new_from_phrase
it should look like :
QString reply = "";
try {
char* resp = litelib_initialize_new_from_phrase(...);
reply = litelib_process_response(resp);
} catch {
...
}
if (reply.isEmpty())) {
// litelib_initialize_new_from_phrase failed
...
}
Yes, isEmpty()
is not a very strict check, we could actually check for valid-looking JSON (starts with a { and ends with a }) as well as making sure the keys "seed" and "birthday" exist. Please implement this.
When checking the return value of litelib_initialize_new
it should look like :
QString reply = "";
try {
char* resp = litelib_initialize_new(...);
reply = litelib_process_response(resp);
} catch {
...
}
if (reply.toUpper().trimmed() != "OK") {
// litelib_initialize_new failed
...
}