self.bindings_header = """
import * as version from './version.mjs';
+import { UInt5 } from './structs/CommonBase.mjs';
const imports: any = {};
imports.env = {};
self.bindings_header += """
// WASM CODEC
-const nextMultipleOfFour = (value: number) => {
- return Math.ceil(value / 4) * 4;
+/* @internal */
+export function uint5ArrToBytes(inputArray: Array<UInt5>): Uint8Array {
+ const arr = new Uint8Array(inputArray.length);
+ for (var i = 0; i < inputArray.length; i++) {
+ arr[i] = inputArray[i].getVal();
+ }
+ return arr;
}
/* @internal */
return actualArrayViewer[idx];
}
+/* @internal */
+export function getU8ArrayElem(arrayPointer: number, idx: number): number {
+ const actualArrayViewer = new Uint8Array(wasm.memory.buffer, arrayPointer + 4, idx + 1);
+ return actualArrayViewer[idx];
+}
+
+
/* @internal */
export function encodeString(str: string): number {
const charArray = new TextEncoder().encode(str);
}
}
-export default class CommonBase {
+export class CommonBase {
protected ptr: number;
protected ptrs_to: object[] = [];
protected constructor(ptr: number, free_fn: (ptr: number) => void) {
finalizer.unregister(o);
}
}
+
+export class UInt5 {
+ public constructor(private val: number) {
+ if (val > 32 || val < 0) throw new Error("UInt5 value is out of range");
+ }
+ public getVal(): number {
+ return this.val;
+ }
+}
"""
self.txout_defn = """export class TxOut extends CommonBase {
}"""
self.hu_struct_file_prefix = """
-import CommonBase from './CommonBase.mjs';
+import { CommonBase, UInt5 } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs'
"""
return None
def create_native_arr_call(self, arr_len, ty_info):
if ty_info.c_ty == "ptrArray":
- assert ty_info.subty is not None and ty_info.subty.c_ty.endswith("Array")
+ assert ty_info.rust_obj == "LDKCVec_u5Z" or (ty_info.subty is not None and ty_info.subty.c_ty.endswith("Array"))
return "init_" + ty_info.c_ty + "(" + arr_len + ", __LINE__)"
def set_native_arr_contents(self, arr_name, arr_len, ty_info):
if ty_info.c_ty == "int8_tArray":
return None
def map_hu_array_elems(self, arr_name, conv_name, arr_ty, elem_ty):
+ if elem_ty.rust_obj == "LDKu5":
+ return arr_name + " != null ? bindings.uint5ArrToBytes(" + arr_name + ") : null"
assert elem_ty.c_ty == "uint32_t" or elem_ty.c_ty.endswith("Array")
return arr_name + " != null ? " + arr_name + ".map(" + conv_name + " => " + elem_ty.from_hu_conv[0] + ") : null"
def get_java_arr_elem(self, elem_ty, arr_name, idx):
if elem_ty.c_ty == "uint32_t" or elem_ty.c_ty == "uintptr_t" or elem_ty.c_ty.endswith("Array"):
return "bindings.getU32ArrayElem(" + arr_name + ", " + idx + ")"
+ elif elem_ty.rust_obj == "LDKu5":
+ return "bindings.getU8ArrayElem(" + arr_name + ", " + idx + ")"
else:
assert False
def constr_hu_array(self, ty_info, arr_len):