Exemple #1
0
func main() {
	if len(os.Args) == 1 {
		showUsage()
	}
	flags.Parse(os.Args[2:])
	matches := argumentRegex.FindStringSubmatch(os.Args[1])
	r, err := websockets.NewRemote(*host)
	checkErr(err)
	glog.Infoln("Connected to: ", *host)
	switch {
	case len(matches) == 0:
		showUsage()
	case len(matches[1]) > 0:
		hash, err := data.NewHash256(matches[1])
		checkErr(err)
		fmt.Println("Getting transaction: ", hash.String())
		result, err := r.Tx(*hash)
		checkErr(err)
		explain(&result.TransactionWithMetaData, terminal.Default)
	case len(matches[2]) > 0:
		seq, err := strconv.ParseUint(matches[2], 10, 32)
		checkErr(err)
		ledger, err := r.Ledger(seq, true)
		checkErr(err)
		fmt.Println("Getting transactions for: ", seq)
		for _, txm := range ledger.Ledger.Transactions {
			explain(txm, terminal.Default)
		}
	case len(matches[3]) > 0:
		account, err := data.NewAccountFromAddress(matches[3])
		checkErr(err)
		fmt.Println("Getting transactions for: ", account.String())
		for txm := range r.AccountTx(*account, *pageSize) {
			explain(txm, terminal.ShowLedgerSequence)
		}
	case len(matches[4]) > 0:
		r := bufio.NewReader(os.Stdin)
		for line, err := r.ReadString('\n'); err == nil; line, err = r.ReadString('\n') {
			// TODO: Accept nodeid:nodedata format
			b, err := hex.DecodeString(line[:len(line)-1])
			checkErr(err)
			var nodeid data.Hash256
			v, err := data.ReadPrefix(bytes.NewReader(b), nodeid)
			checkErr(err)
			terminal.Println(v, terminal.Default)
		}
	}
}
Exemple #2
0
// https://ripplecn.com/bridge?type=quote&amount=1%2FCNY&destination=z&address=ra5tSyQ2cvJUHfAvEdmC89HKSKZTn7xXMw&alipay_account=aa&full_name=bb&contact_info=cc
func (c *MainController) ApiQuote() {
	sa := c.Ctx.Request.URL.Query().Get("amount")
	address := c.Ctx.Request.URL.Query().Get("address")
	bank_name := c.Ctx.Request.URL.Query().Get("bank_name")
	card_number := c.Ctx.Request.URL.Query().Get("card_number")
	full_name := c.Ctx.Request.URL.Query().Get("full_name")
	contact_info := c.Ctx.Request.URL.Query().Get("contact_info")

	a, err := data.NewAmount(sa)
	if err != nil {
		glog.Error(err)
		resp := quoteErrorResp("the query amount err")
		sendResp(resp, c.Ctx)
		return
	}
	glog.Info("ApiQuote:", address, bank_name, card_number, full_name, contact_info, a, a.IsNative())
	sv := a.Value.String()
	am, err := strconv.ParseFloat(sv, 64)
	if err != nil {
		glog.Error(err)
		resp := quoteErrorResp("the query amount err2")
		sendResp(resp, c.Ctx)
		return
	}

	if a.IsNative() {
		pv, _ := data.NewNativeValue(1e6)
		a.Value, _ = a.Value.Divide(*pv)
	}

	currency := a.Currency.String()
	fee := am * models.Gconf.Fees.Rate
	min := models.Gconf.Fees.FeeMap[currency][0]
	max := models.Gconf.Fees.FeeMap[currency][1]
	if fee < min {
		fee = min
	}
	if fee > max {
		fee = max
	}
	acc, err := data.NewAccountFromAddress(models.Gconf.ColdWallet)
	if err != nil {
		glog.Fatal(err)
	}
	a.Issuer = *acc

	u := &models.User{
		UName:     full_name,
		UWallet:   address,
		UBankName: bank_name,
		UBankId:   card_number,
		UContact:  contact_info,
	}

	t := models.Withdrawal
	if a.IsNative() {
		t = models.Redeem
	}
	req, err := models.AddReq("", models.Gconf.ColdWallet, t, u, a.Currency.String(), am/1e6, fee)
	if err != nil {
		// glog.Error(err)
		return
	}

	fv, err := data.NewValue(fmt.Sprintf("%f", fee), a.IsNative())
	if err != nil {
		glog.Fatal(err)
	}

	a.Value, err = a.Value.Add(*fv)
	if err != nil {
		glog.Fatal(err)
	}

	if a.IsNative() {
		pv, _ := data.NewNativeValue(1e6)
		a.Value, _ = a.Value.Divide(*pv)
		a.Currency, _ = data.NewCurrency("ICC")
	}

	quote := &Quote{
		Address:        models.Gconf.ColdWallet,
		DestinationTag: 2147483647,
		Send:           []data.Amount{*a},
		InvoiceID:      req.InvoiceId,
	}
	resp := &QuoteResp{
		Result:    "success",
		QuoteJson: quote,
	}
	glog.Info("Quote:", address, full_name, "OK")
	sendResp(resp, c.Ctx)
}