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

Feature/polkadot #16

Open
wants to merge 10 commits into
base: feature/imkey_core_integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ members = [
"wallet/coin-ethereum",
"wallet/coin-eos",
"wallet/coin-cosmos",
"wallet/coin-substrate",
]
1 change: 1 addition & 0 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ coin-bitcoin = {path = "../wallet/coin-bitcoin"}
coin-eos = {path = "../wallet/coin-eos"}
coin-cosmos = {path = "../wallet/coin-cosmos"}
coin-filecoin = {path = "../wallet/coin-filecoin"}
coin-substrate = {path = "../wallet/coin-substrate"}
common = {path = "../common"}
bitcoin = "0.25.0"
ethereum-types = "0.6.0"
Expand Down
12 changes: 12 additions & 0 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub mod ethereum_signer;
pub mod filecoin_address;
pub mod filecoin_signer;
pub mod message_handler;
pub mod substrate_address;
pub mod substrate_signer;
use std::sync::Mutex;

#[macro_use]
Expand Down Expand Up @@ -119,6 +121,8 @@ pub unsafe extern "C" fn call_imkey_api(hex_str: *const c_char) -> *const c_char
"ETHEREUM" => ethereum_address::get_address(&param),
"COSMOS" => cosmos_address::get_address(&param),
"FILECOIN" => filecoin_address::get_address(&param),
"POLKADOT" => substrate_address::get_address(&param),
"KUSAMA" => substrate_address::get_address(&param),
_ => Err(format_err!("get_address unsupported_chain")),
}
}),
Expand Down Expand Up @@ -149,6 +153,8 @@ pub unsafe extern "C" fn call_imkey_api(hex_str: *const c_char) -> *const c_char
"ETHEREUM" => ethereum_address::register_address(&param),
"COSMOS" => cosmos_address::display_cosmos_address(&param),
"FILECOIN" => filecoin_address::display_filecoin_address(&param),
"POLKADOT" => substrate_address::display_address(&param),
"KUSAMA" => substrate_address::display_address(&param),
_ => Err(format_err!("register_address unsupported_chain")),
}
}),
Expand All @@ -175,6 +181,12 @@ pub unsafe extern "C" fn call_imkey_api(hex_str: *const c_char) -> *const c_char
&param.clone().input.unwrap().value,
&param,
),
"POLKADOT" => {
substrate_signer::sign_transaction(&param.clone().input.unwrap().value, &param)
}
"KUSAMA" => {
substrate_signer::sign_transaction(&param.clone().input.unwrap().value, &param)
}
_ => Err(format_err!("sign_tx unsupported_chain")),
}
}),
Expand Down
37 changes: 37 additions & 0 deletions api/src/substrate_address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::api::{AddressParam, AddressResult};
use crate::error_handling::Result;
use crate::message_handler::encode_message;
use coin_substrate::address::{AddressType, SubstrateAddress};
use prost::Message;

pub fn get_address(param: &AddressParam) -> Result<Vec<u8>> {
let address_type = match param.chain_type.as_str() {
"POLKADOT" => AddressType::Polkadot,
"KUSAMA" => AddressType::Kusama,
_ => panic!("address type not support"),
};
let address = SubstrateAddress::get_address(param.path.as_ref(), &address_type)?;

let address_message = AddressResult {
path: param.path.to_owned(),
chain_type: param.chain_type.to_string(),
address,
};
encode_message(address_message)
}

pub fn display_address(param: &AddressParam) -> Result<Vec<u8>> {
let address_type = match param.chain_type.as_str() {
"POLKADOT" => AddressType::Polkadot,
"KUSAMA" => AddressType::Kusama,
_ => panic!("address type not support"),
};
let address = SubstrateAddress::display_address(param.path.as_ref(), &address_type)?;

let address_message = AddressResult {
path: param.path.to_owned(),
chain_type: param.chain_type.to_string(),
address,
};
encode_message(address_message)
}
12 changes: 12 additions & 0 deletions api/src/substrate_signer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::error_handling::Result;
use crate::message_handler::encode_message;
use coin_substrate::substrateapi::SubstrateRawTxIn;
use coin_substrate::transaction::Transaction;
use common::SignParam;
use prost::Message;

pub fn sign_transaction(data: &[u8], sign_param: &SignParam) -> Result<Vec<u8>> {
let input: SubstrateRawTxIn = SubstrateRawTxIn::decode(data).unwrap();
let signed = Transaction::sign_transaction(&input, sign_param)?;
encode_message(signed)
}
Loading