Skip to content

Commit 2eb1742

Browse files
committed
java: allow non-const maps to be passed as null
This allows e.g. skipping caching on the new signature hash call.
1 parent 349236e commit 2eb1742

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/swig_java/src/com/blockstream/test/test_elements_tx.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,23 @@ public void test_elements_taproot_sighash() {
4747

4848
final String expected = "2c478ce6d5637e0ea8be37a53090e0955b6c501773fccf6738520cfcc5442150";
4949

50+
// Compute the signature hash
5051
Wally.tx_get_input_signature_hash(tx, input_idx, scripts, assets, values,
5152
tapleaf_script, key_version, codesep_pos, annex, genesis, sighash, sighash_type,
5253
cache, bytes_out
5354
);
54-
55+
assert_eq(expected, h(bytes_out), "different sighash");
56+
// Compute again to ensure the cache works as expected
57+
Wally.tx_get_input_signature_hash(tx, input_idx, scripts, assets, values,
58+
tapleaf_script, key_version, codesep_pos, annex, genesis, sighash, sighash_type,
59+
cache, bytes_out
60+
);
61+
assert_eq(expected, h(bytes_out), "different sighash");
62+
// Compute with the cache disabled (passed as null)
63+
Wally.tx_get_input_signature_hash(tx, input_idx, scripts, assets, values,
64+
tapleaf_script, key_version, codesep_pos, annex, genesis, sighash, sighash_type,
65+
null, bytes_out
66+
);
5567
assert_eq(expected, h(bytes_out), "different sighash");
5668

5769
Wally.map_free(cache);

src/swig_java/swig.i

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,13 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) {
393393
%typemap(jtype) const struct NAME * "Object"
394394
%typemap(jni) const struct NAME * "jobject"
395395
%typemap (in) struct NAME * {
396-
$1 = (struct NAME *)get_obj_or_throw(jenv, $input, ID, "NAME");
397-
if (!$1)
398-
return $null;
396+
if (strcmp("NAME", "wally_map") == 0)
397+
$1 = (struct NAME *)get_obj(jenv, $input, ID);
398+
else {
399+
$1 = (struct NAME *)get_obj_or_throw(jenv, $input, ID, "NAME");
400+
if (!$1)
401+
return $null;
402+
}
399403
}
400404
%typemap(jtype) struct NAME * "Object"
401405
%typemap(jni) struct NAME * "jobject"

0 commit comments

Comments
 (0)