BTCPay E̴x̴t̴e̴n̴s̴i̴o̴n̴s̴ Plugins #2244
Replies: 3 comments
-
Just an idea regarding the plugin creation: I think we should either have some scaffolding for this or better yet, offer a blueprint plugin with everything set up and some sample code, which plugin devs can fork. This would ease getting started and we could offer a coded solution with versioning instead of lengthy documentation for such a boilerplate. (also +1 for the We also need a namespace for plugin routes and assets, so that different plugins do not interfere. I saw that the test plugin is using the |
Beta Was this translation helpful? Give feedback.
-
One reason to opt for a sunmodule is that you would also want the I dont think we can do much in terms of routes, some plugins would be designed to inject and work inside existing features and endpoints. Obviously, plugins should try and be sensible and not try to use obvious paths. Namespacing, |
Beta Was this translation helpful? Give feedback.
-
excellent stuff .. this feels good @Kukks |
Beta Was this translation helpful? Give feedback.
-
With the introduction of plugins, we need to outline what will be extendable and how.
Creating a plugin
BaseBTCPayServerPlugin
_ViewImports.cshtml
with@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
as its contents.Edit the project's csproj file and include the following:
.btcpay
.btcpay.json
. Be sure to include a link to the source code so that we can verify that there is no malicious code. We should probably find a good automated way to verify plugins vs srcWhat can you build?
Backend Services
BaseBTCPayServerPlugin
implementation, in the Execute(IServiceCollection services) override methodyou are able to initiate and register any services you want. This could be new a new feature, extension points, etc.
UI Extension Points
The most obvious plugin is being able to inject additional UI into the current Ui in specific places. Wherever you see
<vc:ui-extension-point location="xxx" />
in the BTCPay Server codebase indicates a UI extension point with the location namedxxx
. You can inject an unlimited number of Razor partial views by:Views/Shared
BaseBTCPayServerPlugin
implementation, in the Execute(IServiceCollection services) override methodwhere
MyOwnUIExtension
is the name of the partial you created (minus the cshtml file extension) andx
is the location.The current (this may not be updated, check the latest src code) available locations are:
Interestingly enough, in your UI extension partial, you can define your own locations!
For example, you could do the following:
This means that other plugins can extend your own plugins!
System plugins
System plugins are plugins which are directly referenced andbuilt with BTCPay. They cannot be removed.
Developing your plugin
Load the BTCPay Dev env, import your plugin project to the btcpay solution and reference the plugin project in BTCPay. It will be loaded as if it were a system plugin.
Next steps
Dependencies
We need a way for plugins to depend on a specific version of BTCPay.
BaseBTCPayServerPlugin
contains astring[] Dependencies
which will hold the formatpackage:{semver}
. Semver will be used to determine version compatibilityBTCPay will present itself to the plugin system as if it were a system plugin itself under the name
BTCPayServer
BTCPayServer:^1.0.5.8
indicates that it requires BTCPay to be at least 1.0.5.8 but less than 2.x. (see https://semver.npmjs.com/ to learn the full syntax) ---- #2020 enables thisDocker Dependencies
Some extensions may require additional external services to be running. We currently manage external services through btcpayserver-docker, a docker-compose generator on steroids in that it has a plugin architecture to expand what is run.
Let's come up with an example:
Imagine a new plugin has been created: BTCPay Wasabi Bridge - a plugin that lets you connect to a wasabi daemon to synchronize a store's wallet to a wasabi wallet in that it will share labels between the 2 labelling systems, allow you to participate in a ZeroLink Chaumian coinjoin directly from the BTCPay UI. This plugin requires that you run a Wasabi daemon, in which we have create a plugin(fragment) for the docker deployment to be able to do so.
To achieve the first scenario, we can utilize the SSH service we have available inside BTCPay, add the fragments needed, and run the setup.
To achieve the second scenario, we will need to add some sort of config option to BTCPay,
BTCPAY_REQUIRED_PLUGINS
which would say which plugins are required to start with. the fragment would add it to the btcpay container docker compose section.Data
Currently, ISettingsRepository allows you to set/read generic data to the db. This may be enough for small plugins that only need to save a small configuration but for those that need to keep a complicated state, with complex relations, we will need a more sophisticated approach. We should allow plugins to create their own
DbContext
with their own migrations, but sitll using the same database as BTCPay, provided that they have the plugin identifier prefixed to all their tables.if there is data being persisted by plugins, exclusively for plugins, we need a way to also clean up this data. I propose that
BaseBTCPayServerPlugin
also hasTask Uninstall( )
signature which can be implemented to clean up before it is uninstalled.Crazy shit
Looking at the current BTCPay codebase, there are many, many parts that make sense to move to a separate plugin. This, however, comes with many challenges. Moving Payment Requests, Pull Payments, Apps to a plugin requires a huge undertaking. We must consider that these are features that have been released, use many services which are not decoupled properly and may or may not have other features utilziing them AND have dedicated tables, columns and properties in Blobs to them.
A high-level plan consists of
Moving an existing feature from a system plugin to an installable one
This will be tricky. While the abopve upgarde path ensures that the plugin can do the migration before the original data is deleted, removing a system plugin will require some forward thinking. Some logic must live inside BTCPay for each time we do this in that: If a migration is pending, automatically install plugin before this migration runs.
Beta Was this translation helpful? Give feedback.
All reactions