Peer has asked us to RBF */
| 666 | |
| 667 | /* Peer has asked us to RBF */ |
| 668 | static struct command_result * |
| 669 | json_rbf_channel_call(struct command *cmd, |
| 670 | const char *buf, |
| 671 | const jsmntok_t *params) |
| 672 | { |
| 673 | struct open_info *info = new_open_info(cmd); |
| 674 | u64 feerate_our_max, feerate_our_min; |
| 675 | const char *err; |
| 676 | struct out_req *req; |
| 677 | |
| 678 | err = json_scan(tmpctx, buf, params, |
| 679 | "{rbf_channel:" |
| 680 | "{id:%" |
| 681 | ",channel_id:%" |
| 682 | ",their_funding_msat:%" |
| 683 | ",funding_feerate_per_kw:%" |
| 684 | ",feerate_our_max:%" |
| 685 | ",feerate_our_min:%" |
| 686 | ",locktime:%}}", |
| 687 | JSON_SCAN(json_to_node_id, &info->id), |
| 688 | JSON_SCAN(json_to_channel_id, &info->cid), |
| 689 | JSON_SCAN(json_to_msat_as_sats, &info->their_funding), |
| 690 | JSON_SCAN(json_to_u64, &info->funding_feerate_perkw), |
| 691 | JSON_SCAN(json_to_u64, &feerate_our_max), |
| 692 | JSON_SCAN(json_to_u64, &feerate_our_min), |
| 693 | JSON_SCAN(json_to_u32, &info->locktime)); |
| 694 | |
| 695 | if (err) |
| 696 | plugin_err(cmd->plugin, |
| 697 | "`rbf_channel` payload did not scan %s: %.*s", |
| 698 | err, json_tok_full_len(params), |
| 699 | json_tok_full(buf, params)); |
| 700 | |
| 701 | /* If there's no channel_max, it's actually infinity */ |
| 702 | err = json_scan(tmpctx, buf, params, |
| 703 | "{rbf_channel:{channel_max_msat:%}}", |
| 704 | JSON_SCAN(json_to_msat_as_sats, &info->channel_max)); |
| 705 | if (err) |
| 706 | info->channel_max = AMOUNT_SAT(UINT64_MAX); |
| 707 | |
| 708 | /* We don't fund anything that's above or below our feerate */ |
| 709 | if (info->funding_feerate_perkw < feerate_our_min |
| 710 | || info->funding_feerate_perkw > feerate_our_max) { |
| 711 | |
| 712 | plugin_log(cmd->plugin, LOG_DBG, |
| 713 | "their feerate %"PRIu64" is out of" |
| 714 | " our bounds (%"PRIu64"-%"PRIu64")", |
| 715 | info->funding_feerate_perkw, |
| 716 | feerate_our_min, |
| 717 | feerate_our_max); |
| 718 | |
| 719 | return command_hook_success(cmd); |
| 720 | } |
| 721 | |
| 722 | /* Figure out what our funds are... same flow |
| 723 | * as with openchannel2 callback. We assume that THEY |
| 724 | * will use the same inputs, so we use whatever we want here */ |
| 725 | req = jsonrpc_request_start(cmd->plugin, cmd, |
nothing calls this directly
no test coverage detected