Improve NewWallets and fix comments
This commit is contained in:
parent
75105982ae
commit
2b0619e103
7
cli.go
7
cli.go
|
@ -18,7 +18,7 @@ func (cli *CLI) createBlockchain(address string) {
|
|||
}
|
||||
|
||||
func (cli *CLI) createWallet() {
|
||||
wallets := NewWallets()
|
||||
wallets, _ := NewWallets()
|
||||
address := wallets.CreateWallet()
|
||||
wallets.SaveToFile()
|
||||
|
||||
|
@ -40,7 +40,10 @@ func (cli *CLI) getBalance(address string) {
|
|||
}
|
||||
|
||||
func (cli *CLI) listAddresses() {
|
||||
wallets := NewWallets()
|
||||
wallets, err := NewWallets()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
addresses := wallets.GetAddresses()
|
||||
|
||||
for _, address := range addresses {
|
||||
|
|
13
wallet.go
13
wallet.go
|
@ -131,22 +131,17 @@ func (ws *Wallets) GetAddresses() []string {
|
|||
return addresses
|
||||
}
|
||||
|
||||
// NewWallets ...
|
||||
func NewWallets() *Wallets {
|
||||
// NewWallets creates Wallets and fills it from a file if it exists
|
||||
func NewWallets() (*Wallets, error) {
|
||||
wallets := Wallets{}
|
||||
wallets.Wallets = make(map[string]*Wallet)
|
||||
|
||||
err := wallets.LoadFromFile()
|
||||
if err != nil {
|
||||
fmt.Println("Wallets file doesn't exist")
|
||||
// wallets.CreateWallet()
|
||||
// wallets.SaveToFile()
|
||||
}
|
||||
|
||||
return &wallets
|
||||
return &wallets, err
|
||||
}
|
||||
|
||||
// Checksum ...
|
||||
// Checksum generates a checksum for a public key
|
||||
func checksum(payload []byte) []byte {
|
||||
firstSHA := sha256.Sum256(payload)
|
||||
secondSHA := sha256.Sum256(firstSHA[:])
|
||||
|
|
Loading…
Reference in New Issue