Skip to content

Commit

Permalink
Added new miner: GorillaPool
Browse files Browse the repository at this point in the history
Closes #39
  • Loading branch information
mrz1836 committed Nov 16, 2021
1 parent 7099ddb commit 28ebec9
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 9 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<details>
<summary><strong><code>Library Deployment</code></strong></summary>
Expand Down Expand Up @@ -155,8 +160,8 @@ View the [examples](examples)

## Maintainers
| [<img src="https://github.com/mrz1836.png" height="50" alt="MrZ" />](https://github.com/mrz1836) |
|:---:|
| [MrZ](https://github.com/mrz1836) |
|:------------------------------------------------------------------------------------------------:|
| [MrZ](https://github.com/mrz1836) |

<br/>

Expand Down
22 changes: 22 additions & 0 deletions best_quote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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(`{
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 7 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 10 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
}
]
`
20 changes: 20 additions & 0 deletions fastest_quote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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(`{
Expand Down
14 changes: 11 additions & 3 deletions fee_quote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 28ebec9

Please sign in to comment.