Allow modifications of gas when confirming in signer (#3798)

This commit is contained in:
Tomasz Drwięga 2016-12-10 20:18:42 +01:00 committed by Arkadiy Paronyan
parent a6fcd8a0d9
commit 08a47ea2d4
3 changed files with 19 additions and 7 deletions

View File

@ -89,11 +89,13 @@ impl<C: 'static, M: 'static> Signer for SignerClient<C, M> where C: MiningBlockC
signer.peek(&id).map(|confirmation| {
let mut payload = confirmation.payload.clone();
// Modify payload
match (&mut payload, modification.gas_price) {
(&mut ConfirmationPayload::SendTransaction(ref mut request), Some(gas_price)) => {
if let ConfirmationPayload::SendTransaction(ref mut request) = payload {
if let Some(gas_price) = modification.gas_price {
request.gas_price = gas_price.into();
},
_ => {},
}
if let Some(gas) = modification.gas {
request.gas = gas.into();
}
}
// Execute
let result = dispatch::execute(&*client, &*miner, &*accounts, payload, Some(pass));

View File

@ -183,7 +183,7 @@ fn should_confirm_transaction_and_dispatch() {
let t = Transaction {
nonce: U256::zero(),
gas_price: U256::from(0x1000),
gas: U256::from(10_000_000),
gas: U256::from(0x50505),
action: Action::Call(recipient),
value: U256::from(0x1),
data: vec![]
@ -198,7 +198,7 @@ fn should_confirm_transaction_and_dispatch() {
let request = r#"{
"jsonrpc":"2.0",
"method":"signer_confirmRequest",
"params":["0x1", {"gasPrice":"0x1000"}, "test"],
"params":["0x1", {"gasPrice":"0x1000","gas":"0x50505"}, "test"],
"id":1
}"#;
let response = r#"{"jsonrpc":"2.0","result":""#.to_owned() + format!("0x{:?}", t.hash()).as_ref() + r#"","id":1}"#;

View File

@ -142,6 +142,8 @@ pub struct TransactionModification {
/// Modified gas price
#[serde(rename="gasPrice")]
pub gas_price: Option<U256>,
/// Modified gas
pub gas: Option<U256>,
}
/// Represents two possible return values.
@ -275,18 +277,26 @@ mod tests {
let s1 = r#"{
"gasPrice":"0xba43b7400"
}"#;
let s2 = r#"{}"#;
let s2 = r#"{"gas": "0x1233"}"#;
let s3 = r#"{}"#;
// when
let res1: TransactionModification = serde_json::from_str(s1).unwrap();
let res2: TransactionModification = serde_json::from_str(s2).unwrap();
let res3: TransactionModification = serde_json::from_str(s3).unwrap();
// then
assert_eq!(res1, TransactionModification {
gas_price: Some(U256::from_str("0ba43b7400").unwrap()),
gas: None,
});
assert_eq!(res2, TransactionModification {
gas_price: None,
gas: Some(U256::from_str("1233").unwrap()),
});
assert_eq!(res3, TransactionModification {
gas_price: None,
gas: None,
});
}
}