}
function get_chanman(): Node {
const fee_est = ldk.FeeEstimator.new_impl({
- get_est_sat_per_1000_weight(confirmation_target: ldk.ConfirmationTarget): number {
+ get_est_sat_per_1000_weight(_confirmation_target: ldk.ConfirmationTarget): number {
return 253;
}
} as ldk.FeeEstimatorInterface);
- var tx_broadcaster;
- const tx_broadcasted: Promise<Uint8Array> = new Promise((resolve, reject) => {
+ var tx_broadcaster: ldk.BroadcasterInterface;
+ const tx_broadcasted: Promise<Uint8Array> = new Promise((resolve, _reject) => {
tx_broadcaster = ldk.BroadcasterInterface.new_impl({
broadcast_transaction(tx: Uint8Array): void { console.log("Tx Broadcast: " + tx); resolve(tx); }
} as ldk.BroadcasterInterfaceInterface);
} as ldk.LoggerInterface);
const persister = ldk.Persist.new_impl({
- persist_new_channel(channel_id: ldk.OutPoint, data: ldk.ChannelMonitor, update_id: ldk.MonitorUpdateId): ldk.ChannelMonitorUpdateStatus {
+ persist_new_channel(_channel_id: ldk.OutPoint, _data: ldk.ChannelMonitor, _update_id: ldk.MonitorUpdateId): ldk.ChannelMonitorUpdateStatus {
return ldk.ChannelMonitorUpdateStatus.LDKChannelMonitorUpdateStatus_Completed;
},
- update_persisted_channel(channel_id: ldk.OutPoint, update: ldk.ChannelMonitorUpdate, data: ldk.ChannelMonitor, update_id: ldk.MonitorUpdateId): ldk.ChannelMonitorUpdateStatus {
+ update_persisted_channel(_channel_id: ldk.OutPoint, _update: ldk.ChannelMonitorUpdate, _data: ldk.ChannelMonitor, _update_id: ldk.MonitorUpdateId): ldk.ChannelMonitorUpdateStatus {
return ldk.ChannelMonitorUpdateStatus.LDKChannelMonitorUpdateStatus_Completed;
}
} as ldk.PersistInterface);
- const chain_monitor = ldk.ChainMonitor.constructor_new(ldk.Option_FilterZ.constructor_none(), tx_broadcaster, logger, fee_est, persister);
+ const chain_monitor = ldk.ChainMonitor.constructor_new(ldk.Option_FilterZ.constructor_none(), tx_broadcaster!, logger, fee_est, persister);
const chain_watch: ldk.Watch = chain_monitor.as_Watch();
const seed = new Uint8Array(32);
const config = ldk.UserConfig.constructor_default();
const params = ldk.ChainParameters.constructor_new(ldk.Network.LDKNetwork_Testnet, ldk.BestBlock.constructor_from_genesis(ldk.Network.LDKNetwork_Testnet));
- const chan_man = ldk.ChannelManager.constructor_new(fee_est, chain_watch, tx_broadcaster, logger, keys_interface, config, params);
+ const chan_man = ldk.ChannelManager.constructor_new(fee_est, chain_watch, tx_broadcaster!, logger, keys_interface, config, params);
return new Node(chan_man, tx_broadcasted, logger, keys_interface);
}
chan_man.as_EventsProvider().process_pending_events(event_handler);
assert(events.length == 1);
- return events[0];
+ return events[0]!;
}
tests.push(async () => {
const sock_a = ldk.SocketDescriptor.new_impl({
send_data(data: Uint8Array, resume_read: boolean): number {
assert(pm_b.read_event(sock_b, data) instanceof ldk.Result_boolPeerHandleErrorZ_OK);
+ assert(resume_read);
return data.length;
},
disconnect_socket(): void {
sock_b = ldk.SocketDescriptor.new_impl({
send_data(data: Uint8Array, resume_read: boolean): number {
assert(pm_a.read_event(sock_a, data) instanceof ldk.Result_boolPeerHandleErrorZ_OK);
+ assert(resume_read);
return data.length;
},
disconnect_socket(): void {
for (var i = 0; i < 44; i++) assert(buffer[i] == 67);
return ldk.Result_COption_CustomOnionMessageContentsZDecodeErrorZ.constructor_ok(ldk.Option_CustomOnionMessageContentsZ.constructor_some(ldk.CustomOnionMessageContents.new_impl({
tlv_type(): bigint { return 9998n; },
- write(): Uint8Array { assert(false); return null; }
+ write(): Uint8Array { throw new Error(); }
} as ldk.CustomOnionMessageContentsInterface)));
},
handle_custom_message(msg: ldk.CustomOnionMessageContents) {
for (var i = 0; i < 43; i++) assert(buffer[i] == 66);
return ldk.Result_COption_CustomOnionMessageContentsZDecodeErrorZ.constructor_ok(ldk.Option_CustomOnionMessageContentsZ.constructor_some(ldk.CustomOnionMessageContents.new_impl({
tlv_type(): bigint { return 9999n; },
- write(): Uint8Array { assert(false); return null; }
+ write(): Uint8Array { throw new Error(); }
} as ldk.CustomOnionMessageContentsInterface)));
},
handle_custom_message(msg: ldk.CustomOnionMessageContents) {
const sock_a = ldk.SocketDescriptor.new_impl({
send_data(data: Uint8Array, resume_read: boolean): number {
assert(pm_b.read_event(sock_b, data) instanceof ldk.Result_boolPeerHandleErrorZ_OK);
+ assert(resume_read);
return data.length;
},
disconnect_socket(): void {
sock_b = ldk.SocketDescriptor.new_impl({
send_data(data: Uint8Array, resume_read: boolean): number {
assert(pm_a.read_event(sock_a, data) instanceof ldk.Result_boolPeerHandleErrorZ_OK);
+ assert(resume_read);
return data.length;
},
disconnect_socket(): void {
console.log("all tests passed: " + result);
if (result !== true || !check_leaks) { return result; }
- const allocs_finished = new Promise((resolve, reject) => {
+ const allocs_finished = new Promise((resolve, _reject) => {
var loop_count = 0;
const interval_id = setInterval(() => {
const alloc_count = rawldk.getRemainingAllocationCount();
for (var i = 0; i < iovec_array_len; i++) {
const bytes_view = new Uint8Array(wasm.memory.buffer, ptr_len_view[i*2], ptr_len_view[i*2+1]);
console.log("[fd " + fd + "]: " + String.fromCharCode(...bytes_view));
- bytes_written += ptr_len_view[i*2+1];
+ bytes_written += ptr_len_view[i*2+1]!;
}
const written_view = new Uint32Array(wasm.memory.buffer, bytes_written_ptr, 1);
written_view[0] = bytes_written;
out_len_view[0] = 0;
return 0;
},
- "environ_get": (environ_ptr: number, environ_buf_ptr: number) => {
+ "environ_get": (_environ_ptr: number, _environ_buf_ptr: number) => {
// This is called before fd_write to format + print panic messages,
// but only if we have variables in environ_sizes_get, so shouldn't ever actually happen!
console.log("wasi_snapshot_preview1:environ_get");
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();
+ arr[i] = inputArray[i]!.getVal();
}
return arr;
}
export function WitnessVersionArrToBytes(inputArray: Array<WitnessVersion>): Uint8Array {
const arr = new Uint8Array(inputArray.length);
for (var i = 0; i < inputArray.length; i++) {
- arr[i] = inputArray[i].getVal();
+ arr[i] = inputArray[i]!.getVal();
}
return arr;
}
}
/* @internal */
-export function check_arr_len(arr: Uint8Array|null, len: number): Uint8Array {
+export function check_arr_len(arr: Uint8Array|null, len: number): Uint8Array|null {
if (arr !== null && arr.length != len) { throw new Error("Expected array of length " + len + " got " + arr.length); }
return arr;
}
/* @internal */
export function getArrayLength(arrayPointer: number): number {
const arraySizeViewer = new BigUint64Array(wasm.memory.buffer, arrayPointer, 1);
- const len = arraySizeViewer[0];
+ const len = arraySizeViewer[0]!;
if (len >= (2n ** 32n)) throw new Error("Bogus Array Size");
return Number(len % (2n ** 32n));
}
/* @internal */
export function getU64ArrayElem(arrayPointer: number, idx: number): bigint {
const actualArrayViewer = new BigUint64Array(wasm.memory.buffer, arrayPointer + 8, idx + 1);
- return actualArrayViewer[idx];
+ return actualArrayViewer[idx]!;
}
/* @internal */
export function getU32ArrayElem(arrayPointer: number, idx: number): number {
const actualArrayViewer = new Uint32Array(wasm.memory.buffer, arrayPointer + 8, idx + 1);
- return actualArrayViewer[idx];
+ return actualArrayViewer[idx]!;
}
/* @internal */
export function getU8ArrayElem(arrayPointer: number, idx: number): number {
const actualArrayViewer = new Uint8Array(wasm.memory.buffer, arrayPointer + 8, idx + 1);
- return actualArrayViewer[idx];
+ return actualArrayViewer[idx]!;
}
}
export class UnqualifiedError {
- public constructor(val: number) {}
+ public constructor(_val: number) {}
}
"""
public value: bigint;
/* @internal */
- public constructor(_dummy: object, ptr: bigint) {
+ public constructor(_dummy: null, ptr: bigint) {
super(ptr, bindings.TxOut_free);
this.script_pubkey = bindings.decodeUint8Array(bindings.TxOut_get_script_pubkey(ptr));
this.value = bindings.TxOut_get_value(ptr);
public scalar_bytes: Uint8Array;
/* @internal */
- public constructor(_dummy: object, ptr: bigint) {
+ public constructor(_dummy: null, ptr: bigint) {
super(ptr, bindings.BigEndianScalar_free);
this.scalar_bytes = bindings.decodeUint8Array(bindings.BigEndianScalar_get_bytes(ptr));
}
else:
bindings_instantiator += ", " + first_to_lower(var.arg_name)
else:
- bindings_instantiator += ", " + first_to_lower(var[1]) + ".instance_idx"
+ bindings_instantiator += ", " + first_to_lower(var[1]) + ".instance_idx!"
super_instantiator += first_to_lower(var[1]) + "_impl, "
pointer_to_adder += "\t\timpl_holder.held.ptrs_to.push(" + first_to_lower(var[1]) + ");\n"
impl_constructor_arguments += f", {first_to_lower(var[1])}_impl: {var[0].replace('LDK', '')}Interface"
trait_constructor_arguments += ", " + var.arg_name
else:
super_constructor_statements += "\t\tconst " + first_to_lower(var[1]) + " = " + var[1] + ".new_impl(" + super_instantiator + ");\n"
- trait_constructor_arguments += ", " + first_to_lower(var[1]) + ".instance_idx"
+ trait_constructor_arguments += ", " + first_to_lower(var[1]) + ".instance_idx!"
for suparg in var[2]:
if isinstance(suparg, ConvInfo):
trait_constructor_arguments += ", " + suparg.arg_name
{out_java_interface}}}
class {struct_name}Holder {{
- held: {struct_name.replace("LDK", "")};
+ held: {struct_name.replace("LDK", "")}|null = null;
}}
/**
*/
export class {struct_name.replace("LDK","")} extends CommonBase {{
/* @internal */
- public bindings_instance?: bindings.{struct_name};
+ public bindings_instance: bindings.{struct_name}|null;
/* @internal */
public instance_idx?: number;
/* @internal */
- constructor(_dummy: object, ptr: bigint) {{
+ constructor(_dummy: null, ptr: bigint) {{
super(ptr, bindings.{struct_name.replace("LDK","")}_free);
this.bindings_instance = null;
}}
impl_holder.held = new {struct_name.replace("LDK", "")}(null, ptr_idx[0]);
impl_holder.held.instance_idx = ptr_idx[1];
impl_holder.held.bindings_instance = structImplementation;
-{pointer_to_adder} return impl_holder.held;
+{pointer_to_adder} return impl_holder.held!;
}}
"""
java_hu_class = "/**\n * " + enum_doc_comment.replace("\n", "\n * ") + "\n */\n"
java_hu_class += "export class " + java_hu_type + " extends CommonBase {\n"
- java_hu_class += "\tprotected constructor(_dummy: object, ptr: bigint) { super(ptr, bindings." + bindings_type + "_free); }\n"
+ java_hu_class += "\tprotected constructor(_dummy: null, ptr: bigint) { super(ptr, bindings." + bindings_type + "_free); }\n"
java_hu_class += "\t/* @internal */\n"
java_hu_class += f"\tpublic static constr_from_ptr(ptr: bigint): {java_hu_type} {{\n"
java_hu_class += f"\t\tconst raw_ty: number = bindings." + struct_name + "_ty_from_ptr(ptr);\n"
*/
export class {hu_name} extends CommonBase {implementations}{{
/* @internal */
- public constructor(_dummy: object, ptr: bigint) {{
+ public constructor(_dummy: null, ptr: bigint) {{
{constructor_body}
}}{extra_body}
suffixes += "\tpublic res: " + res_map.java_hu_ty + ";\n"
suffixes += f"""
/* @internal */
- public constructor(_dummy: object, ptr: bigint) {{
+ public constructor(_dummy: null, ptr: bigint) {{
super(_dummy, ptr);
"""
if res_map.java_hu_ty == "void":
suffixes += "\tpublic err: " + err_map.java_hu_ty + ";\n"
suffixes += f"""
/* @internal */
- public constructor(_dummy: object, ptr: bigint) {{
+ public constructor(_dummy: null, ptr: bigint) {{
super(_dummy, ptr);
"""
if err_map.java_hu_ty == "void":
return f"""{self.hu_struct_file_prefix}
export class {human_ty} extends CommonBase {{
- protected constructor(_dummy: object, ptr: bigint) {{
+ protected constructor(_dummy: null, ptr: bigint) {{
super(ptr, bindings.{struct_name.replace("LDK","")}_free);
}}
/* @internal */
out_java_struct += arg.arg_name + "_" + explode_arg.arg_name + ": " + explode_arg.java_hu_ty
else:
out_java_struct += arg.arg_name + ": " + arg.java_hu_ty
+ if arg.nullable:
+ out_java_struct += "|null"
out_c += (") {\n")
if out_java_struct is not None:
bindings.write("""
js_invoke = function(obj_ptr: number, fn_id: number, arg1: bigint|number, arg2: bigint|number, arg3: bigint|number, arg4: bigint|number, arg5: bigint|number, arg6: bigint|number, arg7: bigint|number, arg8: bigint|number, arg9: bigint|number, arg10: bigint|number) {
- const weak: WeakRef<object> = js_objs[obj_ptr];
+ const weak: WeakRef<object>|undefined = js_objs[obj_ptr];
if (weak == null || weak == undefined) {
console.error("Got function call on unknown/free'd JS object!");
throw new Error("Got function call on unknown/free'd JS object!");
}
- const obj: object = weak.deref();
+ const obj = weak.deref();
if (obj == null || obj == undefined) {
console.error("Got function call on GC'd JS object!");
throw new Error("Got function call on GC'd JS object!");