-
Notifications
You must be signed in to change notification settings - Fork 13
/
setup.go
51 lines (43 loc) · 1005 Bytes
/
setup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: ISC
// Copyright (c) 2014-2020 Bitmark Inc.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package rpccalls
import (
"crypto/tls"
"io"
"net"
"net/rpc"
"net/rpc/jsonrpc"
)
// Client - to hold RPC connections streams
type Client struct {
conn net.Conn
client *rpc.Client
testnet bool
verbose bool
handle io.Writer // if verbose is set output items here
}
// NewClient - create a RPC connection to a bitmarkd
func NewClient(testnet bool, connect string, verbose bool, handle io.Writer) (*Client, error) {
tlsConfig := &tls.Config{
InsecureSkipVerify: true,
}
conn, err := tls.Dial("tcp", connect, tlsConfig)
if nil != err {
return nil, err
}
r := &Client{
conn: conn,
client: jsonrpc.NewClient(conn),
testnet: testnet,
verbose: verbose,
handle: handle,
}
return r, nil
}
// Close - shutdown the bitmarkd connection
func (c *Client) Close() {
c.client.Close()
c.conn.Close()
}