sync_engine_shim_for_ndk 0.3.1 copy "sync_engine_shim_for_ndk: ^0.3.1" to clipboard
sync_engine_shim_for_ndk: ^0.3.1 copied to clipboard

Downward sync engine for the ndk package. Declare what you need, the engine keeps the NDK cache in sync with the relays.

example/sync_engine_shim_for_ndk_example.dart

import 'package:ndk/ndk.dart';
import 'package:sembast/sembast_io.dart' hide Filter;
import 'package:sync_engine_shim_for_ndk/sync_engine_shim_for_ndk.dart';

const somePubkey =
    '56e8c688aabb49e9bb68f9d8d6722c809366ad1ad959042db45970cc63152d75';

Future<void> main() async {
  final db = await databaseFactoryIo.openDatabase('sync_engine.db');

  final cache = await SembastCacheManager.create(databasePath: '.');
  final ndk = Ndk(
    NdkConfig(eventVerifier: Bip340EventVerifier(), cache: cache),
  );

  final engine = SyncEngine(ndk, db: db);
  engine.start();

  final filter = Filter(kinds: [1], authors: [somePubkey]);

  final handle = engine.ensure(
    SyncRequest(
      filters: [filter],
      relays: const ['wss://relay.damus.io', 'wss://nos.lol'],
    ),
  );

  await engine
      .watchStatus(handle)
      .firstWhere(
        (status) =>
            status.phase == SyncRequestPhase.synced ||
            status.phase == SyncRequestPhase.failed,
      );

  // Synced events land in the NDK cache, read them from there.
  final notes = await cache.loadEvents(kinds: [1], pubKeys: [somePubkey]);
  print('${notes.length} notes');

  engine.release(handle);
  await engine.dispose();
  ndk.destroy();
}
1
likes
160
points
298
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Downward sync engine for the ndk package. Declare what you need, the engine keeps the NDK cache in sync with the relays.

Repository (GitHub)
View/report issues

Topics

#nostr #ndk #sync

License

MIT (license)

Dependencies

crypto, ndk, rxdart, sembast

More

Packages that depend on sync_engine_shim_for_ndk