Skip to content

Commit

Permalink
Update backend to handle new type
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Jul 19, 2023
1 parent a1f9661 commit 353bbc2
Show file tree
Hide file tree
Showing 14 changed files with 2,909 additions and 475 deletions.
259 changes: 242 additions & 17 deletions sponsoredTransactions/backend/Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sponsoredTransactions/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license-file = "../../LICENSE"

[dependencies]
tokio = { version = "1", features = ["full"] }
tonic = {version = "0.8", features = ["tls", "tls-roots"]} # Use system trust roots.
warp = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
20 changes: 15 additions & 5 deletions sponsoredTransactions/backend/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,27 @@ pub async fn submit_transaction(
hex::decode_to_slice(request_signature, &mut signature)
.map_err(|_| LogError::SignatureError)?;

let mut inner_signature_map: BTreeMap<u8, types::SignatureEd25519> = BTreeMap::new();
inner_signature_map.insert(0, types::SignatureEd25519(signature));
let mut inner_signature_map = BTreeMap::new();
inner_signature_map.insert(
0,
types::Signature::Ed25519(types::SignatureEd25519(signature)),
);

let mut signature_map: BTreeMap<u8, BTreeMap<u8, types::SignatureEd25519>> = BTreeMap::new();
signature_map.insert(0, inner_signature_map);
let mut signature_map = BTreeMap::new();
signature_map.insert(
0,
types::CredentialSignatures {
sigs: inner_signature_map,
},
);

log::debug!("Create Parameter.");

let param: PermitParam = PermitParam {
message,
signature: signature_map,
signature: AccountSignatures {
sigs: signature_map,
},
signer,
};

Expand Down
15 changes: 14 additions & 1 deletion sponsoredTransactions/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use tokio::sync::Mutex;
use tonic::transport::ClientTlsConfig;
use warp::http;
use warp::Filter;

/// Structure used to receive the correct command line arguments.
Expand Down Expand Up @@ -59,7 +61,18 @@ async fn main() -> anyhow::Result<()> {
log_builder.filter_level(app.log_level); // filter filter_module(module_path!(), app.log_level);
log_builder.init();

let mut client_update_operator = concordium_rust_sdk::v2::Client::new(app.endpoint).await?;
let endpoint = if app
.endpoint
.uri()
.scheme()
.map_or(false, |x| x == &http::uri::Scheme::HTTPS)
{
app.endpoint.tls_config(ClientTlsConfig::new())?
} else {
app.endpoint
};

let mut client_update_operator = concordium_rust_sdk::v2::Client::new(endpoint).await?;

let client_transfer = client_update_operator.clone();

Expand Down
28 changes: 26 additions & 2 deletions sponsoredTransactions/backend/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ pub struct UpdateOperatorParams(#[concordium(size_length = 2)] pub Vec<UpdateOpe

#[derive(Debug, Serial, Clone)]
pub struct PermitParam {
#[concordium(size_length = 1)]
pub signature: BTreeMap<u8, BTreeMap<u8, SignatureEd25519>>,
pub signature: AccountSignatures,
pub signer: AccountAddress,
pub message: PermitMessage,
}
Expand All @@ -129,3 +128,28 @@ pub struct Server {
// The rate_limits are transient and are reset on server restart.
pub rate_limits: Arc<Mutex<HashMap<AccountAddress, u8>>>,
}

pub(crate) type CredentialIndex = u8;
pub(crate) type KeyIndex = u8;

#[derive(Serial, Debug, Clone)]
#[non_exhaustive]
/// A cryptographic signature indexed by the signature scheme. Currently only a
/// single scheme is supported, `ed25519`.
pub enum Signature {
Ed25519(SignatureEd25519),
}

#[derive(Debug, Serial, Clone)]
#[concordium(transparent)]
pub struct AccountSignatures {
#[concordium(size_length = 1)]
pub sigs: BTreeMap<CredentialIndex, CredentialSignatures>,
}

#[derive(Debug, Serial, Clone)]
#[concordium(transparent)]
pub struct CredentialSignatures {
#[concordium(size_length = 1)]
pub sigs: BTreeMap<KeyIndex, Signature>,
}
57 changes: 57 additions & 0 deletions sponsoredTransactions/frontend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: ['airbnb', 'airbnb-typescript', 'plugin:prettier/recommended', 'plugin:@typescript-eslint/recommended'],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
project: 'tsconfig.json',
createDefaultProgram: true,
},
env: {
browser: true,
jest: true,
node: true,
},
rules: {
'import/prefer-default-export': 0,
'no-restricted-exports': 0,
'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'],
'react/jsx-props-no-spreading': 0,
'react/require-default-props': 0,
'class-methods-use-this': 0,
'jsx-a11y/no-autofocus': 0,
'no-await-in-loop': 0,
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [
'**/*.stories.tsx',
'**/build/**/*',
'**/*.config.js',
'**/*.config.ts',
'**/test/**/*',
],
},
],
'jsx-a11y/label-has-associated-control': [
'error',
{
required: {
some: ['nesting', 'id'],
},
},
],
'prettier/prettier': [
'error',
{
trailingComma: 'es5',
singleQuote: true,
printWidth: 120,
tabWidth: 4,
},
],
},
};
2 changes: 1 addition & 1 deletion sponsoredTransactions/frontend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 2.0.0

- Remove tap to register public key
- Remove tab to register public key

## 1.1.0

Expand Down
19 changes: 18 additions & 1 deletion sponsoredTransactions/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"@concordium/browser-wallet-api-helpers": "2.4.0",
"@concordium/react-components": "^0.2.1",
"@concordium/react-components": "^0.3.0",
"@concordium/web-sdk": "^3.4.0",
"@thi.ng/leb128": "^2.1.18",
"@types/sha256": "^0.2.0",
Expand All @@ -26,12 +26,29 @@
"@types/node": "^18.7.23",
"@types/react": "^18.0.9",
"@types/react-dom": "^18.0.5",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"cross-env": "^7.0.3",
"esbuild": "^0.14.42",
"esbuild-plugin-svgr": "^1.0.1",
"eslint": "7",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.4.0",
"fs": "^0.0.1-security",
"live-server": "^1.2.2",
"prettier": "^2.6.2",
"process": "^0.11.10",
"stylelint": "^14.7.1",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-standard-scss": "^3.0.0",
"stylelint-prettier": "^2.0.0",
"stylelint-scss": "^4.2.0",
"ts-node": "^10.8.0",
"typescript": "^4.7.2"
},
Expand Down
4 changes: 3 additions & 1 deletion sponsoredTransactions/frontend/src/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default function Root() {
return (
<div>
<main className="sponsoredTransactions">
<WithWalletConnector network={TESTNET}>{(props) => <SponsoredTransactions {...props} />}</WithWalletConnector>
<WithWalletConnector network={TESTNET}>
{(props) => <SponsoredTransactions {...props} />}
</WithWalletConnector>
</main>
</div>
);
Expand Down
Loading

0 comments on commit 353bbc2

Please sign in to comment.