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

Refactor: Add Intent entity + refactor calculate path logic #225

Merged
merged 5 commits into from
Aug 31, 2020

Conversation

0xGabi
Copy link
Contributor

@0xGabi 0xGabi commented Aug 20, 2020

Closes #217

Builds on #224

@0xGabi 0xGabi requested a review from bpierre August 20, 2020 21:26
@0xGabi 0xGabi added this to In progress in Roadmap to v1.0.0 via automation Aug 20, 2020
@@ -90,11 +90,11 @@ export default class App {
return this.artifact.abi
}

get intents(): AppIntent[] {
get methods(): AppMethod[] {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decide to change the name to methods instead of intents as it was confusing. I'm also wondering if we may want to remove those methods at all 🤔

@@ -61,6 +61,19 @@ export default class App {
return this.organization.connection.orgConnector
}

contract(): ethers.Contract {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I include a helper to have access to an Ethers contract object to make it super easy to interact with the blockchain for the particular App.

}

// Retrieve a single forwarding path. Defaults to the shortest one.
async path({ actAs, path }: PathOptions): Promise<TransactionPath> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We removed all the logic related to the description of a path and handle that responsibility to the Forwarding Path.


// Retrieve the different possible forwarding paths.
async paths({ actAs, path }: PathOptions): Promise<TransactionPath[]> {
// TODO: support logic to calculate multiple Forwarding paths
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We left the calculation of multiple Forwarding Path for a later PR.

}

const createForwarderTransaction = createForwarderTransactionBuilder(
sender,
directTransaction
)

const buildForwardingPath = async (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted this logic as it was used multiple times.

@@ -181,34 +150,26 @@ async function calculateForwardingPath(
*/
export async function calculateTransactionPath(
sender: string,
destination: string,
destinationApp: App,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now accept an App entity instead.

}

// Make sure the method signature is correct
const method = validateMethod(destination, methodSignature, destinationApp)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We no longer need this logic because we use the Ethers interface object inside createDirectTransactionForApp: https://github.com/aragon/connect/pull/224/files#diff-a9188376c85e9975a721384535e75e5aR19

? ethers.utils.isAddress(finalForwarder)
: false

const method = getAppMethod(destinationApp, methodSignature)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are only using the method to know if it's protected by a role. I wonder if we can get this information in other way 🤔

@@ -249,11 +210,13 @@ export async function calculateTransactionPath(
(role) => role.name === method.roles[0]
)
const allowedEntities =
role?.permissions?.map((permission) => permission.granteeAddress) || []
role?.permissions
?.filter((permission) => permission.allowed)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We missed to check if the permission was allowed.

// No forwarders can perform the requested action
if (forwardersWithPermission.length === 0) {
return { path: [] }
return []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We return an array the Transaction object.

This was referenced Aug 20, 2020
@0xGabi 0xGabi moved this from In progress to In review in Roadmap to v1.0.0 Aug 21, 2020
@codecov
Copy link

codecov bot commented Aug 21, 2020

Codecov Report

Merging #225 into refactor-transaction will not change coverage.
The diff coverage is 0.00%.

Impacted file tree graph

@@                  Coverage Diff                  @@
##           refactor-transaction     #225   +/-   ##
=====================================================
  Coverage                 35.96%   35.96%           
=====================================================
  Files                        97       97           
  Lines                      1760     1760           
  Branches                    277      277           
=====================================================
  Hits                        633      633           
  Misses                     1127     1127           
Flag Coverage Δ
#unittests 35.96% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/connect-core/src/entities/App.ts 0.00% <0.00%> (ø)
packages/connect-core/src/entities/Intent.ts 0.00% <0.00%> (ø)
packages/connect-core/src/entities/Organization.ts 0.00% <0.00%> (ø)
packages/connect-core/src/utils/app.ts 0.00% <0.00%> (ø)
...kages/connect-core/src/utils/path/calculatePath.ts 0.00% <0.00%> (ø)
packages/connect-core/src/utils/radspec/index.ts 0.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 552bda1...562c639. Read the comment docs.

@0xGabi 0xGabi mentioned this pull request Aug 21, 2020
@0xGabi 0xGabi merged commit 068a952 into refactor-transaction Aug 31, 2020
Roadmap to v1.0.0 automation moved this from In review to Done Aug 31, 2020
@0xGabi 0xGabi deleted the refactor-intent branch August 31, 2020 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

1 participant