mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 02:51:01 +00:00
Merge commit '392447f5c8f986ded2559a78457f4cd87942f393' into update-bridges-subtree-r/w
This commit is contained in:
@@ -14,17 +14,22 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::ethereum_client::{bridge_contract, EthereumHighLevelRpc};
|
||||
use crate::rpc_errors::RpcError;
|
||||
use crate::{
|
||||
error::{Error, Result},
|
||||
ethereum_client::{bridge_contract, EthereumHighLevelRpc},
|
||||
rpc_errors::RpcError,
|
||||
};
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use num_traits::Zero;
|
||||
use relay_ethereum_client::{
|
||||
Client as EthereumClient, ConnectionParams as EthereumConnectionParams, SigningParams as EthereumSigningParams,
|
||||
Client as EthereumClient, ConnectionParams as EthereumConnectionParams,
|
||||
SigningParams as EthereumSigningParams,
|
||||
};
|
||||
use relay_rialto_client::{HeaderId as RialtoHeaderId, Rialto};
|
||||
use relay_substrate_client::{
|
||||
Client as SubstrateClient, ConnectionParams as SubstrateConnectionParams, OpaqueGrandpaAuthoritiesSet,
|
||||
Client as SubstrateClient, ConnectionParams as SubstrateConnectionParams,
|
||||
OpaqueGrandpaAuthoritiesSet,
|
||||
};
|
||||
use relay_utils::HeaderId;
|
||||
|
||||
@@ -100,21 +105,21 @@ pub async fn run(params: EthereumDeployContractParams) {
|
||||
async fn prepare_initial_header(
|
||||
sub_client: &SubstrateClient<Rialto>,
|
||||
sub_initial_header: Option<Vec<u8>>,
|
||||
) -> Result<(RialtoHeaderId, Vec<u8>), String> {
|
||||
) -> Result<(RialtoHeaderId, Vec<u8>)> {
|
||||
match sub_initial_header {
|
||||
Some(raw_initial_header) => match rialto_runtime::Header::decode(&mut &raw_initial_header[..]) {
|
||||
Ok(initial_header) => Ok((
|
||||
HeaderId(initial_header.number, initial_header.hash()),
|
||||
raw_initial_header,
|
||||
)),
|
||||
Err(error) => Err(format!("Error decoding initial header: {}", error)),
|
||||
Some(raw_initial_header) => {
|
||||
match rialto_runtime::Header::decode(&mut &raw_initial_header[..]) {
|
||||
Ok(initial_header) =>
|
||||
Ok((HeaderId(initial_header.number, initial_header.hash()), raw_initial_header)),
|
||||
Err(error) => Err(Error::DecodeInitialHeader(error)),
|
||||
}
|
||||
},
|
||||
None => {
|
||||
let initial_header = sub_client.header_by_number(Zero::zero()).await;
|
||||
initial_header
|
||||
.map(|header| (HeaderId(Zero::zero(), header.hash()), header.encode()))
|
||||
.map_err(|error| format!("Error reading Substrate genesis header: {:?}", error))
|
||||
}
|
||||
.map_err(Error::ReadGenesisHeader)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,13 +128,13 @@ async fn prepare_initial_authorities_set(
|
||||
sub_client: &SubstrateClient<Rialto>,
|
||||
sub_initial_header_hash: rialto_runtime::Hash,
|
||||
sub_initial_authorities_set: Option<Vec<u8>>,
|
||||
) -> Result<OpaqueGrandpaAuthoritiesSet, String> {
|
||||
) -> Result<OpaqueGrandpaAuthoritiesSet> {
|
||||
let initial_authorities_set = match sub_initial_authorities_set {
|
||||
Some(initial_authorities_set) => Ok(initial_authorities_set),
|
||||
None => sub_client.grandpa_authorities_set(sub_initial_header_hash).await,
|
||||
};
|
||||
|
||||
initial_authorities_set.map_err(|error| format!("Error reading GRANDPA authorities set: {:?}", error))
|
||||
initial_authorities_set.map_err(Error::ReadAuthorities)
|
||||
}
|
||||
|
||||
/// Deploy bridge contract to Ethereum chain.
|
||||
@@ -140,15 +145,20 @@ async fn deploy_bridge_contract(
|
||||
initial_header: Vec<u8>,
|
||||
initial_set_id: u64,
|
||||
initial_authorities: Vec<u8>,
|
||||
) -> Result<(), String> {
|
||||
) -> Result<()> {
|
||||
eth_client
|
||||
.submit_ethereum_transaction(
|
||||
params,
|
||||
None,
|
||||
None,
|
||||
false,
|
||||
bridge_contract::constructor(contract_code, initial_header, initial_set_id, initial_authorities),
|
||||
bridge_contract::constructor(
|
||||
contract_code,
|
||||
initial_header,
|
||||
initial_set_id,
|
||||
initial_authorities,
|
||||
),
|
||||
)
|
||||
.await
|
||||
.map_err(|error| format!("Error deploying contract: {:?}", error))
|
||||
.map_err(Error::DeployContract)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user