-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rust/Cosmos]: Move Cosmos blockchain into Rust (#3498)
- Loading branch information
1 parent
a60033f
commit 7119750
Showing
203 changed files
with
7,743 additions
and
1,936 deletions.
There are no files selected for viewing
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
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
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,13 @@ | ||
[package] | ||
name = "tw_cosmos" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
tw_coin_entry = { path = "../../tw_coin_entry" } | ||
tw_cosmos_sdk = { path = "../../tw_cosmos_sdk" } | ||
tw_keypair = { path = "../../tw_keypair" } | ||
tw_proto = { path = "../../tw_proto" } | ||
|
||
[dev-dependencies] | ||
tw_cosmos_sdk = { path = "../../tw_cosmos_sdk", features = ["test-utils"] } |
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,94 @@ | ||
// Copyright © 2017-2023 Trust Wallet. | ||
// | ||
// This file is part of Trust. The full Trust copyright notice, including | ||
// terms governing use, modification, and redistribution, is contained in the | ||
// file LICENSE at the root of the source code distribution tree. | ||
|
||
use std::str::FromStr; | ||
use tw_coin_entry::coin_context::CoinContext; | ||
use tw_coin_entry::coin_entry::{CoinEntry, PublicKeyBytes, SignatureBytes}; | ||
use tw_coin_entry::derivation::Derivation; | ||
use tw_coin_entry::error::AddressResult; | ||
use tw_coin_entry::modules::json_signer::NoJsonSigner; | ||
use tw_coin_entry::modules::message_signer::NoMessageSigner; | ||
use tw_coin_entry::modules::plan_builder::NoPlanBuilder; | ||
use tw_cosmos_sdk::address::{Address, Bech32Prefix}; | ||
use tw_cosmos_sdk::context::StandardCosmosContext; | ||
use tw_cosmos_sdk::modules::compiler::tw_compiler::TWTransactionCompiler; | ||
use tw_cosmos_sdk::modules::signer::tw_signer::TWSigner; | ||
use tw_keypair::tw; | ||
use tw_proto::Cosmos::Proto; | ||
use tw_proto::TxCompiler::Proto as CompilerProto; | ||
|
||
pub struct CosmosEntry; | ||
|
||
impl CoinEntry for CosmosEntry { | ||
type AddressPrefix = Bech32Prefix; | ||
type Address = Address; | ||
type SigningInput<'a> = Proto::SigningInput<'a>; | ||
type SigningOutput = Proto::SigningOutput<'static>; | ||
type PreSigningOutput = CompilerProto::PreSigningOutput<'static>; | ||
type JsonSigner = NoJsonSigner; | ||
type PlanBuilder = NoPlanBuilder; | ||
type MessageSigner = NoMessageSigner; | ||
|
||
#[inline] | ||
fn parse_address( | ||
&self, | ||
coin: &dyn CoinContext, | ||
address: &str, | ||
prefix: Option<Self::AddressPrefix>, | ||
) -> AddressResult<Self::Address> { | ||
Address::from_str_with_coin_and_prefix(coin, address.to_string(), prefix) | ||
} | ||
|
||
#[inline] | ||
fn parse_address_unchecked( | ||
&self, | ||
_coin: &dyn CoinContext, | ||
address: &str, | ||
) -> AddressResult<Self::Address> { | ||
Address::from_str(address) | ||
} | ||
|
||
#[inline] | ||
fn derive_address( | ||
&self, | ||
coin: &dyn CoinContext, | ||
public_key: tw::PublicKey, | ||
_derivation: Derivation, | ||
prefix: Option<Self::AddressPrefix>, | ||
) -> AddressResult<Self::Address> { | ||
Address::with_public_key_coin_context(coin, &public_key, prefix) | ||
} | ||
|
||
#[inline] | ||
fn sign(&self, coin: &dyn CoinContext, input: Self::SigningInput<'_>) -> Self::SigningOutput { | ||
TWSigner::<StandardCosmosContext>::sign(coin, input) | ||
} | ||
|
||
#[inline] | ||
fn preimage_hashes( | ||
&self, | ||
coin: &dyn CoinContext, | ||
input: Self::SigningInput<'_>, | ||
) -> Self::PreSigningOutput { | ||
TWTransactionCompiler::<StandardCosmosContext>::preimage_hashes(coin, input) | ||
} | ||
|
||
#[inline] | ||
fn compile( | ||
&self, | ||
coin: &dyn CoinContext, | ||
input: Self::SigningInput<'_>, | ||
signatures: Vec<SignatureBytes>, | ||
public_keys: Vec<PublicKeyBytes>, | ||
) -> Self::SigningOutput { | ||
TWTransactionCompiler::<StandardCosmosContext>::compile( | ||
coin, | ||
input, | ||
signatures, | ||
public_keys, | ||
) | ||
} | ||
} |
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,7 @@ | ||
// Copyright © 2017-2023 Trust Wallet. | ||
// | ||
// This file is part of Trust. The full Trust copyright notice, including | ||
// terms governing use, modification, and redistribution, is contained in the | ||
// file LICENSE at the root of the source code distribution tree. | ||
|
||
pub mod entry; |
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,14 @@ | ||
[package] | ||
name = "tw_native_evmos" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
tw_coin_entry = { path = "../../tw_coin_entry" } | ||
tw_cosmos_sdk = { path = "../../tw_cosmos_sdk" } | ||
tw_keypair = { path = "../../tw_keypair" } | ||
tw_memory = { path = "../../tw_memory" } | ||
tw_proto = { path = "../../tw_proto" } | ||
|
||
[dev-dependencies] | ||
tw_cosmos_sdk = { path = "../../tw_cosmos_sdk", features = ["test-utils"] } |
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,22 @@ | ||
// Copyright © 2017-2023 Trust Wallet. | ||
// | ||
// This file is part of Trust. The full Trust copyright notice, including | ||
// terms governing use, modification, and redistribution, is contained in the | ||
// file LICENSE at the root of the source code distribution tree. | ||
|
||
use crate::ethermint_public_key::EthermintEthSecp256PublicKey; | ||
use tw_cosmos_sdk::address::Address; | ||
use tw_cosmos_sdk::context::CosmosContext; | ||
use tw_cosmos_sdk::hasher::keccak256_hasher::Keccak256Hasher; | ||
use tw_cosmos_sdk::private_key::secp256k1::Secp256PrivateKey; | ||
use tw_cosmos_sdk::signature::secp256k1::Secp256k1Signature; | ||
|
||
pub struct NativeEvmosContext; | ||
|
||
impl CosmosContext for NativeEvmosContext { | ||
type Address = Address; | ||
type TxHasher = Keccak256Hasher; | ||
type PrivateKey = Secp256PrivateKey; | ||
type PublicKey = EthermintEthSecp256PublicKey; | ||
type Signature = Secp256k1Signature; | ||
} |
Oops, something went wrong.