Esempio n. 1
0
func getTransactionByID(gate *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		if r.Method != "GET" {
			wh.Error405(w, "")
			return
		}
		txid := r.FormValue("txid")
		if txid == "" {
			wh.Error400(w, "txid is empty")
			return
		}

		h, err := cipher.SHA256FromHex(txid)
		if err != nil {
			wh.Error400(w, err.Error())
			return
		}

		tx, err := gate.V.GetTransaction(h)
		if err != nil {
			wh.Error400(w, err.Error())
			return
		}
		if tx == nil {
			wh.Error404(w, "not found")
			return
		}

		resTx := visor.TransactionResult{
			Transaction: visor.NewReadableTransaction(tx),
			Status:      tx.Status,
		}
		wh.SendOr404(w, &resTx)
	}
}
Esempio n. 2
0
// TODO
// - split send into
// -- get addresses
// -- get unspent outputs
// -- construct transaction
// -- sign transaction
// -- inject transaction
func Spend(d *daemon.Daemon, v *daemon.Visor, wrpc *WalletRPC,
	walletID wallet.WalletID, amt wallet.Balance, fee uint64,
	dest cipher.Address) *SpendResult {

	txn, err := Spend2(v.Visor, wrpc, walletID, amt, fee, dest)
	errString := ""
	if err != nil {
		errString = err.Error()
		logger.Error("Failed to make a spend: %v", err)
	}

	b, _ := wrpc.GetWalletBalance(v.Visor, walletID)

	if err != nil {
		log.Printf("transaction creation failed: %v", err)
	} else {
		log.Printf("Spend: \ntx= \n %s \n", visor.TransactionToJSON(txn))
	}

	v.Visor.InjectTxn(txn)
	//could call daemon, inject transaction
	//func (self *Visor) InjectTransaction(txn coin.Transaction, pool *Pool) (coin.Transaction, error) {
	//func (self *Visor) BroadcastTransaction(t coin.Transaction, pool *Pool)

	v.BroadcastTransaction(txn, d.Pool)

	return &SpendResult{
		Balance:     b,
		Transaction: visor.NewReadableTransaction(&txn),
		Error:       errString,
	}
}
Esempio n. 3
0
func (self RPC) Spend(v *Visor, pool *Pool, vrpc visor.RPC, amt visor.Balance,
	fee uint64, dest coin.Address) *SpendResult {
	if v.Visor == nil {
		return nil
	}
	txn, err := v.Spend(amt, fee, dest, pool)
	errString := ""
	if err != nil {
		errString = err.Error()
		logger.Error("Failed to make a spend: %v", err)
	}
	b := vrpc.GetTotalBalance(v.Visor, true)
	return &SpendResult{
		RemainingBalance: *b,
		Transaction:      visor.NewReadableTransaction(&txn),
		Error:            errString,
	}
}
Esempio n. 4
0
// getLastTxs get the last confirmed txs.
func getLastTxs(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		if r.Method != "GET" {
			wh.Error405(w, "")
			return
		}
		txs, err := gateway.V.GetLastTxs()
		if err != nil {
			wh.Error500(w, err.Error())
			return
		}

		resTxs := make([]visor.TransactionResult, len(txs))
		for i, tx := range txs {
			resTxs[i] = visor.TransactionResult{
				Transaction: visor.NewReadableTransaction(tx),
				Status:      tx.Status,
			}
		}

		wh.SendOr404(w, &resTxs)
	}
}