Skip to content

Commit

Permalink
Rename Primitive Crates (paritytech#271)
Browse files Browse the repository at this point in the history
* Rename Ethereum PoA primitives crate

The "sp" prefix comes from Substrate primitives, since this crate originated
in that repo. However, it is not part of Substrate anymore and its name should
be updated to reflect that.

* Rename currency exchange primitives

* Rust Fmt

* Update import in benchmarking module

* Rust Fmt

* Split pub and no-pub

* Sort toml files.

Co-authored-by: Tomasz Drwięga <tomasz@parity.io>
  • Loading branch information
2 people authored and bkchr committed Apr 10, 2024
1 parent 868814e commit 9f6bd28
Show file tree
Hide file tree
Showing 25 changed files with 104 additions and 102 deletions.
2 changes: 1 addition & 1 deletion bridges/bin/node/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
name = "bridge-node"

[dependencies]
bp-eth-poa = { version = "0.1.0", path = "../../../primitives/ethereum-poa" }
futures = "0.3.5"
jsonrpc-core = "14.2.0"
log = "0.4.11"
structopt = "0.3.15"
sp-bridge-eth-poa = { version = "0.1.0", path = "../../../primitives/ethereum-poa" }

[dependencies.bridge-node-runtime]
version = "0.1.0"
Expand Down
44 changes: 23 additions & 21 deletions bridges/bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,6 @@ tag = 'v2.0.0-rc5'
default-features = false
git = "https://github.com/paritytech/substrate/"

[dependencies.sp-bridge-eth-poa]
version = "0.1.0"
default-features = false
path = "../../../primitives/ethereum-poa"

[dependencies.sp-currency-exchange]
version = "0.1.0"
default-features = false
path = "../../../primitives/currency-exchange"

[dependencies.sp-consensus-aura]
version = "0.8.0-rc5"
tag = 'v2.0.0-rc5'
Expand Down Expand Up @@ -206,12 +196,24 @@ tag = 'v2.0.0-rc5'
default-features = false
git = "https://github.com/paritytech/substrate/"

[dependencies.bp-currency-exchange]
version = "0.1.0"
default-features = false
path = "../../../primitives/currency-exchange"

[dependencies.bp-eth-poa]
version = "0.1.0"
default-features = false
path = "../../../primitives/ethereum-poa"

# Dev Dependencies

[dev-dependencies.libsecp256k1]
version = "0.3.4"
default-features = false
features = ["hmac"]

[dev-dependencies.sp-bridge-eth-poa]
[dev-dependencies.bp-eth-poa]
version = "0.1.0"
default-features = false
features = ["std"]
Expand All @@ -226,23 +228,26 @@ git = "https://github.com/paritytech/substrate/"
[features]
default = ["std"]
std = [
"pallet-aura/std",
"pallet-balances/std",
"pallet-bridge-eth-poa/std",
"pallet-bridge-currency-exchange/std",
"bp-currency-exchange/std",
"bp-eth-poa/std",
"codec/std",
"frame-benchmarking/std",
"frame-executive/std",
"frame-support/std",
"frame-system/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"pallet-aura/std",
"pallet-balances/std",
"pallet-bridge-currency-exchange/std",
"pallet-bridge-eth-poa/std",
"pallet-grandpa/std",
"pallet-randomness-collective-flip/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment/std",
"serde",
"sp-api/std",
"sp-block-builder/std",
"sp-bridge-eth-poa/std",
"sp-currency-exchange/std",
"sp-consensus-aura/std",
"sp-core/std",
"sp-inherents/std",
Expand All @@ -253,9 +258,6 @@ std = [
"sp-std/std",
"sp-transaction-pool/std",
"sp-version/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment/std",
]
runtime-benchmarks = [
"frame-benchmarking",
Expand Down
18 changes: 9 additions & 9 deletions bridges/bin/node/runtime/src/exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
//! to the PoA -> Substrate bridge module (it can be provided by you);
//! 5) receive tokens by providing proof-of-inclusion of PoA transaction.
use bp_currency_exchange::{
Error as ExchangeError, LockFundsTransaction, MaybeLockFundsTransaction, Result as ExchangeResult,
};
use bp_eth_poa::{transaction_decode_rlp, RawTransaction, RawTransactionReceipt};
use codec::{Decode, Encode};
use frame_support::RuntimeDebug;
use hex_literal::hex;
use sp_bridge_eth_poa::{transaction_decode_rlp, RawTransaction, RawTransactionReceipt};
use sp_currency_exchange::{
Error as ExchangeError, LockFundsTransaction, MaybeLockFundsTransaction, Result as ExchangeResult,
};
use sp_std::vec::Vec;

/// Ethereum address where locked PoA funds must be sent to.
Expand Down Expand Up @@ -130,12 +130,12 @@ impl MaybeLockFundsTransaction for EthTransaction {
#[cfg(feature = "runtime-benchmarks")]
pub(crate) fn prepare_environment_for_claim<T: pallet_bridge_eth_poa::Trait<I>, I: pallet_bridge_eth_poa::Instance>(
transactions: &[(RawTransaction, RawTransactionReceipt)],
) -> sp_bridge_eth_poa::H256 {
) -> bp_eth_poa::H256 {
use bp_eth_poa::compute_merkle_root;
use pallet_bridge_eth_poa::{
test_utils::{insert_header, validator_utils::validator, HeaderBuilder},
BridgeStorage, Storage,
};
use sp_bridge_eth_poa::compute_merkle_root;

let mut storage = BridgeStorage::<T, I>::new();
let header = HeaderBuilder::with_parent_number_on_runtime::<T, I>(0)
Expand All @@ -153,9 +153,9 @@ pub(crate) fn prepare_environment_for_claim<T: pallet_bridge_eth_poa::Trait<I>,
#[cfg(any(feature = "runtime-benchmarks", test))]
pub(crate) fn prepare_ethereum_transaction(
recipient: &crate::AccountId,
editor: impl Fn(&mut sp_bridge_eth_poa::UnsignedTransaction),
editor: impl Fn(&mut bp_eth_poa::UnsignedTransaction),
) -> (RawTransaction, RawTransactionReceipt) {
use sp_bridge_eth_poa::{signatures::SignTransaction, Receipt, TransactionOutcome};
use bp_eth_poa::{signatures::SignTransaction, Receipt, TransactionOutcome};

// prepare tx for OpenEthereum private dev chain:
// chain id is 0x11
Expand All @@ -166,7 +166,7 @@ pub(crate) fn prepare_ethereum_transaction(
))
.unwrap();
let recipient_raw: &[u8; 32] = recipient.as_ref();
let mut eth_tx = sp_bridge_eth_poa::UnsignedTransaction {
let mut eth_tx = bp_eth_poa::UnsignedTransaction {
nonce: 0.into(),
to: Some(LOCK_FUNDS_ADDRESS.into()),
value: 100.into(),
Expand Down
2 changes: 1 addition & 1 deletion bridges/bin/node/runtime/src/kovan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

use crate::exchange::EthereumTransactionInclusionProof;

use bp_eth_poa::{Address, Header, RawTransaction, U256};
use frame_support::RuntimeDebug;
use hex_literal::hex;
use pallet_bridge_currency_exchange::PeerBlockchain;
use pallet_bridge_eth_poa::{
AuraConfiguration, PruningStrategy as BridgePruningStrategy, ValidatorsConfiguration, ValidatorsSource,
};
use sp_bridge_eth_poa::{Address, Header, RawTransaction, U256};
use sp_std::prelude::*;

frame_support::parameter_types! {
Expand Down
44 changes: 22 additions & 22 deletions bridges/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ impl pallet_bridge_currency_exchange::Trait<RialtoCurrencyExchange> for Runtime
type OnTransactionSubmitted = ();
type PeerBlockchain = rialto::RialtoBlockchain;
type PeerMaybeLockFundsTransaction = exchange::EthTransaction;
type RecipientsMap = sp_currency_exchange::IdentityRecipients<AccountId>;
type RecipientsMap = bp_currency_exchange::IdentityRecipients<AccountId>;
type Amount = Balance;
type CurrencyConverter = sp_currency_exchange::IdentityCurrencyConverter<Balance>;
type CurrencyConverter = bp_currency_exchange::IdentityCurrencyConverter<Balance>;
type DepositInto = DepositInto;
}

Expand All @@ -262,19 +262,19 @@ impl pallet_bridge_currency_exchange::Trait<KovanCurrencyExchange> for Runtime {
type OnTransactionSubmitted = ();
type PeerBlockchain = kovan::KovanBlockchain;
type PeerMaybeLockFundsTransaction = exchange::EthTransaction;
type RecipientsMap = sp_currency_exchange::IdentityRecipients<AccountId>;
type RecipientsMap = bp_currency_exchange::IdentityRecipients<AccountId>;
type Amount = Balance;
type CurrencyConverter = sp_currency_exchange::IdentityCurrencyConverter<Balance>;
type CurrencyConverter = bp_currency_exchange::IdentityCurrencyConverter<Balance>;
type DepositInto = DepositInto;
}

pub struct DepositInto;

impl sp_currency_exchange::DepositInto for DepositInto {
impl bp_currency_exchange::DepositInto for DepositInto {
type Recipient = AccountId;
type Amount = Balance;

fn deposit_into(recipient: Self::Recipient, amount: Self::Amount) -> sp_currency_exchange::Result<()> {
fn deposit_into(recipient: Self::Recipient, amount: Self::Amount) -> bp_currency_exchange::Result<()> {
// let balances module make all checks for us (it won't allow depositing lower than existential
// deposit, balance overflow, ...)
let deposited = <pallet_balances::Module<Runtime> as Currency<AccountId>>::deposit_creating(&recipient, amount);
Expand Down Expand Up @@ -307,7 +307,7 @@ impl sp_currency_exchange::DepositInto for DepositInto {
recipient,
);

Err(sp_currency_exchange::Error::DepositFailed)
Err(bp_currency_exchange::Error::DepositFailed)
}
_ => {
frame_support::debug::error!(
Expand All @@ -319,7 +319,7 @@ impl sp_currency_exchange::DepositInto for DepositInto {
);

// we can't return DepositFailed error here, because storage changes were made
Err(sp_currency_exchange::Error::DepositPartiallyFailed)
Err(bp_currency_exchange::Error::DepositPartiallyFailed)
}
}
}
Expand Down Expand Up @@ -557,53 +557,53 @@ impl_runtime_apis! {
}
}

impl sp_bridge_eth_poa::RialtoHeaderApi<Block> for Runtime {
fn best_block() -> (u64, sp_bridge_eth_poa::H256) {
impl bp_eth_poa::RialtoHeaderApi<Block> for Runtime {
fn best_block() -> (u64, bp_eth_poa::H256) {
let best_block = BridgeRialto::best_block();
(best_block.number, best_block.hash)
}

fn finalized_block() -> (u64, sp_bridge_eth_poa::H256) {
fn finalized_block() -> (u64, bp_eth_poa::H256) {
let finalized_block = BridgeRialto::finalized_block();
(finalized_block.number, finalized_block.hash)
}

fn is_import_requires_receipts(header: sp_bridge_eth_poa::Header) -> bool {
fn is_import_requires_receipts(header: bp_eth_poa::Header) -> bool {
BridgeRialto::is_import_requires_receipts(header)
}

fn is_known_block(hash: sp_bridge_eth_poa::H256) -> bool {
fn is_known_block(hash: bp_eth_poa::H256) -> bool {
BridgeRialto::is_known_block(hash)
}
}

impl sp_bridge_eth_poa::KovanHeaderApi<Block> for Runtime {
fn best_block() -> (u64, sp_bridge_eth_poa::H256) {
impl bp_eth_poa::KovanHeaderApi<Block> for Runtime {
fn best_block() -> (u64, bp_eth_poa::H256) {
let best_block = BridgeKovan::best_block();
(best_block.number, best_block.hash)
}

fn finalized_block() -> (u64, sp_bridge_eth_poa::H256) {
fn finalized_block() -> (u64, bp_eth_poa::H256) {
let finalized_block = BridgeKovan::finalized_block();
(finalized_block.number, finalized_block.hash)
}

fn is_import_requires_receipts(header: sp_bridge_eth_poa::Header) -> bool {
fn is_import_requires_receipts(header: bp_eth_poa::Header) -> bool {
BridgeKovan::is_import_requires_receipts(header)
}

fn is_known_block(hash: sp_bridge_eth_poa::H256) -> bool {
fn is_known_block(hash: bp_eth_poa::H256) -> bool {
BridgeKovan::is_known_block(hash)
}
}

impl sp_currency_exchange::RialtoCurrencyExchangeApi<Block, exchange::EthereumTransactionInclusionProof> for Runtime {
impl bp_currency_exchange::RialtoCurrencyExchangeApi<Block, exchange::EthereumTransactionInclusionProof> for Runtime {
fn filter_transaction_proof(proof: exchange::EthereumTransactionInclusionProof) -> bool {
BridgeRialtoCurrencyExchange::filter_transaction_proof(&proof)
}
}

impl sp_currency_exchange::KovanCurrencyExchangeApi<Block, exchange::EthereumTransactionInclusionProof> for Runtime {
impl bp_currency_exchange::KovanCurrencyExchangeApi<Block, exchange::EthereumTransactionInclusionProof> for Runtime {
fn filter_transaction_proof(proof: exchange::EthereumTransactionInclusionProof) -> bool {
BridgeKovanCurrencyExchange::filter_transaction_proof(&proof)
}
Expand Down Expand Up @@ -714,7 +714,7 @@ impl_runtime_apis! {
fn make_proof(
proof_params: BridgeCurrencyExchangeProofParams<AccountId>,
) -> crate::exchange::EthereumTransactionInclusionProof {
use sp_currency_exchange::DepositInto;
use bp_currency_exchange::DepositInto;

if proof_params.recipient_exists {
<Runtime as pallet_bridge_currency_exchange::Trait<KovanCurrencyExchange>>::DepositInto::deposit_into(
Expand Down Expand Up @@ -761,7 +761,7 @@ impl_runtime_apis! {
#[cfg(test)]
mod tests {
use super::*;
use sp_currency_exchange::DepositInto;
use bp_currency_exchange::DepositInto;

#[test]
fn shift_session_manager_works() {
Expand Down
2 changes: 1 addition & 1 deletion bridges/bin/node/runtime/src/rialto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

use crate::exchange::EthereumTransactionInclusionProof;

use bp_eth_poa::{Address, Header, RawTransaction, U256};
use frame_support::RuntimeDebug;
use hex_literal::hex;
use pallet_bridge_currency_exchange::PeerBlockchain;
use pallet_bridge_eth_poa::{
AuraConfiguration, PruningStrategy as TPruningStrategy, ValidatorsConfiguration, ValidatorsSource,
};
use sp_bridge_eth_poa::{Address, Header, RawTransaction, U256};
use sp_std::prelude::*;

frame_support::parameter_types! {
Expand Down
8 changes: 4 additions & 4 deletions bridges/modules/currency-exchange/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ edition = "2018"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]
serde = { version = "1.0", optional = true }
bp-currency-exchange = { path = "../../primitives/currency-exchange", default-features = false }
codec = { package = "parity-scale-codec", version = "1.3.1", default-features = false }
sp-currency-exchange = { path = "../../primitives/currency-exchange", default-features = false }
serde = { version = "1.0", optional = true }

# Substrate Based Dependencies
[dependencies.frame-support]
Expand Down Expand Up @@ -56,13 +56,13 @@ git = "https://github.com/paritytech/substrate/"
[features]
default = ["std"]
std = [
"bp-currency-exchange/std",
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"serde",
"sp-currency-exchange/std",
"sp-std/std",
"sp-runtime/std",
"sp-std/std",
]
runtime-benchmarks = ["frame-benchmarking"]
Loading

0 comments on commit 9f6bd28

Please sign in to comment.