From 9b73f0b08d48d07c5976712b37349ca7b6e4212b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Ram=C3=ADrez?= <58293609+ToniRamirezM@users.noreply.github.com> Date: Mon, 6 May 2024 10:39:27 +0200 Subject: [PATCH] add gas offset (#34) * add gas offset --- README.md | 2 +- ethtxmanager/ethtxmanager.go | 4 ++-- ethtxmanager/monitoredtx.go | 2 +- test/main.go | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index df2717d..6529c1f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Stateless manager to send transactions to L1. ## Main Funtions ### Add Transaction -`func (c *Client) Add(ctx context.Context, to *common.Address, forcedNonce *uint64, value *big.Int, data []byte) (common.Hash, error)` +`func (c *Client) Add(ctx context.Context, to *common.Address, forcedNonce *uint64, value *big.Int, data []byte, gasOffset uint64, sidecar *types.BlobTxSidecar) (common.Hash, error)` Adds a transaction to be sent to L1. The returned hash is calculated over the *to*, *nonce*, *value* and *data* fields. diff --git a/ethtxmanager/ethtxmanager.go b/ethtxmanager/ethtxmanager.go index fe3de7f..db8e713 100644 --- a/ethtxmanager/ethtxmanager.go +++ b/ethtxmanager/ethtxmanager.go @@ -179,7 +179,7 @@ func (c *Client) getTxNonce(ctx context.Context, from common.Address) (uint64, e } // Add a transaction to be sent and monitored -func (c *Client) Add(ctx context.Context, to *common.Address, forcedNonce *uint64, value *big.Int, data []byte, sidecar *types.BlobTxSidecar) (common.Hash, error) { +func (c *Client) Add(ctx context.Context, to *common.Address, forcedNonce *uint64, value *big.Int, data []byte, gasOffset uint64, sidecar *types.BlobTxSidecar) (common.Hash, error) { var nonce uint64 var err error @@ -285,7 +285,7 @@ func (c *Client) Add(ctx context.Context, to *common.Address, forcedNonce *uint6 mTx := monitoredTx{ ID: id, From: c.from, To: to, Nonce: nonce, Value: value, Data: data, - Gas: gas, GasPrice: gasPrice, + Gas: gas, GasPrice: gasPrice, GasOffset: gasOffset, BlobSidecar: sidecar, BlobGas: tx.BlobGas(), BlobGasPrice: blobFeeCap, GasTipCap: gasTipCap, diff --git a/ethtxmanager/monitoredtx.go b/ethtxmanager/monitoredtx.go index c7b3909..6b07859 100644 --- a/ethtxmanager/monitoredtx.go +++ b/ethtxmanager/monitoredtx.go @@ -122,7 +122,7 @@ func (mTx monitoredTx) Tx() *types.Transaction { Data: mTx.Data, GasFeeCap: uint256.MustFromBig(mTx.GasPrice), GasTipCap: uint256.MustFromBig(mTx.GasTipCap), - Gas: mTx.Gas, + Gas: mTx.Gas + mTx.GasOffset, BlobFeeCap: uint256.MustFromBig(mTx.BlobGasPrice), BlobHashes: mTx.BlobSidecar.BlobHashes(), Sidecar: mTx.BlobSidecar, diff --git a/test/main.go b/test/main.go index a55ba1f..c9908a4 100644 --- a/test/main.go +++ b/test/main.go @@ -110,7 +110,7 @@ func main() { } func sendTransaction(ctx context.Context, ethtxmanager *ethtxmanager.Client, nonce uint64) common.Hash { - id, err := ethtxmanager.Add(ctx, &to0, &nonce, big.NewInt(1), []byte{byte(rand.Intn(256)), byte(rand.Intn(256)), byte(rand.Intn(256))}, nil) + id, err := ethtxmanager.Add(ctx, &to0, &nonce, big.NewInt(1), []byte{byte(rand.Intn(256)), byte(rand.Intn(256)), byte(rand.Intn(256))}, 0, nil) if err != nil { log.Errorf("Error sending transaction: %s", err) } else { @@ -130,7 +130,7 @@ func sendBlobTransaction(ctx context.Context, ethtxmanager *ethtxmanager.Client, // data := []byte{228, 103, 97, 196} // pol method data := []byte{} - id, err := ethtxmanager.Add(ctx, &to0, &nonce, big.NewInt(0), data, blobSidecar) + id, err := ethtxmanager.Add(ctx, &to0, &nonce, big.NewInt(0), data, 0, blobSidecar) if err != nil { log.Errorf("Error sending Blob transaction: %s", err) } else {