Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

reverse call data decoding given transaction data & method #2312

Merged
merged 7 commits into from
Sep 26, 2016

Conversation

jacogr
Copy link
Contributor

@jacogr jacogr commented Sep 25, 2016

api.util.* -

  • decodeCallData - converts transaction data into the signature and data parts
  • methodToAbi - converts string in the format of transfer(address,uint) to a method abi
  • decodeMethodInput - with an ABI & data from the first call, decode the data (string, uint, etc.)

Allows decoding of values for https://github.com/ethcore/parity/issues/2208 & https://github.com/ethcore/parity/issues/2280

@parity-cla-bot
Copy link

It looks like this contributor signed our Contributor License Agreement. 👍

Many thanks,

Ethcore CLA Bot

@jacogr jacogr added A0-pleasereview 🤓 Pull request needs code review. M6-rpcapi 📣 RPC API. labels Sep 25, 2016
@jacogr jacogr changed the title reverse call data decoding, given transaction data & method reverse call data decoding given transaction data & method Sep 25, 2016
Copy link
Contributor

@derhuerst derhuerst left a comment

Choose a reason for hiding this comment

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

Except the methodToAbi thing, minor grumbles.

const CREATE_METHOD = '60606040';

export function decodeCallData (data) {
if (!data || !data.length) {
Copy link
Contributor

@derhuerst derhuerst Sep 26, 2016

Choose a reason for hiding this comment

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

I'd let it fail/throw here actually, to encourage consumers of this function to use it properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 (Actually does do so later on when no signature + data, removed)

export function decodeMethodInput (methodAbi, paramdata) {
if (!methodAbi) {
throw new Error('decodeMethodInput should receive valid method-specific ABI');
} else if (!paramdata) {
Copy link
Contributor

@derhuerst derhuerst Sep 26, 2016

Choose a reason for hiding this comment

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

Those checks don't have an AND relation, so it should be else if -> if. Every single failed check is a reason for decodeMethodInput to fail, but multiple can fail at once.

I that with throw, it doesn't make a big difference, but it's more robust.

}

// takes a method in form name(..., types) and returns the interred abi definition
export function methodToAbi (method) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The indexOf feels too brittle. This function should validate the syntax of method properly (right now, it will already give a false positive with spaces inside method).

If this is a standard format, as @jacogr told me, there should be an independent module for validating!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Type checking to be done, as discussed.

@jacogr jacogr merged commit f840ded into js Sep 26, 2016
@jacogr jacogr deleted the jg-abi-method-input-decode branch September 27, 2016 15:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-pleasereview 🤓 Pull request needs code review. M6-rpcapi 📣 RPC API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants