Skip to content

Commit

Permalink
Fix Binding Outlay Tracking, update API as a result (#97)
Browse files Browse the repository at this point in the history
* Add Testing and Evaluation Warning.

* Add bindingmemberoutlayreset user story to readme.

* Add prism-bindingmemberoutlayreset

* Remove Millisatoshi Type, use int. Refactor outlay logic.

* Add additional exception handling.

* Fix prism-pay bug by respecting outlay_factor.

* Change label to description.

* Change "split" property to a float type.

* Set prism_id and member_id to unique per record.

* Improve Member validation.

* Nitpicks

* Update tests for label->description and split-float.

* Update pytest Dockerfile with latest CLN image.

* Update README for new updates.

* add test for `update_outlays` rpc

* cast sent amount to int before performing arithmetic

* Rename bindingmemberoutlayreset to setoutlay.

* Bump prism_db_version to v2.1

* Add check to ensure member_id exists.

* Remove entrypoint.sh

* Update readme with latest updates.

* Update outlay_factor description.

---------

Co-authored-by: gudnuf <[email protected]>
  • Loading branch information
farscapian and gudnuf authored Jul 8, 2024
1 parent b5a27ca commit b21305c
Show file tree
Hide file tree
Showing 7 changed files with 445 additions and 266 deletions.
10 changes: 3 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
FROM tuq5hg6cxpz7e/cln:v24.02.2

RUN apt update

FROM lnplay/cln:v24.05
RUN apt-get update && apt-get install -y \
python3.10 \
python3-pip \
Expand All @@ -12,6 +9,5 @@ RUN pip install pytest pyln-testing==24.2.1
RUN mkdir /cln-plugins
ADD *.py /cln-plugins
WORKDIR /cln-plugins
ADD docker-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]

ENTRYPOINT [ "python3", "-m", "pytest", "." ]
305 changes: 182 additions & 123 deletions README.md

Large diffs are not rendered by default.

47 changes: 42 additions & 5 deletions bolt12-prism.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,21 @@ def init(options, configuration, plugin, **kwargs):


@plugin.method("prism-create")
def createprism(plugin, members, prism_id="", outlay_factor: float = 1.0, pay_to_self_enabled: bool = False):
def createprism(plugin, members, description: str = "", outlay_factor: float = 1.0, pay_to_self_enabled: bool = False):
'''Create a prism.'''

plugin.log(f"prism-create invoked having an outlay_factor of {outlay_factor}", "info")
if description == "":
raise Exception("ERROR: you need to set a description.")

plugin.log(f"prism-create invoked having an outlay_factor of {outlay_factor} and a description='{description}'", "info")

prism_members = [Member(plugin=plugin, member_dict=m) for m in members]

if description == "":
raise Exception("You must provide a unique destription!")

# create a new prism object (this is used for our return object only)
prism = Prism.create(plugin=plugin, prism_id=prism_id, members=prism_members, outlay_factor=outlay_factor)
prism = Prism.create(plugin=plugin, description=description, members=prism_members, outlay_factor=outlay_factor)

# now we want to create a unique offer that is associated with this prism
# this offer facilitates pay-to-self-destination use case.
Expand Down Expand Up @@ -197,6 +203,35 @@ def bindprism(plugin: Plugin, prism_id, offer_id=None, invoice_label=""):

return add_binding_result



# set the outlay for a binding-member.
@plugin.method("prism-setoutlay")
def set_binding_member_outlay(plugin: Plugin, offer_id=None, member_id=None, new_outlay_msat=0):
'''Change the member outlay value for a specific prism-binding-member.'''

# Ensure new_outlay_msat is converted to an integer
try:
new_outlay_msat = int(new_outlay_msat)
except ValueError:
raise ValueError("new_outlay_msat must be convertible to an integer")

# then we're going to return a single binding.
binding = PrismBinding.get(plugin, offer_id)

if not binding:
raise Exception("ERROR: could not find a binding for this offer.")

plugin.log(f"Updating outlay for Prism Binding offer_id={offer_id}, member_id={member_id}, new outlay: '{new_outlay_msat}msat'", "info")

PrismBinding.set_member_outlay(binding, member_id, new_outlay_msat)

prism_response = {
f"bolt12_prism_bindings": binding.to_dict()
}

return prism_response

@plugin.method("prism-bindingremove")
def remove_prism_binding(plugin, offer_id=None, invoice_label=""):
'''Removes a prism binding.'''
Expand Down Expand Up @@ -263,8 +298,10 @@ def prism_execute(plugin, prism_id, amount_msat=0, label=""):

if prism is None:
raise Exception("ERROR: could not find prism.")

pay_results = prism.pay(amount_msat=amount_msat)

total_outlays = amount_msat * prism.outlay_factor
plugin.log(f"Total outlays will be {total_outlays} after applying an outlay factor of {prism.outlay_factor} to the income amount {amount_msat}.")
pay_results = prism.pay(amount_msat=total_outlays)

return {
"prism_member_payouts": pay_results
Expand Down
5 changes: 0 additions & 5 deletions docker-entrypoint.sh

This file was deleted.

Loading

0 comments on commit b21305c

Please sign in to comment.