untested change to add serial context to coin before attempting to id it

This commit is contained in:
julian
2023-12-14 14:54:38 -06:00
parent 0cd581045d
commit 1574ed2e29
6 changed files with 67 additions and 2 deletions

View File

@@ -93,6 +93,7 @@ abstract final class LibSpark {
final String serializedCoin, {
required final String privateKeyHex,
required final int index,
required final Uint8List context,
final bool isTestNet = false,
}) {
// take sublist as tx hash is also appended here for some reason
@@ -101,17 +102,21 @@ abstract final class LibSpark {
final serializedCoinPtr = b64CoinDecoded.unsignedCharPointer();
final privateKeyPtr =
privateKeyHex.to32BytesFromHex().unsignedCharPointer();
final contextPtr = context.unsignedCharPointer();
final result = _bindings.idAndRecoverCoin(
serializedCoinPtr,
b64CoinDecoded.length,
privateKeyPtr,
index,
contextPtr,
context.length,
isTestNet ? 1 : 0,
);
malloc.free(serializedCoinPtr);
malloc.free(privateKeyPtr);
malloc.free(contextPtr);
if (result.address == nullptr.address) {
return null;

View File

@@ -59,6 +59,8 @@ class FlutterLibsparkmobileBindings {
int serializedCoinLength,
ffi.Pointer<ffi.UnsignedChar> keyData,
int index,
ffi.Pointer<ffi.UnsignedChar> context,
int contextLength,
int isTestNet,
) {
return _idAndRecoverCoin(
@@ -66,6 +68,8 @@ class FlutterLibsparkmobileBindings {
serializedCoinLength,
keyData,
index,
context,
contextLength,
isTestNet,
);
}
@@ -77,10 +81,18 @@ class FlutterLibsparkmobileBindings {
ffi.Int,
ffi.Pointer<ffi.UnsignedChar>,
ffi.Int,
ffi.Pointer<ffi.UnsignedChar>,
ffi.Int,
ffi.Int)>>('idAndRecoverCoin');
late final _idAndRecoverCoin = _idAndRecoverCoinPtr.asFunction<
ffi.Pointer<AggregateCoinData> Function(ffi.Pointer<ffi.UnsignedChar>,
int, ffi.Pointer<ffi.UnsignedChar>, int, int)>();
ffi.Pointer<AggregateCoinData> Function(
ffi.Pointer<ffi.UnsignedChar>,
int,
ffi.Pointer<ffi.UnsignedChar>,
int,
ffi.Pointer<ffi.UnsignedChar>,
int,
int)>();
/// FFI-friendly wrapper for spark::createSparkMintRecipients.
///