From 01186c52c83bccffad17dde5a24712b86dc3e68e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 7 Jun 2015 11:53:32 -0400 Subject: Move `sendMoney` func to `purchase` package Create a new package for sending money. Take API keys as args which obviously is not a good idea but it's a hackathon. * Add functions in main.go to initiate hard-coded transactions for house buyer and seller * Move from "com.teddywing" to "github.com/teddywing" --- main.go | 40 +++++++++++++++++++--------------------- purchase/purchase.go | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 21 deletions(-) create mode 100644 purchase/purchase.go diff --git a/main.go b/main.go index adc6ef7..41f09cc 100644 --- a/main.go +++ b/main.go @@ -1,41 +1,39 @@ package main import ( - "com.teddywing/new-house-on-the-block/vendor/_nuts/github.com/fabioberger/coinbase-go" "fmt" "log" "net/http" "os" -) -func sendMoney(from string, to string, amount string) (transaction_id string, err error) { - c := coinbase.ApiKeyClientSandbox(os.Getenv("COINBASE_KEY"), os.Getenv("COINBASE_SECRET")) + "github.com/teddywing/new-house-on-the-block/purchase" +) - params := &coinbase.TransactionParams{ - To: to, - Amount: amount, - Notes: "You just bought a house", +func sendMoneyToSeller() { + transaction_id, err := purchase.SendMoney(os.Getenv("COINBASE_KEY"), + os.Getenv("COINBASE_SECRET"), + "n2Qd6da1jiFgij5SSncFKh7MoFN74GdUxv", + "0.0001") + if err != nil { + log.Println(err) + } else { + fmt.Println(transaction_id) } +} - confirmation, err := c.SendMoney(params) +func sendTokenToBuyer() { + transaction_id, err := purchase.SendMoney(os.Getenv("SELLER_COINBASE_KEY"), + os.Getenv("SELLER_COINBASE_SECRET"), + "mqy3kT6aFHymTcvmdwZLKq1Svo2m6sUtzH", + "0.0001") if err != nil { - return "", err + log.Println(err) } else { - fmt.Println(confirmation.Transaction.Status) - fmt.Println(confirmation.Transaction.Id) - - return confirmation.Transaction.Id, nil + fmt.Println(transaction_id) } } func main() { - // transaction_id, err := sendMoney("TODO", "n2Qd6da1jiFgij5SSncFKh7MoFN74GdUxv", "0.0001") - // if err != nil { - // log.Println(err) - // } else { - // fmt.Println(transaction_id) - // } - fs := http.FileServer(http.Dir("static")) http.Handle("/", fs) diff --git a/purchase/purchase.go b/purchase/purchase.go new file mode 100644 index 0000000..0bce2a4 --- /dev/null +++ b/purchase/purchase.go @@ -0,0 +1,22 @@ +package purchase + +import ( + "github.com/teddywing/new-house-on-the-block/vendor/_nuts/github.com/fabioberger/coinbase-go" +) + +func SendMoney(from_key string, from_secret string, to string, amount string) (transaction_id string, err error) { + c := coinbase.ApiKeyClientSandbox(from_key, from_secret) + + params := &coinbase.TransactionParams{ + To: to, + Amount: amount, + Notes: "You just bought a house", + } + + confirmation, err := c.SendMoney(params) + if err != nil { + return "", err + } else { + return confirmation.Transaction.Id, nil + } +} -- cgit v1.2.3