From 59cedba71476f74d7bf7625f66cc7035fb49c83a Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Mon, 1 Apr 2019 12:23:55 -0300 Subject: [PATCH 1/5] add handlemethoddata gaba support --- app/util/transactions.js | 88 ++++++----------- package-lock.json | 202 +++++++++++++++++++++++++++------------ package.json | 2 +- 3 files changed, 170 insertions(+), 122 deletions(-) diff --git a/app/util/transactions.js b/app/util/transactions.js index 7a875d867089..10d69be33b7f 100644 --- a/app/util/transactions.js +++ b/app/util/transactions.js @@ -3,6 +3,7 @@ import { rawEncode, rawDecode } from 'ethereumjs-abi'; import Engine from '../core/Engine'; import { strings } from '../../locales/i18n'; import contractMap from 'eth-contract-metadata'; +import { isSmartContractCode } from 'gaba/util'; export const TOKEN_METHOD_TRANSFER = 'transfer'; export const TOKEN_METHOD_APPROVE = 'approve'; @@ -10,10 +11,10 @@ export const TOKEN_METHOD_TRANSFER_FROM = 'transferfrom'; export const CONTRACT_METHOD_DEPLOY = 'deploy'; export const SEND_ETHER_ACTION_KEY = 'sentEther'; -export const DEPLOY_CONTRACT_ACTION_KEY = 'contractDeployment'; +export const DEPLOY_CONTRACT_ACTION_KEY = 'deploy'; export const APPROVE_ACTION_KEY = 'approve'; -export const SEND_TOKEN_ACTION_KEY = 'sentTokens'; -export const TRANSFER_FROM_ACTION_KEY = 'transferFrom'; +export const SEND_TOKEN_ACTION_KEY = 'transfer'; +export const TRANSFER_FROM_ACTION_KEY = 'transferfrom'; export const UNKNOWN_FUNCTION_KEY = 'unknownFunction'; export const SMART_CONTRACT_INTERACTION_ACTION_KEY = 'smartContractInteraction'; @@ -21,22 +22,6 @@ export const TRANSFER_FUNCTION_SIGNATURE = '0xa9059cbb'; export const TRANSFER_FROM_FUNCTION_SIGNATURE = '0x23b872dd'; export const CONTRACT_CREATION_SIGNATURE = '0x60a060405260046060527f48302e31'; -/** - * Utility class with the single responsibility - * of caching ActionKeys - */ -class ActionKeys { - static cache = {}; -} - -/** - * Utility class with the single responsibility - * of caching SmartContractAddresses - */ -class SmartContractAddresses { - static cache = {}; -} - /** * Utility class with the single responsibility * of caching CollectibleAddresses @@ -124,8 +109,9 @@ export function decodeTransferData(type, data) { * @param {string} data - Transaction data * @returns {object} - Method data object containing the name if is valid */ -export function getMethodData(data) { - // TODO use eth-method-registry from GABA +export async function getMethodData(data) { + if (data.length < 10) return {}; + const { TransactionController } = Engine.context; if (data.substr(0, 10) === TRANSFER_FUNCTION_SIGNATURE) { return { name: TOKEN_METHOD_TRANSFER }; } else if (data.substr(0, 10) === TRANSFER_FROM_FUNCTION_SIGNATURE) { @@ -133,6 +119,15 @@ export function getMethodData(data) { } else if (data.substr(0, 32) === CONTRACT_CREATION_SIGNATURE) { return { name: CONTRACT_METHOD_DEPLOY }; } + // If it's a new method, use on-chain method registry + try { + const registryObject = await TransactionController.handleMethodData(data.substr(0, 10)); + if (registryObject) { + return registryObject.parsedRegistryMethod; + } + } catch (e) { + // + } return {}; } @@ -143,22 +138,15 @@ export function getMethodData(data) { * @returns {boolean} - Wether the given address is a contract */ export async function isSmartContractAddress(address) { - const cache = SmartContractAddresses.cache[address]; - if (cache) { - return Promise.resolve(cache); - } - + address = toChecksumAddress(address); + // If in contract map we don't need to cache it if (contractMap[address]) { - SmartContractAddresses.cache[address] = true; return Promise.resolve(true); } - const { TransactionController } = Engine.context; const code = address ? await TransactionController.query('getCode', [address]) : undefined; - // Geth will return '0x', and ganache-core v2.2.1 will return '0x0' - const codeIsEmpty = !code || code === '0x' || code === '0x0'; - SmartContractAddresses.cache[address] = !codeIsEmpty; - return !codeIsEmpty; + const isSmartContract = isSmartContractCode(code); + return isSmartContract; } /** @@ -189,37 +177,16 @@ export async function isCollectibleAddress(address, tokenId) { * @returns {string} - Corresponding transaction action key */ export async function getTransactionActionKey(transaction) { - const { transactionHash, transaction: { data, to } = {} } = transaction; - const cache = ActionKeys.cache[transactionHash]; - if (transactionHash && cache) { - return Promise.resolve(cache); - } + const { transaction: { data, to } = {} } = transaction; let ret; // if data in transaction try to get method data if (data && data !== '0x') { - const methodData = getMethodData(data); + const methodData = await getMethodData(data); const { name } = methodData; - const methodName = name && name.toLowerCase(); - switch (methodName) { - case TOKEN_METHOD_TRANSFER: - ret = SEND_TOKEN_ACTION_KEY; - break; - case TOKEN_METHOD_APPROVE: - ret = APPROVE_ACTION_KEY; - break; - case TOKEN_METHOD_TRANSFER_FROM: - ret = TRANSFER_FROM_ACTION_KEY; - break; - case CONTRACT_METHOD_DEPLOY: - ret = DEPLOY_CONTRACT_ACTION_KEY; - break; - } - if (ret) { - ActionKeys.cache[transactionHash] = ret; - return ret; - } + if (name) return name; } - const toSmartContract = await isSmartContractAddress(to); + const toSmartContract = + transaction.toSmartContract !== undefined ? transaction.toSmartContract : await isSmartContractAddress(to); if (toSmartContract) { // There is no data or unknown method data, if is smart contract ret = SMART_CONTRACT_INTERACTION_ACTION_KEY; @@ -227,7 +194,6 @@ export async function getTransactionActionKey(transaction) { // If there is no data and no smart contract interaction ret = SEND_ETHER_ACTION_KEY; } - ActionKeys.cache[transactionHash] = ret; return ret; } @@ -258,7 +224,7 @@ export async function getActionKey(tx, selectedAddress) { case SMART_CONTRACT_INTERACTION_ACTION_KEY: return strings('transactions.smart_contract_interaction'); default: - return strings('transactions.smart_contract_interaction'); + return actionKey; } } @@ -282,6 +248,6 @@ export async function getTransactionReviewActionKey(transaction) { case SMART_CONTRACT_INTERACTION_ACTION_KEY: return strings('transactions.tx_review_confirm'); default: - return strings('transactions.tx_review_unknown'); + return actionKey; } } diff --git a/package-lock.json b/package-lock.json index 7a55d1ba0438..8d3fd698e758 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "metamask", - "version": "0.1.5", + "version": "0.1.6", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -4101,9 +4101,9 @@ "integrity": "sha512-i47mqjF9UbjxJhxGf+pZ6kSxrnI3wBLlnGI2ArWJ4r0VrvDS7ZYXkprq/pLaBWYq4GM0r4zdHY+NNRqEMU7uew==" }, "bip39": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/bip39/-/bip39-2.5.0.tgz", - "integrity": "sha512-xwIx/8JKoT2+IPJpFEfXoWdYwP7UVAoUxxLNfGCfVowaJE7yg1Y5B1BVPqlUNsBq5/nGwmFkwRJ8xDW4sX8OdA==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/bip39/-/bip39-2.6.0.tgz", + "integrity": "sha512-RrnQRG2EgEoqO24ea+Q/fftuPUZLmrEM3qNhhGsA3PbaXaCW791LTzPuVyx/VprXQcTbPJ3K3UeTna8ZnVl2sg==", "requires": { "create-hash": "^1.1.0", "pbkdf2": "^3.0.9", @@ -4428,9 +4428,9 @@ } }, "caniuse-lite": { - "version": "1.0.30000950", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000950.tgz", - "integrity": "sha512-Cs+4U9T0okW2ftBsCIHuEYXXkki7mjXmjCh4c6PzYShk04qDEr76/iC7KwhLoWoY65wcra1XOsRD+S7BptEb5A==" + "version": "1.0.30000955", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000955.tgz", + "integrity": "sha512-6AwmIKgqCYfDWWadRkAuZSHMQP4Mmy96xAXEdRBlN/luQhlRYOKgwOlZ9plpCOsVbBuqbTmGqDK3JUM/nlr8CA==" }, "capture-exit": { "version": "1.2.0", @@ -5435,9 +5435,9 @@ "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" }, "electron-to-chromium": { - "version": "1.3.116", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.116.tgz", - "integrity": "sha512-NKwKAXzur5vFCZYBHpdWjTMO8QptNLNP80nItkSIgUOapPAo9Uia+RvkCaZJtO7fhQaVElSvBPWEc2ku6cKsPA==" + "version": "1.3.122", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.122.tgz", + "integrity": "sha512-3RKoIyCN4DhP2dsmleuFvpJAIDOseWH88wFYBzb22CSwoFDSWRc4UAMfrtc9h8nBdJjTNIN3rogChgOy6eFInw==" }, "elegant-spinner": { "version": "1.0.1", @@ -6210,12 +6210,12 @@ "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-1.4.2.tgz", "integrity": "sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=", "requires": { - "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git", + "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git#572d4bafe08a8a231137e1f9daeb0f8a23f197d2", "ethereumjs-util": "^5.1.1" } }, "ethereumjs-abi": { - "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#d8d7fc9cc1fd781186c25676af100d1ec727013e", + "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#572d4bafe08a8a231137e1f9daeb0f8a23f197d2", "from": "git+https://github.com/ethereumjs/ethereumjs-abi.git", "requires": { "bn.js": "^4.11.8", @@ -6254,6 +6254,13 @@ } } }, + "eth-method-registry": { + "version": "github:estebanmino/eth-method-registry#da1612361ad2589093a81f30ac3f59ad8a254884", + "from": "github:estebanmino/eth-method-registry#master", + "requires": { + "ethjs": "^0.3.0" + } + }, "eth-phishing-detect": { "version": "1.1.13", "resolved": "https://registry.npmjs.org/eth-phishing-detect/-/eth-phishing-detect-1.1.13.tgz", @@ -6272,9 +6279,9 @@ } }, "eth-sig-util": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-2.1.1.tgz", - "integrity": "sha512-B9VA2WCuf+dp0UbWlzsCXWcryZe1H9PixrNmG+tQDBpyTiIbDvf2w8jUb1BNPbxFXeWHUcr2I6pmg+MkdA4Ovg==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-2.1.2.tgz", + "integrity": "sha512-bNgt7txkEmaNlLf+PrbwYIdp4KRkB3E7hW0/QwlBpgv920pVVyQnF0evoovfiRveNKM4OrtPYZTojjmsfuCUOw==", "requires": { "buffer": "^5.2.1", "elliptic": "^6.4.0", @@ -6630,6 +6637,87 @@ } } }, + "ethjs": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/ethjs/-/ethjs-0.3.9.tgz", + "integrity": "sha512-gOQzA3tDUjoLpNONSOALJ/rUFtHi5tXl2mholHasF1cvXhoddqi06yU4OJFJu9AGd6n9v9ywzHlYeIKg1t1hdw==", + "requires": { + "bn.js": "4.11.6", + "ethjs-abi": "0.2.1", + "ethjs-contract": "0.2.2", + "ethjs-filter": "0.1.8", + "ethjs-provider-http": "0.1.6", + "ethjs-query": "0.3.7", + "ethjs-unit": "0.1.6", + "ethjs-util": "0.1.3", + "js-sha3": "0.5.5", + "number-to-bn": "1.7.0" + }, + "dependencies": { + "bn.js": { + "version": "4.11.6", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=" + }, + "ethjs-abi": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/ethjs-abi/-/ethjs-abi-0.2.1.tgz", + "integrity": "sha1-4KepOn6BFjqUR3utVu3lJKtt5TM=", + "requires": { + "bn.js": "4.11.6", + "js-sha3": "0.5.5", + "number-to-bn": "1.7.0" + } + }, + "ethjs-contract": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/ethjs-contract/-/ethjs-contract-0.2.2.tgz", + "integrity": "sha512-xxPqEjsULQ/QNWuvX6Ako0PGs5RxALA8N/H3+boLvnaXDFZVGpD7H63H1gBCRTZyYqCldPpVlVHuw/rD45vazw==", + "requires": { + "ethjs-abi": "0.2.0", + "ethjs-filter": "0.1.8", + "ethjs-util": "0.1.3", + "js-sha3": "0.5.5" + }, + "dependencies": { + "ethjs-abi": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/ethjs-abi/-/ethjs-abi-0.2.0.tgz", + "integrity": "sha1-0+LCIQEVIPxJm3FoIDbBT8wvWyU=", + "requires": { + "bn.js": "4.11.6", + "js-sha3": "0.5.5", + "number-to-bn": "1.7.0" + } + } + } + }, + "ethjs-query": { + "version": "0.3.7", + "resolved": "https://registry.npmjs.org/ethjs-query/-/ethjs-query-0.3.7.tgz", + "integrity": "sha512-TZnKUwfkWjy0SowFdPLtmsytCorHi0i4vvkQn7Jg8rZt33cRzKhuzOwKr/G3vdigCc+ePXOhUGMcJSAPlOG44A==", + "requires": { + "ethjs-format": "0.2.7", + "ethjs-rpc": "0.2.0", + "promise-to-callback": "^1.0.0" + } + }, + "ethjs-util": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.3.tgz", + "integrity": "sha1-39XqSkANxeQhqInK9H4IGtp4u1U=", + "requires": { + "is-hex-prefixed": "1.0.0", + "strip-hex-prefix": "1.0.0" + } + }, + "js-sha3": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.5.5.tgz", + "integrity": "sha1-uvDA6MVK1ZA0R9+Wreekobynmko=" + } + } + }, "ethjs-abi": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/ethjs-abi/-/ethjs-abi-0.2.0.tgz", @@ -6805,6 +6893,14 @@ } } }, + "ethjs-provider-http": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/ethjs-provider-http/-/ethjs-provider-http-0.1.6.tgz", + "integrity": "sha1-HsXZtL4lfvHValALIqdBmF6IlCA=", + "requires": { + "xhr2": "0.1.3" + } + }, "ethjs-query": { "version": "0.3.8", "resolved": "https://registry.npmjs.org/ethjs-query/-/ethjs-query-0.3.8.tgz", @@ -7359,8 +7455,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -7378,13 +7473,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -7397,18 +7490,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -7511,8 +7601,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -7522,7 +7611,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -7535,20 +7623,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.3.5", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -7565,7 +7650,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -7638,8 +7722,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -7649,7 +7732,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -7725,8 +7807,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -7756,7 +7837,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -7774,7 +7854,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -7813,13 +7892,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.0.3", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -7893,14 +7970,14 @@ } }, "gaba": { - "version": "1.0.0-beta.64", - "resolved": "https://registry.npmjs.org/gaba/-/gaba-1.0.0-beta.64.tgz", - "integrity": "sha512-2eQrMdDxb4VBd7xWRwt9TMSgqUpIk+WcAf14ZsJNmLIJym74mbq1PXUx2/BFsf8s4rgENiqGd3IjTWVPFE7+DA==", + "version": "file:../gaba/dist/gaba-1.0.0-beta.67.tgz", + "integrity": "sha512-KNkdzB5IWEH4ezWQN9LNd06ZdxMOLu8T6GyFmvk2ZDBB/l01CEW2akzDDAJgQnqXpV5yISNbrwl3L6BnQiCm9A==", "requires": { "await-semaphore": "^0.1.3", - "eth-contract-metadata": "github:estebanmino/eth-contract-metadata#e307359ca9ea6be4ded6ac58ac7e16f192ae4e2a", + "eth-contract-metadata": "github:MetaMask/eth-contract-metadata#faa4f56fb17b3ae8579df68708be59d617732f31", "eth-json-rpc-infura": "^3.1.2", "eth-keyring-controller": "^4.0.0", + "eth-method-registry": "github:estebanmino/eth-method-registry#da1612361ad2589093a81f30ac3f59ad8a254884", "eth-phishing-detect": "^1.1.13", "eth-query": "^2.1.2", "eth-sig-util": "^2.1.0", @@ -7919,8 +7996,8 @@ }, "dependencies": { "eth-contract-metadata": { - "version": "github:estebanmino/eth-contract-metadata#e307359ca9ea6be4ded6ac58ac7e16f192ae4e2a", - "from": "github:estebanmino/eth-contract-metadata#e307359ca9ea6be4ded6ac58ac7e16f192ae4e2a" + "version": "github:MetaMask/eth-contract-metadata#faa4f56fb17b3ae8579df68708be59d617732f31", + "from": "github:MetaMask/eth-contract-metadata#faa4f56fb17b3ae8579df68708be59d617732f31" }, "ethereumjs-util": { "version": "5.2.0", @@ -17954,7 +18031,7 @@ "resolved": "https://registry.npmjs.org/web3/-/web3-0.20.7.tgz", "integrity": "sha512-VU6/DSUX93d1fCzBz7WP/SGCQizO1rKZi4Px9j/3yRyfssHyFcZamMw2/sj4E8TlfMXONvZLoforR8B4bRoyTQ==", "requires": { - "bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git", + "bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934", "crypto-js": "^3.1.4", "utf8": "^2.1.1", "xhr2-cookies": "^1.1.0", @@ -17998,26 +18075,26 @@ "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-1.4.2.tgz", "integrity": "sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=", "requires": { - "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git", + "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git#572d4bafe08a8a231137e1f9daeb0f8a23f197d2", "ethereumjs-util": "^5.1.1" } }, "ethereumjs-abi": { - "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#d84a96796079c8595a0c78accd1e7709f2277215", + "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#572d4bafe08a8a231137e1f9daeb0f8a23f197d2", "from": "git+https://github.com/ethereumjs/ethereumjs-abi.git", "requires": { - "bn.js": "^4.10.0", - "ethereumjs-util": "^5.0.0" + "bn.js": "^4.11.8", + "ethereumjs-util": "^6.0.0" }, "dependencies": { "ethereumjs-util": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz", - "integrity": "sha512-CJAKdI0wgMbQFLlLRtZKGcy/L6pzVRgelIZqRqNbuVFM3K9VEnyfbcvz0ncWMRNCe4kaHWjwRYQcYMucmwsnWA==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.1.0.tgz", + "integrity": "sha512-URESKMFbDeJxnAxPppnk2fN6Y3BIatn9fwn76Lm8bQlt+s52TpG8dN9M66MLPuRAiAOIqL3dfwqWJf0sd0fL0Q==", "requires": { "bn.js": "^4.11.0", "create-hash": "^1.1.2", - "ethjs-util": "^0.1.3", + "ethjs-util": "0.1.6", "keccak": "^1.0.2", "rlp": "^2.0.0", "safe-buffer": "^5.1.1", @@ -18177,6 +18254,11 @@ "xtend": "^4.0.0" } }, + "xhr2": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/xhr2/-/xhr2-0.1.3.tgz", + "integrity": "sha1-y/xHWaabSoiOeM9PILBRA4dXvRE=" + }, "xhr2-cookies": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/xhr2-cookies/-/xhr2-cookies-1.1.0.tgz", diff --git a/package.json b/package.json index a082eef9c211..db97ed1df977 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ethjs-unit": "0.1.6", "events": "3.0.0", "fuse.js": "3.4.4", - "gaba": "1.0.0-beta.64", + "gaba": "file:../gaba/dist/gaba-1.0.0-beta.67.tgz", "https-browserify": "0.0.1", "jsc-android": "236355.1.1", "multihashes": "0.4.14", From 1e325962f37f89c61500549ba1f2eebb18dbefc4 Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Mon, 1 Apr 2019 13:32:50 -0300 Subject: [PATCH 2/5] update action keys methods --- app/util/transactions.js | 86 +++++++++++++++++++++++----------------- locales/en.json | 2 + locales/es.json | 2 + 3 files changed, 53 insertions(+), 37 deletions(-) diff --git a/app/util/transactions.js b/app/util/transactions.js index 10d69be33b7f..f9e52f150a60 100644 --- a/app/util/transactions.js +++ b/app/util/transactions.js @@ -20,6 +20,7 @@ export const SMART_CONTRACT_INTERACTION_ACTION_KEY = 'smartContractInteraction'; export const TRANSFER_FUNCTION_SIGNATURE = '0xa9059cbb'; export const TRANSFER_FROM_FUNCTION_SIGNATURE = '0x23b872dd'; +export const APPROVE_FUNCTION_SIGNATURE = '0x095ea7b3'; export const CONTRACT_CREATION_SIGNATURE = '0x60a060405260046060527f48302e31'; /** @@ -30,6 +31,29 @@ class CollectibleAddresses { static cache = {}; } +/** + * Object containing all known action keys, to be used in transaction review + */ +const reviewActionKeys = { + [SEND_TOKEN_ACTION_KEY]: strings('transactions.tx_review_transfer'), + [SEND_ETHER_ACTION_KEY]: strings('transactions.tx_review_confirm'), + [DEPLOY_CONTRACT_ACTION_KEY]: strings('transactions.tx_review_contract_deployment'), + [TRANSFER_FROM_ACTION_KEY]: strings('transactions.tx_review_transfer_from'), + [SMART_CONTRACT_INTERACTION_ACTION_KEY]: strings('transactions.tx_review_confirm'), + [APPROVE_ACTION_KEY]: strings('transactions.tx_review_approve') +}; + +/** + * Object containing all known action keys, to be used in transactions list + */ +const actionKeys = { + [SEND_TOKEN_ACTION_KEY]: strings('transactions.sent_tokens'), + [TRANSFER_FROM_ACTION_KEY]: strings('transactions.sent_collectible'), + [DEPLOY_CONTRACT_ACTION_KEY]: strings('transactions.contract_deploy'), + [SMART_CONTRACT_INTERACTION_ACTION_KEY]: strings('transactions.smart_contract_interaction'), + [APPROVE_ACTION_KEY]: strings('transactions.approve') +}; + /** * Generates transfer data for specified method * @@ -111,22 +135,25 @@ export function decodeTransferData(type, data) { */ export async function getMethodData(data) { if (data.length < 10) return {}; - const { TransactionController } = Engine.context; - if (data.substr(0, 10) === TRANSFER_FUNCTION_SIGNATURE) { + const fourByteSignature = data.substr(0, 10); + if (fourByteSignature === TRANSFER_FUNCTION_SIGNATURE) { return { name: TOKEN_METHOD_TRANSFER }; - } else if (data.substr(0, 10) === TRANSFER_FROM_FUNCTION_SIGNATURE) { + } else if (fourByteSignature === TRANSFER_FROM_FUNCTION_SIGNATURE) { return { name: TOKEN_METHOD_TRANSFER_FROM }; + } else if (fourByteSignature === APPROVE_FUNCTION_SIGNATURE) { + return { name: TOKEN_METHOD_APPROVE }; } else if (data.substr(0, 32) === CONTRACT_CREATION_SIGNATURE) { return { name: CONTRACT_METHOD_DEPLOY }; } + const { TransactionController } = Engine.context; // If it's a new method, use on-chain method registry try { - const registryObject = await TransactionController.handleMethodData(data.substr(0, 10)); + const registryObject = await TransactionController.handleMethodData(fourByteSignature); if (registryObject) { return registryObject.parsedRegistryMethod; } } catch (e) { - // + // Ignore and return empty object } return {}; } @@ -206,26 +233,20 @@ export async function getTransactionActionKey(transaction) { */ export async function getActionKey(tx, selectedAddress) { const actionKey = await getTransactionActionKey(tx); - const incoming = toChecksumAddress(tx.transaction.to) === toChecksumAddress(selectedAddress); - const selfSent = incoming && toChecksumAddress(tx.transaction.from) === toChecksumAddress(selectedAddress); - switch (actionKey) { - case SEND_TOKEN_ACTION_KEY: - return strings('transactions.sent_tokens'); - case TRANSFER_FROM_ACTION_KEY: - return strings('transactions.sent_collectible'); - case SEND_ETHER_ACTION_KEY: - return incoming - ? selfSent - ? strings('transactions.self_sent_ether') - : strings('transactions.received_ether') - : strings('transactions.sent_ether'); - case DEPLOY_CONTRACT_ACTION_KEY: - return strings('transactions.contract_deploy'); - case SMART_CONTRACT_INTERACTION_ACTION_KEY: - return strings('transactions.smart_contract_interaction'); - default: - return actionKey; + if (actionKey === SEND_ETHER_ACTION_KEY) { + const incoming = toChecksumAddress(tx.transaction.to) === toChecksumAddress(selectedAddress); + const selfSent = incoming && toChecksumAddress(tx.transaction.from) === toChecksumAddress(selectedAddress); + return incoming + ? selfSent + ? strings('transactions.self_sent_ether') + : strings('transactions.received_ether') + : strings('transactions.sent_ether'); + } + const transactionActionKey = actionKeys[actionKey]; + if (transactionActionKey) { + return transactionActionKey; } + return actionKey; } /** @@ -236,18 +257,9 @@ export async function getActionKey(tx, selectedAddress) { */ export async function getTransactionReviewActionKey(transaction) { const actionKey = await getTransactionActionKey({ transaction }); - switch (actionKey) { - case SEND_TOKEN_ACTION_KEY: - return strings('transactions.tx_review_transfer'); - case SEND_ETHER_ACTION_KEY: - return strings('transactions.tx_review_confirm'); - case DEPLOY_CONTRACT_ACTION_KEY: - return strings('transactions.tx_review_contract_deployment'); - case TRANSFER_FROM_ACTION_KEY: - return strings('transactions.tx_review_transfer_from'); - case SMART_CONTRACT_INTERACTION_ACTION_KEY: - return strings('transactions.tx_review_confirm'); - default: - return actionKey; + const transactionReviewActionKey = reviewActionKeys[actionKey]; + if (transactionReviewActionKey) { + return transactionReviewActionKey; } + return actionKey; } diff --git a/locales/en.json b/locales/en.json index d87a344f5923..75a8bb46a83e 100644 --- a/locales/en.json +++ b/locales/en.json @@ -385,6 +385,7 @@ "tx_review_contract_deployment": "CONTRACT DEPLOYMENT", "tx_review_transfer_from": "TRANSFER FROM", "tx_review_unknown": "UNKNOWN METHOD", + "tx_review_approve": "APPROVE", "sent_ether": "Sent Ether", "self_sent_ether": "Sent Yourself Ether", "received_ether": "Received Ether", @@ -394,6 +395,7 @@ "contract_deploy": "Contract Deployment", "to_contract": "New Contract", "smart_contract_interaction": "Smart Contract Interaction", + "approve": "Approve", "hash": "Hash", "from": "From", "to": "To", diff --git a/locales/es.json b/locales/es.json index 2a3f07a9cc3c..b1e0c9873c9d 100644 --- a/locales/es.json +++ b/locales/es.json @@ -383,6 +383,7 @@ "tx_review_contract_deployment": "CONTRATO DESPLEGADO", "tx_review_transfer_from": "TRANSFERIR DESDE", "tx_review_unknown": "MÉTODO DESCONOCIDO", + "tx_review_approve": "APROBAR", "sent_ether": "Enviaste Ether", "self_sent_ether": "Enviaste Ether a ti mismo", "received_ether": "Recibiste Ether", @@ -392,6 +393,7 @@ "contract_deploy": "Despliegue de contrato", "to_contract": "Nuevo Contrato", "smart_contract_interaction": "Interación con contrato inteligente ", + "approve": "Aprobar", "hash": "Hash", "from": "Desde", "to": "Para", From ce2adb2caaa5ad17c1b8f243dd8bd213bec93c20 Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Mon, 1 Apr 2019 13:33:16 -0300 Subject: [PATCH 3/5] update tests --- app/util/transactions.test.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/util/transactions.test.js b/app/util/transactions.test.js index 19d184e6772f..dd558f8e3e1d 100644 --- a/app/util/transactions.test.js +++ b/app/util/transactions.test.js @@ -69,17 +69,21 @@ describe('Transactions utils :: decodeTransferData', () => { }); describe('Transactions utils :: getMethodData', () => { - it('getMethodData', () => { + it('getMethodData', async () => { const transferData = '0xa9059cbb00000000000000000000000056ced0d816c668d7c0bcc3fbf0ab2c6896f589a00000000000000000000000000000000000000000000000000000000000000001'; const contractData = '0x60a060405260046060527f48302e31000000000000000000000000000000000000000000000000000000006080526006805460008290527f48302e310000000000000000000000000000000000000000000000000000000882556100b5907ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f602060026001841615610100026000190190931692909204601f01919091048101905b8082111561017957600081556001016100a1565b505060405161094b38038061094b833981'; - const randomData = '0x987654321'; + const randomData = '0x987654321000000000'; const transferFromData = '0x23b872dd0000000000000000000000000000'; - expect(getMethodData(transferData).name).toEqual(TOKEN_METHOD_TRANSFER); - expect(getMethodData(contractData).name).toEqual(CONTRACT_METHOD_DEPLOY); - expect(getMethodData(transferFromData).name).toEqual(TOKEN_METHOD_TRANSFER_FROM); - expect(getMethodData(randomData)).toEqual({}); + const firstMethodData = await getMethodData(transferData); + const secondtMethodData = await getMethodData(contractData); + const thirdMethodData = await getMethodData(transferFromData); + const fourthMethodData = await getMethodData(randomData); + expect(firstMethodData.name).toEqual(TOKEN_METHOD_TRANSFER); + expect(secondtMethodData.name).toEqual(CONTRACT_METHOD_DEPLOY); + expect(thirdMethodData.name).toEqual(TOKEN_METHOD_TRANSFER_FROM); + expect(fourthMethodData).toEqual({}); }); }); @@ -109,12 +113,12 @@ describe('Transactions utils :: getTransactionActionKey', () => { const randomData = '0x987654321'; const transferFromData = '0x23b872dd0000000000000000000000000000'; it('getTransactionActionKey send ether', async () => { - const get = await getTransactionActionKey({ transactionHash: '0x1', transaction: {} }); + const get = await getTransactionActionKey({ transactionHash: '0x1', transaction: { to: '0x0' } }); expect(get).toEqual(SEND_ETHER_ACTION_KEY); }); it('getTransactionActionKey send ether with empty data', async () => { - const get = await getTransactionActionKey({ transactionHash: '0x1', transaction: { data: '0x' } }); + const get = await getTransactionActionKey({ transactionHash: '0x1', transaction: { data: '0x', to: '0x0' } }); expect(get).toEqual(SEND_ETHER_ACTION_KEY); }); it('getTransactionActionKey send token', async () => { From db4217095589563a42b9ef39d314838f52687c0c Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Wed, 3 Apr 2019 12:39:33 -0300 Subject: [PATCH 4/5] in tx review if method data unknown default to unknown method --- app/util/transactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/util/transactions.js b/app/util/transactions.js index f9e52f150a60..daf9ce42bbc8 100644 --- a/app/util/transactions.js +++ b/app/util/transactions.js @@ -39,7 +39,7 @@ const reviewActionKeys = { [SEND_ETHER_ACTION_KEY]: strings('transactions.tx_review_confirm'), [DEPLOY_CONTRACT_ACTION_KEY]: strings('transactions.tx_review_contract_deployment'), [TRANSFER_FROM_ACTION_KEY]: strings('transactions.tx_review_transfer_from'), - [SMART_CONTRACT_INTERACTION_ACTION_KEY]: strings('transactions.tx_review_confirm'), + [SMART_CONTRACT_INTERACTION_ACTION_KEY]: strings('transactions.tx_review_unknown'), [APPROVE_ACTION_KEY]: strings('transactions.tx_review_approve') }; From f71644ddbb4d4c256fee31a352cce2db3022703c Mon Sep 17 00:00:00 2001 From: Esteban Mino Date: Wed, 3 Apr 2019 16:01:21 -0300 Subject: [PATCH 5/5] bump gaba --- package-lock.json | 28 +++++++++++++++------------- package.json | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7db2a4e61371..01824f5e42b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4428,9 +4428,9 @@ } }, "caniuse-lite": { - "version": "1.0.30000955", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000955.tgz", - "integrity": "sha512-6AwmIKgqCYfDWWadRkAuZSHMQP4Mmy96xAXEdRBlN/luQhlRYOKgwOlZ9plpCOsVbBuqbTmGqDK3JUM/nlr8CA==" + "version": "1.0.30000957", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000957.tgz", + "integrity": "sha512-8wxNrjAzyiHcLXN/iunskqQnJquQQ6VX8JHfW5kLgAPRSiSuKZiNfmIkP5j7jgyXqAQBSoXyJxfnbCFS0ThSiQ==" }, "capture-exit": { "version": "1.2.0", @@ -6254,13 +6254,6 @@ } } }, - "eth-method-registry": { - "version": "github:estebanmino/eth-method-registry#da1612361ad2589093a81f30ac3f59ad8a254884", - "from": "github:estebanmino/eth-method-registry#master", - "requires": { - "ethjs": "^0.3.0" - } - }, "eth-phishing-detect": { "version": "1.1.13", "resolved": "https://registry.npmjs.org/eth-phishing-detect/-/eth-phishing-detect-1.1.13.tgz", @@ -7970,14 +7963,15 @@ } }, "gaba": { - "version": "file:../gaba/dist/gaba-1.0.0-beta.67.tgz", - "integrity": "sha512-KNkdzB5IWEH4ezWQN9LNd06ZdxMOLu8T6GyFmvk2ZDBB/l01CEW2akzDDAJgQnqXpV5yISNbrwl3L6BnQiCm9A==", + "version": "1.0.0-beta.68", + "resolved": "https://registry.npmjs.org/gaba/-/gaba-1.0.0-beta.68.tgz", + "integrity": "sha512-1qZ0sn5qd/FnPyLimzL8gNEe54qyyMuVADKduB7fCmDI6FrZG7sfAGJTuHvKu1zp9c4kd00XNrlCzgqAoQB1BA==", "requires": { "await-semaphore": "^0.1.3", "eth-contract-metadata": "github:MetaMask/eth-contract-metadata#faa4f56fb17b3ae8579df68708be59d617732f31", "eth-json-rpc-infura": "^3.1.2", "eth-keyring-controller": "^4.0.0", - "eth-method-registry": "github:estebanmino/eth-method-registry#da1612361ad2589093a81f30ac3f59ad8a254884", + "eth-method-registry": "1.1.0", "eth-phishing-detect": "^1.1.13", "eth-query": "^2.1.2", "eth-sig-util": "^2.1.0", @@ -7999,6 +7993,14 @@ "version": "github:MetaMask/eth-contract-metadata#faa4f56fb17b3ae8579df68708be59d617732f31", "from": "github:MetaMask/eth-contract-metadata#faa4f56fb17b3ae8579df68708be59d617732f31" }, + "eth-method-registry": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/eth-method-registry/-/eth-method-registry-1.1.0.tgz", + "integrity": "sha512-jGbbGYd19XJCtoGFtUD2qJYWefKCCbFcu7F/AQ5sJXvqTIVAHnFn3paaV2zhN5t7iyKYp1qxc+ugOky+72xcbg==", + "requires": { + "ethjs": "^0.3.0" + } + }, "ethereumjs-util": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz", diff --git a/package.json b/package.json index 6f7ef5007fef..2c477aea1dc7 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "ethjs-unit": "0.1.6", "events": "3.0.0", "fuse.js": "3.4.4", - "gaba": "file:../gaba/dist/gaba-1.0.0-beta.67.tgz", + "gaba": "^1.0.0-beta.68", "https-browserify": "0.0.1", "jsc-android": "236355.1.1", "multihashes": "0.4.14",