diff --git a/interop/executor.go b/interop/executor.go index 67d6d13..556005e 100644 --- a/interop/executor.go +++ b/interop/executor.go @@ -10,8 +10,8 @@ import ( "github.com/0xPolygon/beethoven/tx" "github.com/0xPolygon/beethoven/types" + jRPC "github.com/0xPolygon/cdk-data-availability/rpc" "github.com/0xPolygonHermez/zkevm-node/jsonrpc/client" - rpctypes "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" "github.com/0xPolygonHermez/zkevm-node/log" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" @@ -168,11 +168,11 @@ func (e *Executor) Settle(ctx context.Context, signedTx tx.SignedTx, dbTx pgx.Tx return signedTx.Tx.Hash(), nil } -func (e *Executor) GetTxStatus(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (result string, err rpctypes.Error) { +func (e *Executor) GetTxStatus(ctx context.Context, hash common.Hash, dbTx pgx.Tx) (result string, err jRPC.Error) { res, innerErr := e.ethTxMan.Result(ctx, ethTxManOwner, hash.Hex(), dbTx) if innerErr != nil { result = "0x0" - err = rpctypes.NewRPCError(rpctypes.DefaultErrorCode, fmt.Sprintf("failed to get tx, error: %s", innerErr)) + err = jRPC.NewRPCError(jRPC.DefaultErrorCode, fmt.Sprintf("failed to get tx, error: %s", innerErr)) return } diff --git a/interop/executor_test.go b/interop/executor_test.go index 4ea0830..6e495f3 100644 --- a/interop/executor_test.go +++ b/interop/executor_test.go @@ -6,10 +6,7 @@ import ( "math/big" "testing" - "github.com/0xPolygon/beethoven/config" - "github.com/0xPolygon/beethoven/mocks" - "github.com/0xPolygon/beethoven/tx" - + jRPC "github.com/0xPolygon/cdk-data-availability/rpc" "github.com/0xPolygonHermez/zkevm-node/ethtxmanager" rpctypes "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" "github.com/0xPolygonHermez/zkevm-node/log" @@ -18,6 +15,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + + "github.com/0xPolygon/beethoven/config" + "github.com/0xPolygon/beethoven/mocks" + "github.com/0xPolygon/beethoven/tx" ) func TestNewExecutor(t *testing.T) { @@ -269,7 +270,7 @@ func TestExecutor_GetTxStatus(t *testing.T) { hash := common.HexToHash("0x1234567890abcdef") expectedResult := "0x1" - expectedError := rpctypes.NewRPCError(rpctypes.DefaultErrorCode, "failed to get tx, error: sampleError") + expectedError := jRPC.NewRPCError(rpctypes.DefaultErrorCode, "failed to get tx, error: sampleError") ethTxManager.On("Result", mock.Anything, ethTxManOwner, hash.Hex(), dbTx). Return(ethtxmanager.MonitoredTxResult{ diff --git a/rpc/rpc.go b/rpc/rpc.go index 266347b..ff09623 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -4,14 +4,13 @@ import ( "context" "fmt" - "github.com/0xPolygon/beethoven/interop" - "github.com/0xPolygon/beethoven/types" - - rpctypes "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" + jRPC "github.com/0xPolygon/cdk-data-availability/rpc" "github.com/0xPolygonHermez/zkevm-node/log" "github.com/ethereum/go-ethereum/common" + "github.com/0xPolygon/beethoven/interop" "github.com/0xPolygon/beethoven/tx" + "github.com/0xPolygon/beethoven/types" ) // INTEROP is the namespace of the interop service @@ -40,25 +39,25 @@ func NewInteropEndpoints( } } -func (i *InteropEndpoints) SendTx(signedTx tx.SignedTx) (interface{}, rpctypes.Error) { +func (i *InteropEndpoints) SendTx(signedTx tx.SignedTx) (interface{}, jRPC.Error) { // Check if the RPC is actually registered, if not it won't be possible to assert soundness (in the future once we are stateless won't be needed) if err := i.executor.CheckTx(signedTx); err != nil { - return "0x0", rpctypes.NewRPCError(rpctypes.DefaultErrorCode, fmt.Sprintf("there is no RPC registered for %d", signedTx.Tx.RollupID)) + return "0x0", jRPC.NewRPCError(jRPC.DefaultErrorCode, fmt.Sprintf("there is no RPC registered for %d", signedTx.Tx.RollupID)) } // Verify ZKP using eth_call if err := i.executor.Verify(i.ctx, signedTx); err != nil { - return "0x0", rpctypes.NewRPCError(rpctypes.DefaultErrorCode, fmt.Sprintf("failed to verify tx: %s", err)) + return "0x0", jRPC.NewRPCError(jRPC.DefaultErrorCode, fmt.Sprintf("failed to verify tx: %s", err)) } if err := i.executor.Execute(i.ctx, signedTx); err != nil { - return "0x0", rpctypes.NewRPCError(rpctypes.DefaultErrorCode, fmt.Sprintf("failed to execute tx: %s", err)) + return "0x0", jRPC.NewRPCError(jRPC.DefaultErrorCode, fmt.Sprintf("failed to execute tx: %s", err)) } // Send L1 tx dbTx, err := i.db.BeginStateTransaction(i.ctx) if err != nil { - return "0x0", rpctypes.NewRPCError(rpctypes.DefaultErrorCode, fmt.Sprintf("failed to begin dbTx, error: %s", err)) + return "0x0", jRPC.NewRPCError(jRPC.DefaultErrorCode, fmt.Sprintf("failed to begin dbTx, error: %s", err)) } _, err = i.executor.Settle(i.ctx, signedTx, dbTx) @@ -66,21 +65,21 @@ func (i *InteropEndpoints) SendTx(signedTx tx.SignedTx) (interface{}, rpctypes.E if errRollback := dbTx.Rollback(i.ctx); errRollback != nil { log.Error("rollback err: ", errRollback) } - return "0x0", rpctypes.NewRPCError(rpctypes.DefaultErrorCode, fmt.Sprintf("failed to add tx to ethTxMan, error: %s", err)) + return "0x0", jRPC.NewRPCError(jRPC.DefaultErrorCode, fmt.Sprintf("failed to add tx to ethTxMan, error: %s", err)) } if err := dbTx.Commit(i.ctx); err != nil { - return "0x0", rpctypes.NewRPCError(rpctypes.DefaultErrorCode, fmt.Sprintf("failed to commit dbTx, error: %s", err)) + return "0x0", jRPC.NewRPCError(jRPC.DefaultErrorCode, fmt.Sprintf("failed to commit dbTx, error: %s", err)) } log.Debugf("successfuly added tx %s to ethTxMan", signedTx.Tx.Hash().Hex()) return signedTx.Tx.Hash(), nil } -func (i *InteropEndpoints) GetTxStatus(hash common.Hash) (result interface{}, err rpctypes.Error) { +func (i *InteropEndpoints) GetTxStatus(hash common.Hash) (result interface{}, err jRPC.Error) { dbTx, innerErr := i.db.BeginStateTransaction(i.ctx) if innerErr != nil { result = "0x0" - err = rpctypes.NewRPCError(rpctypes.DefaultErrorCode, fmt.Sprintf("failed to begin dbTx, error: %s", innerErr)) + err = jRPC.NewRPCError(jRPC.DefaultErrorCode, fmt.Sprintf("failed to begin dbTx, error: %s", innerErr)) return } @@ -88,14 +87,14 @@ func (i *InteropEndpoints) GetTxStatus(hash common.Hash) (result interface{}, er defer func() { if innerErr := dbTx.Rollback(i.ctx); innerErr != nil { result = "0x0" - err = rpctypes.NewRPCError(rpctypes.DefaultErrorCode, fmt.Sprintf("failed to rollback dbTx, error: %s", innerErr)) + err = jRPC.NewRPCError(jRPC.DefaultErrorCode, fmt.Sprintf("failed to rollback dbTx, error: %s", innerErr)) } }() result, innerErr = i.executor.GetTxStatus(i.ctx, hash, dbTx) if innerErr != nil { result = "0x0" - err = rpctypes.NewRPCError(rpctypes.DefaultErrorCode, fmt.Sprintf("failed to get tx, error: %s", innerErr)) + err = jRPC.NewRPCError(jRPC.DefaultErrorCode, fmt.Sprintf("failed to get tx, error: %s", innerErr)) return }