2024-05-23 16:22:57 +00:00
|
|
|
package transfer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
ethTypes "github.com/ethereum/go-ethereum/core/types"
|
2024-06-06 20:08:25 +00:00
|
|
|
"github.com/status-im/status-go/services/wallet/router/pathprocessor"
|
2024-05-23 16:22:57 +00:00
|
|
|
)
|
|
|
|
|
2024-06-06 20:08:25 +00:00
|
|
|
func (tm *TransactionManager) buildTransactions(pathProcessors map[string]pathprocessor.PathProcessor) ([]string, error) {
|
2024-05-23 16:22:57 +00:00
|
|
|
tm.transactionsForKeycardSigning = make(map[common.Hash]*TransactionDescription)
|
|
|
|
var hashes []string
|
2024-08-12 12:07:32 +00:00
|
|
|
usedNonces := make(map[uint64]int64)
|
2024-06-06 20:08:25 +00:00
|
|
|
for _, bridgeTx := range tm.multipathTransactionsData {
|
2024-08-12 12:07:32 +00:00
|
|
|
|
|
|
|
lastUsedNonce := int64(-1)
|
|
|
|
if nonce, ok := usedNonces[bridgeTx.ChainID]; ok {
|
|
|
|
lastUsedNonce = nonce
|
|
|
|
}
|
|
|
|
|
|
|
|
builtTx, usedNonce, err := pathProcessors[bridgeTx.Name].BuildTransaction(bridgeTx, lastUsedNonce)
|
2024-05-23 16:22:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return hashes, err
|
|
|
|
}
|
|
|
|
|
|
|
|
signer := ethTypes.NewLondonSigner(big.NewInt(int64(bridgeTx.ChainID)))
|
|
|
|
txHash := signer.Hash(builtTx)
|
|
|
|
|
|
|
|
tm.transactionsForKeycardSigning[txHash] = &TransactionDescription{
|
|
|
|
from: common.Address(bridgeTx.From()),
|
|
|
|
chainID: bridgeTx.ChainID,
|
|
|
|
builtTx: builtTx,
|
|
|
|
}
|
|
|
|
|
2024-08-12 12:07:32 +00:00
|
|
|
usedNonces[bridgeTx.ChainID] = int64(usedNonce)
|
|
|
|
|
2024-05-23 16:22:57 +00:00
|
|
|
hashes = append(hashes, txHash.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
return hashes, nil
|
|
|
|
}
|