コード例 #1
0
ファイル: updates.go プロジェクト: hsk81/btcgui
// cmdGetAddressesByAccount requests all addresses for an account.
//
// TODO(jrick): support non-default accounts.
// TODO(jrick): stop throwing away errors.
func cmdGetAddressesByAccount(ws *websocket.Conn) {
	n := <-NewJSONID
	msg, err := btcjson.CreateMessageWithId("getaddressesbyaccount", n, "")
	if err != nil {
		updateChans.addrs <- []string{}
	}

	replyHandlers.Lock()
	replyHandlers.m[n] = func(result interface{}, err *btcjson.Error) {
		if r, ok := result.([]interface{}); ok {
			addrs := []string{}
			for _, v := range r {
				addrs = append(addrs, v.(string))
			}
			updateChans.addrs <- addrs
		} else {
			if err.Code == btcjson.ErrWalletInvalidAccountName.Code {
				glib.IdleAdd(func() {
					if dialog, err := createNewWalletDialog(); err != nil {
						dialog.Run()
					}
				})
			}
			updateChans.addrs <- []string{}
		}
	}
	replyHandlers.Unlock()

	if err = websocket.Message.Send(ws, msg); err != nil {
		replyHandlers.Lock()
		delete(replyHandlers.m, n)
		replyHandlers.Unlock()
		updateChans.addrs <- []string{}
	}
}
コード例 #2
0
ファイル: updates.go プロジェクト: hsk81/btcgui
// cmdGetNewAddress requests a new wallet address.
//
// TODO(jrick): support non-default accounts
func cmdGetNewAddress(ws *websocket.Conn) {
	var err error
	defer func() {
		if err != nil {

		}
	}()

	n := <-NewJSONID
	msg, err := btcjson.CreateMessageWithId("getnewaddress", n, "")
	if err != nil {
		triggerReplies.newAddr <- err
		return
	}

	replyHandlers.Lock()
	replyHandlers.m[n] = func(result interface{}, err *btcjson.Error) {
		switch {
		case err == nil:
			if addr, ok := result.(string); ok {
				triggerReplies.newAddr <- addr
			}

		case err.Code == btcjson.ErrWalletKeypoolRanOut.Code:
			success := make(chan bool)
			glib.IdleAdd(func() {
				dialog, err := createUnlockDialog(unlockForKeypool, success)
				if err != nil {
					log.Print(err)
					success <- false
					return
				}
				dialog.Run()
			})
			if <-success {
				triggers.newAddr <- 1
			}

		default: // all other non-nil errors
			triggerReplies.newAddr <- errors.New(err.Message)
		}
	}
	replyHandlers.Unlock()

	if err = websocket.Message.Send(ws, msg); err != nil {
		replyHandlers.Lock()
		delete(replyHandlers.m, n)
		replyHandlers.Unlock()
		triggerReplies.newAddr <- err
	}
}
コード例 #3
0
ファイル: updates.go プロジェクト: hsk81/btcgui
// cmdWalletLock locks the currently-opened wallet.  A reply handler
// is not set up because the GUI will be updated after a
// "btcwallet:newwalletlockstate" notification is sent.
func cmdWalletLock(ws *websocket.Conn) error {
	n := <-NewJSONID
	msg, err := btcjson.CreateMessageWithId("walletlock", n)
	if err != nil {
		return err
	}

	// We don't actually care about the reply and rely on the
	// notification to update widgets, but adding an empty handler
	// prevents warnings printed to logging output.
	replyHandlers.Lock()
	replyHandlers.m[n] = func(result interface{}, err *btcjson.Error) {}
	replyHandlers.Unlock()

	return websocket.Message.Send(ws, msg)
}
コード例 #4
0
ファイル: updates.go プロジェクト: hsk81/btcgui
// cmdSetTxFee requests wallet to set the global transaction fee added
// to newly-created transactions and awarded to the block miner who
// includes the transaction.
func cmdSetTxFee(ws *websocket.Conn, fee float64) error {
	n := <-NewJSONID
	msg, err := btcjson.CreateMessageWithId("settxfee", n, fee)
	if err != nil {
		triggerReplies.setTxFeeErr <- err
		return err // TODO(jrick): this gets thrown away so just send via triggerReplies.
	}

	replyHandlers.Lock()
	replyHandlers.m[n] = func(result interface{}, err *btcjson.Error) {
		if err != nil {
			triggerReplies.setTxFeeErr <- err
		} else {
			// success
			triggerReplies.setTxFeeErr <- nil
		}
	}
	replyHandlers.Unlock()

	return websocket.Message.Send(ws, msg)
}