fix: contract creation on trezor (#695)
* fix contract creation on trezor * handle when _to_ param is an empty string * return TrezorError when receiving an ENS name * fix typo
This commit is contained in:
parent
6cbdc89187
commit
5bf3f73548
|
@ -264,13 +264,34 @@ mod tests {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
async fn test_sign_empty_txes() {
|
async fn test_sign_empty_txes() {
|
||||||
|
// Contract creation (empty `to`), requires data.
|
||||||
|
// To test without the data field, we need to specify a `to` address.
|
||||||
let trezor = TrezorEthereum::new(DerivationType::TrezorLive(0), 1).await.unwrap();
|
let trezor = TrezorEthereum::new(DerivationType::TrezorLive(0), 1).await.unwrap();
|
||||||
{
|
{
|
||||||
let tx_req = Eip1559TransactionRequest::new().into();
|
let tx_req = Eip1559TransactionRequest::new()
|
||||||
|
.to("2ed7afa17473e17ac59908f088b4371d28585476".parse::<Address>().unwrap())
|
||||||
|
.into();
|
||||||
let tx = trezor.sign_transaction(&tx_req).await.unwrap();
|
let tx = trezor.sign_transaction(&tx_req).await.unwrap();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let tx_req = TransactionRequest::new().into();
|
let tx_req = TransactionRequest::new()
|
||||||
|
.to("2ed7afa17473e17ac59908f088b4371d28585476".parse::<Address>().unwrap())
|
||||||
|
.into();
|
||||||
|
let tx = trezor.sign_transaction(&tx_req).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = hex::decode("095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap();
|
||||||
|
|
||||||
|
// Contract creation (empty `to`, with data) should show on the trezor device as:
|
||||||
|
// ` "0 Wei ETH
|
||||||
|
// ` new contract?"
|
||||||
|
let trezor = TrezorEthereum::new(DerivationType::TrezorLive(0), 1).await.unwrap();
|
||||||
|
{
|
||||||
|
let tx_req = Eip1559TransactionRequest::new().data(data.clone()).into();
|
||||||
|
let tx = trezor.sign_transaction(&tx_req).await.unwrap();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let tx_req = TransactionRequest::new().data(data.clone()).into();
|
||||||
let tx = trezor.sign_transaction(&tx_req).await.unwrap();
|
let tx = trezor.sign_transaction(&tx_req).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use ethers_core::types::{transaction::eip2718::TypedTransaction, NameOrAddress, H160, U256};
|
use ethers_core::types::{transaction::eip2718::TypedTransaction, NameOrAddress, U256};
|
||||||
use trezor_client::client::AccessListItem as Trezor_AccessListItem;
|
use trezor_client::client::AccessListItem as Trezor_AccessListItem;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -49,6 +49,8 @@ pub enum TrezorError {
|
||||||
/// Error when signing EIP712 struct with not compatible Trezor ETH app
|
/// Error when signing EIP712 struct with not compatible Trezor ETH app
|
||||||
#[error("Trezor ethereum app requires at least version: {0:?}")]
|
#[error("Trezor ethereum app requires at least version: {0:?}")]
|
||||||
UnsupportedFirmwareVersion(String),
|
UnsupportedFirmwareVersion(String),
|
||||||
|
#[error("Does not support ENS.")]
|
||||||
|
NoENSSupport,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trezor Transaction Struct
|
/// Trezor Transaction Struct
|
||||||
|
@ -72,9 +74,13 @@ impl TrezorTransaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(tx: &TypedTransaction) -> Result<Self, TrezorError> {
|
pub fn load(tx: &TypedTransaction) -> Result<Self, TrezorError> {
|
||||||
let to: String = match tx.to().unwrap_or(&NameOrAddress::Address(H160::from(&[0; 20]))) {
|
let to: String = match tx.to() {
|
||||||
NameOrAddress::Name(_) => unimplemented!(),
|
Some(v) => match v {
|
||||||
|
NameOrAddress::Name(_) => return Err(TrezorError::NoENSSupport),
|
||||||
NameOrAddress::Address(value) => format!("0x{}", hex::encode(value)),
|
NameOrAddress::Address(value) => format!("0x{}", hex::encode(value)),
|
||||||
|
},
|
||||||
|
// Contract Creation
|
||||||
|
None => "".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let nonce = tx.nonce().map_or(vec![], Self::to_trimmed_big_endian);
|
let nonce = tx.nonce().map_or(vec![], Self::to_trimmed_big_endian);
|
||||||
|
|
Loading…
Reference in New Issue