Skip to content

Commit

Permalink
Merge pull request #4 from qrest/balancesharing-plugin
Browse files Browse the repository at this point in the history
initial en- and decoding
  • Loading branch information
renepickhardt authored May 10, 2020
2 parents c99335d + 9a8c273 commit ecb71e0
Showing 1 changed file with 22 additions and 3 deletions.
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

0 comments on commit ecb71e0

Please sign in to comment.