From 24aafc3375d04b8c545b94e30b8df47359091a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Depierrepont?= Date: Fri, 23 May 2014 20:17:13 +0200 Subject: [PATCH] + sendMany, SendToAddress MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Depierrepont --- README.md | 19 ++++++++++++++++++- bitcoind.go | 20 ++++++++++++++++++++ bitcoind_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4574fbc..1094ba6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -go-bitcoind +bitcoind =========== [![Build Status](https://travis-ci.org/Toorop/go-bitcoind.svg)](https://travis-ci.org/Toorop/go-bitcoind) @@ -11,6 +11,23 @@ Documentation ----- [![GoDoc](https://godoc.org/github.com/Toorop/go-bitcoind?status.png)](https://godoc.org/github.com/Toorop/go-bitcoind) +Todo +----- +* https +* GetBlockTemplate +* sendrawtransaction +* signrawtransaction +* setaccount +* setgenerate +* settxfee +* signmessage +* stop +* submitblock +* validateaddress +* verifymessage +* walletlock +* walletpassphrasechange + Donation ------ diff --git a/bitcoind.go b/bitcoind.go index 475a378..c76c803 100644 --- a/bitcoind.go +++ b/bitcoind.go @@ -561,6 +561,26 @@ func (b *Bitcoind) SendFrom(fromAccount, toAddress string, amount float64, minco return } +// SenMany send multiple times +func (b *Bitcoind) SendMany(fromAccount string, amounts map[string]float64, minconf uint32, comment string) (txID string, err error) { + r, err := b.client.call("sendmany", []interface{}{fromAccount, amounts, minconf, comment}) + if err = handleError(err, &r); err != nil { + return + } + err = json.Unmarshal(r.Result, &txID) + return +} + +// SendToAddress send an amount to a given address +func (b *Bitcoind) SendToAddress(toAddress string, amount float64, comment, commentTo string) (txID string, err error) { + r, err := b.client.call("sendtoaddress", []interface{}{toAddress, amount, comment, commentTo}) + if err = handleError(err, &r); err != nil { + return + } + err = json.Unmarshal(r.Result, &txID) + return +} + // walletPassphrase stores the wallet decryption key in memory for seconds. func (b *Bitcoind) WalletPassphrase(passPhrase string, timeout uint64) error { r, err := b.client.call("walletpassphrase", []interface{}{passPhrase, timeout}) diff --git a/bitcoind_test.go b/bitcoind_test.go index dbf8112..fbabed5 100644 --- a/bitcoind_test.go +++ b/bitcoind_test.go @@ -1820,6 +1820,54 @@ var _ = Describe("Bitcoind", func() { }) }) + Describe("Testing SendMany", func() { + Context("when success", func() { + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, `{"result":"ddb9d58a175de0173d6f2d16c5159f3bc747baf3c1af5926d916b185da5b6882","error":null,"id":1400852951961136429}`) + }) + ts, host, port, err := getNewTestServer(handler) + if err != nil { + log.Fatalln(err) + } + defer ts.Close() + bitcoindClient, _ := New(host, port, "x", "fake", false) + amounts := make(map[string]float64) + amounts["1HgpsmxV52eAjDcoNpVGpYEhGfgN7mM1JB"] = 0.0001 + amounts["1Ldfez73eanxUZhudrS62BXqk8BrLxYQFj"] = 0.0001 + txID, err := bitcoindClient.SendMany("tests", amounts, 1, "test sendMany") + It("should not error", func() { + Expect(err).NotTo(HaveOccurred()) + }) + It("should return a transaction ID ", func() { + Expect(txID).Should(Equal("ddb9d58a175de0173d6f2d16c5159f3bc747baf3c1af5926d916b185da5b6882")) + }) + }) + }) + + Describe("Testing SendToAddress", func() { + Context("when success", func() { + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, `{"result":"72cb80e576096d4ea36d7a11df9844c4e416dc45a3701f0592ab1a015780923b","error":null,"id":1400868678615467745}`) + }) + ts, host, port, err := getNewTestServer(handler) + if err != nil { + log.Fatalln(err) + } + defer ts.Close() + bitcoindClient, _ := New(host, port, "x", "fake", false) + amounts := make(map[string]float64) + amounts["1HgpsmxV52eAjDcoNpVGpYEhGfgN7mM1JB"] = 0.0001 + amounts["1Ldfez73eanxUZhudrS62BXqk8BrLxYQFj"] = 0.0001 + txID, err := bitcoindClient.SendToAddress("1Ldfez73eanxUZhudrS62BXqk8BrLxYQFj", 0.0001, "send to address test", "send to cx") + It("should not error", func() { + Expect(err).NotTo(HaveOccurred()) + }) + It("should return a transaction ID ", func() { + Expect(txID).Should(Equal("72cb80e576096d4ea36d7a11df9844c4e416dc45a3701f0592ab1a015780923b")) + }) + }) + }) + /*Describe("walletpassphrase", func() { Context("when success", func() { handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {