Pages
  • LNROOM newsletter
  • First live coding session [#1]
  • pyln-client and Python decorators [#2]
  • Write tests for CLN plugins and Unix domain sockets [#3]
  • pyln-client implementation and Torq node management software [#4]
  • CLN Hooks and BOLT11 [#5]
  • nostr-control and scaling-lightning [#6]
  • bcli and Securing a $100M Lightning node [#7]
  • LDK Node, Greenlight and Breez SDK [#8]
  • Remote control and L402 [#9]
  • LN summit in NY, splicing and Mutiny [#10]
  • commando, lnsocket and CLN 23.08 rc1 [#11]
  • CLN v23.08, sovereign stack and BOLT #12 [#12]
  • Vincenzo Palazzo, LSPs & renepay plugin [#13]
  • Testing applications & 4 major LN implementations [#14]
  • LSP, VLS and Bitcoin Education [#15]
  • LN limitations, Timeout Trees, Greenlight and River report [#16]
  • 1 year of lnroom.live [#17]
  • BOLT#11, clangd and renepay [#18]
  • BOLT#11, Rusty Russell, Clams and CLN v23.11 [#19]
  • Bech32, Chaincode Labs, Christian Decker and Severin Bühler [#20]
  • PeerSwap, Breez SDK and Mutiny Wallet FAQ [#21]
LNROOM newsletter
  • LNROOM newsletter
  • First live coding session [#1]
  • pyln-client and Python decorators [#2]
  • Write tests for CLN plugins and Unix domain sockets [#3]
  • pyln-client implementation and Torq node management software [#4]
  • CLN Hooks and BOLT11 [#5]
  • nostr-control and scaling-lightning [#6]
  • bcli and Securing a $100M Lightning node [#7]
  • LDK Node, Greenlight and Breez SDK [#8]
  • Remote control and L402 [#9]
  • LN summit in NY, splicing and Mutiny [#10]
  • commando, lnsocket and CLN 23.08 rc1 [#11]
  • CLN v23.08, sovereign stack and BOLT #12 [#12]
  • Vincenzo Palazzo, LSPs & renepay plugin [#13]
  • Testing applications & 4 major LN implementations [#14]
  • LSP, VLS and Bitcoin Education [#15]
  • LN limitations, Timeout Trees, Greenlight and River report [#16]
  • 1 year of lnroom.live [#17]
  • BOLT#11, clangd and renepay [#18]
  • BOLT#11, Rusty Russell, Clams and CLN v23.11 [#19]
  • Bech32, Chaincode Labs, Christian Decker and Severin Bühler [#20]
  • PeerSwap, Breez SDK and Mutiny Wallet FAQ [#21]

pyln-client and Python decorators

#2・April 06, 2023

Tuesday, March 28 was the first live coding session, maybe you joined us maybe not. In both cases you can find the writeup of the session on LNROOM.

Do you know about Python decorators? This is a mechanism that allows to modify a function's definition. For instance, if we want to modify the function's definition func where decorator is a function that takes a function as argument and return a function, we can use decorators and write something like this using @ symbol

@decorator
def func():
    pass

which is equivalent to

def func():
    pass
func = decorator(func)

See https://peps.python.org/pep-0318/.

Why talking about Python decorators?

Because this is the mechanism pyln-client library uses to declare new JSON-RPC methods in plugins.

For instance if we want to add a method mymethod via a plugin that returns our node id we can write this plugin:

from pyln.client import Plugin

plugin = Plugin()

@plugin.method("mymethod")
def mymethod(plugin):
    node_id = plugin.rpc.getinfo()["id"]
    return { "id": node_id }

plugin.run()

If you want to know more about pyln-client library come join us on Thursday, March 13 at the next event.

Two weeks ago I attended Liquidity Ads: Everything You Need To Know event where Alex Myer insisted on the importance of building LN at the protocol level in order to have a better P2P network in the long run.

Maybe you want to give it a try and watch the recording.

He also recommended this article about liquidity ads written by Lysa Neigut in this follow-up.

Have an amazing day, Tony Aldon https://lnroom.live

PREVRANDOMNEXT