processJson method

  1. @override
Future<String> processJson(
  1. String jsonString
)
override

Implementation-specific: take the unsigned transaction JSON, compute the signing digests, and return the result transaction JSON string.

Implementation

@override
Future<String> processJson(String jsonString) async {
  final inputPtr = jsonString.toNativeUtf8();
  final outputPtrPtr = malloc<ffi.Pointer<Utf8>>();

  try {
    final result = _processScTransaction(inputPtr, outputPtrPtr);
    final outputPtr = outputPtrPtr.value;

    if (result != 0) {
      // On failure Go still allocates an error-JSON string; read it for the
      // message and free it so it doesn't leak.
      var detail = '';
      if (outputPtr != ffi.nullptr) {
        detail = ': ${outputPtr.toDartString()}';
        _freeString(outputPtr);
      }
      throw StateError('Go library call failed with code $result$detail');
    }

    if (outputPtr == ffi.nullptr) {
      throw StateError('Go library returned null output');
    }

    final output = outputPtr.toDartString();
    _freeString(outputPtr);

    return output;
  } finally {
    malloc.free(inputPtr);
    malloc.free(outputPtrPtr);
  }
}