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

Add api.util.encodeMethodCall to parity.js #4330

Merged
merged 5 commits into from
Jan 30, 2017
Merged

Conversation

jacogr
Copy link
Contributor

@jacogr jacogr commented Jan 27, 2017

@jacogr jacogr added A0-pleasereview 🤓 Pull request needs code review. M6-rpcapi 📣 RPC API. labels Jan 27, 2017
import Abi from '~/abi';
import Func from '~/abi/spec/function';

export function encodeMethodCall (methodAbi, options = {}, values = []) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not 100% convinced the options are needed for the extra options.data in all the use-cases.

@gavofyork
Copy link
Contributor

gavofyork commented Jan 30, 2017

from #4325:

would be good to have two (basically) symmetric calls:

  • parity.api.util.abiEncode(name, types, params) -> data (name may be null, in which case it skips the function sig, making it useful for encoding events/constructor/fallback)
  • parity.api.util.abiDecode(types, data) -> params
    Here's my polyfill for the current PR:
parity.api.util.abiEncode = function(name, types, data) {
   let r = parity.api.util.encodeMethodCall(name || '', types, data);
   return name === null ? `0x${r.substr(10)}` : r;
};
parity.api.util.abiDecode = function (types, data) {
   return parity.api.util.decodeMethodInput({inputs: types.map(t => {return {type: t};})}, data);
};

@jacogr
Copy link
Contributor Author

jacogr commented Jan 30, 2017

Added abiEncode & abiDecode (99.9% copy from provided, just tests added)

@gavofyork gavofyork added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jan 30, 2017
@gavofyork gavofyork merged commit c0468fa into master Jan 30, 2017
@gavofyork gavofyork deleted the jg-jsapi-call-encode branch January 30, 2017 10:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M6-rpcapi 📣 RPC API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants