-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #534 from multiversx/TOOL-355-add-relayed-controllers
Add relayed controller
- Loading branch information
Showing
8 changed files
with
101 additions
and
50 deletions.
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
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,2 @@ | ||
export * from "./relayedController"; | ||
export * from "./relayedTransactionsFactory"; |
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,49 @@ | ||
import { IAccount } from "../accounts/interfaces"; | ||
import { Transaction } from "../transaction"; | ||
import { TransactionComputer } from "../transactionComputer"; | ||
import { TransactionsFactoryConfig } from "../transactionsFactories"; | ||
import { RelayedTransactionsFactory } from "./relayedTransactionsFactory"; | ||
import { RelayedV1TransactionInput, RelayedV2TransactionInput } from "./resources"; | ||
|
||
export class RelayedController { | ||
private factory: RelayedTransactionsFactory; | ||
private txComputer: TransactionComputer; | ||
|
||
/** | ||
* The transactions are created from the perspective of the relayer. | ||
* The 'sender' represents the relayer. | ||
*/ | ||
constructor(options: { chainID: string }) { | ||
this.factory = new RelayedTransactionsFactory({ | ||
config: new TransactionsFactoryConfig(options), | ||
}); | ||
this.txComputer = new TransactionComputer(); | ||
} | ||
|
||
async createRelayedV1Transaction( | ||
sender: IAccount, | ||
nonce: bigint, | ||
options: RelayedV1TransactionInput, | ||
): Promise<Transaction> { | ||
const transaction = this.factory.createRelayedV1Transaction(sender.address, options); | ||
|
||
transaction.nonce = nonce; | ||
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); | ||
|
||
return transaction; | ||
} | ||
|
||
async createRelayedV2Transaction( | ||
sender: IAccount, | ||
nonce: bigint, | ||
options: RelayedV2TransactionInput, | ||
): Promise<Transaction> { | ||
const transaction = this.factory.createRelayedV2Transaction(sender.address, options); | ||
|
||
transaction.nonce = nonce; | ||
transaction.gasLimit = BigInt(0); | ||
transaction.signature = await sender.sign(this.txComputer.computeBytesForSigning(transaction)); | ||
|
||
return transaction; | ||
} | ||
} |
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.