def openchannel_v2(plugin, node_id, amount): change_output_weight = (9 + 22) * 4 funding_output_weight = (9 + 34) * 4 core_weight = 44 feerate_val = 2000 feerate = '{}perkw'.format(feerate_val) funding = plugin.rpc.fundpsbt(amount, feerate, funding_output_weight + core_weight) psbt_obj = psbt_from_base64(funding['psbt']) excess = Millisatoshi(funding['excess_msat']) # FIXME: convert feerate ?! change_cost = Millisatoshi(change_output_weight * feerate_val // 1000 * 1000) dust_limit = Millisatoshi(feerate_val * 1000) if excess > (dust_limit + change_cost): addr = plugin.rpc.newaddr()['bech32'] change = excess - change_cost output = tx_output_init(int(change.to_satoshi()), get_script(addr)) psbt_add_output_at(psbt_obj, 0, 0, output) resp = plugin.rpc.openchannel_init(node_id, amount, psbt_to_base64(psbt_obj, 0), commitment_feerate=feerate, funding_feerate=feerate) cid = resp['channel_id'] # We don't have an updates, so we send update until our peer is also # finished while not resp['commitments_secured']: resp = plugin.rpc.openchannel_update(cid, resp['psbt']) # fixme: pass in array of our input indexes to signonly signed = plugin.rpc.signpsbt(resp['psbt']) return plugin.rpc.openchannel_signed(cid, signed['signed_psbt'])
def on_openchannel(openchannel2, plugin, **kwargs): # We mirror what the peer does, wrt to funding amount amount = openchannel2['their_funding'] feerate = openchannel2['feerate_per_kw_funding'] locktime = openchannel2['locktime'] funding = plugin.rpc.fundpsbt(amount, ''.join([str(feerate), 'perkw']), 0, reserve=True, locktime=locktime) psbt_obj = psbt_from_base64(funding['psbt']) excess = Millisatoshi(funding['excess_msat']) change_cost = Millisatoshi(164 * feerate // 1000 * 1000) dust_limit = Millisatoshi(253 * 1000) if excess > (dust_limit + change_cost): addr = plugin.rpc.newaddr()['bech32'] change = excess - change_cost output = tx_output_init(int(change.to_satoshi()), get_script(addr)) psbt_add_output_at(psbt_obj, 0, 0, output) return { 'result': 'continue', 'psbt': psbt_to_base64(psbt_obj, 0), 'accepter_funding_msat': amount }
def on_openchannel(openchannel2, plugin, **kwargs): # We mirror what the peer does, wrt to funding amount ... amount = Millisatoshi(openchannel2['their_funding']) locktime = openchannel2['locktime'] if amount > plugin.max_fund: plugin.log("amount adjusted from {} to {}".format( amount, plugin.max_fund)) amount = plugin.max_fund if amount == 0: plugin.log("accepter_max_funding set to zero") return {'result': 'continue'} # ...unless they send us totally unacceptable feerates. feerate = find_feerate(openchannel2['funding_feerate_best'], openchannel2['funding_feerate_min'], openchannel2['funding_feerate_max'], openchannel2['feerate_our_min'], openchannel2['feerate_our_max']) # Their feerate range is out of bounds, we're not going to # participate. if not feerate: plugin.log("Declining to fund, no feerate found.") return {'result': 'continue'} funding = plugin.rpc.fundpsbt( int(amount.to_satoshi()), '{}perkw'.format(feerate), 0, # because we're the accepter!! reserve=True, locktime=locktime, minconf=0, min_witness_weight=110) psbt_obj = psbt_from_base64(funding['psbt']) excess = Millisatoshi(funding['excess_msat']) change_cost = Millisatoshi(124 * feerate) dust_limit = Millisatoshi(253 * 1000) if excess > (dust_limit + change_cost): addr = plugin.rpc.newaddr()['bech32'] change = excess - change_cost output = tx_output_init(change.to_whole_satoshi(), get_script(addr)) psbt_add_output_at(psbt_obj, 0, 0, output) psbt = psbt_to_base64(psbt_obj, 0) add_inflight(plugin, openchannel2['id'], openchannel2['channel_id'], psbt) plugin.log("contributing {} at feerate {}".format(amount, feerate)) return { 'result': 'continue', 'psbt': psbt, 'accepter_funding_msat': amount, 'funding_feerate': feerate }
def on_openchannel(openchannel2, plugin, **kwargs): # We mirror what the peer does, wrt to funding amount ... amount = openchannel2['their_funding'] locktime = openchannel2['locktime'] # ...unless they send us totally unacceptable feerates. feerate = find_feerate(openchannel2['funding_feerate_best'], openchannel2['funding_feerate_min'], openchannel2['funding_feerate_max'], openchannel2['feerate_our_min'], openchannel2['feerate_our_max']) # Their feerate range is out of bounds, we're not going to # participate. if not feerate: return {'result': 'continue'} funding = plugin.rpc.fundpsbt(amount, '{}perkw'.format(feerate), 0, reserve=True, locktime=locktime, min_witness_weight=110) psbt_obj = psbt_from_base64(funding['psbt']) excess = Millisatoshi(funding['excess_msat']) change_cost = Millisatoshi(124 * feerate) dust_limit = Millisatoshi(253 * 1000) if excess > (dust_limit + change_cost): addr = plugin.rpc.newaddr()['bech32'] change = excess - change_cost output = tx_output_init(change.to_whole_satoshi(), get_script(addr)) psbt_add_output_at(psbt_obj, 0, 0, output) return { 'result': 'continue', 'psbt': psbt_to_base64(psbt_obj, 0), 'accepter_funding_msat': amount, 'funding_feerate': feerate }