コード例 #1
0
ファイル: wallets.go プロジェクト: vipwzw/gocoin
func xml_addrs(w http.ResponseWriter, r *http.Request) {
	if !ipchecker(r) {
		return
	}

	w.Header()["Content-Type"] = []string{"text/xml"}

	w.Write([]byte("<addrbook>"))
	// Address Book
	book := wallet.LoadWalfile(common.GocoinHomeDir+"wallet/"+wallet.AddrBookFileName, 0)
	for i := range book {
		w.Write([]byte("<entry>"))
		w.Write([]byte("<addr>" + book[i].Enc58str + "</addr>"))
		w.Write([]byte("<label>"))
		xml.EscapeText(w, []byte(book[i].Extra.Label))
		w.Write([]byte("</label>"))
		w.Write([]byte("<wallet>"))
		xml.EscapeText(w, []byte(book[i].Extra.Wallet))
		w.Write([]byte("</wallet>"))
		w.Write([]byte("</entry>"))
	}
	w.Write([]byte("</addrbook>"))
}
コード例 #2
0
ファイル: sendtx.go プロジェクト: Bitoy/gocoin
func p_snd(w http.ResponseWriter, r *http.Request) {
	if !ipchecker(r) {
		return
	}

	s := load_template("send.html")

	wallet.LockBal()
	if wallet.MyWallet != nil && len(wallet.MyBalance) > 0 {
		wal := load_template("send_wal.html")
		row_tmp := load_template("send_wal_row.html")
		wal = strings.Replace(wal, "{TOTAL_BTC}", fmt.Sprintf("%.8f", float64(wallet.LastBalance)/1e8), 1)
		wal = strings.Replace(wal, "{UNSPENT_OUTS}", fmt.Sprint(len(wallet.MyBalance)), -1)
		for i := range wallet.MyBalance {
			row := row_tmp
			row = strings.Replace(row, "{WALLET_FILE}", html.EscapeString(wallet.MyBalance[i].BtcAddr.Extra.Wallet), 1)
			lab := wallet.MyBalance[i].BtcAddr.Extra.Label
			if wallet.MyBalance[i].BtcAddr.Extra.Virgin {
				lab += " ***"
			}
			row = strings.Replace(row, "{ADDR_LABEL}", html.EscapeString(lab), 1)
			row = strings.Replace(row, "{ROW_NUMBER}", fmt.Sprint(i+1), -1)
			row = strings.Replace(row, "{MINED_IN}", fmt.Sprint(wallet.MyBalance[i].MinedAt), 1)
			row = strings.Replace(row, "{TX_ID}", btc.NewUint256(wallet.MyBalance[i].TxPrevOut.Hash[:]).String(), -1)
			row = strings.Replace(row, "{TX_VOUT}", fmt.Sprint(wallet.MyBalance[i].TxPrevOut.Vout), -1)
			row = strings.Replace(row, "{BTC_AMOUNT}", fmt.Sprintf("%.8f", float64(wallet.MyBalance[i].Value)/1e8), 1)
			row = strings.Replace(row, "{OUT_VALUE}", fmt.Sprint(wallet.MyBalance[i].Value), 1)
			row = strings.Replace(row, "{BTC_ADDR}", wallet.MyBalance[i].BtcAddr.String(), 1)
			wal = templ_add(wal, "<!--UTXOROW-->", row)
		}

		// Own wallet
		for i := range wallet.MyWallet.Addrs {
			row := "wallet.push({'addr':'" + wallet.MyWallet.Addrs[i].Enc58str + "', " +
				"'label':'" + wallet.MyWallet.Addrs[i].Extra.Label + "', " +
				"'wallet':'" + wallet.MyWallet.Addrs[i].Extra.Wallet + "', " +
				"'virgin':" + fmt.Sprint(wallet.MyWallet.Addrs[i].Extra.Virgin) + "})\n"
			wal = templ_add(wal, "/*WALLET_ENTRY_JS*/", row)
		}

		// Address Book
		book := wallet.LoadWalfile(common.GocoinHomeDir+"wallet/ADDRESS", 0)
		for i := range book {
			row := "addrbook.push({'addr':'" + book[i].Enc58str + "', " +
				"'label':'" + book[i].Extra.Label + "', " +
				"'wallet':'" + book[i].Extra.Wallet + "'})\n"
			wal = templ_add(wal, "/*WALLET_ENTRY_JS*/", row)
		}
		wal = strings.Replace(wal, "/*WALLET_ENTRY_JS*/", "const ADDR_LIST_SIZE = "+fmt.Sprint(common.CFG.WebUI.AddrListLen), 1)

		s = strings.Replace(s, "<!--WALLET-->", wal, 1)
	} else {
		if wallet.MyWallet == nil {
			s = strings.Replace(s, "<!--WALLET-->", "You have no wallet", 1)
		} else {
			s = strings.Replace(s, "<!--WALLET-->", "Your current wallet is empty", 1)
		}
	}
	wallet.UnlockBal()

	write_html_head(w, r)
	w.Write([]byte(s))
	write_html_tail(w)
}