2022-05-09 09:58:04 +02:00
|
|
|
package net
|
2022-05-08 13:13:45 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/lmittmann/w3/module/eth"
|
|
|
|
"math/big"
|
|
|
|
)
|
|
|
|
|
2022-05-09 09:58:04 +02:00
|
|
|
func (c *CicNet) LastNonce(ctx context.Context, address common.Address) (uint64, error) {
|
2022-05-08 13:13:45 +02:00
|
|
|
var nonce uint64
|
|
|
|
|
|
|
|
err := c.ethClient.CallCtx(
|
|
|
|
ctx,
|
|
|
|
eth.Nonce(address, nil).Returns(&nonce),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nonce, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CicNet) signAndCall(ctx context.Context, input []byte, txData WriteTx) (common.Hash, error) {
|
|
|
|
var txHash common.Hash
|
|
|
|
|
|
|
|
tx, err := types.SignNewTx(&txData.privateKey, c.kitabuSigner, &types.LegacyTx{
|
|
|
|
To: &txData.to,
|
2022-05-09 09:58:04 +02:00
|
|
|
Nonce: txData.nonce,
|
2022-05-08 13:13:45 +02:00
|
|
|
Data: input,
|
|
|
|
Gas: txData.gasLimit,
|
|
|
|
GasPrice: big.NewInt(1),
|
|
|
|
})
|
|
|
|
|
|
|
|
err = c.ethClient.CallCtx(
|
|
|
|
ctx,
|
|
|
|
eth.SendTransaction(tx).Returns(&txHash),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return [32]byte{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return txHash, nil
|
|
|
|
}
|