Commit e96b4141 authored by QM's avatar QM

add ethereum chainId

parent 9b764957
......@@ -28,6 +28,7 @@ func main() {
rootCmd.PersistentFlags().String("paraName", "", "para chain name,Eg:user.p.fzm.")
rootCmd.PersistentFlags().String("expire", "120m", "transaction expire time (optional)")
rootCmd.PersistentFlags().Int32("chainID", 0, "chain id, default to 0")
rootCmd.PersistentFlags().Int64("chainEthId", 256, "ethereum chain id, default to 0")
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
......
......@@ -57,6 +57,7 @@ func DeployERC20(cmd *cobra.Command, _ []string) {
owner, _ := cmd.Flags().GetString("owner")
symbol, _ := cmd.Flags().GetString("symbol")
amount, _ := cmd.Flags().GetString("amount")
chainEthId, _ := cmd.Flags().GetInt64("chainEthId")
bnAmount := big.NewInt(1)
bnAmount, _ = bnAmount.SetString(utils.TrimZeroAndDot(amount), 10)
client, err := ethclient.Dial(url)
......@@ -96,7 +97,7 @@ func DeployERC20(cmd *cobra.Command, _ []string) {
}
infos = append(infos, &deployInfo)
fileName := fmt.Sprintf("deployErc20%s.txt", symbol)
err = NewTxWrite(infos, common.HexToAddress(deployerAddr), url, fileName)
err = NewTxWrite(infos, common.HexToAddress(deployerAddr), url, fileName, chainEthId)
if err != nil {
fmt.Println("NewTxWrite error", err.Error())
return
......
......@@ -50,6 +50,7 @@ func createTx(cmd *cobra.Command, _ []string) {
validatorsAddrs, _ := cmd.Flags().GetString("validatorsAddrs")
initpowers, _ := cmd.Flags().GetString("initPowers")
owner, _ := cmd.Flags().GetString("owner")
chainEthId, _ := cmd.Flags().GetInt64("chainEthId")
deployerAddr := common.HexToAddress(owner)
validatorsAddrsArray := strings.Split(validatorsAddrs, ",")
initPowersArray := strings.Split(initpowers, ",")
......@@ -78,13 +79,13 @@ func createTx(cmd *cobra.Command, _ []string) {
initPowers = append(initPowers, big.NewInt(vint64))
}
err := createDeployTxs(url, deployerAddr, validators, initPowers)
err := createDeployTxs(url, deployerAddr, validators, initPowers, chainEthId)
if err != nil {
panic(err)
}
}
func createDeployTxs(url string, deployerAddr common.Address, validators []common.Address, initPowers []*big.Int) error {
func createDeployTxs(url string, deployerAddr common.Address, validators []common.Address, initPowers []*big.Int, chainEthId int64) error {
client, err := ethclient.Dial(url)
if err != nil {
return err
......@@ -156,10 +157,10 @@ func createDeployTxs(url string, deployerAddr common.Address, validators []commo
mulSignAddr := crypto.CreateAddress(deployerAddr, startNonce+7)
infos = append(infos, &DeployInfo{PackData: packData, ContractorAddr: mulSignAddr, Name: "mulSignAddr", Nonce: startNonce + 7, To: nil})
return NewTxWrite(infos, deployerAddr, url, "deploytxs.txt")
return NewTxWrite(infos, deployerAddr, url, "deploytxs.txt", chainEthId)
}
func NewTxWrite(infos []*DeployInfo, deployerAddr common.Address, url, fileName string) error {
func NewTxWrite(infos []*DeployInfo, deployerAddr common.Address, url, fileName string, chainId int64) error {
ctx := context.Background()
client, err := ethclient.Dial(url)
if err != nil {
......@@ -184,7 +185,8 @@ func NewTxWrite(infos []*DeployInfo, deployerAddr common.Address, url, fileName
if gasLimit < 100*10000 {
gasLimit = 100 * 10000
}
ntx := types.NewTx(&types.LegacyTx{
ntx := types.NewTx(&types.AccessListTx{
ChainID: big.NewInt(chainId),
Nonce: info.Nonce,
Gas: gasLimit,
GasPrice: price,
......@@ -327,6 +329,7 @@ func addCreateWithFileFlags(cmd *cobra.Command) {
func createWithFileTx(cmd *cobra.Command, _ []string) {
url, _ := cmd.Flags().GetString("rpc_laddr_ethereum")
cfgpath, _ := cmd.Flags().GetString("conf")
chainEthId, _ := cmd.Flags().GetInt64("chainEthId")
var deployCfg DeployConfigInfo
InitCfg(cfgpath, &deployCfg)
deployPrivateKey, err := crypto.ToECDSA(common.FromHex(deployCfg.DeployerPrivateKey))
......@@ -351,7 +354,7 @@ func createWithFileTx(cmd *cobra.Command, _ []string) {
initPowers = append(initPowers, big.NewInt(deployCfg.InitPowers[i]))
}
err = createDeployTxs(url, deployerAddr, validators, initPowers)
err = createDeployTxs(url, deployerAddr, validators, initPowers, chainEthId)
if err != nil {
fmt.Println("createDeployTxs Err:", err)
return
......
......@@ -4,25 +4,17 @@ import (
"context"
"encoding/json"
"fmt"
//"github.com/33cn/plugin/plugin/dapp/cross2eth/contracts/contracts4eth/generated"
//erc20 "github.com/33cn/plugin/plugin/dapp/cross2eth/contracts/erc20/generated"
//"github.com/33cn/plugin/plugin/dapp/cross2eth/ebrelayer/utils"
tml "github.com/BurntSushi/toml"
"github.com/ethereum/go-ethereum"
//"github.com/ethereum/go-ethereum/accounts/abi"
"io/ioutil"
"math/big"
"os"
tml "github.com/BurntSushi/toml"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/spf13/cobra"
//"strings"
//"time"
)
type DeployContractRet struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment