Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(options ...option) *service
New returns a high fidelity mock RTWire service. The *service struct implements http.Handler and exposes HTTP endpoints identical to those described in https://rtwire.com/docs. This means *service can be combined httptest.Server to unit test your RTWire integration code locally. For example:
s := httptest.NewServer(cervice.New()) defer s.Close() req, err := http.NewRequest("GET", s.URL+"/v1/mainnet/accounts", nil) req.SetBasicAuth("user", "pass") req.Header.Set("Content-Type", "application/json") resp, err := http.DefaultClient.Do(req) // Handle error if not nil. resp.Body will contain a JSON object with all // accounts created so far with the mock service.
This will allow the s.URL to expose the same HTTP endpoints as RTWire's. See https://github.com/rtwire/go/client/ for examples. Importantly this mock service exposes one extra endpoint:
POST /v1/[network]/addresses/[address]
This endpoint can be passed the folliwng JSON object that will credit the account at address [address] with value [value].
{ "value": [value] }
Note that you must specify a "Content-Type: application/json" header with this endpoint. Using this endpoint is the equivalent to receiving bitcoins from the network.
The default basic authentication username is user is 'user' and password is 'pass'. Both can be changed by using the UserPass option.