-
Notifications
You must be signed in to change notification settings - Fork 456
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
Add web3::contract::deploy::execute_no_unlock
#252
Changes from 2 commits
7cb9e68
c99e2bc
6ac5d7d
b5b2f56
6f2f992
5c45bcd
2204f5d
0589a9b
1df0720
2cee697
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,11 +44,12 @@ impl<T: Transport> Builder<T> { | |
self | ||
} | ||
|
||
/// Execute deployment passing code and contructor parameters. | ||
pub fn execute<P, V>(self, code: V, params: P, from: Address) -> Result<PendingContract<T>, ethabi::Error> | ||
fn execute_core<P, V, F>(self, code: V, params: P, from: Address, f: F) -> Result<PendingContract<T>, ethabi::Error> | ||
where | ||
P: Tokenize, | ||
V: AsRef<str>, | ||
T: Transport, | ||
F: Fn(TransactionRequest, T, core::time::Duration, usize) -> confirm::SendTransactionWithConfirmation<T>, | ||
{ | ||
let options = self.options; | ||
let eth = self.eth; | ||
|
@@ -89,11 +90,11 @@ impl<T: Transport> Builder<T> { | |
condition: options.condition, | ||
}; | ||
|
||
let waiting = confirm::send_transaction_with_confirmation( | ||
eth.transport().clone(), | ||
let waiting = f( | ||
tx, | ||
self.poll_interval, | ||
self.confirmations, | ||
eth.transport().clone(), | ||
self.poll_interval.clone(), | ||
self.confirmations.clone(), | ||
); | ||
|
||
Ok(PendingContract { | ||
|
@@ -102,6 +103,50 @@ impl<T: Transport> Builder<T> { | |
waiting, | ||
}) | ||
} | ||
|
||
/// Execute deployment passing code and contructor parameters. | ||
pub fn execute<P, V>(self, code: V, params: P, from: Address) -> Result<PendingContract<T>, ethabi::Error> | ||
where | ||
P: Tokenize, | ||
V: AsRef<str>, | ||
T: Transport, | ||
{ | ||
let f = |tx, eth: T, poll_interval, confirmations| { | ||
confirm::send_transaction_with_confirmation(eth, tx, poll_interval, confirmations) | ||
}; | ||
self.execute_core(code, params, from, f) | ||
} | ||
|
||
/// Execute deployment passing code and contructor parameters. | ||
/// | ||
/// Unlike the above `execute`, this method uses | ||
/// `sign_raw_transaction_with_confirmation` instead of | ||
/// `sign_transaction_with_confirmation`, which requires the account from | ||
/// which the transaction is sent to be unlocked. | ||
pub fn execute_no_unlock<P, V>( | ||
self, | ||
code: V, | ||
params: P, | ||
from: Address, | ||
password: &str, | ||
web3: crate::Web3<T>, | ||
) -> Result<PendingContract<T>, ethabi::Error> | ||
where | ||
P: Tokenize, | ||
V: AsRef<str>, | ||
T: Transport, | ||
{ | ||
let f = |tx, eth: T, poll_interval, confirmations| { | ||
let raw_tx = web3 | ||
.personal() | ||
.sign_transaction(tx, password) | ||
.wait() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is making a synchronous call, it's not acceptable in async context. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then how should I fetch the value that I can chain this computation with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Almost forgot: the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most likely we need to change
and then use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was reluctant to change Thank you for your attention 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that the type signatures you wrote here are merely suggestive, but what does I have not come across this syntax before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a generic parameter, but with a default value. So that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I split the two functions back again since the previous refactoring would not work with this change to However, now I'm getting an error on this line I am not sure I understand: F
mismatched types
expected type parameter, found struct `futures::AndThen`
note: expected type `Ft`
found type `futures::AndThen<helpers::CallFuture<types::transaction::RawTransaction, <T as Transport>::Out>, confirm::SendTransactionWithConfirmation<T>, [closure@src\contract\deploy.rs:165:79: 172:10 eth:_, self:_]>`rustc(E0308)
deploy.rs(177, 13): expected type parameter, found struct `futures::AndThen` I was under the impression Do you mind lending me a hand with this? I apologise for my unreasonable request. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thing is that you let the caller specify So the error is just saying that the caller expected a custom |
||
.expect("Transaction signing failed"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We definitely should not panic if we can't sign the transaction - it should just be a regular There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. |
||
|
||
confirm::send_raw_transaction_with_confirmation(eth, raw_tx.raw, poll_interval, confirmations) | ||
}; | ||
self.execute_core(code, params, from, f) | ||
} | ||
} | ||
|
||
/// Contract being deployed. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call it
sign_and_execute
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!