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

Fix sort ordering logic #696

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/app/execution/txHelper.js
Expand Up @@ -32,20 +32,20 @@ module.exports = {
},

sortAbiFunction: function (contractabi) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a comment above here explaining the order? e.g. constructor, fallback, constant functions, non-constant functions?

Copy link
Author

Choose a reason for hiding this comment

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

@axic Okay, added now.

var abi = contractabi.sort(function (a, b) {
if (a.name > b.name) {
return -1
} else {
return contractabi.sort(function (a, b) {
if (a.constant === true && b.constant !== true) {
return 1
}
}).sort(function (a, b) {
if (a.constant === true) {
} else if (b.constant === true && a.constant !== true) {
return -1
} else {
}
// If we reach here, either a and b are both constant or both not; sort by name then
// special case for fallback and constructor
if (a.type === 'function' && typeof a.name !== 'undefined') {
return a.name.localeCompare(b.name)
Copy link
Member

Choose a reason for hiding this comment

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

Hm, this shouldn't be locale specific I think. Also identifiers can be ASCII only.

Copy link
Author

Choose a reason for hiding this comment

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

localeCompare() is the only native string-comparison function in Javascript; would you rather multiple separate calls to check greater, less, and equal?

Copy link
Member

Choose a reason for hiding this comment

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

Since this is only used for display purposes it should be fine, though I'd add a comment.

If this would be critical piece of code, either:

  • a manual implementation
  • or setting the locale to ASCII English upfront

would be needed, because certain languages consider di/trigraphs with different sorting order.

} else if (a.type === 'constructor' || a.type === 'fallback') {
return 1
}
})
return abi
},

getConstructorInterface: function (abi) {
Expand Down