Skip to content

Commit

Permalink
feat: adds APIType to NewClient method
Browse files Browse the repository at this point in the history
  • Loading branch information
wregulski committed May 17, 2023
1 parent 6f9e36c commit da09133
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 58 deletions.
7 changes: 4 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type HTTPInterface interface {

// Client is the parent struct that contains the miner clients and list of miners to use
type Client struct {
apiType APIType // The API type to use
httpClient HTTPInterface // Interface for all HTTP requests
miners []*Miner // List of loaded miners
Options *ClientOptions // Client options config
Expand Down Expand Up @@ -167,14 +168,14 @@ func DefaultClientOptions() (clientOptions *ClientOptions) {
// customHTTPClient: use your own custom HTTP client
// customMiners: use your own custom list of miners
func NewClient(clientOptions *ClientOptions, customHTTPClient HTTPInterface,
customMiners []*Miner) (client ClientInterface, err error) {
apiType APIType, customMiners []*Miner) (client ClientInterface, err error) {

// Create the new client
return createClient(clientOptions, customHTTPClient, customMiners)
return createClient(clientOptions, apiType, customHTTPClient, customMiners)
}

// createClient will make a new http client based on the options provided
func createClient(options *ClientOptions, customHTTPClient HTTPInterface, customMiners []*Miner) (c *Client, err error) {
func createClient(options *ClientOptions, apiType APIType, customHTTPClient HTTPInterface, customMiners []*Miner) (c *Client, err error) {

// Create a client
c = new(Client)
Expand Down
106 changes: 62 additions & 44 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,63 +117,81 @@ const (
)

// KnownMiners is a pre-filled list of known miners
// Any pre-filled tokens are for free use only
// update your custom token with client.MinerUpdateToken("name", "token")
const KnownMiners = `
[
{
"name":"Taal",
"miner_id":"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270",
"apis":[
{
"token":"",
"url":"https://merchantapi.taal.com",
"type":"mAPI"
},
{
"token":"",
"url":"https://tapi.taal.com/arc",
"type":"Arc"
}
]
"miner_id":"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270"
},
{
"name":"Mempool",
"miner_id":"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270",
"apis":[
{
"token":"561b756d12572020ea9a104c3441b71790acbbce95a6ddbf7e0630971af9424b",
"url":"https://www.ddpurse.com/openapi",
"type":"mAPI"
}
]
"miner_id":"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270"
},
{
"name":"Matterpool",
"miner_id":"0253a9b2d017254b91704ba52aad0df5ca32b4fb5cb6b267ada6aefa2bc5833a93",
"apis":[
{
"token":"",
"url":"https://merchantapi.matterpool.io",
"type":"mAPI"
}
]
"miner_id":"0253a9b2d017254b91704ba52aad0df5ca32b4fb5cb6b267ada6aefa2bc5833a93"
},
{
"name":"GorillaPool",
"miner_id":"03ad780153c47df915b3d2e23af727c68facaca4facd5f155bf5018b979b9aeb83",
"apis":[
{
"token":"",
"url":"https://merchantapi.gorillapool.io",
"type":"mAPI"
},
{
"token":"",
"url":"https://arc.gorillapool.io",
"type":"Arc"
}
]
"miner_id":"03ad780153c47df915b3d2e23af727c68facaca4facd5f155bf5018b979b9aeb83"
}
]
`

// Any pre-filled tokens are for free use only
// update your custom token with client.MinerUpdateToken("name", "token")
// TODO: Update client.MinerUpdateToken method and related
const KnownMinersAPIs = `
[
{
"miner_id":"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270",
"apis":[
{
"token":"",
"url":"https://merchantapi.taal.com",
"type":"mAPI"
},
{
"token":"",
"url":"https://tapi.taal.com/arc",
"type":"Arc"
}
],
},
{
"miner_id":"03e92d3e5c3f7bd945dfbf48e7a99393b1bfb3f11f380ae30d286e7ff2aec5a270",
"apis":[
{
"token":"561b756d12572020ea9a104c3441b71790acbbce95a6ddbf7e0630971af9424b",
"url":"https://www.ddpurse.com/openapi",
"type":"mAPI"
}
]
},
{
"miner_id":"0253a9b2d017254b91704ba52aad0df5ca32b4fb5cb6b267ada6aefa2bc5833a93",
"apis":[
{
"token":"",
"url":"https://merchantapi.matterpool.io",
"type":"mAPI"
}
]
},
{
"miner_id":"03ad780153c47df915b3d2e23af727c68facaca4facd5f155bf5018b979b9aeb83",
"apis":[
{
"token":"",
"url":"https://merchantapi.gorillapool.io",
"type":"mAPI"
},
{
"token":"",
"url":"https://arc.gorillapool.io",
"type":"Arc"
}
]
}
]
`
4 changes: 4 additions & 0 deletions definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
type Miner struct {
MinerID string `json:"miner_id,omitempty"`
Name string `json:"name,omitempty"`
}

type MinerAPIs struct {
MinerID string `json:"miner_id,omitempty"`
APIs []API `json:"apis,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion examples/add_miner/add_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func main() {

// Create a new client
client, err := minercraft.NewClient(nil, nil, nil)
client, err := minercraft.NewClient(nil, nil, "", nil)
if err != nil {
log.Fatalf("error occurred: %s", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/best_quote/best_quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func main() {

// Create a new client
client, err := minercraft.NewClient(nil, nil, nil)
client, err := minercraft.NewClient(nil, nil, "", nil)
if err != nil {
log.Fatalf("error occurred: %s", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/calculate_fee/calculate_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func main() {

// Create a new client
client, err := minercraft.NewClient(nil, nil, nil)
client, err := minercraft.NewClient(nil, nil, "", nil)
if err != nil {
log.Fatalf("error occurred: %s", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/fastest_quote/fastest_quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func main() {

// Create a new client
client, err := minercraft.NewClient(nil, nil, nil)
client, err := minercraft.NewClient(nil, nil, "", nil)
if err != nil {
log.Fatalf("error occurred: %s", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/fee_quote/fee_quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func main() {

// Create a new client
client, err := minercraft.NewClient(nil, nil, nil)
client, err := minercraft.NewClient(nil, nil, "", nil)
if err != nil {
log.Fatalf("error occurred: %s", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/policy_quote/policy_quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func main() {

// Create a new client
client, err := minercraft.NewClient(nil, nil, nil)
client, err := minercraft.NewClient(nil, nil, "", nil)
if err != nil {
log.Fatalf("error occurred: %s", err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions examples/query_transaction/query_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
func main() {

// Create a new client
client, err := minercraft.NewClient(nil, nil, nil)
client, err := minercraft.NewClient(nil, nil, "", nil)
if err != nil {
log.Fatalf("error occurred: %s", err.Error())
}

// Select the miner
miner := client.MinerByName(minercraft.MinerGorillaPoolArc)
miner := client.MinerByName(minercraft.MinerGorillaPool)

// Query the transaction status
var response *minercraft.QueryTransactionResponse
Expand Down
2 changes: 1 addition & 1 deletion examples/remove_miner/remove_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func main() {

// Create a new client
client, err := minercraft.NewClient(nil, nil, nil)
client, err := minercraft.NewClient(nil, nil, "", nil)
if err != nil {
log.Fatalf("error occurred: %s", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/submit_transaction/submit_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func main() {

// Create a new client
client, err := minercraft.NewClient(nil, nil, nil)
client, err := minercraft.NewClient(nil, nil, "", nil)
if err != nil {
log.Fatalf("error occurred: %s", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion query_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func queryTransaction(ctx context.Context, client *Client, miner *Miner, txHash
o(defaultOpts)
}
sb := strings.Builder{}
// TODO: Align with new structure

// sb.WriteString(miner.URL + routeQueryTx + txHash)
if defaultOpts.includeProof {
sb.WriteString("?merkleProof=true&merkleFormat=" + defaultOpts.merkleFormat)
Expand Down

0 comments on commit da09133

Please sign in to comment.