Skip to content

Commit

Permalink
Merge branch 'main' into feature/fragments-endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Rosa authored Nov 20, 2023
2 parents dda613f + e82e3c8 commit 1e51360
Show file tree
Hide file tree
Showing 53 changed files with 735 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .config/dictionaries/project.dic
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dotglob
drep
dreps
encryptor
gapless
gcloud
genhtml
gmtime
Expand All @@ -50,6 +51,7 @@ netkey
oneshot
openapi
opentelemetry
pbxproj
Pdart
permissionless
pg_isready
Expand All @@ -75,12 +77,14 @@ thiserror
timelike
Traceback
TXNZD
unmanaged
vitss
voteplan
voteplans
xcconfig
xcfilelist
xcodebuild
xcodeproj
xctest
xctestrun
xcworkspace
Expand Down
18 changes: 16 additions & 2 deletions catalyst-gateway/bin/src/service/api/v0/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
//! `v0` Endpoints
use std::sync::Arc;

use poem::web::Data;
use poem_openapi::{payload::Binary, OpenApi};

use crate::service::common::tags::ApiTags;
use crate::{service::common::tags::ApiTags, state::State};

mod message_post;
mod plans_get;

/// `v0` API Endpoints
pub(crate) struct V0Api;

#[OpenApi(prefix_path = "/v0", tag = "ApiTags::V0")]
impl V0Api {
#[oai(path = "/message", method = "post", operation_id = "Message")]
/// Posts a signed transaction.
#[oai(path = "/message", method = "post", operation_id = "Message")]
async fn message_post(&self, message: Binary<Vec<u8>>) -> message_post::AllResponses {
message_post::endpoint(message).await
}

/// Get all active vote plans endpoint.
#[oai(
path = "/vote/active/plans",
method = "get",
operation_id = "GetActivePlans"
)]
async fn plans_get(&self, state: Data<&Arc<State>>) -> plans_get::AllResponses {
plans_get::endpoint(state).await
}
}

// Poem Tests cause license violation...
Expand Down
41 changes: 41 additions & 0 deletions catalyst-gateway/bin/src/service/api/v0/plans_get.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! Implementation of the GET /vote/active/plans endpoint
use std::sync::Arc;

use poem::web::Data;
use poem_extensions::{response, UniResponse::T200};
use poem_openapi::payload::Json;

use crate::{
service::common::{
objects::vote_plan::VotePlan,
responses::{
resp_2xx::OK,
resp_5xx::{ServerError, ServiceUnavailable},
},
},
state::State,
};

/// All responses
pub(crate) type AllResponses = response! {
200: OK<Json<Vec<VotePlan>>>,
500: ServerError,
503: ServiceUnavailable,
};

/// GET /v0/vote/active/plans
///
/// Get all active vote plans endpoint.
///
/// ## Responses
///
/// * 200 with a JSON array with the list of vote plans with their respective data.
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible
/// but unlikely)
/// * 503 Service Unavailable - Service has not started, do not send other requests.
#[allow(clippy::unused_async)]
pub(crate) async fn endpoint(_state: Data<&Arc<State>>) -> AllResponses {
// otherwise everything seems to be A-OK
T200(OK(Json(Vec::new())))
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub(crate) type AllResponses = response! {
503: ServiceUnavailable,
};

#[allow(clippy::unused_async)]
/// GET /v1/votes/plans/account-votes/:account_id
///
/// Get votes for an `account_id` endpoint.
Expand All @@ -38,6 +37,7 @@ pub(crate) type AllResponses = response! {
/// * 500 Server Error - If anything within this function fails unexpectedly. (Possible
/// but unlikely)
/// * 503 Service Unavailable - Service has not started, do not send other requests.
#[allow(clippy::unused_async)]
pub(crate) async fn endpoint(
_state: Data<&Arc<State>>, _account_id: Path<AccountId>,
) -> AllResponses {
Expand Down
1 change: 1 addition & 0 deletions catalyst-gateway/bin/src/service/common/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub(crate) mod fragments_batch;
pub(crate) mod fragments_processing_summary;
pub(crate) mod hash;
pub(crate) mod stake_public_key;
pub(crate) mod vote_plan;
pub(crate) mod voter_group_id;
pub(crate) mod voter_info;
pub(crate) mod voter_registration;
Expand Down
26 changes: 26 additions & 0 deletions catalyst-gateway/bin/src/service/common/objects/vote_plan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! Define the Vote Plan
use poem_openapi::{types::Example, Object};

/// Vote Plan
#[derive(Object)]
#[oai(example = true)]
pub(crate) struct VotePlan {
/// Voting token identifier
#[oai(validator(
max_length = 121,
min_length = 59,
pattern = r"[0-9a-f]{56}\.[0-9a-f]{2,64}"
))]
voting_token: String,
}

impl Example for VotePlan {
fn example() -> Self {
Self {
voting_token:
"134c2d0a0b5761445d3f2d08492a5c193e3a19194453511426153630.0418401957301613"
.to_string(),
}
}
}
25 changes: 23 additions & 2 deletions catalyst_voices/lib/dummy/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
import 'package:catalyst_voices/dummy/dummy.dart';
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart';
import 'package:flutter/material.dart';

final class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});

@override
Widget build(BuildContext context) {
return const Scaffold(
return Scaffold(
key: WidgetKeys.homeScreen,
body: Center(
child: Text('Catalyst Voices'),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Catalyst Voices',
style: TextStyle(
color: VoicesColors.purpleGradientStart,
fontFamily: VoicesFonts.sFPro,
fontSize: 32,
),
),
const SizedBox(height: 20),
SizedBox(
height: 200,
width: 200,
child: CatalystImage.asset(
VoicesAssets.images.dummyCatalystVoices.path,
),
),
],
),
),
);
}
Expand Down
10 changes: 5 additions & 5 deletions catalyst_voices/lib/dummy/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class _LoginPageState extends State<LoginPage> {
padding: const EdgeInsets.all(16),
child: ElevatedButton(
key: WidgetKeys.loginButton,
onPressed: () => _loginButtonPressed(context),
onPressed: () async => _loginButtonPressed(context),
child: const Text(_Constants.loginButtonText),
),
),
Expand All @@ -87,16 +87,16 @@ final class _LoginPageState extends State<LoginPage> {
passwordTextController = TextEditingController();
}

void _loginButtonPressed(BuildContext context) {
Future<void> _loginButtonPressed(BuildContext context) async {
if (_validateCredentials()) {
_navigateToHomeScreen(context);
await _navigateToHomeScreen(context);
} else {
_showError(context);
}
}

void _navigateToHomeScreen(BuildContext context) {
Navigator.push(
Future<void> _navigateToHomeScreen(BuildContext context) async {
await Navigator.push(
context,
MaterialPageRoute<HomeScreen>(
builder: (context) => const HomeScreen(),
Expand Down
4 changes: 2 additions & 2 deletions catalyst_voices/lib/main_development.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:catalyst_voices/app/app.dart';
import 'package:catalyst_voices/bootstrap.dart';

void main() {
bootstrap(() => const App());
void main() async {
await bootstrap(() => const App());
}
4 changes: 2 additions & 2 deletions catalyst_voices/lib/main_production.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:catalyst_voices/app/app.dart';
import 'package:catalyst_voices/bootstrap.dart';

void main() {
bootstrap(() => const App());
void main() async {
await bootstrap(() => const App());
}
4 changes: 2 additions & 2 deletions catalyst_voices/lib/main_staging.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:catalyst_voices/app/app.dart';
import 'package:catalyst_voices/bootstrap.dart';

void main() {
bootstrap(() => const App());
void main() async {
await bootstrap(() => const App());
}
Empty file removed catalyst_voices/packages/.gitkeep
Empty file.
43 changes: 43 additions & 0 deletions catalyst_voices/packages/catalyst_voices_assets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# VSCode related
.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/
pubspec.lock

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Test related
coverage
5 changes: 5 additions & 0 deletions catalyst_voices/packages/catalyst_voices_assets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Catalyst Voices Assets

```sh
dart run build_runner build
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFF</color>
<color name="dark_background ">#000000</color>
<color name="purple">#512DA8</color>
<color name="purple_gradient_start">#673AB7</color>
<color name="purple_gradient_stop">#512DA8</color>
<color name="dark_card">#222126</color>
<color name="green">#7CAE7A</color>
<color name="red">#B02E0C</color>
<color name="today">#565656</color>
</resources>
Binary file not shown.
Binary file not shown.
43 changes: 43 additions & 0 deletions catalyst_voices/packages/catalyst_voices_assets/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
30 changes: 30 additions & 0 deletions catalyst_voices/packages/catalyst_voices_assets/example/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "db7ef5bf9f59442b0e200a90587e8fa5e0c6336a"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: db7ef5bf9f59442b0e200a90587e8fa5e0c6336a
base_revision: db7ef5bf9f59442b0e200a90587e8fa5e0c6336a
- platform: web
create_revision: db7ef5bf9f59442b0e200a90587e8fa5e0c6336a
base_revision: db7ef5bf9f59442b0e200a90587e8fa5e0c6336a

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
Loading

0 comments on commit 1e51360

Please sign in to comment.