Wallet file name must depend on node ID
This commit is contained in:
parent
57f3680551
commit
0c91da0e52
4
cli.go
4
cli.go
|
@ -118,11 +118,11 @@ func (cli *CLI) Run() {
|
|||
}
|
||||
|
||||
if createWalletCmd.Parsed() {
|
||||
cli.createWallet()
|
||||
cli.createWallet(nodeID)
|
||||
}
|
||||
|
||||
if listAddressesCmd.Parsed() {
|
||||
cli.listAddresses()
|
||||
cli.listAddresses(nodeID)
|
||||
}
|
||||
|
||||
if printChainCmd.Parsed() {
|
||||
|
|
|
@ -2,8 +2,8 @@ package main
|
|||
|
||||
import "fmt"
|
||||
|
||||
func (cli *CLI) createWallet() {
|
||||
wallets, _ := NewWallets()
|
||||
func (cli *CLI) createWallet(nodeID string) {
|
||||
wallets, _ := NewWallets(nodeID)
|
||||
address := wallets.CreateWallet()
|
||||
wallets.SaveToFile()
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"log"
|
||||
)
|
||||
|
||||
func (cli *CLI) listAddresses() {
|
||||
wallets, err := NewWallets()
|
||||
func (cli *CLI) listAddresses(nodeID string) {
|
||||
wallets, err := NewWallets(nodeID)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,13 @@ func (cli *CLI) send(from, to string, amount int, nodeID string) {
|
|||
UTXOSet := UTXOSet{bc}
|
||||
defer bc.db.Close()
|
||||
|
||||
tx := NewUTXOTransaction(from, to, amount, &UTXOSet)
|
||||
wallets, err := NewWallets(nodeID)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
wallet := wallets.GetWallet(from)
|
||||
|
||||
tx := NewUTXOTransaction(&wallet, to, amount, &UTXOSet)
|
||||
cbTx := NewCoinbaseTX(from, "")
|
||||
txs := []*Transaction{cbTx, tx}
|
||||
|
||||
|
|
|
@ -191,15 +191,10 @@ func NewCoinbaseTX(to, data string) *Transaction {
|
|||
}
|
||||
|
||||
// NewUTXOTransaction creates a new transaction
|
||||
func NewUTXOTransaction(from, to string, amount int, UTXOSet *UTXOSet) *Transaction {
|
||||
func NewUTXOTransaction(wallet *Wallet, to string, amount int, UTXOSet *UTXOSet) *Transaction {
|
||||
var inputs []TXInput
|
||||
var outputs []TXOutput
|
||||
|
||||
wallets, err := NewWallets()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
wallet := wallets.GetWallet(from)
|
||||
pubKeyHash := HashPubKey(wallet.PublicKey)
|
||||
acc, validOutputs := UTXOSet.FindSpendableOutputs(pubKeyHash, amount)
|
||||
|
||||
|
@ -221,6 +216,7 @@ func NewUTXOTransaction(from, to string, amount int, UTXOSet *UTXOSet) *Transact
|
|||
}
|
||||
|
||||
// Build a list of outputs
|
||||
from := fmt.Sprintf("%s", wallet.GetAddress())
|
||||
outputs = append(outputs, *NewTXOutput(amount, to))
|
||||
if acc > amount {
|
||||
outputs = append(outputs, *NewTXOutput(acc-amount, from)) // a change
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
)
|
||||
|
||||
const version = byte(0x00)
|
||||
const walletFile = "wallet.dat"
|
||||
const addressChecksumLen = 4
|
||||
|
||||
// Wallet stores private and public keys
|
||||
|
|
|
@ -10,13 +10,15 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
const walletFile = "wallet_%s.dat"
|
||||
|
||||
// Wallets stores a collection of wallets
|
||||
type Wallets struct {
|
||||
Wallets map[string]*Wallet
|
||||
}
|
||||
|
||||
// NewWallets creates Wallets and fills it from a file if it exists
|
||||
func NewWallets() (*Wallets, error) {
|
||||
func NewWallets(nodeID string) (*Wallets, error) {
|
||||
wallets := Wallets{}
|
||||
wallets.Wallets = make(map[string]*Wallet)
|
||||
|
||||
|
|
Loading…
Reference in New Issue