func sendRequest(c *node.Client, req *msg.OcReq) *msg.OcResp { // Parse/attach payments if *fDefer != "" { pv, err := msg.NewPaymentValueParseString(*fDefer) if err != nil { log.Fatal(err.Error()) } req.AttachDeferredPayment(pv) } // TODO(ortutay): handle non-deferred payments err := c.SignRequest(req) if err != nil { log.Fatal(err.Error()) } if *fVerbosity > 0 { fmt.Printf("sending request to %v\n%v\n\n", *fAddr, req.String()) } resp, err := c.SendRequest(*fAddr, req) if err != nil { log.Fatal(err.Error()) } fmt.Printf("%v\n", resp.String()) if resp.Status == msg.PLEASE_PAY { var pr msg.PaymentRequest err := json.Unmarshal(resp.Body, &pr) if err != nil { panic(err) } fmt.Printf("Server is requesting payment: %v%v to %v\n", util.S2B(pr.Amount), pr.Currency, pr.Addr) } return resp }
func payBtc(c *node.Client, cmdArgs []string) { amt := cmdArgs[1] addr := cmdArgs[2] pv, err := msg.NewPaymentValueParseString(amt) if err != nil { log.Fatal(err.Error()) } // TODO(ortutay): validate bitcoin address pa := msg.PaymentAddr{ Currency: msg.BTC, Addr: addr, } txid, err := c.SendBtcPayment(pv, &pa) if err != nil { log.Fatal(err.Error()) } fmt.Printf("sent payment, txid: %v\n", txid) }