Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(driver): do not fetch GoldenTouchAddress (#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored May 3, 2024
1 parent 90411c9 commit 3a01470
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
27 changes: 12 additions & 15 deletions driver/anchor_tx_constructor/anchor_tx_constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,27 @@ import (
"github.com/taikoxyz/taiko-client/pkg/rpc"
)

// Each TaikoL2.anchor transaction should use this value as it's gas limit.
const AnchorGasLimit = 250_000
var (
// Each TaikoL2.anchor transaction should use this value as it's gas limit.
AnchorGasLimit uint64 = 250_000
GoldenTouchAddress = common.HexToAddress("0x0000777735367b36bC9B61C50022d9D0700dB4Ec")
)

// AnchorTxConstructor is responsible for assembling the anchor transaction (TaikoL2.anchor) in
// each L2 block, which must be the first transaction, and its sender must be the golden touch account.
type AnchorTxConstructor struct {
rpc *rpc.Client
goldenTouchAddress common.Address
signer *signer.FixedKSigner
rpc *rpc.Client
signer *signer.FixedKSigner
}

// New creates a new AnchorConstructor instance.
func New(rpc *rpc.Client) (*AnchorTxConstructor, error) {
goldenTouchAddress, err := rpc.TaikoL2.GOLDENTOUCHADDRESS(nil)
if err != nil {
return nil, err
}

signer, err := signer.NewFixedKSigner("0x" + encoding.GoldenTouchPrivKey)
if err != nil {
return nil, fmt.Errorf("invalid golden touch private key %s", encoding.GoldenTouchPrivKey)
}

return &AnchorTxConstructor{rpc, goldenTouchAddress, signer}, nil
return &AnchorTxConstructor{rpc, signer}, nil
}

// AssembleAnchorTx assembles a signed TaikoL2.anchor transaction.
Expand Down Expand Up @@ -90,22 +87,22 @@ func (c *AnchorTxConstructor) transactOpts(
)

// Get the nonce of golden touch account at the specified parentHeight.
nonce, err := c.rpc.L2AccountNonce(ctx, c.goldenTouchAddress, parentHeight)
nonce, err := c.rpc.L2AccountNonce(ctx, GoldenTouchAddress, parentHeight)
if err != nil {
return nil, err
}

log.Info(
"Golden touch account nonce",
"address", c.goldenTouchAddress,
"address", GoldenTouchAddress,
"nonce", nonce,
"parent", parentHeight,
)

return &bind.TransactOpts{
From: c.goldenTouchAddress,
From: GoldenTouchAddress,
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
if address != c.goldenTouchAddress {
if address != GoldenTouchAddress {
return nil, bind.ErrNotAuthorized
}
signature, err := c.signTxPayload(signer.Hash(tx).Bytes())
Expand Down
2 changes: 1 addition & 1 deletion driver/anchor_tx_constructor/anchor_tx_constructor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *AnchorTxConstructorTestSuite) SetupTest() {
}

func (s *AnchorTxConstructorTestSuite) TestGasLimit() {
s.Greater(AnchorGasLimit, 0)
s.Greater(AnchorGasLimit, uint64(0))
}

func (s *AnchorTxConstructorTestSuite) TestAssembleAnchorTx() {
Expand Down

0 comments on commit 3a01470

Please sign in to comment.