Skip to content

Commit

Permalink
fix: fixes golint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
wregulski committed Jun 9, 2023
1 parent 0e78654 commit 8784797
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 69 deletions.
2 changes: 1 addition & 1 deletion apis/arc/fee_quote.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// arc package provides the API structures for the ARC service
// Package arc provides the API structures for the ARC service
package arc

import "github.com/libsv/go-bt/v2"
Expand Down
98 changes: 49 additions & 49 deletions apis/arc/tx_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@ package arc
// TxStatus is the status of the transaction
type TxStatus string

// List of statuses available here: https://github.com/bitcoin-sv/arc
const (
// List of statuses available here: https://github.com/bitcoin-sv/arc
UNKNOWN TxStatus = "UNKNOWN" // 0
QUEUED TxStatus = "QUEUED" // 1
RECEIVED TxStatus = "RECEIVED" // 2
STORED TxStatus = "STORED" // 3
ANNOUNCED_TO_NETWORK TxStatus = "ANNOUNCED_TO_NETWORK" // 4
REQUESTED_BY_NETWORK TxStatus = "REQUESTED_BY_NETWORK" // 5
SENT_TO_NETWORK TxStatus = "SENT_TO_NETWORK" // 6
ACCEPTED_BY_NETWORK TxStatus = "ACCEPTED_BY_NETWORK" // 7
SEEN_ON_NETWORK TxStatus = "SEEN_ON_NETWORK" // 8
MINED TxStatus = "MINED" // 9
CONFIRMED TxStatus = "CONFIRMED" // 108
REJECTED TxStatus = "REJECTED" // 109
// Unknown contains value for unknown status
Unknown TxStatus = "UNKNOWN" // 0
// Queued contains value for queued status
Queued TxStatus = "QUEUED" // 1
// Received contains value for received status
Received TxStatus = "RECEIVED" // 2
// Stored contains value for stored status
Stored TxStatus = "STORED" // 3
// AnnouncedToNetwork contains value for announced to network status
AnnouncedToNetwork TxStatus = "ANNOUNCED_TO_NETWORK" // 4
// RequestedByNetwork contains value for requested by network status
RequestedByNetwork TxStatus = "REQUESTED_BY_NETWORK" // 5
// SentToNetwork contains value for sent to network status
SentToNetwork TxStatus = "SENT_TO_NETWORK" // 6
// AcceptedByNetwork contains value for accepted by network status
AcceptedByNetwork TxStatus = "ACCEPTED_BY_NETWORK" // 7
// SeenOnNetwork contains value for seen on network status
SeenOnNetwork TxStatus = "SEEN_ON_NETWORK" // 8
// Mined contains value for mined status
Mined TxStatus = "MINED" // 9
// Confirmed contains value for confirmed status
Confirmed TxStatus = "CONFIRMED" // 108
// Rejected contains value for rejected status
Rejected TxStatus = "REJECTED" // 109
)

// String returns the string representation of the TxStatus
func (s TxStatus) String() string {
statuses := map[TxStatus]string{
// UNKNOWN contains value for unknown status
UNKNOWN: "UNKNOWN",
// QUEUED contains value for queued status
QUEUED: "QUEUED",
// RECEIVED contains value for received status
RECEIVED: "RECEIVED",
// STORED contains value for stored status
STORED: "STORED",
// ANNOUNCED_TO_NETWORK contains value for announced to network status
ANNOUNCED_TO_NETWORK: "ANNOUNCED_TO_NETWORK",
// REQUESTED_BY_NETWORK contains value for requested by network status
REQUESTED_BY_NETWORK: "REQUESTED_BY_NETWORK",
// SENT_TO_NETWORK contains value for sent to network status
SENT_TO_NETWORK: "SENT_TO_NETWORK",
// ACCEPTED_BY_NETWORK contains value for accepted by network status
ACCEPTED_BY_NETWORK: "ACCEPTED_BY_NETWORK",
// SEEN_ON_NETWORK contains value for seen on network status
SEEN_ON_NETWORK: "SEEN_ON_NETWORK",
// MINED contains value for mined status
MINED: "MINED",
// CONFIRMED contains value for confirmed status
CONFIRMED: "CONFIRMED",
// REJECTED contains value for rejected status
REJECTED: "REJECTED",
Unknown: "UNKNOWN",
Queued: "QUEUED",
Received: "RECEIVED",
Stored: "STORED",
AnnouncedToNetwork: "ANNOUNCED_TO_NETWORK",
RequestedByNetwork: "REQUESTED_BY_NETWORK",
SentToNetwork: "SENT_TO_NETWORK",
AcceptedByNetwork: "ACCEPTED_BY_NETWORK",
SeenOnNetwork: "SEEN_ON_NETWORK",
Mined: "MINED",
Confirmed: "CONFIRMED",
Rejected: "REJECTED",
}

if status, ok := statuses[s]; ok {
Expand All @@ -58,18 +58,18 @@ func (s TxStatus) String() string {
// MapTxStatusToInt maps the TxStatus to an int value
func MapTxStatusToInt(status TxStatus) (int, bool) {
waitForStatusMap := map[TxStatus]int{
UNKNOWN: 0,
QUEUED: 1,
RECEIVED: 2,
STORED: 3,
ANNOUNCED_TO_NETWORK: 4,
REQUESTED_BY_NETWORK: 5,
SENT_TO_NETWORK: 6,
ACCEPTED_BY_NETWORK: 7,
SEEN_ON_NETWORK: 8,
MINED: 9,
CONFIRMED: 108,
REJECTED: 109,
Unknown: 0,
Queued: 1,
Received: 2,
Stored: 3,
AnnouncedToNetwork: 4,
RequestedByNetwork: 5,
SentToNetwork: 6,
AcceptedByNetwork: 7,
SeenOnNetwork: 8,
Mined: 9,
Confirmed: 108,
Rejected: 109,
}

value, ok := waitForStatusMap[status]
Expand Down
3 changes: 2 additions & 1 deletion apis/mapi/fee_quote.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package mapi provides the API structures for the mAPI service
package mapi

import (
Expand Down Expand Up @@ -105,7 +106,7 @@ type (
Bytes int `json:"bytes"` // Number of bytes that the Fee covers
}

// feeObj displays the MiningFee as well as the RelayFee for a specific
// FeeObj displays the MiningFee as well as the RelayFee for a specific
// FeeType, for example 'standard' or 'data'
// see https://github.com/bitcoin-sv-specs/brfc-merchantapi#expanded-payload-1
FeeObj struct {
Expand Down
15 changes: 9 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package minercraft

import (
"crypto/rand"
"encoding/json"
"errors"
"fmt"
"math/rand"
"math/big"
"net"
"net/http"
"strings"
Expand Down Expand Up @@ -134,6 +135,8 @@ func MinerByID(miners []*Miner, minerID string) *Miner {
}
return nil
}

// MinerAPIByMinerID will return a miner's API given a miner id and API type
func (c *Client) MinerAPIByMinerID(minerID string, apiType APIType) (*API, error) {
for _, minerAPI := range c.minerAPIs {
if minerAPI.MinerID == minerID {
Expand Down Expand Up @@ -369,16 +372,16 @@ func (c *Client) isUniqueMinerID(minerID string) bool {

// generateUniqueMinerID will generate a unique miner ID
func generateUniqueMinerID() string {
// Implement your logic to generate a unique miner ID
// Here's a simple example that generates a random ID
const idLength = 8
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

rand.Seed(time.Now().UnixNano())

id := make([]byte, idLength)
for i := range id {
id[i] = letters[rand.Intn(len(letters))]
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
if err != nil {
return ""
}
id[i] = letters[num.Int64()]
}

return string(id)
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ const KnownMiners = `
]
`

// KnownMinersAPIs is a pre-filled list of known miners with their APIs
// Any pre-filled tokens are for free use only
// update your custom token with client.MinerUpdateToken("name", "token")
// KnownMinersAPIs is a pre-filled list of known miners with their APIs
const KnownMinersAPIs = `
[
{
Expand Down
2 changes: 1 addition & 1 deletion definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type APISpecificRoute struct {
type JSONEnvelope struct {
Miner *Miner `json:"miner"` // Custom field for our internal Miner configuration
Validated bool `json:"validated"` // Custom field if the signature has been validated
ApiType APIType `json:"apiType"` // Custom field for the API type
APIType APIType `json:"apiType"` // Custom field for the API type
envelope.JSONEnvelope
}

Expand Down
14 changes: 11 additions & 3 deletions policy_quote.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ import (
"github.com/tonicpow/go-minercraft/apis/mapi"
)

// PolicyQuoteModelAdapter is the interface for the adapter to get the policy quote response
type PolicyQuoteModelAdapter interface {
GetPolicyData() *PolicyPayload
}

// PolicyQuoteMapiAdapter is the adapter for the mAPI response
type PolicyQuoteMapiAdapter struct {
*mapi.PolicyQuoteModel
}

// PolicyQuoteArcAdapter is the adapter for the Arc response
type PolicyQuoteArcAdapter struct {
*arc.PolicyQuoteModel
}

// UnifiedPolicy is the unmarshalled version of the policy
type UnifiedPolicy struct {
AcceptNonStdOutputs bool `json:"acceptnonstdoutputs"`
DataCarrier bool `json:"datacarrier"`
Expand All @@ -45,6 +49,7 @@ type UnifiedPolicy struct {
MaxTxSigOpsCount uint32 `json:"maxtxsigopscount"`
}

// UnifiedFeePayload is the unmarshalled version of the payload envelope
type UnifiedFeePayload struct {
mapi.FeePayloadFields
Fees []*bt.Fee `json:"fees"`
Expand Down Expand Up @@ -95,7 +100,7 @@ func (c *Client) PolicyQuote(ctx context.Context, miner *Miner) (*PolicyQuoteRes

quoteResponse := &PolicyQuoteResponse{
JSONEnvelope: JSONEnvelope{
ApiType: c.apiType,
APIType: c.apiType,
Miner: result.Miner,
},
}
Expand All @@ -105,7 +110,7 @@ func (c *Client) PolicyQuote(ctx context.Context, miner *Miner) (*PolicyQuoteRes
switch c.apiType {
case MAPI:
model := &mapi.PolicyQuoteModel{}
err := quoteResponse.process(result.Miner, result.Response.BodyContents)
err = quoteResponse.process(result.Miner, result.Response.BodyContents)
if err != nil || len(quoteResponse.Payload) <= 0 {
return nil, err
}
Expand All @@ -118,7 +123,7 @@ func (c *Client) PolicyQuote(ctx context.Context, miner *Miner) (*PolicyQuoteRes
modelAdapter = &PolicyQuoteMapiAdapter{PolicyQuoteModel: model}
case Arc:
model := &arc.PolicyQuoteModel{}
err := json.Unmarshal(result.Response.BodyContents, model)
err = json.Unmarshal(result.Response.BodyContents, model)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -146,6 +151,7 @@ func (c *Client) PolicyQuote(ctx context.Context, miner *Miner) (*PolicyQuoteRes
return quoteResponse, nil
}

// GetPolicyData will return the policy data from the mapi adapter
func (a *PolicyQuoteMapiAdapter) GetPolicyData() *PolicyPayload {
// Tworzenie instancji UnifiedFeePayload
feePayload := UnifiedFeePayload{
Expand All @@ -171,6 +177,7 @@ func (a *PolicyQuoteMapiAdapter) GetPolicyData() *PolicyPayload {

callbacks := make([]*mapi.PolicyCallback, len(a.Callbacks))
for i, cb := range a.Callbacks {
//nolint:gosec,exportloopref // ignore those linter errors
callbacks[i] = &cb
}

Expand Down Expand Up @@ -201,6 +208,7 @@ func (a *PolicyQuoteMapiAdapter) GetPolicyData() *PolicyPayload {
return policyPayload
}

// GetPolicyData will return the policy data from the arc adapter
func (a *PolicyQuoteArcAdapter) GetPolicyData() *PolicyPayload {

feePayload := UnifiedFeePayload{
Expand Down
7 changes: 6 additions & 1 deletion query_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ const QueryTransactionFailure = "failure"
// QueryTransactionInMempoolFailure in mempool but not in a block yet
const QueryTransactionInMempoolFailure = "Transaction in mempool but not yet in block"

// QueryTxModelAdapter is the interface for the adapter to get the query tx response
type QueryTxModelAdapter interface {
GetQueryTxResponse() *QueryTxResponse
}

// QueryTxMapiAdapter is the adapter for the mAPI response
type QueryTxMapiAdapter struct {
*mapi.QueryTxModel
}

// QueryTxArcAdapter is the adapter for the Arc response
type QueryTxArcAdapter struct {
*arc.QueryTxModel
}
Expand Down Expand Up @@ -183,7 +186,7 @@ func (c *Client) QueryTransaction(ctx context.Context, miner *Miner, txID string

queryResponse := &QueryTransactionResponse{
JSONEnvelope: JSONEnvelope{
ApiType: c.apiType,
APIType: c.apiType,
Miner: result.Miner,
},
}
Expand Down Expand Up @@ -281,6 +284,7 @@ func queryTransaction(ctx context.Context, client *Client, miner *Miner, txHash
return
}

// GetQueryTxResponse will return the query tx response from mapi adapter
func (m *QueryTxMapiAdapter) GetQueryTxResponse() *QueryTxResponse {
response := &QueryTxResponse{
TxID: m.TxID,
Expand All @@ -301,6 +305,7 @@ func (m *QueryTxMapiAdapter) GetQueryTxResponse() *QueryTxResponse {
return response
}

// GetQueryTxResponse will return the query tx response from arc adapter
func (m *QueryTxArcAdapter) GetQueryTxResponse() *QueryTxResponse {
response := &QueryTxResponse{
TxID: m.TxID,
Expand Down
Loading

0 comments on commit 8784797

Please sign in to comment.