mirror of
https://github.com/ElementsProject/lightning.git
synced 2026-08-16 13:00:32 +02:00
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
27 lines
712 B
Python
Executable file
27 lines
712 B
Python
Executable file
#!/usr/bin/env python3
|
|
"""
|
|
This plugin is used to test the currency command
|
|
"""
|
|
from pyln.client import Plugin, Millisatoshi
|
|
|
|
plugin = Plugin()
|
|
_rate = 5000 # msat per unit
|
|
|
|
|
|
@plugin.method("currencyconvert")
|
|
def currencyconvert(plugin, amount, currency):
|
|
"""Converts currency using given APIs."""
|
|
if currency in ('USD', 'AUD'):
|
|
return {"msat": Millisatoshi(round(amount * _rate))}
|
|
raise Exception("No values available for currency {}".format(currency.upper()))
|
|
|
|
|
|
@plugin.method("setcurrencyrate")
|
|
def setcurrencyrate(plugin, msat_per_unit):
|
|
"""Change the msat-per-unit rate (for testing)."""
|
|
global _rate
|
|
_rate = msat_per_unit
|
|
return {"msat_per_unit": _rate}
|
|
|
|
|
|
plugin.run()
|