Skip to content

Commit

Permalink
wip: initial walkthrough of documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dutterbutter committed Mar 28, 2022
1 parent fc5f1e7 commit b3e9949
Show file tree
Hide file tree
Showing 25 changed files with 577 additions and 40 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/publish-rust-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish Docs

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
publish_docs:
if: github.event_name == 'push' && github.event.ref == 'refs/heads/master'
name: Publish Documentation
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly

- name: Update apt repositories
run: sudo apt update

- name: Build documentation
run: cargo doc --no-deps
- name: Publish documentation
run: |
cd target/doc
git init
echo '<meta http-equiv="refresh" content="0; url=https://webb-tools.github.io/relayer/handler/index.html">' > index.html
git add .
git -c user.name='ci' -c user.email='ci' commit -m 'Deploy documentation 🚀'
git push -f -q https://git:${{ secrets.github_token }}@github.com/${{ github.repository }} HEAD:gh-pages
49 changes: 49 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2022 Webb Technologies Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

header:
license:
spdx-id: Apache-2.0
copyright-owner: Webb Technologies Inc.

paths-ignore:
- 'store/*'
- '**/*.env'
- '**/*.bash'
- 'target/*'
- 'rust-toolchain'
- '**/*.conf'
- '.env-example'
- 'tests/protocol-solidity-fixtures/*'
- '.eslintignore'
- 'licenses'
- '**/*.md'
- 'LICENSE'
- 'NOTICE'
- '.gitignore'
- '.dockerignore'
- '.editorconfig'
- '.gitmodules'
- '**/*.yml'
- '**/*.json'
- '**/*.lock'
- '**/*.toml'
- '**/*.yaml'
- '.nvmrc'
- 'jest.config.js'
- '*/**.mjs'
- '**/*.sh'
- 'node_modules/*'

comment: on-failure
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2022 Webb Technologies Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
FROM scratch
LABEL APP ="Webb Relayer"
LABEL AUTHOR="Webb Developers <dev@webb.tools>"
Expand Down
44 changes: 30 additions & 14 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2022 Webb Technologies Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
use std::collections::HashMap;
use std::path::Path;
use std::str::FromStr;
Expand All @@ -22,7 +36,7 @@ const fn max_events_per_step_default() -> u64 {
const fn print_progress_interval_default() -> u64 {
7_000
}

/// WebbRelayerConfig is the configuration for the webb relayer.
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
#[serde(rename_all = "kebab-case")]
pub struct WebbRelayerConfig {
Expand All @@ -45,7 +59,7 @@ pub struct WebbRelayerConfig {
#[serde(default)]
pub experimental: ExperimentalConfig,
}

/// EvmChainConfig is the configuration for the EVM based networks.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct EvmChainConfig {
Expand Down Expand Up @@ -92,7 +106,7 @@ pub struct EvmChainConfig {
#[serde(skip_serializing, default)]
pub tx_queue: TxQueueConfig,
}

/// SubstrateConfig is the configuration for the Substrate based networks.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct SubstrateConfig {
Expand Down Expand Up @@ -157,7 +171,7 @@ pub struct ExperimentalConfig {
pub smart_anchor_updates: bool,
pub smart_anchor_updates_retries: u32,
}

/// TxQueueConfig is the configuration for the TxQueue.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct TxQueueConfig {
Expand All @@ -173,6 +187,7 @@ impl Default for TxQueueConfig {
}
}
}
/// EventsWatchConfig is the configuration for the events watch.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct EventsWatcherConfig {
Expand Down Expand Up @@ -202,7 +217,7 @@ pub struct AnchorWithdrawConfig {
#[serde(skip_serializing)]
pub withdraw_gaslimit: U256,
}

/// LinkedAnchorConfig is the configuration for the linked anchor.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct LinkedAnchorConfig {
Expand All @@ -212,29 +227,29 @@ pub struct LinkedAnchorConfig {
/// The Anchor Contract Address.
pub address: Address,
}

/// Enumerates the supported contract configurations.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "contract")]
pub enum Contract {
Tornado(TornadoContractConfig),
AnchorOverDKG(AnchorContractOverDKGConfig),
GovernanceBravoDelegate(GovernanceBravoDelegateContractConfig),
}

/// Enumerates the supported pallets configurations.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "pallet")]
pub enum Pallet {
DKGProposals(DKGProposalsPalletConfig),
DKGProposalHandler(DKGProposalHandlerPalletConfig),
}

/// Enumerates the supported Substrate runtimes.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SubstrateRuntime {
#[serde(rename = "DKG")]
Dkg,
WebbProtocol,
}

/// CommonContractConfig represents the common configuration for contracts.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct CommonContractConfig {
Expand All @@ -244,7 +259,7 @@ pub struct CommonContractConfig {
#[serde(rename(serialize = "deployedAt"))]
pub deployed_at: u64,
}

/// TornadoContractConfig represents the configuration for the Tornado contract.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct TornadoContractConfig {
Expand All @@ -259,7 +274,7 @@ pub struct TornadoContractConfig {
#[serde(flatten)]
pub withdraw_config: AnchorWithdrawConfig,
}

/// AnchorContractOverDKGConfig represents the configuration for the Anchor contract over DKG.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct AnchorContractOverDKGConfig {
Expand All @@ -281,23 +296,23 @@ pub struct AnchorContractOverDKGConfig {
#[serde(rename(serialize = "linkedAnchors"))]
pub linked_anchors: Vec<LinkedAnchorConfig>,
}

/// GovernanceBravoDelegateContractConfig represents the configuration for the GovernanceBravoDelegate contract.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct GovernanceBravoDelegateContractConfig {
#[serde(flatten)]
pub common: CommonContractConfig,
// TODO(@shekohex): add more fields here...
}

/// DKGProposalsPalletConfig represents the configuration for the DKGProposals pallet.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct DKGProposalsPalletConfig {
/// Controls the events watcher
#[serde(rename(serialize = "eventsWatcher"))]
pub events_watcher: EventsWatcherConfig,
}

/// DKGProposalHandlerPalletConfig represents the configuration for the DKGProposalHandler pallet.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct DKGProposalHandlerPalletConfig {
Expand Down Expand Up @@ -455,6 +470,7 @@ impl<'de> Deserialize<'de> for Suri {
Ok(Self(secret))
}
}
/// load the private key from the environment variable
pub fn load<P: AsRef<Path>>(path: P) -> anyhow::Result<WebbRelayerConfig> {
let mut cfg = config::Config::new();
// A pattern that covers all toml or json files in the config directory and subdirectories.
Expand Down
29 changes: 22 additions & 7 deletions src/context.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2022 Webb Technologies Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
use std::convert::TryFrom;
use std::time::Duration;

Expand All @@ -9,7 +23,7 @@ use webb::substrate::subxt;
use webb::substrate::subxt::sp_core::sr25519::Pair as Sr25519Pair;

use crate::config;

/// RelayerContext contains Relayer's configuration and shutdown signal.
#[derive(Clone)]
pub struct RelayerContext {
pub config: config::WebbRelayerConfig,
Expand All @@ -25,22 +39,23 @@ pub struct RelayerContext {
}

impl RelayerContext {
/// Creates a new RelayerContext.
pub fn new(config: config::WebbRelayerConfig) -> Self {
let (notify_shutdown, _) = broadcast::channel(2);
Self {
config,
notify_shutdown,
}
}

/// Returns a broadcast receiver handle for the shutdown signal.
pub fn shutdown_signal(&self) -> Shutdown {
Shutdown::new(self.notify_shutdown.subscribe())
}

/// Sends a shutdown signal to all active connections.
pub fn shutdown(&self) {
let _ = self.notify_shutdown.send(());
}

/// evm_provider returns an Ethers provider for the configured EVM chain.
pub async fn evm_provider(
&self,
chain_name: &str,
Expand All @@ -53,7 +68,7 @@ impl RelayerContext {
.interval(Duration::from_millis(5u64));
Ok(provider)
}

/// evm_wallet returns an Ethers wallet for the configured EVM chain.
pub async fn evm_wallet(
&self,
chain_name: &str,
Expand All @@ -67,7 +82,7 @@ impl RelayerContext {
let wallet = LocalWallet::from(key).with_chain_id(chain_id);
Ok(wallet)
}

/// substrate_provider returns a Substrate provider for the configured
pub async fn substrate_provider<C: subxt::Config>(
&self,
node_name: &str,
Expand All @@ -87,7 +102,7 @@ impl RelayerContext {
))?;
Ok(client)
}

/// substrate_wallet returns a Substrate wallet for the configured Substrate chain.
pub async fn substrate_wallet(
&self,
node_name: &str,
Expand Down
Loading

0 comments on commit b3e9949

Please sign in to comment.