Commit bd964a8 1 parent b46e966 commit bd964a8 Copy full SHA for bd964a8
File tree 4 files changed +64
-0
lines changed
4 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ func main() {
64
64
buildAllAddrCmd (rootCmd )
65
65
buildAllHistoryCmd (rootCmd )
66
66
buildInfoCmd (rootCmd )
67
+ buildNeuterCmd (rootCmd )
67
68
68
69
err := rootCmd .Execute ()
69
70
if err != nil {
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+
6
+ "github.com/ipfs/boxo/util"
7
+ "github.com/pactus-project/pactus/cmd"
8
+ "github.com/spf13/cobra"
9
+ )
10
+
11
+ func buildNeuterCmd (parentCmd * cobra.Command ) {
12
+ neuterCmd := & cobra.Command {
13
+ Use : "neuter" ,
14
+ Short : "convert full wallet to neutered wallet and can only be used to retrieve balances or stakes" ,
15
+ }
16
+ parentCmd .AddCommand (neuterCmd )
17
+
18
+ neuterCmd .Run = func (_ * cobra.Command , _ []string ) {
19
+ wlt , err := openWallet ()
20
+ cmd .FatalErrorCheck (err )
21
+
22
+ path := wlt .Path () + ".neutered"
23
+
24
+ if util .FileExists (path ) {
25
+ cmd .FatalErrorCheck (fmt .Errorf ("neutered wallet already exists, at %s" , path ))
26
+ }
27
+
28
+ neuteredWallet := wlt .Neuter (path )
29
+
30
+ err = neuteredWallet .Save ()
31
+ cmd .FatalErrorCheck (err )
32
+
33
+ cmd .PrintSuccessMsgf ("neutered wallet created at %s" , path )
34
+ }
35
+ }
Original file line number Diff line number Diff line change @@ -49,6 +49,21 @@ func (s *Store) ToBytes() ([]byte, error) {
49
49
return json .MarshalIndent (s , " " , " " )
50
50
}
51
51
52
+ func (s * Store ) Clone () * Store {
53
+ clonedVault := * s .Vault // Assuming Vault has proper pointer handling internally
54
+ clonedHistory := s .History
55
+
56
+ return & Store {
57
+ Version : s .Version ,
58
+ UUID : s .UUID ,
59
+ CreatedAt : s .CreatedAt ,
60
+ Network : s .Network ,
61
+ VaultCRC : s .VaultCRC ,
62
+ Vault : & clonedVault ,
63
+ History : clonedHistory ,
64
+ }
65
+ }
66
+
52
67
func (s * Store ) ValidateCRC () error {
53
68
crc := s .calcVaultCRC ()
54
69
if s .VaultCRC != crc {
Original file line number Diff line number Diff line change @@ -548,3 +548,16 @@ func (w *Wallet) Info() *Info {
548
548
CreatedAt : w .store .CreatedAt ,
549
549
}
550
550
}
551
+
552
+ // Neuter clones the wallet and neuters it and saves it at the given path.
553
+ func (w * Wallet ) Neuter (path string ) * Wallet {
554
+ clonedStore := w .store .Clone ()
555
+ clonedStore .Vault = w .store .Vault .Neuter ()
556
+
557
+ neuteredWallet := & Wallet {
558
+ store : clonedStore ,
559
+ path : path ,
560
+ }
561
+
562
+ return neuteredWallet
563
+ }
You can’t perform that action at this time.
0 commit comments