Merge pull request #2810 from ethcore/jg-tx-formatting
Cleanup method decoding (Fixes #2811)
This commit is contained in:
commit
9150fce2f1
4
js/src/3rdparty/etherscan/account.js
vendored
4
js/src/3rdparty/etherscan/account.js
vendored
@ -14,6 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import BigNumber from 'bignumber.js';
|
||||||
|
|
||||||
const PAGE_SIZE = 25;
|
const PAGE_SIZE = 25;
|
||||||
|
|
||||||
import util from '../../api/util';
|
import util from '../../api/util';
|
||||||
@ -56,7 +58,7 @@ function transactions (address, page, test = false) {
|
|||||||
from: util.toChecksumAddress(tx.from),
|
from: util.toChecksumAddress(tx.from),
|
||||||
to: util.toChecksumAddress(tx.to),
|
to: util.toChecksumAddress(tx.to),
|
||||||
hash: tx.hash,
|
hash: tx.hash,
|
||||||
blockNumber: tx.blockNumber,
|
blockNumber: new BigNumber(tx.blockNumber),
|
||||||
timeStamp: tx.timeStamp,
|
timeStamp: tx.timeStamp,
|
||||||
value: tx.value
|
value: tx.value
|
||||||
};
|
};
|
||||||
|
@ -42,14 +42,14 @@ export function decodeCallData (data) {
|
|||||||
export function decodeMethodInput (methodAbi, paramdata) {
|
export function decodeMethodInput (methodAbi, paramdata) {
|
||||||
if (!methodAbi) {
|
if (!methodAbi) {
|
||||||
throw new Error('decodeMethodInput should receive valid method-specific ABI');
|
throw new Error('decodeMethodInput should receive valid method-specific ABI');
|
||||||
} else if (!paramdata) {
|
} else if (paramdata && paramdata.length) {
|
||||||
throw new Error('decodeMethodInput should receive valid parameter input data');
|
if (!isHex(paramdata)) {
|
||||||
} else if (!isHex(paramdata)) {
|
throw new Error('Input to decodeMethodInput should be a hex value');
|
||||||
throw new Error('Input to decodeMethodInput should be a hex value');
|
} else if (paramdata.substr(0, 2) === '0x') {
|
||||||
} else if (paramdata.substr(0, 2) === '0x') {
|
return decodeMethodInput(methodAbi, paramdata.slice(2));
|
||||||
return decodeMethodInput(methodAbi, paramdata.slice(2));
|
} else if (paramdata.length % 64 !== 0) {
|
||||||
} else if (paramdata.length % 64 !== 0) {
|
throw new Error('Parameter length in decodeMethodInput not a multiple of 64 characters');
|
||||||
throw new Error('Parameter length in decodeMethodInput not a multiple of 64 characters');
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Func(methodAbi).decodeInput(paramdata).map((decoded) => decoded.value);
|
return new Func(methodAbi).decodeInput(paramdata).map((decoded) => decoded.value);
|
||||||
@ -73,7 +73,7 @@ export function methodToAbi (method) {
|
|||||||
|
|
||||||
const name = method.substr(0, typesStart);
|
const name = method.substr(0, typesStart);
|
||||||
const types = method.substr(typesStart + 1, length - (typesStart + 1) - 1).split(',');
|
const types = method.substr(typesStart + 1, length - (typesStart + 1) - 1).split(',');
|
||||||
const inputs = types.map((_type) => {
|
const inputs = types.filter((_type) => _type.length).map((_type) => {
|
||||||
const type = fromParamType(toParamType(_type));
|
const type = fromParamType(toParamType(_type));
|
||||||
|
|
||||||
return { type };
|
return { type };
|
||||||
|
@ -44,10 +44,6 @@ describe('api/util/decode', () => {
|
|||||||
expect(() => decodeMethodInput(null, null)).to.throw(/should receive valid method/);
|
expect(() => decodeMethodInput(null, null)).to.throw(/should receive valid method/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('expects valid parameter data', () => {
|
|
||||||
expect(() => decodeMethodInput({}, null)).to.throw(/should receive valid parameter/);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('expect valid hex parameter data', () => {
|
it('expect valid hex parameter data', () => {
|
||||||
expect(() => decodeMethodInput({}, 'invalid')).to.throw(/should be a hex value/);
|
expect(() => decodeMethodInput({}, 'invalid')).to.throw(/should be a hex value/);
|
||||||
});
|
});
|
||||||
|
@ -46,7 +46,7 @@ class InputAddress extends Component {
|
|||||||
const { value, text, accountsInfo, tokens } = this.props;
|
const { value, text, accountsInfo, tokens } = this.props;
|
||||||
|
|
||||||
const account = accountsInfo[value] || tokens[value];
|
const account = accountsInfo[value] || tokens[value];
|
||||||
const hasAccount = account && !account.meta.deleted;
|
const hasAccount = account && (!account.meta || !account.meta.deleted);
|
||||||
const inputValue = text && hasAccount ? account.name : value;
|
const inputValue = text && hasAccount ? account.name : value;
|
||||||
const isEmpty = (!inputValue || inputValue.length === 0);
|
const isEmpty = (!inputValue || inputValue.length === 0);
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ class InputAddress extends Component {
|
|||||||
classes.push(isEmpty ? styles.inputEmpty : styles.input);
|
classes.push(isEmpty ? styles.inputEmpty : styles.input);
|
||||||
|
|
||||||
const account = accountsInfo[value] || tokens[value];
|
const account = accountsInfo[value] || tokens[value];
|
||||||
const hasAccount = account && !account.meta.deleted;
|
const hasAccount = account && (!account.meta || !account.meta.deleted);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={ styles.container }>
|
<div className={ styles.container }>
|
||||||
|
Loading…
Reference in New Issue
Block a user