mirror of
https://github.com/btcsuite/btcd.git
synced 2024-11-19 18:00:11 +01:00
Add version
command to JSON-RPC API for API versioning
This commit is contained in:
parent
7903290fd9
commit
0519b86a9d
3
LICENSE
3
LICENSE
@ -1,6 +1,7 @@
|
|||||||
ISC License
|
ISC License
|
||||||
|
|
||||||
Copyright (c) 2014-2015 Conformal Systems LLC.
|
Copyright (c) 2014-2016 The btcsuite developers
|
||||||
|
Copyright (c) 2015-2016 The Decred developers
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
Permission to use, copy, modify, and distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// Copyright (c) 2014-2015 The btcsuite developers
|
// Copyright (c) 2014-2016 The btcsuite developers
|
||||||
|
// Copyright (c) 2015-2016 The Decred developers
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
@ -348,3 +349,53 @@ func (c *Client) SessionAsync() FutureSessionResult {
|
|||||||
func (c *Client) Session() (*btcjson.SessionResult, error) {
|
func (c *Client) Session() (*btcjson.SessionResult, error) {
|
||||||
return c.SessionAsync().Receive()
|
return c.SessionAsync().Receive()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FutureVersionResult is a future promise to delivere the result of a version
|
||||||
|
// RPC invocation (or an applicable error).
|
||||||
|
//
|
||||||
|
// NOTE: This is a btcsuite extension ported from
|
||||||
|
// github.com/decred/dcrrpcclient.
|
||||||
|
type FutureVersionResult chan *response
|
||||||
|
|
||||||
|
// Receive waits for the response promised by the future and returns the version
|
||||||
|
// result.
|
||||||
|
//
|
||||||
|
// NOTE: This is a btcsuite extension ported from
|
||||||
|
// github.com/decred/dcrrpcclient.
|
||||||
|
func (r FutureVersionResult) Receive() (map[string]btcjson.VersionResult,
|
||||||
|
error) {
|
||||||
|
res, err := receiveFuture(r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unmarshal result as a version result object.
|
||||||
|
var vr map[string]btcjson.VersionResult
|
||||||
|
err = json.Unmarshal(res, &vr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return vr, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// VersionAsync 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.
|
||||||
|
//
|
||||||
|
// See Version for the blocking version and more details.
|
||||||
|
//
|
||||||
|
// NOTE: This is a btcsuite extension ported from
|
||||||
|
// github.com/decred/dcrrpcclient.
|
||||||
|
func (c *Client) VersionAsync() FutureVersionResult {
|
||||||
|
cmd := btcjson.NewVersionCmd()
|
||||||
|
return c.sendCmd(cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version returns information about the server's JSON-RPC API versions.
|
||||||
|
//
|
||||||
|
// NOTE: This is a btcsuite extension ported from
|
||||||
|
// github.com/decred/dcrrpcclient.
|
||||||
|
func (c *Client) Version() (map[string]btcjson.VersionResult, error) {
|
||||||
|
return c.VersionAsync().Receive()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user