Skip to content

Commit

Permalink
Rework docker stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch committed Nov 25, 2022
1 parent 4beb6f0 commit f931877
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 73 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"rosetta-cli",
"rosetta-client",
"rosetta-crypto",
"rosetta-server-polkadot",
"rosetta-server-substrate",
"rosetta-types",
"rosetta-wallet",
Expand Down
33 changes: 18 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: "3.9"
services:
bitcoin:
rosetta-bitcoin:
image: "analoglabs/rosetta-bitcoin"
environment:
- NETWORK=REGTEST
Expand All @@ -10,7 +10,7 @@ services:
- "8080:8080"
- "18333:18333"
- "18443:18443"
ethereum:
rosetta-ethereum:
image: "analoglabs/rosetta-ethereum"
environment:
- NETWORK=TESTNET
Expand All @@ -20,26 +20,29 @@ services:
- "8081:8081"
- "30303:30303"
- "8545:8545"
rosetta-substrate:
image: "analoglabs/rosetta-substrate"
rosetta-polkadot:
image: "analoglabs/rosetta-polkadot"
command: "--network dev --url http://0.0.0.0:8082 --rpc-url ws://polkadot:9944"
build:
context: "."
dockerfile: "./rosetta-server-substrate/Dockerfile"
environment:
- PORT=8082
- NETWORK=DEV
- NODE=ws://polkadot:9944
dockerfile: "./rosetta-server-polkadot/Dockerfile"
restart: always
ports:
- "8082:8082"
- "8082:8082"
links:
- polkadot
polkadot:
image: "parity/polkadot:v0.9.32"
command: "--chain dev --ws-external --rpc-external --rpc-cors=all --force-authoring --alice --tmp"
restart: always
ports:
- "30333:30333"
- "9944:9944"
explorer:
image: "analoglabs/rosetta-explorer"
restart: always
ports:
- "3000:3000"
- "3000:3000"
links:
- bitcoin
- ethereum
- polkadot
- rosetta-bitcoin
- rosetta-ethereum
- rosetta-polkadot
12 changes: 12 additions & 0 deletions rosetta-server-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "rosetta-server-polkadot"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.66"
clap = { version = "4.0.27", features = ["derive"] }
femme = "2.2.1"
rosetta-server-substrate = { path = "../rosetta-server-substrate" }
tide = "0.16.0"
tokio = { version = "1.21.2", features = ["full"] }
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM ubuntu:20.04 as builder
FROM rust:1.64 as builder

# build rosetta
COPY . src
RUN cd src && cargo install --path rosetta-server-substrate --root /app
RUN cd src && cargo install --path rosetta-server-polkadot --root /app

# final image
FROM ubuntu:20.04
Expand All @@ -16,8 +16,8 @@ RUN mkdir -p /app \

WORKDIR /app

COPY --from=builder /app/bin/rosetta-server-substrate /app/rosetta-server-substrate
COPY --from=builder /app/bin/rosetta-server-polkadot /app/rosetta-server-polkadot

RUN chmod -R 755 /app/*

CMD /app/rosetta-server-substrate
ENTRYPOINT ["/app/rosetta-server-polkadot"]
63 changes: 63 additions & 0 deletions rosetta-server-polkadot/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use anyhow::{Context, Result};
use clap::Parser;
use rosetta_server_substrate::{Config, Ss58AddressFormatRegistry};

#[derive(Parser)]
struct Opts {
#[clap(long, default_value = "dev")]
network: String,
#[clap(long, default_value = "http://127.0.0.1:8082")]
url: String,
#[clap(long, default_value = "ws://127.0.0.1:9944")]
rpc_url: String,
}

#[tokio::main]
async fn main() -> Result<()> {
femme::start();
let opts = Opts::parse();

let config = match opts.network.as_str() {
"dev" => Config::new(
&opts.rpc_url,
"Polkadot",
"Dev",
"DOT",
10,
Ss58AddressFormatRegistry::PolkadotAccount,
true,
),
"kusama" => Config::new(
&opts.rpc_url,
"Kusama",
"Kusama",
"KSM",
12,
Ss58AddressFormatRegistry::KusamaAccount,
false,
),
"polkadot" => Config::new(
&opts.rpc_url,
"Polkadot",
"Polkadot",
"DOT",
10,
Ss58AddressFormatRegistry::PolkadotAccount,
false,
),
_ => anyhow::bail!("unsupported network"),
};

let server = rosetta_server_substrate::server(&config)
.await
.with_context(|| format!("connecting to {}", &opts.rpc_url))?;

let mut app = tide::new();
app.with(tide::log::LogMiddleware::new());
app.at("/").nest(server);
app.listen(&opts.url)
.await
.with_context(|| format!("listening on {}", &opts.url))?;

Ok(())
}
3 changes: 0 additions & 3 deletions rosetta-server-substrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ anyhow = "1.0.65"
array-bytes = "4.1.0"
blake2-rfc = "0.2.18"
bs58 = "0.4.0"
femme = "2.2.1"
hex = "0.4.3"
parity-scale-codec = "3.2.1"
rosetta-types = { path = "../rosetta-types" }
Expand All @@ -17,7 +16,5 @@ serde_json = "1.0.87"
sp-keyring = "6.0.0"
ss58-registry = "1.31.0"
subxt = "0.24.0"
subxt-codegen = "0.25.0"
syn = "1.0.80"
tide = "0.16.0"
tokio = { version = "1.21.2", features = ["full"] }
3 changes: 2 additions & 1 deletion rosetta-server-substrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rosetta_types::{
NetworkOptionsResponse, NetworkRequest, NetworkStatusResponse, Operation, SignatureType,
SigningPayload, TransactionIdentifier, TransactionIdentifierResponse, Version,
};
use ss58_registry::{Ss58AddressFormat, Ss58AddressFormatRegistry};
use std::str::FromStr;
use std::time::Duration;
use subxt::ext::sp_core::blake2_256;
Expand All @@ -32,6 +31,8 @@ use utils::{
mod ss58;
mod utils;

pub use ss58_registry::{Ss58AddressFormat, Ss58AddressFormatRegistry};

pub struct Config {
pub rpc_url: String,
pub network: NetworkIdentifier,
Expand Down
50 changes: 0 additions & 50 deletions rosetta-server-substrate/src/main.rs

This file was deleted.

0 comments on commit f931877

Please sign in to comment.