This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Make Wallet first-class citizens #3990
Merged
Merged
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f5573df
Fixed hint in Address Select + Wallet as first-class-citizen
ngotchac aee74ce
Separate Owned and not Owned Wallets
ngotchac f3bf753
Fix balance not updating
ngotchac af23c58
Merge branch 'master' into ng-wallet-improv
ngotchac 1b859bb
Fix MethodDecoding for Contract Deployment
ngotchac cb2bef6
Fix TypedInput params
ngotchac 1234364
Fix Token Transfer for Wallet
ngotchac 1c70fe7
Small change to contracts
ngotchac e0232ca
Fix wallets shown twice
ngotchac 03dd6b8
Fix separation of accounts and wallets in Accounts
ngotchac fe1e816
Fix linting
ngotchac f371854
Execute contract methods from Wallet ✓
ngotchac a32bb86
Fixing linting
ngotchac 17cb600
Wallet as first-class citizen: Part 1 (Manual) #3784
ngotchac ea73917
Lower level wallet transaction convertion
ngotchac c307fcc
Fix linting
ngotchac 28e2ce5
Proper autoFocus on right Signer input
ngotchac eab686f
PR Grumble: don't show Wallets in dApps Permissions
ngotchac 84f7b79
Add postTransaction and gasEstimate wrapper methods
ngotchac 69e484b
Extract Wallet postTx and gasEstimate to utils + PATCH api
ngotchac 234919d
Remove invalid test
ngotchac 7a1acd7
Merge branch 'master' into ng-wallet-improv
ngotchac b191961
Merge master
ngotchac fb5d45b
Fix linting
ngotchac 6895afe
Merge branch 'ng-wallet-improv' of github.com:ethcore/parity into ng-…
ngotchac 1fdf8f6
Fix merge issue
ngotchac e4f782c
Rename Portal
ngotchac f087475
Rename Protal => Portal (typo)
ngotchac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,14 @@ | |
// You should have received a copy of the GNU General Public License | ||
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import Abi from '../../abi'; | ||
import BigNumber from 'bignumber.js'; | ||
import { intersection } from 'lodash'; | ||
|
||
import Abi from '~/abi'; | ||
import WalletAbi from '~/contracts/abi/wallet.json'; | ||
import WalletsUtils from '~/util/wallets'; | ||
|
||
const _cachedWalletLookup = {}; | ||
let nextSubscriptionId = 0; | ||
|
||
export default class Contract { | ||
|
@@ -90,8 +96,11 @@ export default class Contract { | |
} | ||
|
||
deployEstimateGas (options, values) { | ||
return this._api.eth | ||
.estimateGas(this._encodeOptions(this.constructors[0], options, values)) | ||
return this | ||
._encodeOptions(this.constructors[0], options, values, false) | ||
.then((_options) => { | ||
return this._api.eth.estimateGas(_options); | ||
}) | ||
.then((gasEst) => { | ||
return [gasEst, gasEst.mul(1.2)]; | ||
}); | ||
|
@@ -115,8 +124,11 @@ export default class Contract { | |
|
||
setState({ state: 'postTransaction', gas }); | ||
|
||
return this._api.parity | ||
.postTransaction(this._encodeOptions(this.constructors[0], options, values)) | ||
return this | ||
._encodeOptions(this.constructors[0], options, values, false) | ||
.then((_options) => { | ||
return this._api.parity.postTransaction(_options); | ||
}) | ||
.then((requestId) => { | ||
setState({ state: 'checkRequest', requestId }); | ||
return this._pollCheckRequest(requestId); | ||
|
@@ -209,9 +221,93 @@ export default class Contract { | |
return `0x${data || ''}${call || ''}`; | ||
} | ||
|
||
_encodeOptions (func, options, values) { | ||
/** | ||
* Check whether the given address could be | ||
* a Wallet. The result is cached in order not | ||
* to make unnecessary calls on non wallet accounts | ||
*/ | ||
_isWallet (address) { | ||
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. Not 100% sure this is the correct place for this functionality. Can we walk through today and discuss? |
||
if (!_cachedWalletLookup[address]) { | ||
const walletContract = new Contract(this._api, WalletAbi); | ||
|
||
_cachedWalletLookup[address] = walletContract | ||
.at(address) | ||
.instance | ||
.m_numOwners | ||
.call() | ||
.then((result) => { | ||
if (!result || result.equals(0)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}) | ||
.then((bool) => { | ||
_cachedWalletLookup[address] = Promise.resolve(bool); | ||
return bool; | ||
}); | ||
} | ||
|
||
return _cachedWalletLookup[address]; | ||
} | ||
|
||
_encodeOptions (func, options, values, tryWallet = true) { | ||
options.data = this.getCallData(func, options, values); | ||
return options; | ||
|
||
if (!tryWallet || !options.from) { | ||
return Promise.resolve(options); | ||
} | ||
|
||
// Try to find out if the `from` field is a Wallet | ||
// And if one of the owners is in the accounts | ||
return this | ||
._isWallet(options.from) | ||
.then((isWallet) => { | ||
if (!isWallet) { | ||
return options; | ||
} | ||
|
||
const walletContract = new Contract(this._api, WalletAbi); | ||
|
||
const promises = [ | ||
this._api.parity.accountsInfo(), | ||
WalletsUtils.fetchOwners(walletContract.at(options.from)) | ||
]; | ||
|
||
return Promise | ||
.all(promises) | ||
.then(([ accounts, owners ]) => { | ||
const addresses = Object.keys(accounts); | ||
const owner = intersection(addresses, owners).pop(); | ||
|
||
if (!owner) { | ||
return false; | ||
} | ||
|
||
return owner; | ||
}) | ||
.then((owner) => { | ||
if (!owner) { | ||
return options; | ||
} | ||
|
||
const _options = Object.assign({}, options); | ||
const { from, to, value = new BigNumber(0), data } = options; | ||
|
||
delete _options.data; | ||
|
||
const nextValues = [ to, value, data ]; | ||
const nextOptions = { | ||
..._options, | ||
from: owner, | ||
to: from | ||
}; | ||
|
||
const execFunc = walletContract.instance.execute; | ||
|
||
return this._encodeOptions(execFunc, nextOptions, nextValues, tryWallet); | ||
}); | ||
}); | ||
} | ||
|
||
_addOptionsTo (options = {}) { | ||
|
@@ -222,24 +318,31 @@ export default class Contract { | |
|
||
_bindFunction = (func) => { | ||
func.call = (options, values = []) => { | ||
const callParams = this._encodeOptions(func, this._addOptionsTo(options), values); | ||
|
||
return this._api.eth | ||
.call(callParams) | ||
return this | ||
._encodeOptions(func, this._addOptionsTo(options), values, false) | ||
.then((callParams) => { | ||
return this._api.eth.call(callParams); | ||
}) | ||
.then((encoded) => func.decodeOutput(encoded)) | ||
.then((tokens) => tokens.map((token) => token.value)) | ||
.then((returns) => returns.length === 1 ? returns[0] : returns); | ||
}; | ||
|
||
if (!func.constant) { | ||
func.postTransaction = (options, values = []) => { | ||
return this._api.parity | ||
.postTransaction(this._encodeOptions(func, this._addOptionsTo(options), values)); | ||
return this | ||
._encodeOptions(func, this._addOptionsTo(options), values) | ||
.then((_options) => { | ||
return this._api.parity.postTransaction(_options); | ||
}); | ||
}; | ||
|
||
func.estimateGas = (options, values = []) => { | ||
return this._api.eth | ||
.estimateGas(this._encodeOptions(func, this._addOptionsTo(options), values)); | ||
return this | ||
._encodeOptions(func, this._addOptionsTo(options), values) | ||
.then((_options) => { | ||
return this._api.eth.estimateGas(_options); | ||
}); | ||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As discussed, these two lines above are UI and implementation specific, and doesn't belong in the API. The API layer takes what is provided and encodes that, sends it, decodes the responses, the role is not to make decisions and tweaks on behalf of the caller (caller is either us or other developers).
Changes made here is valid for the app, just needs a different home outside of
~/api