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

Feat: add operator to assets #857

Merged
merged 9 commits into from
Mar 21, 2019
Merged

Conversation

nachomazzara
Copy link
Contributor

@nachomazzara nachomazzara commented Feb 22, 2019

New version of decentraland-eth needed

Depends on decentraland/decentraland-eth#56 and decentraland/decentraland-eth#57

Close #858

@nachomazzara nachomazzara marked this pull request as ready for review March 6, 2019 20:47
Copy link
Contributor

@nicosantangelo nicosantangelo left a comment

Choose a reason for hiding this comment

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

🔥

token_address: address,
owner: holder.toLowerCase(),
operator: operator.toLowerCase()
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can keep these addresses as lowercase up in line 130 and remove the toLowerCase from insertApproval to keep it consistent

      const holder = event.args.operator.toLowerCase()
      const operator = event.args.holder.toLowerCase()
      const authorized = event.args.authorized === 'true'

      try {
        log.info(
          `[${name}] ${holder} ${
            authorized ? 'set' : 'remove'
          } ${operator} as approved for all`
        )
        if (authorized) {
          await Approval.insert({ address, holder, operator }) // add actual prop names here
        } else {
          await Approval.delete({
            token_address: address,
            owner: holder,
            operator
          })

Copy link
Contributor

Choose a reason for hiding this comment

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

The new changes use the toLowercase correctly, but they're still using insertApproval which is not necessary and can be deleted

@@ -45,3 +47,7 @@ export async function getParcelIdFromEvent(event) {
const { assetId, landId, _landId, _tokenId } = event.args
return Parcel.decodeTokenId(assetId || landId || _landId || _tokenId)
}

export function omitParcelId(name) {
return [eventNames.ApprovalForAll].includes(name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this future proofing for something? why not:

Suggested change
return [eventNames.ApprovalForAll].includes(name)
return eventNames.ApprovalForAll === name

Copy link
Contributor Author

@nachomazzara nachomazzara Mar 7, 2019

Choose a reason for hiding this comment

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

We can have more events that don't need to check the parcelId as approvalForAll. I wanted to leave it ready for that, the performance is imperceptible in this case.

Also, leaving it as an array, help new coders to quickly know how to add a new event to omit. If they only see a strict equal, they may think that something could break if changed

Copy link
Contributor

Choose a reason for hiding this comment

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

Allright. I'm not really an advocate for "leaving it for the future programmer to figure it out", if that's the case I prefer a comment and the correct implementation for the current case (it's not about performance). Let's leave it like this no worries.

On the other hand, the name is not correct (forgot to add it in the first comment, sorry). The method is not omitting anything and there's not connection to a parcelId.
I think maybe shouldOmitEvent makes more sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not an event omit, it is just an omission of a specific argument of the event.

owner,
operator
})
return res !== undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

Doing a count and checking for 0 instead fo a findOne is way faster

Copy link
Contributor

Choose a reason for hiding this comment

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

☝️

src/Authorization/Authorization.router.js Outdated Show resolved Hide resolved
}
default:
throw new Error(`The assetType ${assetType} is invalid`)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Two things about this one:

  • I think we should use contractAddresses here instead of env.get as we do in the rest of the codebase...except Estate.modal, but we need to change that one
  • Not important: You think it's good idea if we add a helper for this? I think we needed it elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The helper will work. We should need where we use contractAddresses with a switch by ASSET_TYPE (issue created)

Copy link
Contributor Author

@nachomazzara nachomazzara Mar 8, 2019

Choose a reason for hiding this comment

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

I should revert it because when we start the server we are not connecting to the eth which is a need for ethereum.js to work

Copy link
Contributor

@nicosantangelo nicosantangelo Mar 11, 2019

Choose a reason for hiding this comment

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

Ah that's a shame. Maybe we can call loadContracts from the server instead (it doesn't connect to a node). We'll leave it to the other issue

Resolve this convo once you read it! :D

if (!parcelId && omitParcelId(event.name)) {
return log.info(`[${name}] Invalid Parcel Id`)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh I don't get this part.

  • If omitParcelId(event.name) is true this won't run and, parcelId will be undefined below
  • If omitParcelId(event.name) is false you don't need to check it again on line 39

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I need to remove omitParcelId from the second if

Copy link
Contributor

Choose a reason for hiding this comment

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

Still my first point stands, what happens when the first if it's not fulfilled:

if (!omitParcelId(event.name)) {                    // <==== This one
  parcelId = await getParcelIdFromEvent(event)
  if (!parcelId) {
    return log.info(`[${name}] Invalid Parcel Id`)
  }
}

parcelId will be undefined moving forward. Isn't that a problem?

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 a problem

} ${_operator} as approved for all`
)
if (_approved) {
await Approval.insertApproval(address, _owner, _operator)
Copy link
Contributor

@nicosantangelo nicosantangelo Mar 7, 2019

Choose a reason for hiding this comment

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

check insertApproval comment above

Copy link
Contributor

Choose a reason for hiding this comment

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

☝️

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

Successfully merging this pull request may close these issues.

2 participants