-
Notifications
You must be signed in to change notification settings - Fork 56
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
API Refactor: Transaction #224
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e3fb789
Refactor: update imports and definitions for Transction entity
0xGabi 453b4ef
Refactor: Create Transaction entity & update how handle transactions
0xGabi 163166a
Comment logic related to forwarding path description
0xGabi 4c0890b
Comment logic related to forwarding path description
0xGabi 552bda1
Merge branch 'refactor-transaction' of github.com:aragon/connect into…
0xGabi 068a952
Refactor: Add Intent entity + refactor calculate path logic (#225)
0xGabi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/connect-core/src/connections/IOrganizationConnector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { ethers } from 'ethers' | ||
|
||
import App from './App' | ||
import Transaction from './Transaction' | ||
import { | ||
AppOrAddress, | ||
ForwardingPathData, | ||
ForwardingPathDescriptionData, | ||
PostProcessDescription, | ||
} from '../types' | ||
import { describeForwardingPath } from '../utils/description' | ||
|
||
export default class ForwardingPath { | ||
#provider: ethers.providers.Provider | ||
readonly apps: App[] | ||
readonly destination: App | ||
readonly transactions: Transaction[] | ||
|
||
constructor(data: ForwardingPathData, provider: ethers.providers.Provider) { | ||
this.#provider = provider | ||
this.apps = data.apps | ||
this.destination = data.destination | ||
this.transactions = data.transactions | ||
} | ||
|
||
// Lets consumers pass a callback to sign any number of transactions. | ||
// This is similar to calling transactions() and using a loop, but shorter. | ||
// It returns the value returned by the library, usually a transaction receipt. | ||
async sign<Receipt>( | ||
callback: (tx: Transaction) => Promise<Receipt> | ||
): Promise<Receipt[]> { | ||
return Promise.all(this.transactions.map(async (tx) => await callback(tx))) | ||
} | ||
|
||
// Return a description of the forwarding path, to be rendered. | ||
async describe(): Promise<ForwardingPathDescription> { | ||
// TODO: Make sure we are safe to only provide the apps on the path here | ||
return describeForwardingPath(this.transactions, this.apps, this.#provider) | ||
} | ||
|
||
// Return a description of the forwarding path, as text. | ||
// Shorthand for .describe().toString() | ||
toString(): string { | ||
return this.describe().toString() | ||
} | ||
} | ||
|
||
type ForwardingPathDescriptionTreeEntry = | ||
| AppOrAddress | ||
| [AppOrAddress, ForwardingPathDescriptionTreeEntry[]] | ||
|
||
export type ForwardingPathDescriptionTree = ForwardingPathDescriptionTreeEntry[] | ||
|
||
export class ForwardingPathDescription { | ||
readonly apps: App[] | ||
readonly describeSteps: PostProcessDescription[] | ||
|
||
constructor(data: ForwardingPathDescriptionData) { | ||
this.apps = data.apps | ||
this.describeSteps = data.describeSteps | ||
} | ||
|
||
// Return a tree that can get used to render the path. | ||
tree(): ForwardingPathDescriptionTree { | ||
// TODO: | ||
return [] | ||
} | ||
|
||
// Renders the forwarding path description as text | ||
toString(): string { | ||
return this.tree().toString() | ||
} | ||
|
||
// TBD: a utility that makes it easy to render the tree, | ||
// e.g. as a nested list in HTML or React. | ||
reduce(callback: Function): any {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { ethers } from 'ethers' | ||
|
||
import Organization from './Organization' | ||
import Transaction from './Transaction' | ||
import TransactionPath from '../transactions/TransactionPath' | ||
import { PathOptions, IntentData } from '../types' | ||
import { calculateTransactionPath } from '../utils/path/calculatePath' | ||
|
||
export default class Intent { | ||
#org: Organization | ||
#provider: ethers.providers.Provider | ||
readonly appAddress: string | ||
readonly functionName: string | ||
readonly functionArgs: any[] | ||
|
||
constructor( | ||
data: IntentData, | ||
org: Organization, | ||
provider: ethers.providers.Provider | ||
) { | ||
this.#org = org | ||
this.#provider = provider | ||
this.appAddress = data.appAddress | ||
this.functionName = data.functionName | ||
this.functionArgs = data.functionArgs | ||
} | ||
|
||
// Retrieve a single forwarding path. Defaults to the shortest one. | ||
async path({ actAs, path }: PathOptions): Promise<TransactionPath> { | ||
const apps = await this.#org.apps() | ||
|
||
// Get the destination app | ||
const destination = apps.find((app) => app.address == this.appAddress) | ||
if (!destination) { | ||
throw new Error( | ||
`Destination (${this.appAddress}) is not an installed app` | ||
) | ||
} | ||
|
||
const transactions = await calculateTransactionPath( | ||
actAs, | ||
destination, | ||
this.functionName, | ||
this.functionArgs, | ||
apps, | ||
this.#provider | ||
) | ||
|
||
return new TransactionPath({ | ||
apps: apps.filter((app) => | ||
transactions | ||
.map((tx) => tx.to) | ||
.some((address) => address === app.address) | ||
), | ||
destination, | ||
transactions, | ||
}) | ||
} | ||
|
||
// Retrieve the different possible forwarding paths. | ||
async paths({ actAs, path }: PathOptions): Promise<TransactionPath[]> { | ||
// TODO: support logic to calculate multiple Forwarding paths | ||
return [await this.path({ actAs, path })] | ||
} | ||
|
||
// A list of transaction requests ready to get signed. | ||
async transactions(options: PathOptions): Promise<Transaction[]> { | ||
return (await this.path(options)).transactions | ||
} | ||
|
||
// Lets consumers pass a callback to sign any number of transactions. | ||
// This is similar to calling transactions() and using a loop, but shorter. | ||
// It returns the value returned by the library, usually a transaction receipt. | ||
async sign<Receipt>( | ||
callback: (tx: Transaction) => Promise<Receipt>, | ||
options: PathOptions | ||
): Promise<Receipt[]> { | ||
const txs = await this.transactions(options) | ||
return Promise.all(txs.map(async (tx) => await callback(tx))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Address } from '@aragon/connect-types' | ||
|
||
import { TransactionData } from '../types' | ||
|
||
export default class Transaction { | ||
readonly data: string | ||
readonly from: Address | ||
readonly to: Address | ||
|
||
constructor(data: TransactionData) { | ||
this.data = data.data | ||
this.from = data.from | ||
this.to = data.to | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
packages/connect-core/src/transactions/TransactionIntent.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A helper to access an Ethers interface object from the app entities.