1// Copyright (c) 2014-2017 The btcsuite developers
2// Use of this source code is governed by an ISC
3// license that can be found in the LICENSE file.
4
5package rpcclient
6
7import (
8	"bytes"
9	"encoding/hex"
10	"encoding/json"
11
12	"github.com/btcsuite/btcd/btcjson"
13	"github.com/btcsuite/btcd/chaincfg/chainhash"
14	"github.com/btcsuite/btcd/wire"
15	"github.com/btcsuite/btcutil"
16)
17
18const (
19	// defaultMaxFeeRate is the default maximum fee rate in sat/KB enforced
20	// by bitcoind v0.19.0 or after for transaction broadcast.
21	defaultMaxFeeRate = btcutil.SatoshiPerBitcoin / 10
22)
23
24// SigHashType enumerates the available signature hashing types that the
25// SignRawTransaction function accepts.
26type SigHashType string
27
28// Constants used to indicate the signature hash type for SignRawTransaction.
29const (
30	// SigHashAll indicates ALL of the outputs should be signed.
31	SigHashAll SigHashType = "ALL"
32
33	// SigHashNone indicates NONE of the outputs should be signed.  This
34	// can be thought of as specifying the signer does not care where the
35	// bitcoins go.
36	SigHashNone SigHashType = "NONE"
37
38	// SigHashSingle indicates that a SINGLE output should be signed.  This
39	// can be thought of specifying the signer only cares about where ONE of
40	// the outputs goes, but not any of the others.
41	SigHashSingle SigHashType = "SINGLE"
42
43	// SigHashAllAnyoneCanPay indicates that signer does not care where the
44	// other inputs to the transaction come from, so it allows other people
45	// to add inputs.  In addition, it uses the SigHashAll signing method
46	// for outputs.
47	SigHashAllAnyoneCanPay SigHashType = "ALL|ANYONECANPAY"
48
49	// SigHashNoneAnyoneCanPay indicates that signer does not care where the
50	// other inputs to the transaction come from, so it allows other people
51	// to add inputs.  In addition, it uses the SigHashNone signing method
52	// for outputs.
53	SigHashNoneAnyoneCanPay SigHashType = "NONE|ANYONECANPAY"
54
55	// SigHashSingleAnyoneCanPay indicates that signer does not care where
56	// the other inputs to the transaction come from, so it allows other
57	// people to add inputs.  In addition, it uses the SigHashSingle signing
58	// method for outputs.
59	SigHashSingleAnyoneCanPay SigHashType = "SINGLE|ANYONECANPAY"
60)
61
62// String returns the SighHashType in human-readable form.
63func (s SigHashType) String() string {
64	return string(s)
65}
66
67// FutureGetRawTransactionResult is a future promise to deliver the result of a
68// GetRawTransactionAsync RPC invocation (or an applicable error).
69type FutureGetRawTransactionResult chan *response
70
71// Receive waits for the response promised by the future and returns a
72// transaction given its hash.
73func (r FutureGetRawTransactionResult) Receive() (*btcutil.Tx, error) {
74	res, err := receiveFuture(r)
75	if err != nil {
76		return nil, err
77	}
78
79	// Unmarshal result as a string.
80	var txHex string
81	err = json.Unmarshal(res, &txHex)
82	if err != nil {
83		return nil, err
84	}
85
86	// Decode the serialized transaction hex to raw bytes.
87	serializedTx, err := hex.DecodeString(txHex)
88	if err != nil {
89		return nil, err
90	}
91
92	// Deserialize the transaction and return it.
93	var msgTx wire.MsgTx
94	if err := msgTx.Deserialize(bytes.NewReader(serializedTx)); err != nil {
95		return nil, err
96	}
97	return btcutil.NewTx(&msgTx), nil
98}
99
100// GetRawTransactionAsync returns an instance of a type that can be used to get
101// the result of the RPC at some future time by invoking the Receive function on
102// the returned instance.
103//
104// See GetRawTransaction for the blocking version and more details.
105func (c *Client) GetRawTransactionAsync(txHash *chainhash.Hash) FutureGetRawTransactionResult {
106	hash := ""
107	if txHash != nil {
108		hash = txHash.String()
109	}
110
111	cmd := btcjson.NewGetRawTransactionCmd(hash, btcjson.Int(0))
112	return c.sendCmd(cmd)
113}
114
115// GetRawTransaction returns a transaction given its hash.
116//
117// See GetRawTransactionVerbose to obtain additional information about the
118// transaction.
119func (c *Client) GetRawTransaction(txHash *chainhash.Hash) (*btcutil.Tx, error) {
120	return c.GetRawTransactionAsync(txHash).Receive()
121}
122
123// FutureGetRawTransactionVerboseResult is a future promise to deliver the
124// result of a GetRawTransactionVerboseAsync RPC invocation (or an applicable
125// error).
126type FutureGetRawTransactionVerboseResult chan *response
127
128// Receive waits for the response promised by the future and returns information
129// about a transaction given its hash.
130func (r FutureGetRawTransactionVerboseResult) Receive() (*btcjson.TxRawResult, error) {
131	res, err := receiveFuture(r)
132	if err != nil {
133		return nil, err
134	}
135
136	// Unmarshal result as a gettrawtransaction result object.
137	var rawTxResult btcjson.TxRawResult
138	err = json.Unmarshal(res, &rawTxResult)
139	if err != nil {
140		return nil, err
141	}
142
143	return &rawTxResult, nil
144}
145
146// GetRawTransactionVerboseAsync returns an instance of a type that can be used
147// to get the result of the RPC at some future time by invoking the Receive
148// function on the returned instance.
149//
150// See GetRawTransactionVerbose for the blocking version and more details.
151func (c *Client) GetRawTransactionVerboseAsync(txHash *chainhash.Hash) FutureGetRawTransactionVerboseResult {
152	hash := ""
153	if txHash != nil {
154		hash = txHash.String()
155	}
156
157	cmd := btcjson.NewGetRawTransactionCmd(hash, btcjson.Int(1))
158	return c.sendCmd(cmd)
159}
160
161// GetRawTransactionVerbose returns information about a transaction given
162// its hash.
163//
164// See GetRawTransaction to obtain only the transaction already deserialized.
165func (c *Client) GetRawTransactionVerbose(txHash *chainhash.Hash) (*btcjson.TxRawResult, error) {
166	return c.GetRawTransactionVerboseAsync(txHash).Receive()
167}
168
169// FutureDecodeRawTransactionResult is a future promise to deliver the result
170// of a DecodeRawTransactionAsync RPC invocation (or an applicable error).
171type FutureDecodeRawTransactionResult chan *response
172
173// Receive waits for the response promised by the future and returns information
174// about a transaction given its serialized bytes.
175func (r FutureDecodeRawTransactionResult) Receive() (*btcjson.TxRawResult, error) {
176	res, err := receiveFuture(r)
177	if err != nil {
178		return nil, err
179	}
180
181	// Unmarshal result as a decoderawtransaction result object.
182	var rawTxResult btcjson.TxRawResult
183	err = json.Unmarshal(res, &rawTxResult)
184	if err != nil {
185		return nil, err
186	}
187
188	return &rawTxResult, nil
189}
190
191// DecodeRawTransactionAsync returns an instance of a type that can be used to
192// get the result of the RPC at some future time by invoking the Receive
193// function on the returned instance.
194//
195// See DecodeRawTransaction for the blocking version and more details.
196func (c *Client) DecodeRawTransactionAsync(serializedTx []byte) FutureDecodeRawTransactionResult {
197	txHex := hex.EncodeToString(serializedTx)
198	cmd := btcjson.NewDecodeRawTransactionCmd(txHex)
199	return c.sendCmd(cmd)
200}
201
202// DecodeRawTransaction returns information about a transaction given its
203// serialized bytes.
204func (c *Client) DecodeRawTransaction(serializedTx []byte) (*btcjson.TxRawResult, error) {
205	return c.DecodeRawTransactionAsync(serializedTx).Receive()
206}
207
208// FutureCreateRawTransactionResult is a future promise to deliver the result
209// of a CreateRawTransactionAsync RPC invocation (or an applicable error).
210type FutureCreateRawTransactionResult chan *response
211
212// Receive waits for the response promised by the future and returns a new
213// transaction spending the provided inputs and sending to the provided
214// addresses.
215func (r FutureCreateRawTransactionResult) Receive() (*wire.MsgTx, error) {
216	res, err := receiveFuture(r)
217	if err != nil {
218		return nil, err
219	}
220
221	// Unmarshal result as a string.
222	var txHex string
223	err = json.Unmarshal(res, &txHex)
224	if err != nil {
225		return nil, err
226	}
227
228	// Decode the serialized transaction hex to raw bytes.
229	serializedTx, err := hex.DecodeString(txHex)
230	if err != nil {
231		return nil, err
232	}
233
234	// Deserialize the transaction and return it.
235	var msgTx wire.MsgTx
236	if err := msgTx.Deserialize(bytes.NewReader(serializedTx)); err != nil {
237		return nil, err
238	}
239	return &msgTx, nil
240}
241
242// CreateRawTransactionAsync returns an instance of a type that can be used to
243// get the result of the RPC at some future time by invoking the Receive
244// function on the returned instance.
245//
246// See CreateRawTransaction for the blocking version and more details.
247func (c *Client) CreateRawTransactionAsync(inputs []btcjson.TransactionInput,
248	amounts map[btcutil.Address]btcutil.Amount, lockTime *int64) FutureCreateRawTransactionResult {
249
250	convertedAmts := make(map[string]float64, len(amounts))
251	for addr, amount := range amounts {
252		convertedAmts[addr.String()] = amount.ToBTC()
253	}
254	cmd := btcjson.NewCreateRawTransactionCmd(inputs, convertedAmts, lockTime)
255	return c.sendCmd(cmd)
256}
257
258// CreateRawTransaction returns a new transaction spending the provided inputs
259// and sending to the provided addresses.
260func (c *Client) CreateRawTransaction(inputs []btcjson.TransactionInput,
261	amounts map[btcutil.Address]btcutil.Amount, lockTime *int64) (*wire.MsgTx, error) {
262
263	return c.CreateRawTransactionAsync(inputs, amounts, lockTime).Receive()
264}
265
266// FutureSendRawTransactionResult is a future promise to deliver the result
267// of a SendRawTransactionAsync RPC invocation (or an applicable error).
268type FutureSendRawTransactionResult chan *response
269
270// Receive waits for the response promised by the future and returns the result
271// of submitting the encoded transaction to the server which then relays it to
272// the network.
273func (r FutureSendRawTransactionResult) Receive() (*chainhash.Hash, error) {
274	res, err := receiveFuture(r)
275	if err != nil {
276		return nil, err
277	}
278
279	// Unmarshal result as a string.
280	var txHashStr string
281	err = json.Unmarshal(res, &txHashStr)
282	if err != nil {
283		return nil, err
284	}
285
286	return chainhash.NewHashFromStr(txHashStr)
287}
288
289// SendRawTransactionAsync returns an instance of a type that can be used to get
290// the result of the RPC at some future time by invoking the Receive function on
291// the returned instance.
292//
293// See SendRawTransaction for the blocking version and more details.
294func (c *Client) SendRawTransactionAsync(tx *wire.MsgTx, allowHighFees bool) FutureSendRawTransactionResult {
295	txHex := ""
296	if tx != nil {
297		// Serialize the transaction and convert to hex string.
298		buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
299		if err := tx.Serialize(buf); err != nil {
300			return newFutureError(err)
301		}
302		txHex = hex.EncodeToString(buf.Bytes())
303	}
304
305	// Due to differences in the sendrawtransaction API for different
306	// backends, we'll need to inspect our version and construct the
307	// appropriate request.
308	version, err := c.BackendVersion()
309	if err != nil {
310		return newFutureError(err)
311	}
312
313	var cmd *btcjson.SendRawTransactionCmd
314	switch version {
315	// Starting from bitcoind v0.19.0, the MaxFeeRate field should be used.
316	case BitcoindPost19:
317		// Using a 0 MaxFeeRate is interpreted as a maximum fee rate not
318		// being enforced by bitcoind.
319		var maxFeeRate int32
320		if !allowHighFees {
321			maxFeeRate = defaultMaxFeeRate
322		}
323		cmd = btcjson.NewBitcoindSendRawTransactionCmd(txHex, maxFeeRate)
324
325	// Otherwise, use the AllowHighFees field.
326	default:
327		cmd = btcjson.NewSendRawTransactionCmd(txHex, &allowHighFees)
328	}
329
330	return c.sendCmd(cmd)
331}
332
333// SendRawTransaction submits the encoded transaction to the server which will
334// then relay it to the network.
335func (c *Client) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) (*chainhash.Hash, error) {
336	return c.SendRawTransactionAsync(tx, allowHighFees).Receive()
337}
338
339// FutureSignRawTransactionResult is a future promise to deliver the result
340// of one of the SignRawTransactionAsync family of RPC invocations (or an
341// applicable error).
342type FutureSignRawTransactionResult chan *response
343
344// Receive waits for the response promised by the future and returns the
345// signed transaction as well as whether or not all inputs are now signed.
346func (r FutureSignRawTransactionResult) Receive() (*wire.MsgTx, bool, error) {
347	res, err := receiveFuture(r)
348	if err != nil {
349		return nil, false, err
350	}
351
352	// Unmarshal as a signrawtransaction result.
353	var signRawTxResult btcjson.SignRawTransactionResult
354	err = json.Unmarshal(res, &signRawTxResult)
355	if err != nil {
356		return nil, false, err
357	}
358
359	// Decode the serialized transaction hex to raw bytes.
360	serializedTx, err := hex.DecodeString(signRawTxResult.Hex)
361	if err != nil {
362		return nil, false, err
363	}
364
365	// Deserialize the transaction and return it.
366	var msgTx wire.MsgTx
367	if err := msgTx.Deserialize(bytes.NewReader(serializedTx)); err != nil {
368		return nil, false, err
369	}
370
371	return &msgTx, signRawTxResult.Complete, nil
372}
373
374// SignRawTransactionAsync returns an instance of a type that can be used to get
375// the result of the RPC at some future time by invoking the Receive function on
376// the returned instance.
377//
378// See SignRawTransaction for the blocking version and more details.
379func (c *Client) SignRawTransactionAsync(tx *wire.MsgTx) FutureSignRawTransactionResult {
380	txHex := ""
381	if tx != nil {
382		// Serialize the transaction and convert to hex string.
383		buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
384		if err := tx.Serialize(buf); err != nil {
385			return newFutureError(err)
386		}
387		txHex = hex.EncodeToString(buf.Bytes())
388	}
389
390	cmd := btcjson.NewSignRawTransactionCmd(txHex, nil, nil, nil)
391	return c.sendCmd(cmd)
392}
393
394// SignRawTransaction signs inputs for the passed transaction and returns the
395// signed transaction as well as whether or not all inputs are now signed.
396//
397// This function assumes the RPC server already knows the input transactions and
398// private keys for the passed transaction which needs to be signed and uses the
399// default signature hash type.  Use one of the SignRawTransaction# variants to
400// specify that information if needed.
401func (c *Client) SignRawTransaction(tx *wire.MsgTx) (*wire.MsgTx, bool, error) {
402	return c.SignRawTransactionAsync(tx).Receive()
403}
404
405// SignRawTransaction2Async returns an instance of a type that can be used to
406// get the result of the RPC at some future time by invoking the Receive
407// function on the returned instance.
408//
409// See SignRawTransaction2 for the blocking version and more details.
410func (c *Client) SignRawTransaction2Async(tx *wire.MsgTx, inputs []btcjson.RawTxInput) FutureSignRawTransactionResult {
411	txHex := ""
412	if tx != nil {
413		// Serialize the transaction and convert to hex string.
414		buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
415		if err := tx.Serialize(buf); err != nil {
416			return newFutureError(err)
417		}
418		txHex = hex.EncodeToString(buf.Bytes())
419	}
420
421	cmd := btcjson.NewSignRawTransactionCmd(txHex, &inputs, nil, nil)
422	return c.sendCmd(cmd)
423}
424
425// SignRawTransaction2 signs inputs for the passed transaction given the list
426// of information about the input transactions needed to perform the signing
427// process.
428//
429// This only input transactions that need to be specified are ones the
430// RPC server does not already know.  Already known input transactions will be
431// merged with the specified transactions.
432//
433// See SignRawTransaction if the RPC server already knows the input
434// transactions.
435func (c *Client) SignRawTransaction2(tx *wire.MsgTx, inputs []btcjson.RawTxInput) (*wire.MsgTx, bool, error) {
436	return c.SignRawTransaction2Async(tx, inputs).Receive()
437}
438
439// SignRawTransaction3Async returns an instance of a type that can be used to
440// get the result of the RPC at some future time by invoking the Receive
441// function on the returned instance.
442//
443// See SignRawTransaction3 for the blocking version and more details.
444func (c *Client) SignRawTransaction3Async(tx *wire.MsgTx,
445	inputs []btcjson.RawTxInput,
446	privKeysWIF []string) FutureSignRawTransactionResult {
447
448	txHex := ""
449	if tx != nil {
450		// Serialize the transaction and convert to hex string.
451		buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
452		if err := tx.Serialize(buf); err != nil {
453			return newFutureError(err)
454		}
455		txHex = hex.EncodeToString(buf.Bytes())
456	}
457
458	cmd := btcjson.NewSignRawTransactionCmd(txHex, &inputs, &privKeysWIF,
459		nil)
460	return c.sendCmd(cmd)
461}
462
463// SignRawTransaction3 signs inputs for the passed transaction given the list
464// of information about extra input transactions and a list of private keys
465// needed to perform the signing process.  The private keys must be in wallet
466// import format (WIF).
467//
468// This only input transactions that need to be specified are ones the
469// RPC server does not already know.  Already known input transactions will be
470// merged with the specified transactions.  This means the list of transaction
471// inputs can be nil if the RPC server already knows them all.
472//
473// NOTE: Unlike the merging functionality of the input transactions, ONLY the
474// specified private keys will be used, so even if the server already knows some
475// of the private keys, they will NOT be used.
476//
477// See SignRawTransaction if the RPC server already knows the input
478// transactions and private keys or SignRawTransaction2 if it already knows the
479// private keys.
480func (c *Client) SignRawTransaction3(tx *wire.MsgTx,
481	inputs []btcjson.RawTxInput,
482	privKeysWIF []string) (*wire.MsgTx, bool, error) {
483
484	return c.SignRawTransaction3Async(tx, inputs, privKeysWIF).Receive()
485}
486
487// SignRawTransaction4Async returns an instance of a type that can be used to
488// get the result of the RPC at some future time by invoking the Receive
489// function on the returned instance.
490//
491// See SignRawTransaction4 for the blocking version and more details.
492func (c *Client) SignRawTransaction4Async(tx *wire.MsgTx,
493	inputs []btcjson.RawTxInput, privKeysWIF []string,
494	hashType SigHashType) FutureSignRawTransactionResult {
495
496	txHex := ""
497	if tx != nil {
498		// Serialize the transaction and convert to hex string.
499		buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
500		if err := tx.Serialize(buf); err != nil {
501			return newFutureError(err)
502		}
503		txHex = hex.EncodeToString(buf.Bytes())
504	}
505
506	cmd := btcjson.NewSignRawTransactionCmd(txHex, &inputs, &privKeysWIF,
507		btcjson.String(string(hashType)))
508	return c.sendCmd(cmd)
509}
510
511// SignRawTransaction4 signs inputs for the passed transaction using the
512// the specified signature hash type given the list of information about extra
513// input transactions and a potential list of private keys needed to perform
514// the signing process.  The private keys, if specified, must be in wallet
515// import format (WIF).
516//
517// The only input transactions that need to be specified are ones the RPC server
518// does not already know.  This means the list of transaction inputs can be nil
519// if the RPC server already knows them all.
520//
521// NOTE: Unlike the merging functionality of the input transactions, ONLY the
522// specified private keys will be used, so even if the server already knows some
523// of the private keys, they will NOT be used.  The list of private keys can be
524// nil in which case any private keys the RPC server knows will be used.
525//
526// This function should only used if a non-default signature hash type is
527// desired.  Otherwise, see SignRawTransaction if the RPC server already knows
528// the input transactions and private keys, SignRawTransaction2 if it already
529// knows the private keys, or SignRawTransaction3 if it does not know both.
530func (c *Client) SignRawTransaction4(tx *wire.MsgTx,
531	inputs []btcjson.RawTxInput, privKeysWIF []string,
532	hashType SigHashType) (*wire.MsgTx, bool, error) {
533
534	return c.SignRawTransaction4Async(tx, inputs, privKeysWIF,
535		hashType).Receive()
536}
537
538// FutureSearchRawTransactionsResult is a future promise to deliver the result
539// of the SearchRawTransactionsAsync RPC invocation (or an applicable error).
540type FutureSearchRawTransactionsResult chan *response
541
542// Receive waits for the response promised by the future and returns the
543// found raw transactions.
544func (r FutureSearchRawTransactionsResult) Receive() ([]*wire.MsgTx, error) {
545	res, err := receiveFuture(r)
546	if err != nil {
547		return nil, err
548	}
549
550	// Unmarshal as an array of strings.
551	var searchRawTxnsResult []string
552	err = json.Unmarshal(res, &searchRawTxnsResult)
553	if err != nil {
554		return nil, err
555	}
556
557	// Decode and deserialize each transaction.
558	msgTxns := make([]*wire.MsgTx, 0, len(searchRawTxnsResult))
559	for _, hexTx := range searchRawTxnsResult {
560		// Decode the serialized transaction hex to raw bytes.
561		serializedTx, err := hex.DecodeString(hexTx)
562		if err != nil {
563			return nil, err
564		}
565
566		// Deserialize the transaction and add it to the result slice.
567		var msgTx wire.MsgTx
568		err = msgTx.Deserialize(bytes.NewReader(serializedTx))
569		if err != nil {
570			return nil, err
571		}
572		msgTxns = append(msgTxns, &msgTx)
573	}
574
575	return msgTxns, nil
576}
577
578// SearchRawTransactionsAsync returns an instance of a type that can be used to
579// get the result of the RPC at some future time by invoking the Receive
580// function on the returned instance.
581//
582// See SearchRawTransactions for the blocking version and more details.
583func (c *Client) SearchRawTransactionsAsync(address btcutil.Address, skip, count int, reverse bool, filterAddrs []string) FutureSearchRawTransactionsResult {
584	addr := address.EncodeAddress()
585	verbose := btcjson.Int(0)
586	cmd := btcjson.NewSearchRawTransactionsCmd(addr, verbose, &skip, &count,
587		nil, &reverse, &filterAddrs)
588	return c.sendCmd(cmd)
589}
590
591// SearchRawTransactions returns transactions that involve the passed address.
592//
593// NOTE: Chain servers do not typically provide this capability unless it has
594// specifically been enabled.
595//
596// See SearchRawTransactionsVerbose to retrieve a list of data structures with
597// information about the transactions instead of the transactions themselves.
598func (c *Client) SearchRawTransactions(address btcutil.Address, skip, count int, reverse bool, filterAddrs []string) ([]*wire.MsgTx, error) {
599	return c.SearchRawTransactionsAsync(address, skip, count, reverse, filterAddrs).Receive()
600}
601
602// FutureSearchRawTransactionsVerboseResult is a future promise to deliver the
603// result of the SearchRawTransactionsVerboseAsync RPC invocation (or an
604// applicable error).
605type FutureSearchRawTransactionsVerboseResult chan *response
606
607// Receive waits for the response promised by the future and returns the
608// found raw transactions.
609func (r FutureSearchRawTransactionsVerboseResult) Receive() ([]*btcjson.SearchRawTransactionsResult, error) {
610	res, err := receiveFuture(r)
611	if err != nil {
612		return nil, err
613	}
614
615	// Unmarshal as an array of raw transaction results.
616	var result []*btcjson.SearchRawTransactionsResult
617	err = json.Unmarshal(res, &result)
618	if err != nil {
619		return nil, err
620	}
621
622	return result, nil
623}
624
625// SearchRawTransactionsVerboseAsync returns an instance of a type that can be
626// used to get the result of the RPC at some future time by invoking the Receive
627// function on the returned instance.
628//
629// See SearchRawTransactionsVerbose for the blocking version and more details.
630func (c *Client) SearchRawTransactionsVerboseAsync(address btcutil.Address, skip,
631	count int, includePrevOut, reverse bool, filterAddrs *[]string) FutureSearchRawTransactionsVerboseResult {
632
633	addr := address.EncodeAddress()
634	verbose := btcjson.Int(1)
635	var prevOut *int
636	if includePrevOut {
637		prevOut = btcjson.Int(1)
638	}
639	cmd := btcjson.NewSearchRawTransactionsCmd(addr, verbose, &skip, &count,
640		prevOut, &reverse, filterAddrs)
641	return c.sendCmd(cmd)
642}
643
644// SearchRawTransactionsVerbose returns a list of data structures that describe
645// transactions which involve the passed address.
646//
647// NOTE: Chain servers do not typically provide this capability unless it has
648// specifically been enabled.
649//
650// See SearchRawTransactions to retrieve a list of raw transactions instead.
651func (c *Client) SearchRawTransactionsVerbose(address btcutil.Address, skip,
652	count int, includePrevOut, reverse bool, filterAddrs []string) ([]*btcjson.SearchRawTransactionsResult, error) {
653
654	return c.SearchRawTransactionsVerboseAsync(address, skip, count,
655		includePrevOut, reverse, &filterAddrs).Receive()
656}
657
658// FutureDecodeScriptResult is a future promise to deliver the result
659// of a DecodeScriptAsync RPC invocation (or an applicable error).
660type FutureDecodeScriptResult chan *response
661
662// Receive waits for the response promised by the future and returns information
663// about a script given its serialized bytes.
664func (r FutureDecodeScriptResult) Receive() (*btcjson.DecodeScriptResult, error) {
665	res, err := receiveFuture(r)
666	if err != nil {
667		return nil, err
668	}
669
670	// Unmarshal result as a decodescript result object.
671	var decodeScriptResult btcjson.DecodeScriptResult
672	err = json.Unmarshal(res, &decodeScriptResult)
673	if err != nil {
674		return nil, err
675	}
676
677	return &decodeScriptResult, nil
678}
679
680// DecodeScriptAsync returns an instance of a type that can be used to
681// get the result of the RPC at some future time by invoking the Receive
682// function on the returned instance.
683//
684// See DecodeScript for the blocking version and more details.
685func (c *Client) DecodeScriptAsync(serializedScript []byte) FutureDecodeScriptResult {
686	scriptHex := hex.EncodeToString(serializedScript)
687	cmd := btcjson.NewDecodeScriptCmd(scriptHex)
688	return c.sendCmd(cmd)
689}
690
691// DecodeScript returns information about a script given its serialized bytes.
692func (c *Client) DecodeScript(serializedScript []byte) (*btcjson.DecodeScriptResult, error) {
693	return c.DecodeScriptAsync(serializedScript).Receive()
694}
695