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

Add web3::contract::deploy::execute_no_unlock #252

Merged
merged 10 commits into from Sep 15, 2019

Conversation

rockbmb
Copy link
Contributor

@rockbmb rockbmb commented Sep 8, 2019

This PR introduces a variant of web3::contract::deploy::execute that does not require the account for which it is used to be unlocked.

This function is a variant of `web3::contract::deploy::execute`
that does not require the account for which it is used to be
unlocked.
@rockbmb rockbmb marked this pull request as ready for review September 8, 2019 15:58
rockbmb added a commit to oscoin/oscoin-parity-wasm-prototype that referenced this pull request Sep 8, 2019
rockbmb added a commit to oscoin/oscoin-parity-wasm-prototype that referenced this pull request Sep 8, 2019
rockbmb added a commit to oscoin/oscoin-parity-wasm-prototype that referenced this pull request Sep 8, 2019
rockbmb added a commit to oscoin/oscoin-parity-wasm-prototype that referenced this pull request Sep 8, 2019
rockbmb added a commit to oscoin/oscoin-parity-wasm-prototype that referenced this pull request Sep 8, 2019
rockbmb added a commit to oscoin/oscoin-parity-wasm-prototype that referenced this pull request Sep 8, 2019
rockbmb added a commit to oscoin/oscoin-parity-wasm-prototype that referenced this pull request Sep 8, 2019
rockbmb added a commit to oscoin/oscoin-parity-wasm-prototype that referenced this pull request Sep 8, 2019
Copy link
Owner

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall idea is ok, but there are few improvements to be made.

let raw_tx = web3
.personal()
.sign_transaction(tx, password)
.wait()
Copy link
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then how should I fetch the value that web3.personal().sign_transaction() returns?

I can chain this computation with and_then(move |signed_tx| {send_raw_transaction_with_confirmation ... }, but that's only moving the Future down the line, and the closure can't return one.

Copy link
Contributor Author

@rockbmb rockbmb Sep 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost forgot: the impl<T: Transport> Future for SendTransactionWithConfirmation<T> has type Item = TransactionReceipt, meaning even if the above is done, we will still be getting a TransactionReceipt where we should be getting a SendTransactionWithConfirmation<T> to be used to create a PendingContract.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely we need to change PendingContract to be able to work with aribtrary Future that resolves to TransactionReceipt:

PendingContract<
  T: Transport, 
  F: Future<Item=TransactionReceipt, Error=...> = SendTransactionWithConfirmation<T>,
> {

}

and then use the and_thencombinator as you've mentioned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reluctant to change PendingContract without the go-ahead of someone more knowledgeable about the code base than me. If it sounds reasonable, then I will do so, and re-request a review.

Thank you for your attention 👍

Copy link
Contributor Author

@rockbmb rockbmb Sep 10, 2019

Choose a reason for hiding this comment

The 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 F: Future<Item=TransactionReceipt, Error=...> = SendTransactionWithConfirmation<T> mean?

I have not come across this syntax before.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a generic parameter, but with a default value. So that PendingContract<T> would still be backward compatible, as the F type would default to SendTransactionWithConfirmation if omitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 PendingContract.

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 and_then returned a struct, AndThen, that implemented Future so I am not sure why PendingContract would have issues with it.

Do you mind lending me a hand with this? I apologise for my unreasonable request.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that you let the caller specify Ft, since it's a generic parameter, but you try to return AndThen later on.

So the error is just saying that the caller expected a custom Ft type, but you tried to force AndThen on them. Try using impl Future in the returned type of PendingContract. If not we can just put Box there.

/// `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>(
Copy link
Owner

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

.personal()
.sign_transaction(tx, password)
.wait()
.expect("Transaction signing failed");
Copy link
Owner

Choose a reason for hiding this comment

The 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 Err that can be later handled by the caller.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right.

tomusdrw
tomusdrw previously approved these changes Sep 12, 2019
from: Address,
password: &str,
web3: crate::Web3<T>,
) -> Result<PendingContract<T, Ft>, ethabi::Error>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
) -> Result<PendingContract<T, Ft>, ethabi::Error>
) -> Result<PendingContract<T, impl Future<...>>, ethabi::Error>

Drop Ft and try this.

@rockbmb
Copy link
Contributor Author

rockbmb commented Sep 12, 2019

@tomusdrw thank you for all the help.

I don't quite like the way sign_and_execute duplicates most of its code, but this can be merged if you approve of it. I can return to it some other time to refactor things.

@tomusdrw
Copy link
Owner

Have a look at: rockbmb#1

@rockbmb
Copy link
Contributor Author

rockbmb commented Sep 12, 2019

I only now realized I still need to update the Future instance for PendingContract, please do not merge yet.

@tomusdrw
Copy link
Owner

@rockbmb good to go now?

@rockbmb
Copy link
Contributor Author

rockbmb commented Sep 13, 2019

@tomusdrw not quite. I'm getting an odd compiler error at sign_and_execute's callsite, and I can't quite figure it out.

I would like to be sure it is not because of anything I did here.

@tomusdrw
Copy link
Owner

Maybe add an example/test to this PR so that we can debug it together?

@rockbmb
Copy link
Contributor Author

rockbmb commented Sep 13, 2019

@tomusdrw I'll add one right next to the test for execute, but sadly this will have to wait - I'll be afk for a few hours.

/// `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 sign_and_execute<P, V, Ft>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Ft parameter is unused. This is problematic for calling code because the compiler cannot infer the instantiation of Ft. This leads to the calling code always requiring an explicit type annotation.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just remove it then. I guess I left it by mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try this out.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it solve the issues you were having?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did. I get other errors now, but as far as this PR goes, it has what we need.
Do you still want me to add a test before we merge?

@tomusdrw
Copy link
Owner

@rockbmb Feel free to add a test in a follow-up PR.

@tomusdrw tomusdrw merged commit 48267cb into tomusdrw:master Sep 15, 2019
@rockbmb rockbmb deleted the execute-no-unlock branch September 15, 2019 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants