-
Notifications
You must be signed in to change notification settings - Fork 15
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 #67 from ptisserand/invoke-v1-support
Add support for Invoke V1 transaction
- Loading branch information
Showing
17 changed files
with
1,099 additions
and
396 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ coverage/ | |
|
||
# Python | ||
**/__pycache__ | ||
.venv | ||
|
||
# Cairo | ||
!contracts/build | ||
!contracts/build | ||
|
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
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 |
---|---|---|
@@ -1,43 +1,69 @@ | ||
import 'package:starknet/starknet.dart'; | ||
|
||
enum AccountSupportedTxVersion { | ||
v0, | ||
v1, | ||
} | ||
|
||
class Account { | ||
Provider provider; | ||
Signer signer; | ||
Felt accountAddress; | ||
Felt chainId; | ||
AccountSupportedTxVersion supportedTxVersion; | ||
|
||
Account({ | ||
required this.provider, | ||
required this.signer, | ||
required this.accountAddress, | ||
required this.chainId, | ||
this.supportedTxVersion = AccountSupportedTxVersion.v0, | ||
}); | ||
|
||
Future<InvokeTransactionResponse> execute({ | ||
required List<FunctionCall> functionCalls, | ||
Felt? maxFee, | ||
Felt? nonce, | ||
}) async { | ||
nonce = nonce ?? Felt.fromInt(0); | ||
maxFee = maxFee ?? defaultMaxFee; | ||
|
||
Account( | ||
{required this.provider, | ||
required this.signer, | ||
required this.accountAddress, | ||
required this.chainId}); | ||
|
||
Future<InvokeTransaction> execute( | ||
{required List<FunctionCall> functionCalls, | ||
Felt? maxFee, | ||
Felt? version, | ||
Felt? nonce}) async { | ||
final signature = signer.signTransactions( | ||
transactions: functionCalls, | ||
contractAddress: accountAddress, | ||
version: supportedTxVersion == AccountSupportedTxVersion.v0 ? 0 : 1, | ||
chainId: chainId, | ||
entryPointSelectorName: "__execute__", | ||
maxFee: maxFee, | ||
nonce: nonce); | ||
|
||
final calldata = functionCallsToCalldata( | ||
functionCalls: functionCalls, nonce: nonce ?? Felt.fromInt(0)); | ||
switch (supportedTxVersion) { | ||
case AccountSupportedTxVersion.v0: | ||
final calldata = | ||
functionCallsToCalldata(functionCalls: functionCalls) + [nonce]; | ||
|
||
return provider.addInvokeTransaction( | ||
InvokeTransactionRequest( | ||
functionInvocation: FunctionCall( | ||
return provider.addInvokeTransaction(InvokeTransactionRequest( | ||
invokeTransaction: InvokeTransactionV0( | ||
contractAddress: accountAddress, | ||
entryPointSelector: getSelectorByName('__execute__'), | ||
calldata: calldata, | ||
maxFee: maxFee, | ||
signature: signature, | ||
), | ||
)); | ||
case AccountSupportedTxVersion.v1: | ||
final calldata = functionCallsToCalldata(functionCalls: functionCalls); | ||
|
||
return provider.addInvokeTransaction( | ||
InvokeTransactionRequest( | ||
invokeTransaction: InvokeTransactionV1( | ||
senderAddress: accountAddress, | ||
calldata: calldata, | ||
signature: signature, | ||
maxFee: maxFee, | ||
nonce: nonce), | ||
), | ||
maxFee: maxFee ?? Felt.fromInt(1000000000000000000), | ||
signature: signature, | ||
version: version ?? Felt.fromInt(0)), | ||
); | ||
); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.