Skip to content

Commit

Permalink
execute wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Sep 1, 2023
1 parent 442e461 commit 2481d76
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,29 @@ func (account *Account) TransactionHash(call rpc.FunctionCall, txDetails rpc.TxD
)
}

func (account *Account) TransactionHash2(callData []*felt.Felt, txDetails rpc.TxDetails) (*felt.Felt, error) {

if len(callData) == 0 || txDetails.Nonce == nil || txDetails.MaxFee == nil || account.accountAddress == nil {
return nil, ErrNotAllParametersSet
}

calldataHash, err := computeHashOnElementsFelt(callData)
if err != nil {
return nil, err
}

return calculateTransactionHashCommon(
new(felt.Felt).SetBytes([]byte(TRANSACTION_PREFIX)),
new(felt.Felt).SetUint64(account.version),
account.accountAddress,
&felt.Zero,
calldataHash,
txDetails.MaxFee,
account.ChainId,
[]*felt.Felt{txDetails.Nonce},
)
}

func (account *Account) Nonce(ctx context.Context) (*felt.Felt, error) {
switch account.version {
case 1:
Expand Down Expand Up @@ -131,16 +154,7 @@ func (account *Account) Sign(ctx context.Context, msg *felt.Felt) ([]*felt.Felt,
}

func (account *Account) SignInvokeTransaction(ctx context.Context, invokeTx *rpc.BroadcastedInvokeV1Transaction) error {
txHash, err := account.TransactionHash(
rpc.FunctionCall{
ContractAddress: invokeTx.SenderAddress,
EntryPointSelector: &felt.Zero,
Calldata: invokeTx.Calldata,
},
rpc.TxDetails{
Nonce: invokeTx.Nonce,
MaxFee: invokeTx.MaxFee,
})
txHash, err := account.TransactionHash2(invokeTx.Calldata, rpc.TxDetails{Nonce: invokeTx.Nonce, MaxFee: invokeTx.MaxFee})
if err != nil {
return err
}
Expand Down

0 comments on commit 2481d76

Please sign in to comment.