Example #1
0
func TestGetWallets(t *testing.T) {
	defer cleanupVisor()
	rpc := RPC{}
	v, _ := setupVisor()
	v.CreateWallet()
	v.CreateWallet()
	assert.Equal(t, len(v.Wallets), 3)
	wallets := rpc.GetWallets(v)
	assert.Equal(t, len(wallets), 3)
	expect := make([]*wallet.ReadableWallet, 3)
	for i, _ := range v.Wallets {
		expect[i] = wallet.NewReadableWallet(v.Wallets[i])
	}
	for i, w := range expect {
		w2 := wallets[i]
		assert.Equal(t, w2.ID, w.ID)
		assert.Equal(t, w2.Type, w.Type)
		assert.Equal(t, w2.Name, w.Name)
		assert.Equal(t, w2.Filename, w.Filename)
		assert.Equal(t, w2.Extra, w.Extra)
		assert.Equal(t, len(w2.Entries), len(w.Entries))
		for j, e := range w.Entries {
			e2 := w2.Entries[j]
			assert.Equal(t, e2.Public, e.Public)
			assert.Equal(t, e2.Address, e.Address)
			// Secret key should not be exposed by GetWallets
			assert.Equal(t, e2.Secret, "")
			assert.NotEqual(t, e.Secret, "")
		}
	}

	assert.Nil(t, rpc.GetWallets(nil))
}
Example #2
0
func (self RPC) CreateWallet(v *Visor) *wallet.ReadableWallet {
	if v == nil {
		return nil
	}
	w := v.CreateWallet()
	return wallet.NewReadableWallet(w)
}
Example #3
0
// Create a wallet Name is set by creation date
func walletCreate(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		logger.Info("API request made to create a wallet")
		seed := r.FormValue("seed")
		label := r.FormValue("label")
		wltName := wallet.NewWalletFilename()
		var wlt wallet.Wallet
		var err error
		// the wallet name may dup, rename it till no conflict.
		for {
			wlt, err = Wg.CreateWallet(wltName, wallet.OptSeed(seed), wallet.OptLabel(label))
			if err != nil && strings.Contains(err.Error(), "renaming") {
				wltName = wallet.NewWalletFilename()
				continue
			}
			break
		}

		if err := Wg.SaveWallet(wlt.GetID()); err != nil {
			wh.Error400(w, err.Error())
			return
		}

		rlt := wallet.NewReadableWallet(wlt)
		wh.SendOr500(w, rlt)
	}
}
Example #4
0
func (self *WalletRPC) GetWalletReadable(walletID wallet.WalletID) *wallet.ReadableWallet {
	w := self.Wallets.Get(walletID)
	if w == nil {
		return nil
	} else {
		return wallet.NewReadableWallet(*w)
	}
}
Example #5
0
func (self RPC) GetWallet(v *Visor,
	walletID wallet.WalletID) *wallet.ReadableWallet {
	if v == nil {
		return nil
	}
	w := v.Wallets.Get(walletID)
	if w == nil {
		return nil
	} else {
		return wallet.NewReadableWallet(w)
	}
}
Example #6
0
func TestGetWallet(t *testing.T) {
	defer cleanupVisor()
	rpc := RPC{}
	v, _ := setupVisor()
	w := v.Wallets[0]
	assert.Equal(t, wallet.NewReadableWallet(w), rpc.GetWallet(v, w.GetID()))
	w2, err := rpc.GetWallet(v, w.GetID()).ToWallet()
	assert.Nil(t, err)
	assert.Equal(t, w, w2)

	assert.Nil(t, rpc.GetWallet(nil, w.GetID()))
}
Example #7
0
// Create a wallet if no ID provided.  Otherwise update an existing wallet.
// Name is set by creation date
func walletCreate(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		logger.Info("API request made to create a wallet")
		seed := r.FormValue("seed")
		w1 := Wg.CreateWallet(seed) //use seed!
		iw := wallet.NewReadableWallet(w1)
		if iw != nil {
			if err := Wg.SaveWallet(w1.GetID()); err != nil {
				m := "Failed to save wallet after renaming: %v"
				logger.Critical(m, err)
			}
		}
		SendOr500(w, iw)
	}
}
Example #8
0
//all this does is update the wallet name
// Does Nothing
func walletUpdate(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		// Update wallet
		id := wallet.WalletID(r.FormValue("id"))
		//name := r.FormValue("name")
		w1 := Wg.GetWallet(id)
		if w1 != nil {
			if err := Wg.SaveWallet(w1.GetID()); err != nil {
				m := "Failed to save wallet after renaming: %v"
				logger.Critical(m, err)
			}
		}
		iw := wallet.NewReadableWallet(*w1)
		SendOr404(w, iw)
	}
}
Example #9
0
func TestGetWallets(t *testing.T) {
	defer cleanupVisor()
	rpc := RPC{}
	v, _ := setupVisor()
	v.CreateWallet()
	v.CreateWallet()
	assert.Equal(t, len(v.Wallets), 3)
	wallets := rpc.GetWallets(v)
	assert.Equal(t, len(wallets), 3)
	expect := make([]*wallet.ReadableWallet, 3)
	for i, _ := range v.Wallets {
		expect[i] = wallet.NewReadableWallet(v.Wallets[i])
	}
	assert.Equal(t, wallets, expect)

	assert.Nil(t, rpc.GetWallets(nil))
}
Example #10
0
func (self *WalletRPC) GetWalletReadable(walletID string) *wallet.ReadableWallet {
	if w, ok := self.Wallets.Get(walletID); ok {
		return wallet.NewReadableWallet(w)
	}
	return nil
}