X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fdemo.c;h=1e9bfb0c283a28c28cfac1840962557f3844e57e;hb=b12e216ff9416617ccbc9891d1873e740b8da6d0;hp=d9508c59e6485aec84aa76cff0937c56deb32214;hpb=1495575b517c90da925698da14f627bf0d5b313f;p=ldk-c-bindings diff --git a/lightning-c-bindings/demo.c b/lightning-c-bindings/demo.c index d9508c5..1e9bfb0 100644 --- a/lightning-c-bindings/demo.c +++ b/lightning-c-bindings/demo.c @@ -1,12 +1,15 @@ -#include "include/rust_types.h" -#include "include/lightning.h" +#include #include #include #include -void print_log(const void *this_arg, const char *record) { - printf("%s", record); +void print_log(const void *this_arg, const LDKRecord *record) { + LDKStr mod = Record_get_module_path(record); + LDKStr str = Record_get_args(record); + printf("%.*s:%d - %.*s\n", (int)mod.len, mod.chars, Record_get_line(record), (int)str.len, str.chars); + Str_free(str); + Str_free(mod); } uint32_t get_fee(const void *this_arg, LDKConfirmationTarget target) { @@ -28,14 +31,19 @@ LDKCResult_NoneChannelMonitorUpdateErrZ add_channel_monitor(const void *this_arg LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, LDKChannelMonitorUpdate monitor) { return CResult_NoneChannelMonitorUpdateErrZ_ok(); } -LDKCVec_MonitorEventZ monitors_pending_monitor_events(const void *this_arg) { - LDKCVec_MonitorEventZ empty_htlc_vec = { +LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ monitors_pending_monitor_events(const void *this_arg) { + LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ empty_htlc_vec = { .data = NULL, .datalen = 0, }; return empty_htlc_vec; } +void never_handle_event(const void *this_arg, const struct LDKEvent* event) { + // Note that we never actually generate any events to handle in the code below. + assert(false); +} + int main() { uint8_t node_seed[32]; memset(node_seed, 0, 32); @@ -74,7 +82,7 @@ int main() { LDKUserConfig config = UserConfig_default(); LDKThirtyTwoBytes chain_tip; memset(&chain_tip, 0, 32); - LDKChainParameters chain = ChainParameters_new(net, chain_tip, 0); + LDKChainParameters chain = ChainParameters_new(net, BestBlock_new(chain_tip, 0)); LDKChannelManager cm = ChannelManager_new(fee_est, mon, broadcast, logger, keys_source, config, chain); LDKCVec_ChannelDetailsZ channels = ChannelManager_list_channels(&cm); @@ -83,9 +91,9 @@ int main() { CVec_ChannelDetailsZ_free(channels); LDKEventsProvider prov = ChannelManager_as_EventsProvider(&cm); - LDKCVec_EventZ events = (prov.get_and_clear_pending_events)(prov.this_arg); - assert((unsigned long)events.data < 4096); // There's an offset, but it should still be an offset against null in the 0 page - assert(events.datalen == 0); + // Check that no events were generated by asserting if any events are passed to never_handle_event. + LDKEventHandler handler = { .handle_event = never_handle_event, .free = NULL }; + (prov.process_pending_events)(prov.this_arg, handler); ChannelManager_free(cm); KeysManager_free(keys);