Exemplo n.º 1
0
func load_tx(par string) {
	if par == "" {
		fmt.Println("Specify a name of a transaction file")
		return
	}
	f, e := os.Open(par)
	if e != nil {
		println(e.Error())
		return
	}
	n, _ := f.Seek(0, os.SEEK_END)
	f.Seek(0, os.SEEK_SET)
	buf := make([]byte, n)
	f.Read(buf)
	f.Close()
	fmt.Println(usif.LoadRawTx(buf))
}
Exemplo n.º 2
0
func p_txs(w http.ResponseWriter, r *http.Request) {
	if !ipchecker(r) {
		return
	}

	var txloadresult string
	var wg sync.WaitGroup
	var tx2in []byte

	// Check if there is a tx upload request
	r.ParseMultipartForm(2e6)
	fil, _, _ := r.FormFile("txfile")
	if fil != nil {
		tx2in, _ = ioutil.ReadAll(fil)
	} else if len(r.Form["rawtx"]) == 1 {
		tx2in, _ = hex.DecodeString(r.Form["rawtx"][0])
	}

	if len(tx2in) > 0 {
		wg.Add(1)
		req := &usif.OneUiReq{Param: string(tx2in)}
		req.Done.Add(1)
		req.Handler = func(dat string) {
			txloadresult = usif.LoadRawTx([]byte(dat))
			wg.Done()
		}
		usif.UiChannel <- req
	}

	s := load_template("txs.html")
	network.TxMutex.Lock()

	var sum uint64
	for _, v := range network.TransactionsToSend {
		sum += uint64(len(v.Data))
	}
	s = strings.Replace(s, "{T2S_CNT}", fmt.Sprint(len(network.TransactionsToSend)), 1)
	s = strings.Replace(s, "{T2S_SIZE}", common.BytesToString(sum), 1)

	sum = 0
	for _, v := range network.TransactionsRejected {
		sum += uint64(v.Size)
	}
	s = strings.Replace(s, "{TRE_CNT}", fmt.Sprint(len(network.TransactionsRejected)), 1)
	s = strings.Replace(s, "{TRE_SIZE}", common.BytesToString(sum), 1)
	s = strings.Replace(s, "{PTR1_CNT}", fmt.Sprint(len(network.TransactionsPending)), 1)
	s = strings.Replace(s, "{PTR2_CNT}", fmt.Sprint(len(network.NetTxs)), 1)
	s = strings.Replace(s, "{SPENT_OUTS_CNT}", fmt.Sprint(len(network.SpentOutputs)), 1)
	s = strings.Replace(s, "{AWAITING_INPUTS}", fmt.Sprint(len(network.WaitingForInputs)), 1)

	network.TxMutex.Unlock()

	wg.Wait()
	if txloadresult != "" {
		ld := load_template("txs_load.html")
		ld = strings.Replace(ld, "{TX_RAW_DATA}", txloadresult, 1)
		s = strings.Replace(s, "<!--TX_LOAD-->", ld, 1)
	}

	if common.CFG.TXPool.Enabled {
		s = strings.Replace(s, "<!--MEM_POOL_ENABLED-->", "Enabled", 1)
	} else {
		s = strings.Replace(s, "<!--MEM_POOL_ENABLED-->", "Disabled", 1)
	}

	if common.CFG.TXRoute.Enabled {
		s = strings.Replace(s, "<!--TX_ROUTE_ENABLED-->", "Enabled", 1)
	} else {
		s = strings.Replace(s, "<!--TX_ROUTE_ENABLED-->", "Disabled", 1)
	}

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