Skip to content

Commit 262c45f

Browse files
Nic-dormanclaude
andcommitted
Merge upstream/main into feat/dart-bindings
Resolves conflicts with C# bindings that were merged separately. Keeps Lua and Dart documentation in README. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2 parents cf29c29 + 026b050 commit 262c45f

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

csharp/AntFfi/Client.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,11 @@ public async Task FileDownloadAsync(DataMapChunk dataMapChunk, string destPath,
282282
/// Estimates the cost to upload a file to the network.
283283
/// </summary>
284284
/// <param name="filePath">The path to the file.</param>
285+
/// <param name="followSymlinks">Whether to follow symbolic links (default: true).</param>
286+
/// <param name="includeHidden">Whether to include hidden files (default: false).</param>
285287
/// <param name="cancellationToken">Cancellation token.</param>
286288
/// <returns>The estimated cost as a string (in tokens).</returns>
287-
public async Task<string> FileCostAsync(string filePath, CancellationToken cancellationToken = default)
289+
public async Task<string> FileCostAsync(string filePath, bool followSymlinks = true, bool includeHidden = false, CancellationToken cancellationToken = default)
288290
{
289291
ThrowIfDisposed();
290292
ArgumentNullException.ThrowIfNull(filePath);
@@ -293,7 +295,7 @@ public async Task<string> FileCostAsync(string filePath, CancellationToken cance
293295
throw new FileNotFoundException("File not found", filePath);
294296

295297
var pathBuffer = UniFFIHelpers.StringToRustBuffer(filePath);
296-
var futureHandle = NativeMethods.ClientFileCost(CloneHandle(), pathBuffer);
298+
var futureHandle = NativeMethods.ClientFileCost(CloneHandle(), pathBuffer, followSymlinks ? (sbyte)1 : (sbyte)0, includeHidden ? (sbyte)1 : (sbyte)0);
297299
var buffer = await AsyncFutureHelper.PollRustBufferAsync(futureHandle, cancellationToken);
298300
return UniFFIHelpers.StringFromRustBuffer(buffer);
299301
}

csharp/AntFfi/Native/NativeMethods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ internal static partial class NativeMethods
735735
public static extern IntPtr NetworkNew(sbyte isLocal, ref RustCallStatus status);
736736

737737
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "uniffi_ant_ffi_fn_constructor_network_custom")]
738-
public static extern IntPtr NetworkCustom(RustBuffer rpcUrl, RustBuffer paymentTokenAddress, RustBuffer dataPaymentsAddress, ref RustCallStatus status);
738+
public static extern IntPtr NetworkCustom(RustBuffer rpcUrl, RustBuffer paymentTokenAddress, RustBuffer dataPaymentsAddress, RustBuffer royaltiesPkHex, ref RustCallStatus status);
739739

740740
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "uniffi_ant_ffi_fn_free_network")]
741741
public static extern void FreeNetwork(IntPtr ptr, ref RustCallStatus status);
@@ -842,7 +842,7 @@ internal static partial class NativeMethods
842842
/// Async: Estimates the cost to upload a file to the network.
843843
/// </summary>
844844
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, EntryPoint = "uniffi_ant_ffi_fn_method_client_file_cost")]
845-
public static extern ulong ClientFileCost(IntPtr ptr, RustBuffer filePath);
845+
public static extern ulong ClientFileCost(IntPtr ptr, RustBuffer filePath, sbyte followSymlinks, sbyte includeHidden);
846846

847847
#endregion
848848

csharp/AntFfi/Native/UniFFIHelpers.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,4 +405,34 @@ internal static string ReadStringFromRecordBuffer(RustBuffer buffer, bool freeBu
405405
}
406406
}
407407
}
408+
409+
/// <summary>
410+
/// Creates a RustBuffer from an optional string in UniFFI Option format.
411+
/// None: 1 byte (0), Some: 1 byte (1) + 4-byte BE length + UTF-8 bytes.
412+
/// </summary>
413+
/// <param name="str">The optional string to convert.</param>
414+
/// <returns>A RustBuffer containing the serialized Option&lt;String&gt;.</returns>
415+
public static RustBuffer OptionStringToRustBuffer(string? str)
416+
{
417+
byte[] rawBytes;
418+
if (str == null)
419+
{
420+
// None variant: just a 0 byte
421+
rawBytes = new byte[] { 0 };
422+
}
423+
else
424+
{
425+
// Some variant: 1 byte + 4-byte BE length + UTF-8 data
426+
var utf8Bytes = System.Text.Encoding.UTF8.GetBytes(str);
427+
rawBytes = new byte[1 + 4 + utf8Bytes.Length];
428+
rawBytes[0] = 1; // Some
429+
rawBytes[1] = (byte)(utf8Bytes.Length >> 24);
430+
rawBytes[2] = (byte)(utf8Bytes.Length >> 16);
431+
rawBytes[3] = (byte)(utf8Bytes.Length >> 8);
432+
rawBytes[4] = (byte)utf8Bytes.Length;
433+
Buffer.BlockCopy(utf8Bytes, 0, rawBytes, 5, utf8Bytes.Length);
434+
}
435+
436+
return RawToRustBuffer(rawBytes);
437+
}
408438
}

csharp/AntFfi/Network.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ public static Network Create(bool isLocal)
4646
/// <param name="rpcUrl">RPC URL for the EVM network (e.g., "http://10.0.2.2:61611").</param>
4747
/// <param name="paymentTokenAddress">Payment token contract address (hex string).</param>
4848
/// <param name="dataPaymentsAddress">Data payments contract address (hex string).</param>
49+
/// <param name="royaltiesPkHex">Optional royalties public key (hex string).</param>
4950
/// <returns>A new Network instance.</returns>
50-
public static Network CreateCustom(string rpcUrl, string paymentTokenAddress, string dataPaymentsAddress)
51+
public static Network CreateCustom(string rpcUrl, string paymentTokenAddress, string dataPaymentsAddress, string? royaltiesPkHex = null)
5152
{
5253
var rpcUrlBuffer = UniFFIHelpers.StringToRustBuffer(rpcUrl);
5354
var paymentTokenBuffer = UniFFIHelpers.StringToRustBuffer(paymentTokenAddress);
5455
var dataPaymentsBuffer = UniFFIHelpers.StringToRustBuffer(dataPaymentsAddress);
56+
var royaltiesBuffer = UniFFIHelpers.OptionStringToRustBuffer(royaltiesPkHex);
5557

5658
var status = RustCallStatus.Create();
57-
var handle = NativeMethods.NetworkCustom(rpcUrlBuffer, paymentTokenBuffer, dataPaymentsBuffer, ref status);
59+
var handle = NativeMethods.NetworkCustom(rpcUrlBuffer, paymentTokenBuffer, dataPaymentsBuffer, royaltiesBuffer, ref status);
5860
if (status.IsError)
5961
throw new NetworkException("Failed to create custom network", status);
6062
return new Network(handle, true);

0 commit comments

Comments
 (0)