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

[pallet-revive] Support all eth tx types #6461

Merged
merged 228 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
228 commits
Select commit Hold shift + click to select a range
4f4efcc
Add RPC integration
pgherveou Sep 30, 2024
43a7bf0
Add prdoc
pgherveou Sep 30, 2024
e74852d
Add missing license headers
pgherveou Sep 30, 2024
5b242f8
missing license header
pgherveou Sep 30, 2024
93f25dd
rm unwrap
pgherveou Oct 1, 2024
e4d6543
Add tests
pgherveou Oct 1, 2024
4a9ca42
fix docstr
pgherveou Oct 1, 2024
658f3ac
fix docstring
pgherveou Oct 1, 2024
b75fa99
rm log
pgherveou Oct 2, 2024
c2f4bee
Improve fee checking logic
pgherveou Oct 3, 2024
38fd681
Make tests pass again
pgherveou Oct 4, 2024
e8947bc
fixes
pgherveou Oct 4, 2024
a5f6f75
fixes
pgherveou Oct 4, 2024
2c5242a
Remove unused
pgherveou Oct 4, 2024
8c35821
Rm additional details from prdoc
pgherveou Oct 4, 2024
dd56741
prep kitchensink integration
pgherveou Oct 4, 2024
62ffb24
fix kitchensink
pgherveou Oct 4, 2024
0b5f646
use subxt-signer & eth feature
pgherveou Oct 4, 2024
ad3c0ee
Move rpc stuff to new PR
pgherveou Oct 7, 2024
74ba6dc
Merge branch 'master' into pg/revive-rpc-fixes-v2
athei Oct 7, 2024
5634757
Fixing compilation issues
pgherveou Oct 7, 2024
7f6a356
rustdoc fixes
pgherveou Oct 7, 2024
059f247
Fix doclink
pgherveou Oct 7, 2024
3893465
fix prdoc
pgherveou Oct 7, 2024
8ad166d
fix keyring
pgherveou Oct 7, 2024
766a6c8
fix
pgherveou Oct 7, 2024
2f22e12
add misssing dep
pgherveou Oct 7, 2024
b4fff28
fix lock
pgherveou Oct 7, 2024
f228f16
fix
pgherveou Oct 7, 2024
034420a
fix
pgherveou Oct 7, 2024
14e8eb6
fix
pgherveou Oct 7, 2024
acd95d8
fixes
pgherveou Oct 7, 2024
feaa973
fix tx-pool
pgherveou Oct 7, 2024
ff86aae
Merge branch 'pg/revive-rpc-fixes-v2' of https://github.com/paritytec…
pgherveou Oct 7, 2024
03bc881
fix
pgherveou Oct 7, 2024
ea0d57d
fix
pgherveou Oct 7, 2024
c69817c
tmp fix
pgherveou Oct 7, 2024
b401c60
fix nonce logic
pgherveou Oct 7, 2024
3cd7491
cleanup tests
pgherveou Oct 8, 2024
e93ef66
fix tests
pgherveou Oct 8, 2024
804f402
fix fee dispatch_call
pgherveou Oct 8, 2024
179c2e3
Fix fees
pgherveou Oct 8, 2024
0ac59c2
why not
pgherveou Oct 8, 2024
b9ce758
restore test as they were
pgherveou Oct 8, 2024
3783095
wip
pgherveou Oct 8, 2024
ab8d7db
fix comp issue
pgherveou Oct 8, 2024
741c366
fix
pgherveou Oct 8, 2024
b8840e7
fix test
pgherveou Oct 8, 2024
4b85368
fix rlp encoding
pgherveou Oct 9, 2024
3739e45
wip
pgherveou Oct 10, 2024
46166f8
PR review
pgherveou Oct 10, 2024
2e12a9d
reorg use / mod
pgherveou Oct 10, 2024
4d909c7
Merge branch 'master' into pg/revive-rpc-fixes-v2
pgherveou Oct 10, 2024
5100f67
merge fixes
pgherveou Oct 10, 2024
b44294f
fix license
pgherveou Oct 10, 2024
75ca3f9
Add pallet-revive Ethereum JSON-RPC
pgherveou Oct 7, 2024
19dbf4c
wip
pgherveou Oct 7, 2024
595e66a
fixes
pgherveou Oct 7, 2024
96fa31d
wip
pgherveou Oct 8, 2024
551cd3d
update rpc stuff
pgherveou Oct 8, 2024
2a90e9b
rlp encoding
pgherveou Oct 8, 2024
4dede9c
Update
pgherveou Oct 8, 2024
c2609fa
add js stuff
pgherveou Oct 9, 2024
444970b
update yarn.lock
pgherveou Oct 9, 2024
f10cf13
nit
pgherveou Oct 9, 2024
f0e21af
server fixes
pgherveou Oct 9, 2024
205d8ab
fix demo
pgherveou Oct 9, 2024
0011601
undo log
pgherveou Oct 9, 2024
ed4c0d0
wip
pgherveou Oct 9, 2024
de0b0ef
rpc updates
pgherveou Oct 10, 2024
a745fb0
fixes
pgherveou Oct 10, 2024
75d39a6
fix examples
pgherveou Oct 10, 2024
7fea557
fix examples
pgherveou Oct 10, 2024
8c7fc93
clean up
pgherveou Oct 10, 2024
865acc4
fixes
pgherveou Oct 10, 2024
9f6bc42
kitchensink node fixes
pgherveou Oct 10, 2024
e806110
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 10, 2024
c95a99f
Update substrate/frame/transaction-payment/Cargo.toml
pgherveou Oct 10, 2024
a4ca32b
fix cargo
pgherveou Oct 10, 2024
53c72c5
fixes
pgherveou Oct 10, 2024
511842f
fix
pgherveou Oct 10, 2024
c43a520
Add prdoc
pgherveou Oct 10, 2024
f7053f1
Fix lock
pgherveou Oct 10, 2024
a1c0ad1
Add missing licenses
pgherveou Oct 10, 2024
4341122
fix markdown
pgherveou Oct 10, 2024
87a84ed
fix
pgherveou Oct 10, 2024
d3f536b
fixes
pgherveou Oct 10, 2024
87a52d1
fix clippy
pgherveou Oct 10, 2024
ef0b614
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 10, 2024
026453f
fix examples lint
pgherveou Oct 11, 2024
71cc897
fix clippy
pgherveou Oct 11, 2024
0446289
CI fixes
pgherveou Oct 11, 2024
a6bad6d
fix lint
pgherveou Oct 11, 2024
91cb4d5
taplo
pgherveou Oct 11, 2024
2afd66b
use blob_length from cyril's branch
pgherveou Oct 11, 2024
e59e9f2
fix test
pgherveou Oct 11, 2024
f1e612b
make it safe
pgherveou Oct 11, 2024
1a6cbec
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 11, 2024
a82401f
use blob_length
pgherveou Oct 11, 2024
9a0b3c6
fix
pgherveou Oct 11, 2024
26abb73
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 11, 2024
3183d67
Fix tests
pgherveou Oct 11, 2024
9539434
Update generated types
pgherveou Oct 11, 2024
7527e9f
Add eth_syncing
pgherveou Oct 11, 2024
c06133d
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 11, 2024
21ff12c
Merge branch 'master' into pg/revive-rpc-fixes-v2
pgherveou Oct 11, 2024
5493d17
Refacor import
pgherveou Oct 11, 2024
222a557
PR review get rid of signed extension
pgherveou Oct 12, 2024
bcd5675
nit
pgherveou Oct 12, 2024
42393f4
fix taplo
pgherveou Oct 12, 2024
e695c13
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 14, 2024
02059a4
Use new polkavm release
pgherveou Oct 15, 2024
e04242b
Fix version
pgherveou Oct 16, 2024
4384b5c
update lock
pgherveou Oct 16, 2024
4be1916
fix bare_eth params
pgherveou Oct 16, 2024
ad463ed
PR review use refactor
pgherveou Oct 17, 2024
abe59ff
Get rid of EthTransactKind
pgherveou Oct 17, 2024
44cd6cc
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 17, 2024
680a83b
rpc rm transact_kind
pgherveou Oct 17, 2024
6b5a956
Get rid codegen in this PR
pgherveou Oct 17, 2024
565a367
Use generic parameter for unchecked extrinsic
pgherveou Oct 17, 2024
39d1fd4
Get rid of ethcontractresultdetails
pgherveou Oct 17, 2024
7bfff66
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 18, 2024
6d91b2e
fix rpc
pgherveou Oct 18, 2024
ab6591e
Add tip
pgherveou Oct 18, 2024
0ec05bf
better log
pgherveou Oct 18, 2024
6eddc80
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 18, 2024
a340467
Fix fees calculuation
pgherveou Oct 18, 2024
dcc72c5
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 18, 2024
87d2bf8
update client
pgherveou Oct 18, 2024
419c4dc
fixes
pgherveou Oct 18, 2024
71a2439
Merge branch 'pg/revive-rpc-fixes-v2' into pg/revive-rpc-server
pgherveou Oct 18, 2024
b359f32
wip
pgherveou Oct 18, 2024
5894fb5
Fix fee calculation
pgherveou Oct 18, 2024
da1ec2d
actual_fee_no_tip -> actual_fee
pgherveou Oct 18, 2024
c419f71
missing
pgherveou Oct 18, 2024
417fa32
fix bad merge
pgherveou Oct 19, 2024
f35e668
rm rpc
pgherveou Oct 19, 2024
f646c9e
Update substrate/frame/revive/src/primitives.rs
pgherveou Oct 19, 2024
50015cb
gas_limit pr review
pgherveou Oct 19, 2024
2c09850
Merge branch 'master' into pg/revive-rpc-fixes-v2
pgherveou Oct 20, 2024
483b638
Update substrate/bin/node/runtime/src/lib.rs
pgherveou Oct 20, 2024
6a58fa5
Add comment on GAS_PRICE constant
pgherveou Oct 20, 2024
13fed3d
rm demo.rs
pgherveou Oct 20, 2024
83c0a38
fix tests
pgherveou Oct 20, 2024
9d06cfe
fix
pgherveou Oct 21, 2024
9e98cbb
simplify
pgherveou Oct 21, 2024
07a6717
Rename things to match #3685
pgherveou Oct 21, 2024
58a6942
typo
pgherveou Oct 21, 2024
d1de70f
fix
pgherveou Oct 21, 2024
e3f3f4b
CI build fixes
pgherveou Oct 21, 2024
05688e2
Restore files from previous PR
pgherveou Oct 21, 2024
5f88ef1
mv prdoc
pgherveou Oct 21, 2024
2f3122f
fix-up Cargo.toml
pgherveou Oct 21, 2024
d5e132d
fix up cargo.toml
pgherveou Oct 21, 2024
d07c790
fixup
pgherveou Oct 21, 2024
744eef7
fix
pgherveou Oct 21, 2024
ba34153
Merge branch 'master' into pg/revive-rpc-server-2
pgherveou Oct 22, 2024
56748fc
wip
pgherveou Oct 22, 2024
3262d34
bump subxt
pgherveou Oct 22, 2024
8e51a2c
fix bump
pgherveou Oct 23, 2024
a812fb7
fix
pgherveou Oct 23, 2024
93da773
Fix hard coded gas estimate in tests
pgherveou Oct 23, 2024
7999974
Update from pgherveou running command 'prdoc --audience runtime_dev -…
actions-user Oct 23, 2024
b435073
Update prdoc/pr_6192.prdoc
pgherveou Oct 23, 2024
d71a0a0
fixes
pgherveou Oct 23, 2024
570da46
unpub
pgherveou Oct 23, 2024
8e8b692
fixup client
pgherveou Oct 23, 2024
7a217b9
fixes
pgherveou Oct 23, 2024
7efcbbd
Merge branch 'master' into pg/revive-rpc-server-2
pgherveou Oct 23, 2024
ac700fc
fix AH config with new runtime api
pgherveou Oct 23, 2024
80182e3
fix missing use
pgherveou Oct 23, 2024
bf00157
add test
pgherveou Oct 23, 2024
15b9c27
lint fixes
pgherveou Oct 23, 2024
52c7290
clean up
pgherveou Oct 23, 2024
a0deaf6
cleanup
pgherveou Oct 23, 2024
deb191c
fix ci
pgherveou Oct 24, 2024
8a4007c
Merge branch 'master' into pg/revive-rpc-server-2
pgherveou Oct 24, 2024
81956a0
fix umbrella
pgherveou Oct 24, 2024
f1ea594
Merge branch 'master' into pg/fix-hardcoded-gas
pgherveou Oct 24, 2024
069c21c
Merge branch 'pg/fix-hardcoded-gas' into pg/revive-rpc-server-2
pgherveou Oct 24, 2024
8bb9db2
fix prdoc
pgherveou Oct 24, 2024
2efc281
update deploy
pgherveou Oct 24, 2024
7f88f8e
revive_api should use usable balance instead of free_balance
pgherveou Oct 24, 2024
22eef3a
Tweak tests
pgherveou Oct 24, 2024
82b4ca2
fix test
pgherveou Oct 24, 2024
67db7c4
fix test
pgherveou Oct 24, 2024
072734f
fix test
pgherveou Oct 24, 2024
83f6686
fix ;
pgherveou Oct 24, 2024
a0c7970
fix log message
pgherveou Oct 24, 2024
f0fe2b9
PR review
pgherveou Oct 24, 2024
552c547
rm Misc
pgherveou Oct 24, 2024
acd84d8
fix ci check
pgherveou Oct 24, 2024
42b9926
Nit changes after testing against AH
pgherveou Oct 25, 2024
5bdd9d7
Best block is fine
pgherveou Oct 25, 2024
f4959cc
Merge branch 'master' into pg/revive-rpc-server-2
pgherveou Oct 25, 2024
72430a0
fixes
pgherveou Oct 25, 2024
76b4b96
fix metadata
pgherveou Oct 25, 2024
79294d4
Add westend local network testing instructions
pgherveou Oct 25, 2024
6588378
nit
pgherveou Oct 25, 2024
cd37a55
add type3 for later support of type 3 tx
pgherveou Oct 28, 2024
c854129
Testing without from
pgherveou Oct 28, 2024
9016b6e
wip
pgherveou Oct 28, 2024
14c482e
Merge branch 'master' into pg/rpc-server-followup
pgherveou Nov 13, 2024
66b8ac8
fixes
pgherveou Nov 13, 2024
29a545e
wip
pgherveou Nov 13, 2024
34ab580
wip
pgherveou Nov 13, 2024
f45073c
Add to generic
pgherveou Nov 14, 2024
ba50dec
fixes
pgherveou Nov 14, 2024
11fdaab
fix
pgherveou Nov 14, 2024
022aac0
fixes
pgherveou Nov 14, 2024
ccf3d3b
test without legacy
pgherveou Nov 15, 2024
2911e08
use from_signed
pgherveou Nov 15, 2024
3b2b834
Merge branch 'master' into pg/rpc-server-followup
pgherveou Nov 15, 2024
8262598
add other types
pgherveou Nov 15, 2024
b44c9a9
fix lint
pgherveou Nov 18, 2024
37195b9
Add prdoc
pgherveou Nov 18, 2024
5fb3b09
send_transaction estimate gas if not provided
pgherveou Nov 18, 2024
e11fca7
fix clippy
pgherveou Nov 18, 2024
6d9624a
rm log
pgherveou Nov 18, 2024
072c394
fix usage of legacy
pgherveou Nov 18, 2024
5cb60ab
fix tests
pgherveou Nov 18, 2024
581a744
rm macro
pgherveou Nov 18, 2024
720757d
reorder fields
pgherveou Nov 18, 2024
df8dc78
rm comment
pgherveou Nov 18, 2024
e217aba
comment change
pgherveou Nov 18, 2024
dd19a5c
combine U256 conversions
pgherveou Nov 19, 2024
7459573
Merge branch 'master' into pg/rpc-server-followup
pgherveou Nov 21, 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
12 changes: 12 additions & 0 deletions prdoc/pr_6461.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
title: '[pallet-revive] add support for all eth tx types'
doc:
- audience: Runtime Dev
description: Add support for 1559, 4844, and 2930 transaction types
crates:
- name: pallet-revive-eth-rpc
bump: minor
- name: pallet-revive
bump: minor

24 changes: 12 additions & 12 deletions substrate/frame/revive/rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
//! The client connects to the source substrate chain
//! and is used by the rpc server to query and send transactions to the substrate chain.
use crate::{
rlp,
runtime::GAS_PRICE,
subxt_client::{
revive::{calls::types::EthTransact, events::ContractEmitted},
runtime_types::pallet_revive::storage::ContractInfo,
},
TransactionLegacySigned, LOG_TARGET,
LOG_TARGET,
};
use futures::{stream, StreamExt};
use jsonrpsee::types::{error::CALL_EXECUTION_FAILED_CODE, ErrorObjectOwned};
Expand Down Expand Up @@ -269,25 +268,26 @@ impl ClientInner {
let extrinsics = extrinsics.iter().flat_map(|ext| {
let call = ext.as_extrinsic::<EthTransact>().ok()??;
let transaction_hash = H256(keccak_256(&call.payload));
let tx = rlp::decode::<TransactionLegacySigned>(&call.payload).ok()?;
let from = tx.recover_eth_address().ok()?;
let contract_address = if tx.transaction_legacy_unsigned.to.is_none() {
Some(create1(&from, tx.transaction_legacy_unsigned.nonce.try_into().ok()?))
let signed_tx = TransactionSigned::decode(&call.payload).ok()?;
let from = signed_tx.recover_eth_address().ok()?;
let tx_info = GenericTransaction::from_signed(signed_tx.clone(), Some(from));
let contract_address = if tx_info.to.is_none() {
Some(create1(&from, tx_info.nonce.unwrap_or_default().try_into().ok()?))
} else {
None
};

Some((from, tx, transaction_hash, contract_address, ext))
Some((from, signed_tx, tx_info, transaction_hash, contract_address, ext))
});

// Map each extrinsic to a receipt
stream::iter(extrinsics)
.map(|(from, tx, transaction_hash, contract_address, ext)| async move {
.map(|(from, signed_tx, tx_info, transaction_hash, contract_address, ext)| async move {
let events = ext.events().await?;
let tx_fees =
events.find_first::<TransactionFeePaid>()?.ok_or(ClientError::TxFeeNotFound)?;

let gas_price = tx.transaction_legacy_unsigned.gas_price;
let gas_price = tx_info.gas_price.unwrap_or_default();
let gas_used = (tx_fees.tip.saturating_add(tx_fees.actual_fee))
.checked_div(gas_price.as_u128())
.unwrap_or_default();
Expand Down Expand Up @@ -324,16 +324,16 @@ impl ClientInner {
contract_address,
from,
logs,
tx.transaction_legacy_unsigned.to,
tx_info.to,
gas_price,
gas_used.into(),
success,
transaction_hash,
transaction_index.into(),
tx.transaction_legacy_unsigned.r#type.as_byte()
tx_info.r#type.unwrap_or_default()
);

Ok::<_, ClientError>((receipt.transaction_hash, (tx.into(), receipt)))
Ok::<_, ClientError>((receipt.transaction_hash, (signed_tx, receipt)))
})
.buffer_unordered(10)
.collect::<Vec<Result<_, _>>>()
Expand Down
9 changes: 4 additions & 5 deletions substrate/frame/revive/rpc/src/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
use crate::{EthRpcClient, ReceiptInfo};
use anyhow::Context;
use pallet_revive::evm::{
rlp::*, Account, BlockTag, Bytes, GenericTransaction, TransactionLegacyUnsigned, H160, H256,
U256,
Account, BlockTag, Bytes, GenericTransaction, TransactionLegacyUnsigned, H160, H256, U256,
};

/// Wait for a transaction receipt.
Expand Down Expand Up @@ -169,11 +168,11 @@ impl TransactionBuilder {

mutate(&mut unsigned_tx);

let tx = signer.sign_transaction(unsigned_tx.clone());
let bytes = tx.rlp_bytes().to_vec();
let tx = signer.sign_transaction(unsigned_tx.into());
let bytes = tx.signed_payload();

let hash = client
.send_raw_transaction(bytes.clone().into())
.send_raw_transaction(bytes.into())
.await
.with_context(|| "transaction failed")?;

Expand Down
57 changes: 22 additions & 35 deletions substrate/frame/revive/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl EthRpcServer for EthRpcServerImpl {
async fn send_raw_transaction(&self, transaction: Bytes) -> RpcResult<H256> {
let hash = H256(keccak_256(&transaction.0));

let tx = rlp::decode::<TransactionLegacySigned>(&transaction.0).map_err(|err| {
let tx = TransactionSigned::decode(&transaction.0).map_err(|err| {
log::debug!(target: LOG_TARGET, "Failed to decode transaction: {err:?}");
EthRpcError::from(err)
})?;
Expand All @@ -147,21 +147,10 @@ impl EthRpcServer for EthRpcServerImpl {
EthRpcError::InvalidSignature
})?;

let tx = GenericTransaction::from_signed(tx, Some(eth_addr));

// Dry run the transaction to get the weight limit and storage deposit limit
let TransactionLegacyUnsigned { to, input, value, .. } = tx.transaction_legacy_unsigned;
let dry_run = self
.client
.dry_run(
&GenericTransaction {
from: Some(eth_addr),
input: Some(input.clone()),
to,
value: Some(value),
..Default::default()
},
BlockTag::Latest.into(),
)
.await?;
let dry_run = self.client.dry_run(&tx, BlockTag::Latest.into()).await?;

let EthContractResult { gas_required, storage_deposit, .. } = dry_run;
let call = subxt_client::tx().revive().eth_transact(
Expand All @@ -174,11 +163,10 @@ impl EthRpcServer for EthRpcServerImpl {
Ok(hash)
}

async fn send_transaction(&self, transaction: GenericTransaction) -> RpcResult<H256> {
async fn send_transaction(&self, mut transaction: GenericTransaction) -> RpcResult<H256> {
log::debug!(target: LOG_TARGET, "{transaction:#?}");
let GenericTransaction { from, gas, gas_price, input, to, value, r#type, .. } = transaction;

let Some(from) = from else {
let Some(from) = transaction.from else {
log::debug!(target: LOG_TARGET, "Transaction must have a sender");
return Err(EthRpcError::InvalidTransaction.into());
};
Expand All @@ -189,27 +177,26 @@ impl EthRpcServer for EthRpcServerImpl {
.find(|account| account.address() == from)
.ok_or(EthRpcError::AccountNotFound(from))?;

let gas_price = gas_price.unwrap_or_else(|| U256::from(GAS_PRICE));
let chain_id = Some(self.client.chain_id().into());
let input = input.unwrap_or_default();
let value = value.unwrap_or_default();
let r#type = r#type.unwrap_or_default();
if transaction.gas.is_none() {
transaction.gas = Some(self.estimate_gas(transaction.clone(), None).await?);
}

let Some(gas) = gas else {
log::debug!(target: LOG_TARGET, "Transaction must have a gas limit");
return Err(EthRpcError::InvalidTransaction.into());
};
if transaction.gas_price.is_none() {
transaction.gas_price = Some(self.gas_price().await?);
}

let r#type = Type0::try_from_byte(r#type.clone())
.map_err(|_| EthRpcError::TransactionTypeNotSupported(r#type))?;
if transaction.nonce.is_none() {
transaction.nonce =
Some(self.get_transaction_count(from, BlockTag::Latest.into()).await?);
}

let nonce = self.get_transaction_count(from, BlockTag::Latest.into()).await?;
if transaction.chain_id.is_none() {
transaction.chain_id = Some(self.chain_id().await?);
}

let tx =
TransactionLegacyUnsigned { chain_id, gas, gas_price, input, nonce, to, value, r#type };
let tx = account.sign_transaction(tx);
let rlp_bytes = rlp::encode(&tx).to_vec();
self.send_raw_transaction(Bytes(rlp_bytes)).await
let tx = transaction.try_into_unsigned().map_err(|_| EthRpcError::InvalidTransaction)?;
let payload = account.sign_transaction(tx).signed_payload();
self.send_raw_transaction(Bytes(payload)).await
}

async fn get_block_by_hash(
Expand Down
2 changes: 0 additions & 2 deletions substrate/frame/revive/src/evm/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ pub use rlp;
mod type_id;
pub use type_id::*;

#[cfg(feature = "std")]
mod rpc_types;

mod rpc_types_gen;
pub use rpc_types_gen::*;

Expand Down
28 changes: 22 additions & 6 deletions substrate/frame/revive/src/evm/api/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
// limitations under the License.
//! Utilities for working with Ethereum accounts.
use crate::{
evm::{TransactionLegacySigned, TransactionLegacyUnsigned},
evm::{TransactionSigned, TransactionUnsigned},
H160,
};
use rlp::Encodable;
use sp_runtime::AccountId32;

/// A simple account that can sign transactions
Expand All @@ -38,6 +37,11 @@ impl From<subxt_signer::eth::Keypair> for Account {
}

impl Account {
/// Create a new account from a secret
pub fn from_secret_key(secret_key: [u8; 32]) -> Self {
subxt_signer::eth::Keypair::from_secret_key(secret_key).unwrap().into()
}

/// Get the [`H160`] address of the account.
pub fn address(&self) -> H160 {
H160::from_slice(&self.0.public_key().to_account_id().as_ref())
Expand All @@ -52,9 +56,21 @@ impl Account {
}

/// Sign a transaction.
pub fn sign_transaction(&self, tx: TransactionLegacyUnsigned) -> TransactionLegacySigned {
let rlp_encoded = tx.rlp_bytes();
let signature = self.0.sign(&rlp_encoded);
TransactionLegacySigned::from(tx, signature.as_ref())
pub fn sign_transaction(&self, tx: TransactionUnsigned) -> TransactionSigned {
let payload = tx.unsigned_payload();
let signature = self.0.sign(&payload).0;
tx.with_signature(signature)
}
}

#[test]
fn from_secret_key_works() {
let account = Account::from_secret_key(hex_literal::hex!(
"a872f6cbd25a0e04a08b1e21098017a9e6194d101d75e13111f71410c59cd57f"
));

assert_eq!(
account.address(),
H160::from(hex_literal::hex!("75e480db528101a381ce68544611c169ad7eb342"))
)
}
Loading
Loading