-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tmp mimic pallet for bitacross (#2634)
* feat: add tmp mimic pallet for bitacross * debug: delete unused method * debug: fmt * debug: fix alloc string * debug: fmt * debug: failed extern pallet
- Loading branch information
Showing
7 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[package] | ||
authors = ['Trust Computing GmbH <info@litentry.com>'] | ||
edition = '2021' | ||
homepage = 'https://litentry.com' | ||
name = "pallet-bitacross-mimic" | ||
repository = 'https://github.com/litentry/litentry-parachain' | ||
version = '0.1.0' | ||
|
||
[dependencies] | ||
parity-scale-codec = { workspace = true } | ||
scale-info = { workspace = true } | ||
|
||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
sp-core = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
sp-std = { workspace = true } | ||
|
||
[features] | ||
default = ["std"] | ||
runtime-benchmarks = [ | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
] | ||
std = [ | ||
"parity-scale-codec/std", | ||
"scale-info/std", | ||
"sp-std/std", | ||
"sp-runtime/std", | ||
"sp-core/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
] | ||
try-runtime = ["frame-support/try-runtime"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2020-2024 Trust Computing GmbH. | ||
// This file is part of Litentry. | ||
// | ||
// Litentry 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. | ||
// | ||
// Litentry 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 Litentry. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
extern crate alloc; | ||
use alloc::string::String; | ||
use parity_scale_codec::{Decode, Encode}; | ||
use scale_info::TypeInfo; | ||
use sp_core::{H160, H256, U256}; | ||
pub type PubKey = [u8; 33]; | ||
|
||
/// custodial bit cross record of a full single tx from BTC to ETH | ||
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, TypeInfo)] | ||
pub struct BtcToEth { | ||
pub tx_index: u64, | ||
pub btc_tx_hash: H256, | ||
pub ethereum_receiver: H160, | ||
pub ethereum_tx_hash: H256, | ||
pub eth_tx_status: bool, | ||
pub symbol: String, | ||
pub amount: U256, | ||
pub tx_timestamp: u64, | ||
} | ||
|
||
/// custodial bit cross record of a full single tx from ETH to BTC | ||
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, TypeInfo)] | ||
pub struct EthToBtc { | ||
pub tx_index: u64, | ||
pub btc_tx_hash: H256, | ||
pub btc_receiver: PubKey, | ||
pub btc_receiver_length: u32, | ||
pub ethereum_tx_hash: H256, | ||
pub eth_tx_status: bool, | ||
pub symbol: String, | ||
pub amount: U256, | ||
pub tx_timestamp: u64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2020-2024 Trust Computing GmbH. | ||
// This file is part of Litentry. | ||
// | ||
// Litentry 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. | ||
// | ||
// Litentry 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 Litentry. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
use frame_support::{dispatch::DispatchResult, pallet_prelude::*}; | ||
use frame_system::pallet_prelude::*; | ||
use sp_core::H160; | ||
|
||
pub use pallet::*; | ||
|
||
mod custodial_type; | ||
pub use custodial_type::*; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use super::*; | ||
|
||
#[pallet::pallet] | ||
#[pallet::without_storage_info] | ||
pub struct Pallet<T>(PhantomData<T>); | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
} | ||
|
||
#[pallet::storage] | ||
#[pallet::getter(fn mimic_btc_to_eth_storage)] | ||
pub type MimicBtcToEthStorage<T: Config> = | ||
StorageDoubleMap<_, Blake2_256, PubKey, Blake2_256, u64, BtcToEth>; | ||
|
||
#[pallet::storage] | ||
#[pallet::getter(fn mimic_eth_to_btc_storage)] | ||
pub type MimicEthToBtcStorage<T: Config> = | ||
StorageDoubleMap<_, Blake2_256, H160, Blake2_256, u64, EthToBtc>; | ||
|
||
#[pallet::event] | ||
#[pallet::generate_deposit(pub(super) fn deposit_event)] | ||
pub enum Event<T: Config> { | ||
BtcToEthSaved { btc: PubKey, tx_index: u64 }, | ||
EthToBtcSaved { eth: H160, tx_index: u64 }, | ||
} | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
/// Set the admin account | ||
/// | ||
/// Weights should be 2 DB writes: 1 for mode and 1 for event | ||
#[pallet::call_index(0)] | ||
#[pallet::weight({195_000_000})] | ||
pub fn write_btc_to_eth( | ||
_origin: OriginFor<T>, | ||
btc_sender: PubKey, | ||
data: BtcToEth, | ||
) -> DispatchResult { | ||
Self::deposit_event(Event::BtcToEthSaved { btc: btc_sender, tx_index: data.tx_index }); | ||
<MimicBtcToEthStorage<T>>::insert(btc_sender, data.tx_index, data); | ||
Ok(()) | ||
} | ||
|
||
#[pallet::call_index(1)] | ||
#[pallet::weight({195_000_000})] | ||
pub fn write_eth_to_btc( | ||
_origin: OriginFor<T>, | ||
eth_sender: H160, | ||
data: EthToBtc, | ||
) -> DispatchResult { | ||
Self::deposit_event(Event::EthToBtcSaved { eth: eth_sender, tx_index: data.tx_index }); | ||
<MimicEthToBtcStorage<T>>::insert(eth_sender, data.tx_index, data); | ||
Ok(()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters