Skip to content

Commit d72c861

Browse files
authored
Adds public key field to transaction (#122)
* Merge master * Adds pubkey to tx
1 parent ac50956 commit d72c861

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ethereum-types = "0.9.0"
1414
frontier-consensus = { path = "../consensus" }
1515
frontier-rpc-core = { path = "core" }
1616
frontier-rpc-primitives = { path = "primitives" }
17+
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
1718
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
1819
sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" }
1920
sp-consensus = { git = "https://github.com/paritytech/substrate.git", branch = "frontier" }

rpc/src/lib.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use std::{marker::PhantomData, sync::Arc};
1818
use std::collections::BTreeMap;
1919
use ethereum::{Block as EthereumBlock, Transaction as EthereumTransaction};
20-
use ethereum_types::{H160, H256, H64, U256, U64};
20+
use ethereum_types::{H160, H256, H64, U256, U64, H512};
2121
use jsonrpc_core::{BoxFuture, Result, ErrorCode, Error, futures::future::{self, Future}};
2222
use futures::future::TryFutureExt;
2323
use sp_runtime::traits::{Block as BlockT, Header as _, UniqueSaturatedInto, Zero, One, Saturating};
@@ -138,6 +138,20 @@ fn transaction_build(
138138
block: EthereumBlock,
139139
status: TransactionStatus
140140
) -> Transaction {
141+
let mut sig = [0u8; 65];
142+
let mut msg = [0u8; 32];
143+
sig[0..32].copy_from_slice(&transaction.signature.r()[..]);
144+
sig[32..64].copy_from_slice(&transaction.signature.s()[..]);
145+
sig[64] = transaction.signature.standard_v();
146+
msg.copy_from_slice(&transaction.message_hash(
147+
transaction.signature.chain_id().map(u64::from)
148+
)[..]);
149+
150+
let pubkey = match sp_io::crypto::secp256k1_ecdsa_recover(&sig, &msg) {
151+
Ok(p) => Some(H512::from(p)),
152+
Err(_e) => None,
153+
};
154+
141155
Transaction {
142156
hash: H256::from_slice(
143157
Keccak256::digest(&rlp::encode(&transaction)).as_slice()
@@ -160,7 +174,7 @@ fn transaction_build(
160174
input: Bytes(transaction.clone().input),
161175
creates: status.contract_address,
162176
raw: Bytes(rlp::encode(&transaction)),
163-
public_key: None, // TODO
177+
public_key: pubkey,
164178
chain_id: transaction.signature.chain_id().map(U64::from),
165179
standard_v: U256::from(transaction.signature.standard_v()),
166180
v: U256::from(transaction.signature.v()),

0 commit comments

Comments
 (0)