Skip to content

Commit

Permalink
Add existsmissedtickets support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed May 17, 2017
1 parent 72bfc4b commit 7208596
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions extensions.go
Expand Up @@ -226,6 +226,46 @@ func (c *Client) ExistsAddresses(addresses []dcrutil.Address) (string, error) {
return c.ExistsAddressesAsync(addresses).Receive()
}

// FutureExistsMissedTicketsResult is a future promise to deliver the result of
// an ExistsMissedTicketsAsync RPC invocation (or an applicable error).
type FutureExistsMissedTicketsResult chan *response

// Receive waits for the response promised by the future and returns whether
// or not the ticket exists in the missed ticket database.
func (r FutureExistsMissedTicketsResult) Receive() (string, error) {
res, err := receiveFuture(r)
if err != nil {
return "", err
}

// Unmarshal the result as a string.
var exists string
err = json.Unmarshal(res, &exists)
if err != nil {
return "", err
}
return exists, nil
}

// ExistsMissedTicketsAsync returns an instance of a type that can be used to
// get the result of the RPC at some future time by invoking the Receive
// function on the returned instance.
func (c *Client) ExistsMissedTicketsAsync(hashes []*chainhash.Hash) FutureExistsMissedTicketsResult {
hashBlob := make([]byte, len(hashes)*chainhash.HashSize)
for i, hash := range hashes {
copy(hashBlob[i*chainhash.HashSize:(i+1)*chainhash.HashSize],
hash[:])
}
cmd := dcrjson.NewExistsMissedTicketsCmd(hex.EncodeToString(hashBlob))
return c.sendCmd(cmd)
}

// ExistsMissedTickets returns a hex-encoded bitset describing whether or not
// ticket hashes exists in the missed ticket database.
func (c *Client) ExistsMissedTickets(hashes []*chainhash.Hash) (string, error) {
return c.ExistsMissedTicketsAsync(hashes).Receive()
}

// FutureExistsExpiredTicketsResult is a future promise to deliver the result
// of a FutureExistsExpiredTicketsResultAsync RPC invocation (or an
// applicable error).
Expand Down

0 comments on commit 7208596

Please sign in to comment.