Skip to content

Commit

Permalink
Adds public key field to transaction (#122)
Browse files Browse the repository at this point in the history
* Merge master

* Adds pubkey to tx
  • Loading branch information
drewstone authored Sep 13, 2020
1 parent ac50956 commit d72c861
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ethereum-types = "0.9.0"
frontier-consensus = { path = "../consensus" }
frontier-rpc-core = { path = "core" }
frontier-rpc-primitives = { path = "primitives" }
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
sp-consensus = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
Expand Down
18 changes: 16 additions & 2 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use std::{marker::PhantomData, sync::Arc};
use std::collections::BTreeMap;
use ethereum::{Block as EthereumBlock, Transaction as EthereumTransaction};
use ethereum_types::{H160, H256, H64, U256, U64};
use ethereum_types::{H160, H256, H64, U256, U64, H512};
use jsonrpc_core::{BoxFuture, Result, ErrorCode, Error, futures::future::{self, Future}};
use futures::future::TryFutureExt;
use sp_runtime::traits::{Block as BlockT, Header as _, UniqueSaturatedInto, Zero, One, Saturating};
Expand Down Expand Up @@ -138,6 +138,20 @@ fn transaction_build(
block: EthereumBlock,
status: TransactionStatus
) -> Transaction {
let mut sig = [0u8; 65];
let mut msg = [0u8; 32];
sig[0..32].copy_from_slice(&transaction.signature.r()[..]);
sig[32..64].copy_from_slice(&transaction.signature.s()[..]);
sig[64] = transaction.signature.standard_v();
msg.copy_from_slice(&transaction.message_hash(
transaction.signature.chain_id().map(u64::from)
)[..]);

let pubkey = match sp_io::crypto::secp256k1_ecdsa_recover(&sig, &msg) {
Ok(p) => Some(H512::from(p)),
Err(_e) => None,
};

Transaction {
hash: H256::from_slice(
Keccak256::digest(&rlp::encode(&transaction)).as_slice()
Expand All @@ -160,7 +174,7 @@ fn transaction_build(
input: Bytes(transaction.clone().input),
creates: status.contract_address,
raw: Bytes(rlp::encode(&transaction)),
public_key: None, // TODO
public_key: pubkey,
chain_id: transaction.signature.chain_id().map(U64::from),
standard_v: U256::from(transaction.signature.standard_v()),
v: U256::from(transaction.signature.v()),
Expand Down

0 comments on commit d72c861

Please sign in to comment.