common/utils: macros to help get copy/compare across different types right.

Things are often equivalent but different types:
1. u8 arrays in libwally.
2. sha256
3. Secrets derived via sha256
4. txids

Rather than open-coding a BUILD_ASSERT & memcpy, create a macro to do it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2024-07-18 10:54:55 +09:30
parent bc5c528910
commit af90fdc0bb
12 changed files with 44 additions and 48 deletions

View File

@@ -315,9 +315,8 @@ static size_t pay_mpp_hash(const struct pay_sort_key *key)
static bool pay_mpp_eq(const struct pay_mpp *pm, const struct pay_sort_key *key)
{
return memcmp(pm->sortkey.payment_hash, key->payment_hash,
sizeof(struct sha256)) == 0 &&
pm->sortkey.groupid == key->groupid;
return sha256_eq(pm->sortkey.payment_hash, key->payment_hash)
&& pm->sortkey.groupid == key->groupid;
}
HTABLE_DEFINE_TYPE(struct pay_mpp, pay_mpp_key, pay_mpp_hash, pay_mpp_eq,