rosetta_config_polkadot/
lib.rs

1use anyhow::Result;
2use rosetta_core::crypto::address::{AddressFormat, Ss58AddressFormatRegistry};
3use rosetta_core::crypto::Algorithm;
4use rosetta_core::BlockchainConfig;
5use serde::{Deserialize, Serialize};
6use std::sync::Arc;
7
8pub fn config(network: &str) -> Result<BlockchainConfig> {
9    let (network, kusama) = match network {
10        "dev" => ("dev", false),
11        "kusama" => ("kusama", true),
12        "polkadot" => ("polkadot", false),
13        _ => anyhow::bail!("unsupported network"),
14    };
15    Ok(BlockchainConfig {
16        blockchain: "polkadot",
17        network,
18        algorithm: Algorithm::Sr25519,
19        address_format: AddressFormat::Ss58(
20            if kusama {
21                Ss58AddressFormatRegistry::PolkadotAccount
22            } else {
23                Ss58AddressFormatRegistry::KusamaAccount
24            }
25            .into(),
26        ),
27        coin: 1,
28        bip44: false,
29        utxo: false,
30        currency_unit: "planck",
31        currency_symbol: if kusama { "KSM" } else { "DOT" },
32        currency_decimals: if kusama { 12 } else { 10 },
33        node_port: 9944,
34        node_image: "parity/polkadot:v0.9.37",
35        node_command: Arc::new(|network, port| {
36            vec![
37                format!("--chain={network}"),
38                "--rpc-cors=all".into(),
39                "--ws-external".into(),
40                format!("--ws-port={port}"),
41                "--alice".into(),
42                "--tmp".into(),
43            ]
44        }),
45        node_additional_ports: &[],
46        connector_port: 8082,
47        testnet: network == "dev",
48    })
49}
50
51#[derive(Clone, Deserialize, Serialize)]
52pub struct PolkadotMetadataParams {
53    pub pallet_name: String,
54    pub call_name: String,
55    pub call_args: Vec<u8>,
56}
57
58#[derive(Deserialize, Serialize)]
59pub struct PolkadotMetadata {
60    pub nonce: u32,
61    pub spec_version: u32,
62    pub transaction_version: u32,
63    pub genesis_hash: [u8; 32],
64    pub pallet_index: u8,
65    pub call_index: u8,
66    pub call_hash: [u8; 32],
67}