Skip to content

Commit ed7a480

Browse files
authored
Merge pull request #25 from libsv/feature/issue_21
Fix #21 : Fully document the package
2 parents 58339eb + 7ebd647 commit ed7a480

File tree

2 files changed

+84
-17
lines changed

2 files changed

+84
-17
lines changed

README.md

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,77 @@
1-
# SPV Channels Client in go
1+
# go-spvchannels
22

3-
This repository contains source code implementing SPV Channels Client in golang for the [SPV Channels Server](https://github.com/bitcoin-sv/spvchannels-reference)
3+
[![Release](https://img.shields.io/github/release-pre/libsv/go-spvchannels.svg?logo=github&style=flat&v=1)](https://github.com/libsv/go-spvchannels/releases)
4+
[![Go](https://github.com/libsv/go-bt/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/libsv/go-bt/actions/workflows/run-tests.yml)
5+
[![Go](https://github.com/libsv/go-bt/actions/workflows/run-tests.yml/badge.svg?event=pull_request)](https://github.com/libsv/go-bt/actions/workflows/run-tests.yml)
46

5-
## Setup SPV Channels server
7+
[![Report](https://goreportcard.com/badge/github.com/libsv/go-spvchannels?style=flat&v=1)](https://goreportcard.com/report/github.com/libsv/go-spvchannels)
8+
[![codecov](https://codecov.io/gh/libsv/go-spvchannels/branch/master/graph/badge.svg?v=1)](https://codecov.io/gh/libsv/go-spvchannels)
9+
[![Go](https://img.shields.io/github/go-mod/go-version/libsv/go-spvchannels?v=1)](https://golang.org/)
10+
[![Sponsor](https://img.shields.io/badge/sponsor-libsv-181717.svg?logo=github&style=flat&v=3)](https://github.com/sponsors/libsv)
11+
[![Donate](https://img.shields.io/badge/donate-bitcoin-ff9900.svg?logo=bitcoin&style=flat&v=3)](https://gobitcoinsv.com/#sponsor)
12+
[![Mergify Status][mergify-status]][mergify]
613

14+
[mergify]: https://mergify.io
15+
[mergify-status]: https://img.shields.io/endpoint.svg?url=https://gh.mergify.io/badges/libsv/go-spvchannels&style=flat
16+
<br/>
17+
18+
Go SPV Channels is a [golang](https://golang.org/) implementation of the [SPV Channels Server](https://github.com/bitcoin-sv/spvchannels-reference).
19+
20+
The library implement all rest api endpoints served in [SPV Channels Server](https://github.com/bitcoin-sv/spvchannels-reference) and the websocket client to listen new message notifications in real time.
21+
22+
## Table of Contents
23+
24+
- [Installation](#installation)
25+
- [Run tests](#run-tests)
26+
- [Setup Local SPV Channels server](#setup-local-spv-channels-server)
27+
- [License](#license)
28+
29+
## Installation
30+
```
31+
go get github.com/libsv/go-spvchannels
32+
```
33+
34+
## Run tests
35+
36+
Run unit test
37+
```
38+
go clean -testcache && go test -v ./...
39+
```
40+
41+
To run integration tests, make sure you have `docker-compose up -d` on your local machine, then run
42+
```
43+
go clean -testcache && go test -race -v -tags=integration ./...
44+
```
45+
46+
## Setup Local SPV Channels server
47+
48+
#### Creating SSL key for secure connection
749
Following the tutorial in the [SPV Channels Server](https://github.com/bitcoin-sv/spvchannels-reference), we first create the certificate using `openssl`:
850
```
951
terminal $> openssl req -x509 -out localhost.crt -keyout localhost.key -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' -extensions EXT -config <( printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
1052
terminal $> openssl pkcs12 -export -out devkey.pfx -inkey localhost.key -in localhost.crt # use devkey as password
1153
```
1254

13-
That will create the `devkey.pfx` with password `devkey`. We then write a `docker-compose.yml` file following the tutorial. To run the [SPV Channels Server](https://github.com/bitcoin-sv/spvchannels-reference) :
55+
That will create the `devkey.pfx` with password `devkey`. We then write a `docker-compose.yml` file following the tutorial.
56+
57+
#### Launch local [SPV Channels Server](https://github.com/bitcoin-sv/spvchannels-reference) :
1458
```
1559
docker-compose up -d
1660
```
1761

62+
#### Create an account
1863
We then need to create a SPV Channels account on the server
1964
```
2065
docker exec spvchannels ./SPVChannels.API.Rest -createaccount spvchannels_dev dev dev
2166
```
2267

23-
## Usage with swagger
68+
#### Usage with swagger
2469

2570
The [SPV Channels Server](https://github.com/bitcoin-sv/spvchannels-reference) run by `docker-compose.yml` listen on `localhost:5010`. We can start playing with the endpoints using swagger, i.e in browser, open `https://localhost:5010/swagger/index.html`
2671

2772
From this page, there are a link `/swagger/v1/swagger.json` to export swagger file
2873

29-
## Usage with Postman
74+
#### Usage with Postman
3075

3176
Interacting with browser might have some difficulty related to adding certificate to the system. It might be easier to use Postman to interact as Postman has a easy possibility to disable SSL certificate check to ease development propose.
3277

@@ -49,14 +94,6 @@ These environment variable are used as _template_ to populate values in the `pos
4994
| MSG_SEQUENCE | .. to define .. |
5095
| NOTIFY_TOKEN | .. to define .. |
5196

52-
## Run tests
97+
## License
5398

54-
Run unit test
55-
```
56-
go clean -testcache && go test -v ./...
57-
```
58-
59-
To run integration tests, make sure you have `docker-compose up -d` on your local machine, then run
60-
```
61-
go clean -testcache && go test -race -v -tags=integration ./...
62-
```
99+
![License](https://img.shields.io/github/license/libsv/go-spvchannels.svg?style=flat&v=1)

client.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
// ISC License
2+
//
3+
// Copyright (c) 2018-2020 The libsv developers
4+
//
5+
// Permission to use, copy, modify, and distribute this software for any
6+
// purpose with or without fee is hereby granted, provided that the above
7+
// copyright notice and this permission notice appear in all copies.
8+
//
9+
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
17+
// Package spvchannels is an golang implementation of the spv channel client.
18+
//
19+
// It implement all the rest api endpoints and the weboscket client to
20+
// listen to notifications from channel in real time.
21+
//
22+
// Using the combination of the notification websocket and the rest api
23+
// to pull unread message, users can have a real time message channel.
24+
//
25+
// SPV Channel BRFC
26+
//
27+
// https://github.com/bitcoin-sv-specs/brfc-spvchannels
28+
//
29+
// SPV Channel server
30+
//
31+
// https://github.com/bitcoin-sv/spvchannels-reference
132
package spvchannels
233

334
import (
@@ -180,7 +211,6 @@ type Client struct {
180211
// To set the brearer token authentification (this will ignore the basic authentification if set)
181212
//
182213
// WithToken(t string)
183-
//
184214
func NewClient(opts ...SPVConfigFunc) *Client {
185215

186216
// Start with the defaults then overwrite config with any set by user

0 commit comments

Comments
 (0)