Skip to content

feat(cat-voices): blockchain slot number config #2534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:catalyst_voices/app/view/app.dart';
import 'package:catalyst_voices/configs/bootstrap.dart';
import 'package:catalyst_voices/routes/routes.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:patrol_finders/patrol_finders.dart';
Expand All @@ -20,6 +21,7 @@ void main() async {

setUp(() async {
await registerDependencies();
registerConfig(AppConfig.dev());
router.go(const DiscoveryRoute().location);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void main() async {

setUp(() async {
await registerDependencies();
registerConfig(AppConfig.dev());
router.go(const DiscoveryRoute().location);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:catalyst_voices/app/view/app.dart';
import 'package:catalyst_voices/configs/bootstrap.dart';
import 'package:catalyst_voices/routes/routes.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:patrol_finders/patrol_finders.dart';
Expand All @@ -18,6 +19,7 @@ void main() async {

setUp(() async {
await registerDependencies();
registerConfig(AppConfig.dev());
router.go(const DiscoveryRoute().location);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:catalyst_voices/app/view/app.dart';
import 'package:catalyst_voices/configs/bootstrap.dart';
import 'package:catalyst_voices/routes/routes.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:patrol_finders/patrol_finders.dart';
Expand All @@ -27,6 +28,7 @@ void main() async {

setUp(() async {
await registerDependencies();
registerConfig(AppConfig.dev());
router.go(const DiscoveryRoute().location);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:catalyst_voices/app/view/app.dart';
import 'package:catalyst_voices/configs/bootstrap.dart';
import 'package:catalyst_voices/routes/routes.dart';
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart' as blocs;
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:patrol_finders/patrol_finders.dart';
Expand Down Expand Up @@ -38,6 +39,7 @@ void main() async {

setUp(() async {
await registerDependencies();
registerConfig(AppConfig.dev());
router.go(const DiscoveryRoute().location);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:catalyst_voices/app/view/app.dart';
import 'package:catalyst_voices/configs/bootstrap.dart';
import 'package:catalyst_voices/routes/routes.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:patrol_finders/patrol_finders.dart';
Expand All @@ -17,6 +18,7 @@ void main() async {

setUp(() async {
await registerDependencies();
registerConfig(AppConfig.dev());
router.go(const ProposalsRoute().location);
});

Expand Down
14 changes: 7 additions & 7 deletions catalyst_voices/apps/voices/lib/configs/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ Future<BootstrapArgs> bootstrap({
environment ??= AppEnvironment.fromEnv();

await _cleanupOldStorages();
await registerDependencies(environment: environment, config: null);
await registerDependencies(environment: environment);
await _initCryptoUtils();

final configSource = ApiConfigSource(Dependencies.instance.get());
final configService = ConfigService(ConfigRepository(configSource));
final config = await configService.getAppConfig(env: environment.type);

Dependencies.instance.registerConfig(config);
registerConfig(config);

router ??= buildAppRouter();

Expand Down Expand Up @@ -96,20 +96,20 @@ GoRouter buildAppRouter({
);
}

@visibleForTesting
void registerConfig(AppConfig config) {
Dependencies.instance.registerConfig(config);
}

@visibleForTesting
Future<void> registerDependencies({
AppEnvironment environment = const AppEnvironment.dev(),
AppConfig? config = const AppConfig.dev(),
}) async {
if (!Dependencies.instance.isInitialized) {
await Dependencies.instance.init(
environment: environment,
);
}

if (config != null) {
Dependencies.instance.registerConfig(config);
}
}

@visibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ final class RegistrationCubit extends Cubit<RegistrationState>
final UserService _userService;
final RegistrationService _registrationService;
final RegistrationProgressNotifier _progressNotifier;
final BlockchainConfig _blockchainConfig;

CatalystId? _accountId;
Keychain? _keychain;
Expand All @@ -42,7 +41,6 @@ final class RegistrationCubit extends Cubit<RegistrationState>
}) : _userService = userService,
_registrationService = registrationService,
_progressNotifier = progressNotifier,
_blockchainConfig = blockchainConfig,
_baseProfileCubit = BaseProfileCubit(),
_keychainCreationCubit = KeychainCreationCubit(
downloaderService: downloaderService,
Expand Down Expand Up @@ -258,7 +256,6 @@ final class RegistrationCubit extends Cubit<RegistrationState>

final transaction = await _registrationService.prepareRegistration(
wallet: wallet,
networkId: _blockchainConfig.networkId,
masterKey: masterKey,
roles: transactionRoles,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void main() {
keychainProvider = VaultKeychainProvider(
secureStorage: const FlutterSecureStorage(),
sharedPreferences: SharedPreferencesAsync(),
cacheConfig: const AppConfig.dev().cache,
cacheConfig: AppConfig.dev().cache,
);
userRepository = _FakeUserRepository();
userObserver = StreamUserObserver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,16 @@ final class BlockchainSlotNumberConfig extends Equatable {
systemStartSlot,
slotLength,
];

BlockchainSlotNumberConfig copyWith({
DateTime? systemStartTimestamp,
SlotBigNum? systemStartSlot,
Duration? slotLength,
}) {
return BlockchainSlotNumberConfig(
systemStartTimestamp: systemStartTimestamp ?? this.systemStartTimestamp,
systemStartSlot: systemStartSlot ?? this.systemStartSlot,
slotLength: slotLength ?? this.slotLength,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class AppConfig extends Equatable {
required this.blockchain,
});

const AppConfig.dev()
AppConfig.dev()
: this(
version: '0.0.1',
cache: const CacheConfig(
Expand All @@ -50,23 +50,24 @@ final class AppConfig extends Equatable {
debug: true,
diagnosticLevel: 'debug',
),
blockchain: const BlockchainConfig(
blockchain: BlockchainConfig(
networkId: NetworkId.testnet,
host: CatalystIdHost.cardanoPreprod,
transactionBuilderConfig: _defaultTransactionBuilderConfig,
slotNumberConfig: BlockchainSlotNumberConfig.testnet(),
),
);

factory AppConfig.env(AppEnvironmentType env) {
return switch (env) {
AppEnvironmentType.dev => const AppConfig.dev(),
AppEnvironmentType.preprod => const AppConfig.preprod(),
AppEnvironmentType.prod => const AppConfig.prod(),
AppEnvironmentType.relative => const AppConfig.dev(),
AppEnvironmentType.dev => AppConfig.dev(),
AppEnvironmentType.preprod => AppConfig.preprod(),
AppEnvironmentType.prod => AppConfig.prod(),
AppEnvironmentType.relative => AppConfig.dev(),
};
}

const AppConfig.preprod()
AppConfig.preprod()
: this(
version: '0.0.1',
cache: const CacheConfig(
Expand All @@ -88,14 +89,15 @@ final class AppConfig extends Equatable {
debug: false,
diagnosticLevel: 'warning',
),
blockchain: const BlockchainConfig(
blockchain: BlockchainConfig(
networkId: NetworkId.testnet,
host: CatalystIdHost.cardanoPreprod,
transactionBuilderConfig: _defaultTransactionBuilderConfig,
slotNumberConfig: BlockchainSlotNumberConfig.testnet(),
),
);

const AppConfig.prod()
AppConfig.prod()
: this(
version: '0.0.1',
cache: const CacheConfig(
Expand All @@ -117,10 +119,11 @@ final class AppConfig extends Equatable {
debug: false,
diagnosticLevel: 'error',
),
blockchain: const BlockchainConfig(
networkId: NetworkId.testnet,
blockchain: BlockchainConfig(
networkId: NetworkId.mainnet,
host: CatalystIdHost.cardano,
transactionBuilderConfig: _defaultTransactionBuilderConfig,
slotNumberConfig: BlockchainSlotNumberConfig.mainnet(),
),
);

Expand Down Expand Up @@ -154,26 +157,35 @@ final class BlockchainConfig extends Equatable {
final NetworkId networkId;
final CatalystIdHost host;
final TransactionBuilderConfig transactionBuilderConfig;
final BlockchainSlotNumberConfig slotNumberConfig;

const BlockchainConfig({
required this.networkId,
required this.host,
required this.transactionBuilderConfig,
required this.slotNumberConfig,
});

@override
List<Object?> get props => [networkId, host, transactionBuilderConfig];
List<Object?> get props => [
networkId,
host,
transactionBuilderConfig,
slotNumberConfig,
];

BlockchainConfig copyWith({
NetworkId? networkId,
CatalystIdHost? host,
TransactionBuilderConfig? transactionBuilderConfig,
BlockchainSlotNumberConfig? slotNumberConfig,
}) {
return BlockchainConfig(
networkId: networkId ?? this.networkId,
host: host ?? this.host,
transactionBuilderConfig:
transactionBuilderConfig ?? this.transactionBuilderConfig,
slotNumberConfig: slotNumberConfig ?? this.slotNumberConfig,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ final class AppConfigFactory {
remoteTransactionBuilderConfig?.selectionStrategy?.build(),
);

// Slot Number Config
final remoteSlotNumberConfig = remoteBlockchainConfig?.slotNumberConfig;
final effectiveSlotNumberConfig = blockchain.slotNumberConfig.copyWith(
systemStartTimestamp: remoteSlotNumberConfig?.systemStartTimestamp,
systemStartSlot: remoteSlotNumberConfig?.systemStartSlot?.asSlotBigNum(),
slotLength: remoteSlotNumberConfig?.slotLength?.asDuration(),
);

return defaultEnvConfig.copyWith(
version: remote.version,
cache: defaultEnvConfig.cache.copyWith(
Expand All @@ -65,6 +73,7 @@ final class AppConfigFactory {
networkId: remoteBlockchainConfig?.networkId?.tryParseNetworkId(),
host: remoteBlockchainConfig?.host?.tryParseCatalystIdHost(),
transactionBuilderConfig: effectiveTransactionBuilderConfig,
slotNumberConfig: effectiveSlotNumberConfig,
),
);
}
Expand All @@ -82,6 +91,8 @@ extension on int {
Coin asCoin() => Coin(this);

Duration asDuration() => Duration(seconds: this);

SlotBigNum asSlotBigNum() => SlotBigNum(this);
}

extension on RemoteTransactionSelectionStrategyType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,37 @@ final class RemoteBlockchainConfig {
final String? networkId;
final String? host;
final RemoteTransactionBuilderConfig? transactionBuilderConfig;
final RemoteSlotNumberConfig? slotNumberConfig;

RemoteBlockchainConfig({
this.networkId,
this.host,
this.transactionBuilderConfig,
this.slotNumberConfig,
});

factory RemoteBlockchainConfig.fromJson(Map<String, dynamic> json) {
return _$RemoteBlockchainConfigFromJson(json);
}
}

@JsonSerializable(createToJson: false)
final class RemoteSlotNumberConfig {
final DateTime? systemStartTimestamp;
final int? systemStartSlot;
final int? slotLength;

RemoteSlotNumberConfig({
this.systemStartTimestamp,
this.systemStartSlot,
this.slotLength,
});

factory RemoteSlotNumberConfig.fromJson(Map<String, dynamic> json) {
return _$RemoteSlotNumberConfigFromJson(json);
}
}

@JsonSerializable(createToJson: false)
final class RemoteTransactionBuilderConfig {
final RemoteTransactionTieredFee? feeAlgo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,37 @@ abstract class Configs {
"diagnosticLevel": "error"
}
}
''';

static String mainnetBlockchainSlotNumber = '''
{
"version": "0.1.0",
"createdAt": "2025-04-02T12:59:50.841808Z",
"blockchain": {
"networkId": "mainnet",
"host": "cardano",
"slotNumberConfig": {
"systemStartTimestamp":"2020-07-29T21:44:51.000000Z",
"systemStartSlot":4492800,
"slotLength":1
}
}
}
''';
static String testnetBlockchainSlotNumber = '''
{
"version": "0.1.0",
"createdAt": "2025-04-02T12:59:50.841808Z",
"blockchain": {
"networkId": "testnet",
"host": "cardano",
"slotNumberConfig": {
"systemStartTimestamp":"2022-06-21T00:00:00.000000Z",
"systemStartSlot":86400,
"slotLength":1
}
}
}
''';

const Configs._();
Expand Down
Loading
Loading