AlphaWallet / alpha-wallet-android

An advanced Ethereum mobile wallet
https://www.alphawallet.com
MIT License
596 stars 530 forks source link

Add option to send transactions private using Eden #2318

Open hboon opened 2 years ago

hboon commented 2 years ago

@oa-s would you help to elaborate? Note that checking for pending transaction status needs to be updated too.

oa-s commented 2 years ago

Its need to update code base with ability to use Eden private network. Checkout RPC url while sending a transaction to network. The icons need for PR could find here: https://app.zeplin.io/project/5d0356be2f25b319dcc5944b/styleguide/components?coid=6197a1c20ba031a7c0eb8347 Note, in case if android doesn't support sending requests for ethermine, check RPC url for seach server: .main - https://rpc.ethermine.org; other servers - use default RPC url. For .eden use the next private RPC urls: .main - https://api.edennetwork.io/v1/rpc; ropsten - https://dev-api.edennetwork.io/v1/rpc; other servers - use default RPC url.

hboon commented 2 years ago

Note, in case if android doesn't support sending requests for ethermine, check RPC url for seach server:

No, it doesn't yet. Might as well do it together.

@oa-s thanks. Help assign this to @JamesSmartCell when you are done. Maybe screenshots of where the changes are in the UI too?

hboon commented 2 years ago

@oa-s bump

asif-finimble commented 2 years ago

@JamesSmartCell can you please guide me on this?
seems like edennetwork website is not accessible right now. Also I dont have the access to the given zeplin project.

JamesSmartCell commented 2 years ago

@oa-s or @hboon can you show the current flow on iOS? Is there any special handling or is it just done as a new network as normal?

If it's a normal network, I see RPC calls but no transaction query API routes. Do these correspond to existing networks? Or a single existing network eg Mainnet?

So, eg would I send the transaction via eden, get a tx hash and then scan for that on mainnet?

"Note, in case if android doesn't support sending requests for ethermine" what does this mean? Why would Android natively support any crypto transaction mechanism? what is "ethermine" and how does it affect or interact with eden?

Sorry I don't really understand any of this PR or how it's supposed to work. Can you clarify with a quick run through for Asif and myself?

hboon commented 2 years ago

@oa-s or @hboon can you show the current flow on iOS? Is there any special handling or is it just done as a new network as normal?

If it's a normal network, I see RPC calls but no transaction query API routes. Do these correspond to existing networks? Or a single existing network eg Mainnet?

So, eg would I send the transaction via eden, get a tx hash and then scan for that on mainnet?

Sure. This isn't the same as adding a chain that we normally do.

What Eden and Ethermine does is, they are miners and they offer an RPC endpoint for us to post transactions to. These transactions are only broadcast after they are mined, to prevent front-running (by others). Hence "private". They also offer some other functionality that involves staking, but we aren't using those.

So technically, if the user has to use Eden, everything stays the same, except when the user sends a transaction on Ethereum mainnet:

This should be built, keeping in mind that we support more than one of this. In fact, we have Eden and Ethermine:

The 3 RPC endpoints are mentioned in the 2nd comment above.

asif-finimble commented 2 years ago

Thanks @hboon for the detailed explanation. I think I understand what needs to be done. How does the user select he wants to use Eden or ethermine? Maybe its in zeplin spec. I can't access that yet.

hboon commented 2 years ago

@asif-finimble Sorry, missed this. Like this:

Screenshot 2022-03-02 at 10 09 21 PM

⬇️

Screenshot 2022-03-02 at 10 09 26 PM

⬇️

Screenshot 2022-03-02 at 10 09 27 PM

Enabled (will look a bit different for Android):

Screenshot 2022-03-02 at 10 11 44 PM
asif-finimble commented 2 years ago

@hboon how can the user disable private transactions? Does the selection state toggles on clicking the selected item? @JamesSmartCell what view do you think we should use here?

hboon commented 2 years ago

@asif-finimble Yes, it should toggle to off if the user taps on a selected item.

I don't know how to present it though.

asif-finimble commented 2 years ago

@asif-finimble Yes, it should toggle to off if the user taps on a selected item.

I don't know how to present it though.

OK. Thanks. Got it

asif-finimble commented 2 years ago

@hboon, @JamesSmartCell is this setting common for all wallets(if the user has multiple wallets) or we need to store the setting separately for each wallet? Also I don't have the icons for Eden, ethermine and private txn settings item.

hboon commented 2 years ago

@asif-finimble Up to @JamesSmartCell , we just make it global for all users on iOS.

Eden icon here: https://github.com/AlphaWallet/alpha-wallet-ios/issues/3445 Ethermine's: https://github.com/AlphaWallet/alpha-wallet-ios/issues/3270#issuecomment-953592854

For iOS, we just use the selected option's (Eden or Ethermine) icon in Settings > Advanced. If none is chose, use Ethermine's

asif-finimble commented 2 years ago

Thanks @hboon.
As for the icons, the ticket contains link to zeplin which I don't have access to.

asif-finimble commented 2 years ago

@JamesSmartCell As per my understanding, we need to add new chain IDs and corresponding NetworkInfo objects for Eden and Ethermine in the networkMap. And we will check at the time of sending transactions, if private transactions are enabled, then we will use the selected private network's rpc for sending on mainnet and ropsten. Am I Right? or can you suggest appropriate flow.

hboon commented 2 years ago

Thanks @hboon. As for the icons, the ticket contains link to zeplin which I don't have access to.

How about this? https://app.zeplin.io/project/5d088205bff2d15de6a4397b/styleguide/components?coid=6197a1c20ba031a7c0eb8347 (the 1st 2 icons). You can get here from the Android project in Zeppelin.

asif-finimble commented 2 years ago

Thanks @hboon. As for the icons, the ticket contains link to zeplin which I don't have access to.

How about this? https://app.zeplin.io/project/5d088205bff2d15de6a4397b/styleguide/components?coid=6197a1c20ba031a7c0eb8347 (the 1st 2 icons). You can get here from the Android project in Zeppelin.

Thanks. This will do.

asif-finimble commented 2 years ago

@JamesSmartCell As per my understanding, we need to add new chain IDs and corresponding NetworkInfo objects for Eden and Ethermine in the networkMap. And we will check at the time of sending transactions, if private transactions are enabled, then we will use the selected private network's rpc for sending on mainnet and ropsten. Am I Right? or can you suggest appropriate flow.

I get it that the chainId will remain 1 - MAINNET_ID. But where do we specify to use the private rpc.?

JamesSmartCell commented 2 years ago

Hi @asif-finimble my apologies these came through while I was at the conference I am going through these now.

Yes, it looks like you stay on mainnet (1) but you'd need to have a shim wherever the transaction is sent to the chain. This only happens in class TransactionRepository and always by web3j.ethSendRawTransaction.

So it would probably be best to abstract that out into a function within that class that selects either: the normal path to send the raw transaction via web3j.ethSendRawTransaction, or, if the Ethermine or Eden options are selected then you'd send the exact same transaction to the Ethermine or Eden.

I would set the Ethermine/Eden usage with SharedPrefs rather then realm since it's a global setting, like default wallet etc.

The pending transaction would still be written to Realm in exactly the same way (within TransactionRepository).

JamesSmartCell commented 2 years ago

@asif-finimble I refactored the code to make this slightly simpler - although you will now have to accomodate EIP1559 and Legacy transactions. Ping me for more info if required, but I suspect the method you'll be modifying is this code:

EthSendTransaction raw = web3j
                            .ethSendRawTransaction(Numeric.toHexString(signedMessage.signature))
                            .send();

You probably want to abstract the 3 uses of this out into a separate function which can switch between sending to Eden/Ethermine or default chain.