Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The order of the functions in play editor is not the same as in the source code #21

Open
gpersoon opened this issue Sep 17, 2019 · 3 comments

Comments

@gpersoon
Copy link
Contributor

The order of the functions in play editor is not the same as in the source code.
For example this source code:

pragma solidity ^0.5.0;

contract Test {
    uint public A;
    uint public B;
    uint public C;  
    uint public D;    
    function a() public  { }
    function b() public  { }
    function c() public  { }
    function d() public  { }
    function e() public  { }
    function f() public  { }
    function g() public  { }
}

Gives this output:
image

@serapath
Copy link
Member

  1. Yeah, another tricky one - because the compiler output doesn't provide all the functions in order sadly, so there is additional effort necessary to figure out the order
  2. also - we were thinking about grouping functions based on whether they are "view", "pure", "payable", "etc... which is often not the case in the code.
  3. we also have an issue where we want to make it possible to click on functions and jump/scroll the other view to the respective function, but it is all quite unclear when we will have time for those features :-)

@gpersoon
Copy link
Contributor Author

Grouping the functions on type is useful, and then you could sort them alphabetically.

@gpersoon
Copy link
Contributor Author

Suggestion for a solution:
Update on the function Sort in:
https://github.com/ethereum-play/smartcontract-ui/blob/master/src/smartcontract-app.js#L159

var mf=
[
{name: "v3", type: "function",   stateMutability: "view"},
{name: "v1", type: "function",   stateMutability: "view"},
{name: "p3", type: "function",   stateMutability: "pure"},
{name: "p2", type: "function",   stateMutability: "pure"},
{name: "v4", type: "function",   stateMutability: "view"},
{name: "p1", type: "function",   stateMutability: "pure"},
{name: "p4", type: "function",   stateMutability: "pure"},
{name: "v2", type: "function",   stateMutability: "view"}
]

      function type2num ({ stateMutability: sm }) {
        if (sm === 'view') return 1
        if (sm === 'nonpayable') return 2
        if (sm === 'pure') return 3
        if (sm === 'payable') return 4
        if (sm === undefined) return 5
      }
    
    function sort (functions) {
      return functions.filter(x => x.type === 'function').sort((a, b) => {
       var d=type2num(a) - type2num(b)
       if (d==0) 
       {
             if (a.name > b.name) return 1;
             if (a.name < b.name) return -1;
       }
       return d;
      }           
     )
    }

    var sorted = sort(mf)
    console.log(sorted);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants