From 28ebec9e925d37cd240c6f44348163dd9f4b64eb Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Tue, 16 Nov 2021 14:16:34 -0500 Subject: [PATCH] Added new miner: GorillaPool Closes #39 --- README.md | 9 +++++++-- best_quote_test.go | 22 ++++++++++++++++++++++ client_test.go | 10 +++++++--- config.go | 11 ++++++++++- fastest_quote_test.go | 20 ++++++++++++++++++++ fee_quote_test.go | 14 +++++++++++--- 6 files changed, 77 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 464ba83..2e0f73c 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,11 @@ View documentation on hosting your own [mAPI server](https://github.com/bitcoin- - `FastestQuote()` asks all miners and returns the fastest quote response - `BestQuote()` gets all quotes from miners and return the best rate/quote - `CalculateFee()` returns the fee for a given transaction +- Public Available Miners: + - [TAAl](https://tpow.app/a0f9475a) + - [Mempool](https://tpow.app/361a5570) + - [Matterpool](https://tpow.app/66b32fae) + - [GorillaPool](https://tpow.app/43adc27e)
Library Deployment @@ -155,8 +160,8 @@ View the [examples](examples) ## Maintainers | [MrZ](https://github.com/mrz1836) | -|:---:| -| [MrZ](https://github.com/mrz1836) | +|:------------------------------------------------------------------------------------------------:| +| [MrZ](https://github.com/mrz1836) |
diff --git a/best_quote_test.go b/best_quote_test.go index dca66bd..d915ec1 100644 --- a/best_quote_test.go +++ b/best_quote_test.go @@ -49,6 +49,13 @@ func (m *mockHTTPValidBestQuote) Do(req *http.Request) (*http.Response, error) { "signature": null,"publicKey": null,"encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } + if req.URL.String() == feeQuoteURLGorillaPool { + resp.StatusCode = http.StatusOK + resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T22:09:04.433Z\",\"expiryTime\":\"2020-10-09T22:19:04.433Z\",\"minerId\":null,\"currentHighestBlockHash\":\"0000000000000000101c34c7cabadbff321f125fac9ba3c2b1294c4d81085f4a\",\"currentHighestBlockHeight\":713780,\"minerReputation\":null,\"fees\":[{\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}}]}", + "signature": null,"publicKey": null,"encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) + } + // Default is valid return resp, nil } @@ -88,6 +95,11 @@ func (m *mockHTTPBadRate) Do(req *http.Request) (*http.Response, error) { resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(``))) } + if req.URL.String() == feeQuoteURLGorillaPool { + resp.StatusCode = http.StatusBadRequest + resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(``))) + } + // Default is valid return resp, nil } @@ -116,6 +128,11 @@ func (m *mockHTTPBestQuoteTwoFailed) Do(req *http.Request) (*http.Response, erro resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(``))) } + if req.URL.String() == feeQuoteURLGorillaPool { + resp.StatusCode = http.StatusBadRequest + resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(``))) + } + if req.URL.String() == feeQuoteURLMempool { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ @@ -156,6 +173,11 @@ func (m *mockHTTPBestQuoteAllFailed) Do(req *http.Request) (*http.Response, erro resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(``))) } + if req.URL.String() == feeQuoteURLGorillaPool { + resp.StatusCode = http.StatusBadRequest + resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(``))) + } + // Default is valid return resp, nil } diff --git a/client_test.go b/client_test.go index 6c9f56c..6ba451a 100644 --- a/client_test.go +++ b/client_test.go @@ -61,7 +61,7 @@ func TestNewClient(t *testing.T) { assert.NoError(t, err) // Test default miners - assert.Equal(t, 3, len(client.Miners)) + assert.Equal(t, 4, len(client.Miners)) }) t.Run("custom http client", func(t *testing.T) { @@ -86,6 +86,10 @@ func TestNewClient(t *testing.T) { // Get Matterpool miner = client.MinerByName(MinerMatterpool) assert.Equal(t, MinerMatterpool, miner.Name) + + // Get GorillaPool + miner = client.MinerByName(MinerGorillaPool) + assert.Equal(t, MinerGorillaPool, miner.Name) }) t.Run("custom miners", func(t *testing.T) { @@ -117,7 +121,7 @@ func ExampleNewClient() { } fmt.Printf("created new client with %d default miners", len(client.Miners)) - // Output:created new client with 3 default miners + // Output:created new client with 4 default miners } // BenchmarkNewClient benchmarks the method NewClient() @@ -576,7 +580,7 @@ func ExampleClient_RemoveMiner() { // Show response fmt.Printf("total miners: %d", len(client.Miners)) - // Output:total miners: 2 + // Output:total miners: 3 } // BenchmarkClient_RemoveMiner benchmarks the method RemoveMiner() diff --git a/config.go b/config.go index 0dd2a93..524ed85 100644 --- a/config.go +++ b/config.go @@ -5,7 +5,7 @@ import "time" const ( // version is the current package version - version = "v0.3.3" + version = "v0.3.4" // defaultUserAgent is the default user agent for all requests defaultUserAgent string = "go-minercraft: " + version @@ -34,6 +34,9 @@ const ( // MinerMatterpool is the name of the known miner for "Matterpool" MinerMatterpool = "Matterpool" + + // MinerGorillaPool is the name of the known miner for "GorillaPool" + MinerGorillaPool = "GorillaPool" ) // KnownMiners is a pre-filled list of known miners @@ -58,6 +61,12 @@ const KnownMiners = ` "miner_id": "0211ccfc29e3058b770f3cf3eb34b0b2fd2293057a994d4d275121be4151cdf087", "token": "", "url": "https://merchantapi.matterpool.io" + }, + { + "name": "GorillaPool", + "miner_id": "03ad780153c47df915b3d2e23af727c68facaca4facd5f155bf5018b979b9aeb83", + "token": "", + "url": "https://merchantapi.gorillapool.io" } ] ` diff --git a/fastest_quote_test.go b/fastest_quote_test.go index bee68d8..fb43644 100644 --- a/fastest_quote_test.go +++ b/fastest_quote_test.go @@ -50,6 +50,13 @@ func (m *mockHTTPValidFastestQuote) Do(req *http.Request) (*http.Response, error "signature": null,"publicKey": null,"encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } + if req.URL.String() == feeQuoteURLGorillaPool { + resp.StatusCode = http.StatusOK + resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T22:09:04.433Z\",\"expiryTime\":\"2020-10-09T22:19:04.433Z\",\"minerId\":null,\"currentHighestBlockHash\":\"0000000000000000101c34c7cabadbff321f125fac9ba3c2b1294c4d81085f4a\",\"currentHighestBlockHeight\":713780,\"minerReputation\":null,\"fees\":[{\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}}]}", + "signature": null,"publicKey": null,"encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) + } + // Default is valid return resp, nil } @@ -94,6 +101,14 @@ func (m *mockHTTPValidFastestQuoteSlow) Do(req *http.Request) (*http.Response, e "signature": null,"publicKey": null,"encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } + if req.URL.String() == feeQuoteURLGorillaPool { + time.Sleep(3 * time.Second) + resp.StatusCode = http.StatusOK + resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T22:09:04.433Z\",\"expiryTime\":\"2020-10-09T22:19:04.433Z\",\"minerId\":null,\"currentHighestBlockHash\":\"0000000000000000101c34c7cabadbff321f125fac9ba3c2b1294c4d81085f4a\",\"currentHighestBlockHeight\":713780,\"minerReputation\":null,\"fees\":[{\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}}]}", + "signature": null,"publicKey": null,"encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) + } + // Default is valid return resp, nil } @@ -122,6 +137,11 @@ func (m *mockHTTPFastestQuoteTwoFailed) Do(req *http.Request) (*http.Response, e resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(``))) } + if req.URL.String() == feeQuoteURLGorillaPool { + resp.StatusCode = http.StatusBadRequest + resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(``))) + } + if req.URL.String() == feeQuoteURLMempool { resp.StatusCode = http.StatusOK resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ diff --git a/fee_quote_test.go b/fee_quote_test.go index c6916e2..d0977f0 100644 --- a/fee_quote_test.go +++ b/fee_quote_test.go @@ -181,9 +181,10 @@ func (m *mockHTTPInvalidSignature) Do(req *http.Request) (*http.Response, error) type mockHTTPBetterRate struct{} const ( - feeQuoteURLMatterPool = "https://merchantapi.matterpool.io/mapi/feeQuote" - feeQuoteURLMempool = "https://www.ddpurse.com/openapi/mapi/feeQuote" - feeQuoteURLTaal = "https://merchantapi.taal.com/mapi/feeQuote" + feeQuoteURLMatterPool = "https://merchantapi.matterpool.io/mapi/feeQuote" + feeQuoteURLMempool = "https://www.ddpurse.com/openapi/mapi/feeQuote" + feeQuoteURLTaal = "https://merchantapi.taal.com/mapi/feeQuote" + feeQuoteURLGorillaPool = "https://merchantapi.gorillapool.io/mapi/feeQuote" ) // Do is a mock http request @@ -220,6 +221,13 @@ func (m *mockHTTPBetterRate) Do(req *http.Request) (*http.Response, error) { "signature": null,"publicKey": null,"encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) } + if req.URL.String() == feeQuoteURLGorillaPool { + resp.StatusCode = http.StatusOK + resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(`{ + "payload": "{\"apiVersion\":\"` + testAPIVersion + `\",\"timestamp\":\"2020-10-09T22:09:04.433Z\",\"expiryTime\":\"2020-10-09T22:19:04.433Z\",\"minerId\":null,\"currentHighestBlockHash\":\"0000000000000000101c34c7cabadbff321f125fac9ba3c2b1294c4d81085f4a\",\"currentHighestBlockHeight\":713780,\"minerReputation\":null,\"fees\":[{\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}},{\"feeType\":\"data\",\"miningFee\":{\"satoshis\":500,\"bytes\":1000},\"relayFee\":{\"satoshis\":250,\"bytes\":1000}}]}", + "signature": null,"publicKey": null,"encoding": "` + testEncoding + `","mimetype": "` + testMimeType + `"}`))) + } + // Default is valid return resp, nil }