pin method

Future<void> pin(
  1. String cid
)

Pins a CID to prevent it from being garbage collected.

Implementation

Future<void> pin(String cid) async {
  try {
    // Create a Pin instance
    final pin = Pin(
      cid: CID.decode(cid),
      type: PinTypeProto.PIN_TYPE_RECURSIVE,
      blockStore: _container.get<BlockStore>(),
    );

    // Pin the content
    final success = await pin.pin();
    if (!success) {
      throw Exception('Failed to pin CID: $cid');
    }

    // Update the datastore to mark the CID as pinned
    await _container.get<DatastoreHandler>().persistPinnedCIDs({cid});

    // print('Successfully pinned CID: $cid');
  } catch (e) {
    // print('Error pinning CID $cid: $e');
    rethrow;
  }
}