Skip to content

Commit

Permalink
fix: read ABI from embedded variable
Browse files Browse the repository at this point in the history
  • Loading branch information
miltonjonat committed Nov 5, 2024
1 parent c81c2eb commit 7dd028f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
13 changes: 2 additions & 11 deletions internal/espressoreader/espresso_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/cartesi/rollups-node/internal/evmreader"
"github.com/cartesi/rollups-node/internal/model"
"github.com/cartesi/rollups-node/internal/repository"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/cartesi/rollups-node/pkg/rollupsmachine"
"github.com/ethereum/go-ethereum/common"
"github.com/tidwall/gjson"
)
Expand Down Expand Up @@ -151,16 +151,7 @@ func (e *EspressoReader) Run(ctx context.Context, ready chan<- struct{}) error {
}
}
// abi encode payload
abiFile, err := os.Open("pkg/rollupsmachine/abi.json")
if err != nil {
slog.Error("failed to open abi file", "error", err)
continue
}
abiObject, err := abi.JSON(abiFile)
if err != nil {
slog.Error("failed to read abi", "error", err)
continue
}
abiObject := rollupsmachine.GetAbi()
chainId := &big.Int{}
chainId.SetInt64(int64(e.chainId))
l1FinalizedCurrentHeightBig := &big.Int{}
Expand Down
15 changes: 2 additions & 13 deletions internal/evmreader/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import (
"fmt"
"log/slog"
"math/big"
"os"

. "github.com/cartesi/rollups-node/internal/model"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/cartesi/rollups-node/pkg/rollupsmachine"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
)
Expand Down Expand Up @@ -335,17 +334,7 @@ func getEpochLength(consensus ConsensusContract) (uint64, error) {

func (r *EvmReader) modifyIndex(ctx context.Context, rawData []byte, appAddress common.Address) ([]byte, error) {
// load contract ABI
abiFile, err := os.Open("pkg/rollupsmachine/abi.json")
if err != nil {
slog.Error("failed to open abi file", "error", err)
return []byte{}, err
}
abiObject, err := abi.JSON(abiFile)
if err != nil {
slog.Error("failed to parse abi", "error", err)
return []byte{}, err
}

abiObject := rollupsmachine.GetAbi()
values, err := abiObject.Methods["EvmAdvance"].Inputs.Unpack(rawData[4:])
if err != nil {
slog.Error("Error unpacking abi", "err", err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/rollupsmachine/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ func decodeArguments(payload []byte) (arguments []any, _ error) {

return method.Inputs.Unpack(payload[4:])
}

func GetAbi() abi.ABI {
return ioABI
}

0 comments on commit 7dd028f

Please sign in to comment.