1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// This file is part of Darwinia.
//
// Copyright (C) 2018-2022 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

//! Pangoro service. Specialized wrapper over substrate service.

// --- std ---
use std::sync::Arc;
// --- darwinia-network ---
use crate::{
	client::DrmlClient,
	service::{self, *},
};
use drml_primitives::OpaqueBlock as Block;
use pangoro_runtime::RuntimeApi;

pub struct Executor;
impl sc_executor::NativeExecutionDispatch for Executor {
	type ExtendHostFunctions =
		(frame_benchmarking::benchmarking::HostFunctions, dp_evm_trace_ext::dvm_ext::HostFunctions);

	fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
		pangoro_runtime::api::dispatch(method, data)
	}

	fn native_version() -> sc_executor::NativeVersion {
		pangoro_runtime::native_version()
	}
}

/// Create a new Pangoro service for a full node.
#[cfg(feature = "full-node")]
pub fn new_full(
	config: sc_service::Configuration,
	authority_discovery_disabled: bool,
	eth_rpc_config: drml_rpc::EthRpcConfig,
) -> ServiceResult<(
	sc_service::TaskManager,
	Arc<impl DrmlClient<Block, FullBackend, RuntimeApi>>,
	sc_service::RpcHandlers,
)> {
	let (components, client, rpc_handlers) = service::new_full::<RuntimeApi, Executor>(
		config,
		authority_discovery_disabled,
		eth_rpc_config,
	)?;

	Ok((components, client, rpc_handlers))
}