Add C# language bindings for payjoin-ffi#1318
Conversation
Pull Request Test Coverage Report for Build 22152746445Details
💛 - Coveralls |
b4799da to
ae74db7
Compare
|
BOOYEAH I like the direction this is going. |
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> |
There was a problem hiding this comment.
Is net8.0 the most common target? I'm very curious what the actual needs of a BTCpayServer plugin or Strike are, because I've dealt with incompatibility issue here, albeit years ago.
There was a problem hiding this comment.
it can: https://blog.btcpayserver.org/btcpay-server-1-12-0/#upgrade-to-net-8. Strike is likely ahead because they don't need to support a bunch of open source stuff.
There was a problem hiding this comment.
I see, any idea which specific runtime they're on?
I did a quick check beforehand to target the most common runtime right now...
Gonna look loser into the Strike repos specifically
There was a problem hiding this comment.
strike very likely on net8.0. probably private repos. i'll ask their team
There was a problem hiding this comment.
Confirmed net8.0 for them and BTCpayServer, and both likely upgrade to net10.0 very soon.
|
I've been working on an experimental C# bindings prototype in my fork (ValeraFinebits#1) while building a BTCPayServer Payjoin plugin, mainly to explore integration possibilities. This PR aligns closely with what I implemented there, and in my local testing everything works as expected. I'll migrate my plugin to these upstream bindings and share any issues or improvement ideas as I go. |
ae74db7 to
4e75d20
Compare
|
Hi @ValeraFinebits I saw your PR open and close. Thanks bigly for writing us updates here. Very eager to see what that plugin can do and challenges hooking it up to BTCPay via the plugin framework. |
ef26b10 to
769f0a9
Compare
DanGould
left a comment
There was a problem hiding this comment.
- What's the plan with the dependency on your personal fork? i'm OK with that with giant, blaring
⚠️ , even better would be in thepayjoinproject, but ultimately we want to upstream whatever fix was necessary. The process of making the PR also serves as documenting what changed. I don't know what changed at all in this PR other than the fact that it's forked. On this note, I'd much rather pin a commit hash than a branch so we have exact dependency that can't drift. - README references chavic/external-types-support but the script installs chavic/csharp-handle-fix. One of them is stale. Prefer commit & to doc in tested code > README in part for this reason
- Missing async persister tests (compared to other bindings) Python and Dart both test JsonReceiverSessionPersisterAsync / JsonSenderSessionPersisterAsync. C# only tests the sync path. Is async support not generated yet,
or just untested? - No Windows CI
C# is disproportionately a Windows ecosystem language. BTCPayServer runs on Windows. The matrix only has ubuntu-latest and macos-latest. Is this a known
limitation or an oversight? I do see this changing, even NicolasDorier BTCPay Emperor has been tweeting about giving up windows, but C# specifically might deserve a windows flow. - Why brew install llvm on macOS?
The other bindings (Python, Dart) don't need this. Is it required for uniffi-bindgen-cs compilation, or the native lib? Should be documented.
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <AllowUnsafeBlocks>true</AllowUnsafeBlocks> |
There was a problem hiding this comment.
Do we need unsafe? known lifetime gotchas? Ideally we'd NOT do this.
There was a problem hiding this comment.
Yes, AllowUnsafeBlocks is currently required for the generated interop code (pointer usage in generated C#). I added an inline comment in the project file documenting this and noting that disabling /unsafe fails with CS0227. I'll revisit this to see if there's a way to avoid it
DanGould
left a comment
There was a problem hiding this comment.
We probably need nuspec too. We've got the Payjoin handle https://www.nuget.org/packages/Payjoin/
Going to make an upstream PR after this works. Could do a draft for documentation. Addressing the rest in upcoming commits. |
6646f19 to
bf7ea11
Compare
eb9f897 to
b859525
Compare
|
Addressed most of the issues mentioned by @DanGould I think this PR it's ready for a second look. @spacebear21 @ValeraFinebits |
Windows now works fine. 👍 |
|
Stoked this is working on Windows now. On very first blush I see your new commits are telling me what happened but not why. The rationale is supercritical. Don't forget! Why > What! |
|
The changes you made to uniffi-bindgen-cs look sane, so I'd like to see them as open PRs there right away so we can get feedback ASAP. They can be one or multiple PRs but I think the feedback there is the most valuable next step we could have. |
DanGould
left a comment
There was a problem hiding this comment.
I think this is pretty much ready to land as an expreiment but I would want @spacebear21's review and I really want to see open PRs upstream so we know we're on the right path.
It would be really nice to have a csharp devshell. I think we could also remove dart from the top level flake and make a devshell so that it doesn't pollute the top level with 300mb of stuff not everyone needs as well which could be done at the same time as as a follow up
csharpDevShell = pkgs.mkShell {
name = "csharp-dev";
buildInputs = with pkgs; [
dotnet-sdk_8
rustToolchains.msrv
];
shellHook = ''
cd payjoin-ffi/csharp
'';
};
# then in devShells:
devShells = devShells // {
default = devShells.nightly;
csharp = csharpDevShell;
# python = pythonDevShell; # from PR #864
}; There was a problem hiding this comment.
Ok so I see now that without this commit, cargo build fails on Windows. Since the C# CI matrix includes windows-latest, this commit unblocks compilation.
This took me about 20 minutes of review to confirm and could have been alleviated by a simple commit message. Next time I will have to refuse to review commits without rationale as part of their message.
| # Run all tests | ||
| dotnet test |
There was a problem hiding this comment.
Would be nice to mirror the same pattern as other repos with a contrib/test.sh
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR/.."
bash ./scripts/generate_bindings.sh
dotnet test --logger "console;verbosity=minimal"
Will do |
spacebear21
left a comment
There was a problem hiding this comment.
utACK b859525 (didn't test locally but CI looks good on all platforms)
+1 on writing explanatory commit descriptions for why each change is made. Other than that the commits organization was nice and easy to follow.
Some thoughts on follow-ups:
- Add integration tests for the end-to-end payjoin flow like we have in the other downstream languages.
- Although I started the trend for dart to include 3rd party bindings generation in payjoin-ffi by hijacking uniffi-bindgen.rs, I think it will be more manageable as we add more languages to remove those optional dependencies/features from payjoin-ffi, and instead silo each language's generator inside that language's directory e.g. by using a cli generator like we do for javascript currently. Notably, adding these optional dependencies still inflates the main Cargo.lock files which can lead to dependency conflicts, MSRV issues, etc.
Integration tests have been added here: |
This work in progress adds C# bindings and implements tests following the pattern in the other languages