Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions balancesharing/balancesharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pyln.client
import json
import os

import struct

plugin = pyln.client.Plugin()

Expand Down Expand Up @@ -55,11 +55,30 @@ def get_channel(channels, peer_id):
return None


def encode_query_foaf_balances(flow_value, amt_to_rebalance):
"""Encode flow_value (char) and amount (unsigend long long) """
return struct.pack("!cQ", flow_value, amt_to_rebalance)


def decode_query_foaf_balances(data):
"""Decode query_foaf_balances. Returns a byte and int"""
return struct.unpack("!cQ", data)


@plugin.method("foafbalance")
def foafbalance(plugin):
"""gets the balance of our friends channels"""
flow_value = 1
amt_to_rebalance = 10
flow_value = b'\x01'
amt_to_rebalance = int(123)
data = encode_query_foaf_balances(flow_value, amt_to_rebalance)
new_flow_value, new_amt_to_rebalance = decode_query_foaf_balances(data)

plugin.log(str(data))
plugin.log("New values: {flow_value} {amt_to_rebalance}".format(
flow_value=new_flow_value,
amt_to_rebalance=new_amt_to_rebalance
))

reply = {}
info = plugin.rpc.getinfo()
msg = r'105b126182746121'
Expand Down