Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Merge v4 changes #73

Merged
merged 133 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
3082cf7
feat: Adapt parachain-template-node to ziggurat
conr2d Sep 16, 2024
985ba6c
feat: Add ecdsa account unification to ziggurat
conr2d Sep 16, 2024
ef1caa8
feat: Add Ethereum compatibility to ziggurat
conr2d Sep 16, 2024
99a52af
chore: Update CLI description
conr2d Sep 19, 2024
caaafbe
fix: Fix Ethereum RPC server
conr2d Sep 19, 2024
2e7c741
feat: Add pallet-cosmos-types
code0xff Sep 10, 2024
9ba8ce8
feat: Add cosmos-runtime-api
code0xff Sep 10, 2024
fd59278
feat: Add cosmos-rpc
code0xff Sep 10, 2024
4cc9cd5
feat: Add pallet-cosmos-x-auth-migrations
code0xff Sep 10, 2024
8b25699
feat: Add pallet-cosmos-x-bank-types
code0xff Sep 10, 2024
175fd2c
feat: Add pallet-cosmos-x-wasm-types
code0xff Sep 10, 2024
c9d556e
feat: Add any_match macro to pallet-cosmos-types
code0xff Sep 10, 2024
17f3755
refactor: Remove type SequenceNumber from pallet-cosmos-types
code0xff Sep 10, 2024
70a2a05
refactor: Remove type Account from pallet-cosmos-types
code0xff Sep 10, 2024
4741009
feat: Add pallet-cosmos-x-auth-signing
code0xff Sep 10, 2024
a378f8a
feat: Add cosmwasm-std
code0xff Sep 10, 2024
24fa5e7
feat: Add composable-support
code0xff Sep 10, 2024
db82c97
feat: Add cosmwasm-vm
code0xff Sep 10, 2024
3df0758
feat: Add cosmwasm-vm-wasmi
code0xff Sep 10, 2024
a1a710a
refactor: Refactor context in pallet-cosmos-types
code0xff Sep 11, 2024
2b55a1b
feat: Add pallet-cosmos weights
code0xff Sep 11, 2024
44285b3
feat: Add pallet-cosmos Config
code0xff Sep 12, 2024
7d4bfb1
feat: Add Error to pallet-cosmos
code0xff Sep 12, 2024
63e88cd
feat: Add pallet-cosmos Call
code0xff Sep 12, 2024
31b94c8
refactor: Refactor handling error in pallet-cosmos call
code0xff Sep 12, 2024
deeb7e4
refactor: Refactor get_sign_bytes in pallet-cosmos-x-auth-signing
code0xff Sep 13, 2024
a1f384c
test: Refactor any_match_test
code0xff Sep 13, 2024
94ed909
feat: Add NativeDenom and NativeAssetId to pallet-cosmos
code0xff Sep 14, 2024
95d89a0
feat: Add pallet-cosmos-x-bank
code0xff Sep 15, 2024
5441e6d
refactor: Use ensure to validation
code0xff Sep 15, 2024
cedc55a
feat: Add pallet-cosmos-x-auth
code0xff Sep 15, 2024
73fc23f
refactor: Refactor sigverify in pallet-cosmos-x-auth
code0xff Sep 16, 2024
c5d126d
feat: Add cosmwasm-runtime-api
code0xff Sep 16, 2024
1d341c5
feat: Add cosmwasm-rpc
code0xff Sep 16, 2024
a680417
feat: Add pallet-cosmwasm
code0xff Sep 16, 2024
2a85b27
feat: Add pallet-cosmos-x-wasm
code0xff Sep 16, 2024
50273f4
feat: Add default AnteDecorators
code0xff Sep 16, 2024
f9beafa
fix: Add client feature to cosmwasm-rpc jsonrpsee dependency
code0xff Sep 17, 2024
fd66b64
chore: Reorganize dependencies in pallet-cosmos-x-auth
code0xff Sep 17, 2024
033742f
chore: Add information about msg_responses
code0xff Sep 18, 2024
adf5ed0
refactor: Remove unused imports from pallet-cosmwasm prelude
code0xff Sep 18, 2024
56317fe
chore: Add allow deprecated to cosmwasm-vm
code0xff Sep 18, 2024
1d248ae
refactor: Remove reference from src and dest in drain_balance
code0xff Sep 19, 2024
ed6bd38
refactor: Reorganize vendor package paths
code0xff Sep 19, 2024
b16ad4b
feat: Implement AddressMapping for pallet-cosmos
code0xff Sep 19, 2024
4697d08
feat: Add pallet origin to pallet-cosmos
code0xff Sep 19, 2024
769be61
feat: Add pallet-cosmos config_preludes
code0xff Sep 19, 2024
9e7054f
feat: Implement pallet-cosmos and pallet-cosmwasm
code0xff Sep 19, 2024
14edd1e
refactor: Remove needless return
code0xff Sep 19, 2024
7a92f44
feat: Implement SelfContainedCall for cosmos transaction
code0xff Sep 20, 2024
78e8dab
feat: Implement cosmos and cosmwasm runtime apis
code0xff Sep 20, 2024
08788ca
feat: Implement cosmos rpc
code0xff Sep 20, 2024
22094ef
feat: Add cosmos rpc to node
code0xff Sep 20, 2024
ebf2a48
refactor: Refactor get sequence from tx
code0xff Sep 20, 2024
42b25ad
feat: Handle descriptor in consume_gas
code0xff Sep 20, 2024
0a6e972
refactor: Extract base_gas from consume_gas
code0xff Sep 20, 2024
b0b40c7
fix: Correct incorrect port print when starting rpc
code0xff Sep 20, 2024
a597f0f
fix: Merge cosmos rpc to system rpc
code0xff Sep 20, 2024
317383a
feat: Add sidecar for cosmos apis
code0xff Sep 20, 2024
d838d94
refactor: Refactor runtime apis
code0xff Sep 21, 2024
52bb6e7
style: Reformat sidecar
code0xff Sep 21, 2024
0da0f03
fix: Fix derive interim account in sidecar
code0xff Sep 21, 2024
e1d4dfb
fix: Replace ante handler error type from TransactionValidityError to…
code0xff Sep 21, 2024
008dcf1
fix: Use run_tx for tx simulation in runtime api
code0xff Sep 21, 2024
86751ed
feat: Add FeeTx trait
code0xff Sep 22, 2024
85468b3
refactor: Rename method from gas_limit to gas in FeeTx
code0xff Sep 22, 2024
ebc52a9
refactor: Replace ethereum-cryptography with polkadot-js
conr2d Sep 21, 2024
819fdbc
chore: Remove eslint fix
code0xff Sep 23, 2024
6b57a66
fix: Add codespace convert
code0xff Sep 23, 2024
d50e576
fix: Add blockhash parameter to simulate rpc
code0xff Sep 23, 2024
34ede29
fix: Add blockHash parameter to account query
code0xff Sep 23, 2024
12e1104
chore: Set RPC port for collator to 9944
code0xff Sep 23, 2024
4b3f21e
fix: Allow blockHash parameter to be nullable in accounts method
code0xff Sep 23, 2024
ac54aa5
refactor: Resolve eslint warnings
code0xff Sep 23, 2024
acbed6f
fix: Fix phase json parse error
code0xff Sep 23, 2024
1e2951b
chore: Modify sidecar log simple
code0xff Sep 23, 2024
1fffe16
feat: Add gas consumption to wasm message handlers
code0xff Sep 23, 2024
9dcd9ee
style: Replace backticks with single quotes in sidecar log
code0xff Sep 24, 2024
889d157
fix: Fix balances bug
code0xff Sep 24, 2024
ace0371
build(deps): Add missing dependency
conr2d Sep 23, 2024
71bc4ee
chore: Allocate initial balance to dev account
conr2d Sep 23, 2024
a4171b4
feat: Add UniqueMap
code0xff Sep 24, 2024
444b346
feat: Implement AssetToDenom with AssetMap
code0xff Sep 24, 2024
c99fa66
feat: Implement pallet-asset callback to map asset id to denom
code0xff Sep 24, 2024
0920705
feat: Add cosmos tx fee validation
code0xff Sep 25, 2024
5d2ee24
refactor: Add np-babel
conr2d Sep 25, 2024
578cc23
feat: Add frame-babel pallet
conr2d Sep 25, 2024
2c6b1e3
feat: Add babel precompile
conr2d Sep 24, 2024
a81e2ed
feat: Add precompile for dispatch call
code0xff Sep 26, 2024
f1a6ca8
chore: Add address mapping to genesis runtime
conr2d Sep 26, 2024
38db23f
feat: Add charge gas to dispatch call and code store
code0xff Sep 26, 2024
68accda
fix: Correct addressMap cosmos code in sidecar
code0xff Sep 27, 2024
c8f0cfa
fix: Add deserialize call error handling
code0xff Sep 27, 2024
e600df3
feat: Require root permission to create asset
conr2d Sep 27, 2024
e85b97d
fix: Add serde rename snake_case to dispatch message
code0xff Sep 27, 2024
81f4fd5
fix: Replace pallet-assets CreateOrigin to NeverEnsureOrigin
code0xff Sep 27, 2024
619d083
feat: Add balances erc20 precomile
conr2d Sep 27, 2024
05ea0ef
refactor: Refactor cosmos check_self_contained
code0xff Sep 27, 2024
138e1e2
fix: Remove asset callback handler
code0xff Sep 27, 2024
9c6cece
feat: Add assets erc20 precompile set
conr2d Sep 27, 2024
8b45418
feat: Add create asset with metadata and denom
code0xff Sep 27, 2024
d1a62a2
fix: Add EnsureSigned dependency
code0xff Sep 27, 2024
af9ea9d
feat: Add handle vm error
code0xff Sep 28, 2024
a808fb7
feat: Add consume gas to msg_send
code0xff Sep 29, 2024
4f60af1
feat: Add handling error to AssetToDenom
code0xff Sep 29, 2024
ac9c0bf
refactor: Move AssetToDenom to runtime
code0xff Sep 29, 2024
4364832
fix: Fix query cosmos balances
code0xff Sep 29, 2024
e42b32f
fix: Preconsume gas before transfer asset
code0xff Sep 29, 2024
8997c7d
feat: Add abci query for balances
code0xff Sep 29, 2024
121579b
feat: Add cosmos_transact to frame_babel
code0xff Sep 30, 2024
0acd6da
feat: Add transfer balances call for multi-type addresses
code0xff Oct 1, 2024
b8d8a5e
feat: Block asset transfer to non-unified accounts
conr2d Oct 2, 2024
1b66254
chore: Remove unused dependency
conr2d Oct 2, 2024
c0d14fc
feat: Block asset transfer to non-unified accounts in cosmwasm
code0xff Oct 2, 2024
42bcf03
fix: Fix type name conflict with Address
conr2d Oct 2, 2024
5163356
chore: Replace chain_id for CosmosHub to ziggurat
code0xff Oct 2, 2024
aefbed0
style: Fix inconsistent Cargo.toml
conr2d Oct 2, 2024
2c756e6
feat: Add chain_info rpc
code0xff Oct 3, 2024
f306445
chore: Remove suggestion chain to wallet page in sidecar
code0xff Oct 3, 2024
bc9f477
refactor: Refactor api routes
code0xff Oct 4, 2024
783e87e
refactor: Refactor chain api
code0xff Oct 4, 2024
a7c9421
fix: Fix typo
code0xff Oct 4, 2024
980fdb3
refactor: Refactor rpc handlers
code0xff Oct 4, 2024
89ace70
fix: Fix handler bind issue
code0xff Oct 4, 2024
a27d280
fix: Add wildcard for cors
code0xff Oct 4, 2024
e208e3e
fix: Remove waiting for tx result in broadcastTx
code0xff Oct 4, 2024
ce22879
style: Fix indent
conr2d Oct 6, 2024
d0cbe71
feat: Use geth estimateGas algorithm
conr2d Oct 7, 2024
eed75d6
build: Extract ziggurat implementation
conr2d Oct 7, 2024
a0c1e0b
test: Fix vendored precompile tests
conr2d Oct 7, 2024
71012de
test: Disable tests from vendor packages
conr2d Oct 7, 2024
aa9cf3e
chore: Fix clippy error
conr2d Oct 7, 2024
83bed6c
fix: Fix simulation gas limit
code0xff Oct 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,68 @@ resolver = "2"
members = [
"core-primitives",
"frame/babel",
"frame/cosmos",
"frame/cosmos/types",
"frame/cosmos/rpc",
"frame/cosmos/runtime-api",
"frame/cosmos/x/auth",
"frame/cosmos/x/auth/migrations",
"frame/cosmos/x/auth/signing",
"frame/cosmos/x/bank",
"frame/cosmos/x/bank/types",
"frame/cosmos/x/wasm",
"frame/cosmos/x/wasm/types",
"frame/multimap",
"primitives/babel",
"primitives/cosmos",
"primitives/ethereum",
"primitives/runtime",
"runtime/common",
"vendor/composable/composable-support",
"vendor/composable/vm",
"vendor/composable/vm-wasmi",
"vendor/cosmwasm/std",
"vendor/composable/cosmwasm",
"vendor/composable/cosmwasm/rpc",
"vendor/composable/cosmwasm/runtime-api",
"vendor/moonbeam/precompiles/assets-erc20",
"vendor/moonbeam/precompiles/balances-erc20",
]
default-members = [
"core-primitives",
"frame/*",
"primitives/*",
"runtime/*",
]

[workspace.dependencies]
composable-support = { path = "vendor/composable/composable-support", default-features = false }
cosmos-rpc = { path = "frame/cosmos/rpc", default-features = false }
cosmos-runtime-api = { path = "frame/cosmos/runtime-api", default-features = false }
cosmwasm-rpc = { path = "vendor/composable/cosmwasm/rpc" }
cosmwasm-runtime-api = { path = "vendor/composable/cosmwasm/runtime-api", default-features = false }
cosmwasm-std = { path = "vendor/cosmwasm/std", default-features = false }
cosmwasm-vm = { path = "vendor/composable/vm", default-features = false }
cosmwasm-vm-wasmi = { path = "vendor/composable/vm-wasmi", default-features = false }
frame-babel = { path = "frame/babel", default-features = false }
noir-core-primitives = { path = "core-primitives", default-features = false }
noir-runtime-common = { path = "runtime/common", default-features = false }
np-babel = { path = "primitives/babel", default-features = false }
np-cosmos = { path = "primitives/cosmos", default-features = false }
np-ethereum = { path = "primitives/ethereum", default-features = false }
np-runtime = { path = "primitives/runtime", default-features = false }
pallet-cosmos = { path = "frame/cosmos", default-features = false }
pallet-cosmos-types = { path = "frame/cosmos/types", default-features = false }
pallet-cosmos-x-auth = { path = "frame/cosmos/x/auth", default-features = false }
pallet-cosmos-x-auth-migrations = { path = "frame/cosmos/x/auth/migrations", default-features = false }
pallet-cosmos-x-auth-signing = { path = "frame/cosmos/x/auth/signing", default-features = false }
pallet-cosmos-x-bank = { path = "frame/cosmos/x/bank", default-features = false }
pallet-cosmos-x-bank-types = { path = "frame/cosmos/x/bank/types", default-features = false }
pallet-cosmos-x-wasm = { path = "frame/cosmos/x/wasm", default-features = false }
pallet-cosmos-x-wasm-types = { path = "frame/cosmos/x/wasm/types", default-features = false }
pallet-cosmwasm = { path = "vendor/composable/cosmwasm", default-features = false }
pallet-evm-precompileset-assets-erc20 = { path = "vendor/moonbeam/precompiles/assets-erc20", default-features = false }
pallet-evm-precompile-balances-erc20 = { path = "vendor/moonbeam/precompiles/balances-erc20", default-features = false }
pallet-multimap = { path = "frame/multimap", default-features = false }

[profile.release]
Expand Down
82 changes: 72 additions & 10 deletions frame/babel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,127 @@ repository = "https://github.com/noirhq/noir.git"
publish = false

[dependencies]
bech32 = { version = "0.11", default-features = false, features = ["alloc"], optional = true }
cosmos-sdk-proto = { version = "0.24", default-features = false, optional = true }
cosmwasm-std = { workspace = true, default-features = false, optional = true }
cosmwasm-vm = { workspace = true, default-features = false, optional = true }
cosmwasm-vm-wasmi = { workspace = true, default-features = false, optional = true }
ethereum = { version = "0.15.0", default-features = false, optional = true }
fp-evm = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false, optional = true }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
hex-literal = "0.4"
np-babel = { workspace = true, default-features = false }
np-cosmos = { workspace = true, optional = true }
np-ethereum = { workspace = true, optional = true }
num_enum = { version = "0.7", default-features = false, optional = true }
pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false, optional = true }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
pallet-cosmos = { workspace = true, default-features = false, optional = true }
pallet-cosmos-types = { workspace = true, default-features = false, optional = true }
pallet-cosmos-x-auth-signing = { workspace = true, default-features = false, optional = true }
pallet-cosmos-x-bank = { workspace = true, default-features = false, optional = true }
pallet-cosmos-x-wasm = { workspace = true, default-features = false, optional = true }
pallet-cosmwasm = { workspace = true, default-features = false, optional = true }
pallet-ethereum = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false, optional = true }
pallet-evm = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false, optional = true }
pallet-evm-precompileset-assets-erc20 = { workspace = true, optional = true }
pallet-evm-precompile-balances-erc20 = { workspace = true, optional = true }
pallet-evm-precompile-blake2 = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false, optional = true }
pallet-evm-precompile-bn128 = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false, optional = true }
pallet-evm-precompile-modexp = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false, optional = true }
pallet-evm-precompile-sha3fips = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false, optional = true }
pallet-evm-precompile-simple = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false, optional = true }
pallet-multimap = { workspace = true }
pallet-multimap = { workspace = true, default-features = false }
parity-scale-codec = { version = "3.6", default-features = false, features = ["derive"] }
precompile-utils = { git = "https://github.com/polkadot-evm/frontier", branch = "stable2407", default-features = false, optional = true }
scale-info = { version = "2.11", default-features = false, features = ["derive"] }
serde = { version = "1.0.210", default-features = false, features = ["derive"], optional = true }
serde-json-wasm = { version = "1.0.1", default-features = false, optional = true }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }

[dev-dependencies]
hex = "0.4.3"

[features]
default = [
"std",
"cosmos",
"ethereum",
]
default = ["std", "pallet"]
std = [
"bech32?/std",
"cosmos-sdk-proto?/std",
"cosmwasm-std?/std",
"cosmwasm-vm?/std",
"cosmwasm-vm-wasmi?/std",
"ethereum?/std",
"fp-evm?/std",
"frame-support/std",
"frame-system/std",
"np-babel/std",
"np-cosmos?/std",
"np-ethereum?/std",
"num_enum?/std",
"pallet-assets?/std",
"pallet-balances/std",
"pallet-cosmos?/std",
"pallet-cosmos-types?/std",
"pallet-cosmos-x-auth-signing?/std",
"pallet-cosmos-x-bank?/std",
"pallet-cosmos-x-wasm?/std",
"pallet-cosmwasm?/std",
"pallet-ethereum?/std",
"pallet-evm?/std",
"pallet-evm-precompileset-assets-erc20?/std",
"pallet-evm-precompile-balances-erc20?/std",
"pallet-evm-precompile-blake2?/std",
"pallet-evm-precompile-bn128?/std",
"pallet-evm-precompile-modexp?/std",
"pallet-evm-precompile-sha3fips?/std",
"pallet-evm-precompile-simple?/std",
"pallet-multimap/std",
"parity-scale-codec/std",
"precompile-utils?/std",
"scale-info/std",
"serde?/std",
"serde-json-wasm?/std",
"sp-core/std",
"sp-runtime/std",
]
cosmos = [
"bech32",
"cosmos-sdk-proto",
"cosmwasm-std",
"cosmwasm-vm",
"cosmwasm-vm-wasmi",
"np-babel/cosmos",
"np-cosmos",
"pallet-assets",
"pallet-cosmos",
"pallet-cosmos-types",
"pallet-cosmos-x-auth-signing",
"pallet-cosmos-x-bank",
"pallet-cosmos-x-wasm",
"pallet-cosmwasm",
"serde",
"serde-json-wasm",
]
ethereum = [
"dep:ethereum",
"np-ethereum",
"fp-evm",
"np-babel/ethereum",
"num_enum",
"pallet-ethereum",
"pallet-evm",
"pallet-evm-precompileset-assets-erc20",
"pallet-evm-precompile-balances-erc20",
"pallet-evm-precompile-blake2",
"pallet-evm-precompile-bn128",
"pallet-evm-precompile-modexp",
"pallet-evm-precompile-sha3fips",
"pallet-evm-precompile-simple",
"precompile-utils",
]
pallet = [
"cosmos",
"ethereum",
"np-babel/serde",
]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
Expand Down
86 changes: 86 additions & 0 deletions frame/babel/src/cosmos/address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// This file is part of Noir.

// Copyright (c) Haderech Pte. Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later

// This program 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.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.

use crate::{extensions::unify_account, VarAddress};
use alloc::{string::String, vec::Vec};
use bech32::{Bech32, Hrp};
use core::marker::PhantomData;
use np_babel::cosmos::{traits::ChainInfo, Address as CosmosAddress};
use pallet_cosmos_types::address::acc_address_from_bech32;
use pallet_cosmwasm::types::AccountIdOf;
use pallet_multimap::traits::UniqueMultimap;
use sp_core::{H160, H256};
use sp_runtime::traits::{AccountIdConversion, Convert};

pub struct AddressMapping<T>(PhantomData<T>);
impl<T> pallet_cosmos::AddressMapping<T::AccountId> for AddressMapping<T>
where
T: unify_account::Config,
{
fn into_account_id(who: H160) -> T::AccountId {
let address = CosmosAddress::from(who);
T::AddressMap::find_key(VarAddress::Cosmos(address.clone()))
.unwrap_or_else(|| address.into_account_truncating())
}
}

pub struct AccountToAddr<T>(PhantomData<T>);
impl<T> Convert<AccountIdOf<T>, String> for AccountToAddr<T>
where
T: pallet_cosmwasm::Config + unify_account::Config,
{
fn convert(account: AccountIdOf<T>) -> String {
let addresses = T::AddressMap::get(account.clone());
let address: Option<&CosmosAddress> = addresses.iter().find_map(|address| match address {
VarAddress::Cosmos(address) => Some(address),
_ => None,
});
let address_raw = match address {
Some(address) => address.as_ref(),
None => account.as_ref(),
};
let hrp = Hrp::parse(T::ChainInfo::bech32_prefix()).unwrap();
bech32::encode::<Bech32>(hrp, address_raw).unwrap()
}
}

impl<T> Convert<String, Result<AccountIdOf<T>, ()>> for AccountToAddr<T>
where
T: pallet_cosmwasm::Config + unify_account::Config,
{
fn convert(address: String) -> Result<AccountIdOf<T>, ()> {
let (_hrp, address_raw) = acc_address_from_bech32(&address).map_err(|_| ())?;
Self::convert(address_raw)
}
}

impl<T> Convert<Vec<u8>, Result<AccountIdOf<T>, ()>> for AccountToAddr<T>
where
T: pallet_cosmwasm::Config + unify_account::Config,
{
fn convert(address: Vec<u8>) -> Result<AccountIdOf<T>, ()> {
match address.len() {
20 => {
let address = CosmosAddress::from(H160::from_slice(&address));
T::AddressMap::find_key(VarAddress::Cosmos(address)).ok_or(())
},
32 => Ok(H256::from_slice(&address).into()),
_ => Err(()),
}
}
}
21 changes: 21 additions & 0 deletions frame/babel/src/cosmos/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This file is part of Noir.

// Copyright (c) Haderech Pte. Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later

// This program 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.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.

pub mod address;
pub mod msg;
pub mod precompile;
55 changes: 55 additions & 0 deletions frame/babel/src/cosmos/msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// This file is part of Noir.

// Copyright (c) Haderech Pte. Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later

// This program 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.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.

use alloc::boxed::Box;
use core::marker::PhantomData;
use cosmos_sdk_proto::{
cosmos::bank::v1beta1::MsgSend,
cosmwasm::wasm::v1::{
MsgExecuteContract, MsgInstantiateContract2, MsgMigrateContract, MsgStoreCode,
MsgUpdateAdmin,
},
Any,
};
use pallet_cosmos_types::{any_match, context, msgservice};
use pallet_cosmos_x_bank::MsgSendHandler;
use pallet_cosmos_x_wasm::msgs::{
MsgExecuteContractHandler, MsgInstantiateContract2Handler, MsgMigrateContractHandler,
MsgStoreCodeHandler, MsgUpdateAdminHandler,
};

pub struct MsgServiceRouter<T>(PhantomData<T>);
impl<T, Context> msgservice::traits::MsgServiceRouter<Context> for MsgServiceRouter<T>
where
T: frame_system::Config + pallet_cosmos::Config + pallet_cosmwasm::Config,
Context: context::traits::Context,
{
fn route(msg: &Any) -> Option<Box<dyn msgservice::traits::MsgHandler<Context>>> {
any_match!(
msg, {
MsgSend => Some(Box::<MsgSendHandler<T>>::default()),
MsgStoreCode => Some(Box::<MsgStoreCodeHandler<T>>::default()),
MsgInstantiateContract2 => Some(Box::<MsgInstantiateContract2Handler<T>>::default()),
MsgExecuteContract => Some(Box::<MsgExecuteContractHandler<T>>::default()),
MsgMigrateContract => Some(Box::<MsgMigrateContractHandler<T>>::default()),
MsgUpdateAdmin => Some(Box::<MsgUpdateAdminHandler<T>>::default()),
},
None
)
}
}
Loading