@@ -10,15 +10,8 @@ import (
 	"github.com/iotexproject/iotex-address/address"
 	"github.com/pkg/errors"
 	"golang.org/x/crypto/sha3"
-
-	"github.com/iotexproject/iotex-core/config"
 )
 
-func init() {
-	// register the extern chain ID
-	config.SetExternChainID(config.Default.Chain.ExternChainID)
-}
-
 type rlpTransaction interface {
 	Nonce() uint64
 	GasPrice() *big.Int
package action

import (
	"math/big"

	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/core/types"
	"github.com/ethereum/go-ethereum/rlp"
	"github.com/iotexproject/go-pkgs/hash"
	"github.com/iotexproject/iotex-address/address"
	"github.com/pkg/errors"
	"golang.org/x/crypto/sha3"

	"github.com/iotexproject/iotex-core/config"
)

func init() {
	// register the extern chain ID
	config.SetExternChainID(config.Default.Chain.ExternChainID)
}

type rlpTransaction interface {
	Nonce() uint64
	GasPrice() *big.Int
	GasLimit() uint64
	Recipient() string
	Amount() *big.Int
	Payload() []byte
}

func rlpRawHash(tx rlpTransaction, chainID uint32) (hash.Hash256, error) {
	rawTx, err := generateRlpTx(tx)
	if err != nil {
		return hash.ZeroHash256, err
	}
	h := types.NewEIP155Signer(big.NewInt(int64(chainID))).Hash(rawTx)
	return hash.BytesToHash256(h[:]), nil
}

func rlpSignedHash(tx rlpTransaction, chainID uint32, sig []byte) (hash.Hash256, error) {
	if len(sig) != 65 {
		return hash.ZeroHash256, errors.Errorf("invalid signature length = %d, expecting 65", len(sig))
	}
	if sig[64] >= 27 {
		sig[64] -= 27
	}

	rawTx, err := generateRlpTx(tx)
	if err != nil {
		return hash.ZeroHash256, err
	}
	signedTx, err := rawTx.WithSignature(types.NewEIP155Signer(big.NewInt(int64(chainID))), sig)
	if err != nil {
		return hash.ZeroHash256, err
	}
	h := sha3.NewLegacyKeccak256()
	rlp.Encode(h, signedTx)
	return hash.BytesToHash256(h.Sum(nil)), nil
}

func generateRlpTx(act rlpTransaction) (*types.Transaction, error) {
	if act == nil {
		return nil, errors.New("nil action to generate RLP tx")
	}

	// generate raw tx
	if to := act.Recipient(); to != EmptyAddress {
		addr, err := address.FromString(to)
		if err != nil {
			return nil, errors.Wrapf(err, "invalid recipient address %s", to)
		}
		ethAddr := common.BytesToAddress(addr.Bytes())
		return types.NewTransaction(act.Nonce(), ethAddr, act.Amount(), act.GasLimit(), act.GasPrice(), act.Payload()), nil
	}
	return types.NewContractCreation(act.Nonce(), act.Amount(), act.GasLimit(), act.GasPrice(), act.Payload()), nil
}

this should be in test file