Skip to content

Commit 3111ff6

Browse files
author
NullpointerW
committed
feat: pl cmd
1 parent f15cf4e commit 3111ff6

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ pks.json
33
txRecords.json
44
.idea
55
.PK
6-
*.exe
6+
*.exe
7+
*.txt

cmd.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@ var pa = &cobra.Command{
5757
PrintPkJsonArray()
5858
},
5959
}
60+
var pl = &cobra.Command{
61+
Use: "pl",
62+
Short: "Print private key as line txt",
63+
Run: func(cmd *cobra.Command, args []string) {
64+
PrintPkLine()
65+
},
66+
}
6067

6168
func init() {
6269
tx.Flags().StringVarP(&Endpoint, "endpoint", "e", "https://ethereum.publicnode.com", "Network rpc endpoint")
63-
ethwt.AddCommand(tx, gen, pa)
70+
ethwt.AddCommand(tx, gen, pa, pl)
6471
}
6572

6673
func main() {

wallet_printer.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"bufio"
45
"encoding/json"
56
"fmt"
67
"os"
@@ -30,3 +31,28 @@ func PrintPkJsonArray() {
3031
_, _ = pkjf.Write(raw)
3132
_ = pkjf.Close()
3233
}
34+
35+
func PrintPkLine() {
36+
var wallets []Wallet
37+
wjr, err := os.ReadFile("wallet.json")
38+
if os.IsNotExist(err) {
39+
fmt.Println("no wallet found")
40+
return
41+
} else if err != nil {
42+
fmt.Println("load wallet err:", err)
43+
return
44+
} else {
45+
_ = json.Unmarshal(wjr, &wallets)
46+
}
47+
var pkls []string
48+
for _, w := range wallets {
49+
unHexPrefix := strings.TrimPrefix(w.PrivateKey, "0x")
50+
fmt.Println(unHexPrefix)
51+
pkls = append(pkls, unHexPrefix)
52+
}
53+
pklsfs, _ := os.Create("pks.txt")
54+
wstr := strings.Join(pkls, "\n")
55+
w := bufio.NewWriter(pklsfs)
56+
_, _ = w.WriteString(wstr)
57+
return
58+
}

0 commit comments

Comments
 (0)