mirror of
https://github.com/grassrootseconomics/cic-go.git
synced 2024-11-13 18:36:47 +01:00
Mohamed Sohail
7731a23e35
* update: (cic_net) add new methods and tests * add: write tx methods and tests - add ci for testing - coveralls for coverage * ci: add test environment * ci: expose secrets to env * docs: add badges
51 lines
1005 B
Go
51 lines
1005 B
Go
package cic_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) latestNonce(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
|
|
|
|
nonce, err := c.latestNonce(ctx, txData.from)
|
|
if err != nil {
|
|
return [32]byte{}, err
|
|
}
|
|
|
|
tx, err := types.SignNewTx(&txData.privateKey, c.kitabuSigner, &types.LegacyTx{
|
|
To: &txData.to,
|
|
Nonce: 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
|
|
}
|