X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fdemo.c;h=1e9bfb0c283a28c28cfac1840962557f3844e57e;hb=HEAD;hp=dfa0e2fadbd835619f38c2dc8e98b4a852d71eec;hpb=4a8a65a3455e8164509ac48069a010e7c72fc639;p=ldk-c-bindings diff --git a/lightning-c-bindings/demo.c b/lightning-c-bindings/demo.c index dfa0e2f..c5993ce 100644 --- a/lightning-c-bindings/demo.c +++ b/lightning-c-bindings/demo.c @@ -4,46 +4,57 @@ #include #include -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); +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); + Record_free(record); } uint32_t get_fee(const void *this_arg, LDKConfirmationTarget target) { - if (target == LDKConfirmationTarget_Background) { + if (target == LDKConfirmationTarget_AnchorChannelFee || target == LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee) { return 253; } else { return 507; } } -void broadcast_tx(const void *this_arg, LDKTransaction tx) { +void broadcast_txn(const void *this_arg, LDKCVec_TransactionZ txn) { //TODO - Transaction_free(tx); + CVec_TransactionZ_free(txn); } -LDKCResult_NoneChannelMonitorUpdateErrZ add_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) { - return CResult_NoneChannelMonitorUpdateErrZ_ok(); +LDKCResult_ChannelMonitorUpdateStatusNoneZ add_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) { + return CResult_ChannelMonitorUpdateStatusNoneZ_ok(ChannelMonitorUpdateStatus_completed()); } -LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, LDKChannelMonitorUpdate monitor) { - return CResult_NoneChannelMonitorUpdateErrZ_ok(); +LDKChannelMonitorUpdateStatus update_channel_monitor(const void *this_arg, LDKOutPoint funding_txo, const LDKChannelMonitorUpdate *monitor) { + return ChannelMonitorUpdateStatus_completed(); } -LDKCVec_MonitorEventZ monitors_pending_monitor_events(const void *this_arg) { - LDKCVec_MonitorEventZ empty_htlc_vec = { +LDKCVec_C4Tuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZZ monitors_pending_monitor_events(const void *this_arg) { + LDKCVec_C4Tuple_OutPointChannelIdCVec_MonitorEventZPublicKeyZZ empty_htlc_vec = { .data = NULL, .datalen = 0, }; return empty_htlc_vec; } -void never_handle_event(const void *this_arg, const struct LDKEvent* event) { +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); } +LDKCResult_RouteLightningErrorZ do_find_route(const void *this_arg, LDKPublicKey payer, const LDKRouteParameters *route_params, LDKCVec_ChannelDetailsZ *first_hops, const LDKInFlightHtlcs inflight_htlcs) { + LDKStr reason = { .chars = (const unsigned char*)"", .len = 0, .chars_is_owned = false }; + return CResult_RouteLightningErrorZ_err(LightningError_new(reason, ErrorAction_ignore_error())); +} + +LDKCResult_RouteLightningErrorZ do_find_route_with_id(const void *this_arg, LDKPublicKey payer, const LDKRouteParameters *route_params, LDKCVec_ChannelDetailsZ *first_hops, const LDKInFlightHtlcs inflight_htlcs, struct LDKThirtyTwoBytes payment_hash, struct LDKThirtyTwoBytes payment_id) { + LDKStr reason = { .chars = (const unsigned char*)"", .len = 0, .chars_is_owned = false }; + return CResult_RouteLightningErrorZ_err(LightningError_new(reason, ErrorAction_ignore_error())); +} + int main() { uint8_t node_seed[32]; memset(node_seed, 0, 32); @@ -71,19 +82,28 @@ int main() { }; LDKBroadcasterInterface broadcast = { - broadcast.this_arg = NULL, - broadcast.broadcast_transaction = broadcast_tx, + .this_arg = NULL, + .broadcast_transactions = broadcast_txn, + .free = NULL, + }; + + LDKRouter router = { + .this_arg = NULL, + .find_route = do_find_route, + .find_route_with_id = do_find_route_with_id, .free = NULL, }; LDKKeysManager keys = KeysManager_new(&node_seed, 0, 0); - LDKKeysInterface keys_source = KeysManager_as_KeysInterface(&keys); + LDKEntropySource entropy_source = KeysManager_as_EntropySource(&keys); + LDKNodeSigner node_signer = KeysManager_as_NodeSigner(&keys); + LDKSignerProvider signer_provider = KeysManager_as_SignerProvider(&keys); LDKUserConfig config = UserConfig_default(); LDKThirtyTwoBytes chain_tip; memset(&chain_tip, 0, 32); LDKChainParameters chain = ChainParameters_new(net, BestBlock_new(chain_tip, 0)); - LDKChannelManager cm = ChannelManager_new(fee_est, mon, broadcast, logger, keys_source, config, chain); + LDKChannelManager cm = ChannelManager_new(fee_est, mon, broadcast, router, logger, entropy_source, node_signer, signer_provider, config, chain, 42); LDKCVec_ChannelDetailsZ channels = ChannelManager_list_channels(&cm); assert((unsigned long)channels.data < 4096); // There's an offset, but it should still be an offset against null in the 0 page