/
setPubKey.go
78 lines (68 loc) · 2.17 KB
/
setPubKey.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package l2txs
import (
"fmt"
"os"
"strconv"
"strings"
zksyncTypes "github.com/assetcloud/plugin/plugin/dapp/zksync/types"
"github.com/spf13/cobra"
)
func setManyPubKeyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "pubkey_many",
Short: "set pubkeys",
Run: setPubKey,
}
setPubKeyFlag(cmd)
return cmd
}
func setPubKeyFlag(cmd *cobra.Command) {
cmd.Flags().StringP("keys", "k", "", "private keys, use ',' separate")
_ = cmd.MarkFlagRequired("keys")
cmd.Flags().StringP("accountIDs", "a", "0", "L2 account ids on chain, use ',' separate")
_ = cmd.MarkFlagRequired("accountIDs")
cmd.Flags().Uint64P("pubkeyT", "t", 0, "self default:0, proxy pubkey ty: 1: normal,2:system,3:super")
cmd.Flags().StringP("pubkeyX", "x", "", "proxy pubkey x value")
cmd.Flags().StringP("pubkeyY", "y", "", "proxy pubkey y value")
}
func setPubKey(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
pubkeyT, _ := cmd.Flags().GetUint64("pubkeyT")
pubkeyX, _ := cmd.Flags().GetString("pubkeyX")
pubkeyY, _ := cmd.Flags().GetString("pubkeyY")
privateKeys, _ := cmd.Flags().GetString("keys")
accountIDs, _ := cmd.Flags().GetString("accountIDs")
paraName, _ := cmd.Flags().GetString("paraName")
ids := strings.Split(accountIDs, ",")
keys := strings.Split(privateKeys, ",")
if pubkeyT > 0 && (len(pubkeyX) == 0 || len(pubkeyY) == 0) {
_, _ = fmt.Fprintln(os.Stderr, fmt.Sprintf("set proxy pubkey, need set pubkeyX pubkeyY"))
}
if len(ids) != len(keys) {
fmt.Println("err len(ids) != len(keys)", len(ids), "!=", len(keys))
return
}
for i := 0; i < len(ids); i++ {
id, _ := strconv.ParseInt(ids[i], 10, 64)
param := &zksyncTypes.ZkSetPubKey{
AccountId: uint64(id),
PubKeyTy: pubkeyT,
PubKey: &zksyncTypes.ZkPubKey{
X: pubkeyX,
Y: pubkeyY,
},
}
action := &zksyncTypes.ZksyncAction{
Ty: zksyncTypes.TySetPubKeyAction,
Value: &zksyncTypes.ZksyncAction_SetPubKey{
SetPubKey: param,
},
}
tx, err := createChainTx(keys[i], getRealExecName(paraName, zksyncTypes.Zksync), action)
if nil != err {
fmt.Println("SetPubKey failed to createChainTx due to err:", err.Error())
return
}
sendTx(rpcLaddr, tx)
}
}