cic-go/net/util.go
Mohamed Sohail 79634affb8
refactor: tests and structure (#3)
module:
- cic-go

packages:
- cic/meta
- cic/net

other fixes:

- nonce is now a settable value
- package init outside test runner scope
2022-05-09 10:58:04 +03:00

46 lines
913 B
Go

package net
import (
"context"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/lmittmann/w3/module/eth"
"math/big"
)
func (c *CicNet) LastNonce(ctx context.Context, address common.Address) (uint64, error) {
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,
Nonce: txData.nonce,
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
}