Example #1
0
func main() {
	registerFlags()
	flag.Parse()

	coin.SetAddressVersion(addressVersion)

	v, gb, err := createGenesisVisor(masterKeys, bcFile, bsFile)
	handleError(err)
	if destAddress != "" {
		addr, err := coin.DecodeBase58Address(destAddress)
		handleError(err)
		_, err = transferAllToAddress(v, gb, addr)
		handleError(err)
		fmt.Printf("Transferred genesis balance to %s\n", destAddress)
	}

	err = v.SaveBlockchain()
	handleError(err)
	fmt.Printf("Saved blockchain to %s\n", bcFile)
	err = v.SaveBlockSigs()
	handleError(err)
	fmt.Printf("Saved blockchain signatures to %s\n", bsFile)

	if showHelp {
		fmt.Println("To get the timestamp:")
		fmt.Printf("\tgo run cmd/blockchain/blockchain.go -i %s -timestamp=true\n",
			bcFile)
		fmt.Println("To get the genesis block signature:")
		fmt.Printf("\tgo run cmd/blocksigs/blocksigs.go -i %s\n", bsFile)
	}
}
Example #2
0
func walletSpendHandler(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		sdst := r.FormValue("dst")
		if sdst == "" {
			Error400(w, "Missing destination address \"dst\"")
			return
		}
		dst, err := coin.DecodeBase58Address(sdst)
		if err != nil {
			Error400(w, "Invalid destination address")
			return
		}
		sfee := r.FormValue("fee")
		fee, err := strconv.ParseUint(sfee, 10, 64)
		if err != nil {
			Error400(w, "Invalid \"fee\" value")
			return
		}
		scoins := r.FormValue("coins")
		shours := r.FormValue("hours")
		coins, err := strconv.ParseUint(scoins, 10, 64)
		if err != nil {
			Error400(w, "Invalid \"coins\" value")
			return
		}
		hours, err := strconv.ParseUint(shours, 10, 64)
		if err != nil {
			Error400(w, "Invalid \"hours\" value")
			return
		}
		SendOr404(w, gateway.Spend(visor.NewBalance(coins, hours), fee, dst))
	}
}
Example #3
0
func walletAddressTransactionsHandler(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		saddr := r.FormValue("addr")
		addr, err := coin.DecodeBase58Address(saddr)
		if err != nil {
			Error404(w)
			return
		}
		SendOr404(w, gateway.GetAddressTransactions(addr))
	}
}
Example #4
0
func walletBalanceHandler(gateway *daemon.Gateway) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		saddr := r.FormValue("addr")
		predicted := r.FormValue("predicted")
		var m interface{}
		if saddr == "" {
			m = gateway.GetTotalBalance(predicted != "")
		} else {
			addr, err := coin.DecodeBase58Address(saddr)
			if err != nil {
				Error400(w, "Invalid address")
				return
			}
			m = gateway.GetBalance(addr, predicted != "")
		}
		SendOr404(w, m)
	}
}