Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Fixed a bunch of linter errors, Id vs ID, ctx etc
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Jul 12, 2023
1 parent ef94609 commit d876c0b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
19 changes: 9 additions & 10 deletions chainstate/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var (
// broadcast will broadcast using a standard strategy
//
// NOTE: if successful (in-mempool), no error will be returned
// NOTE: function register fastest successful broadcast into 'completeChannel' so client doesn't need to wait for other providers
// NOTE: function register the fastest successful broadcast into 'completeChannel' so client doesn't need to wait for other providers
func (c *Client) broadcast(ctx context.Context, id, hex string, timeout time.Duration, completeChannel, errorChannel chan string) {
// Create a context (to cancel or timeout)
ctxWithCancel, cancel := context.WithTimeout(ctx, timeout)
Expand All @@ -61,8 +61,7 @@ func (c *Client) broadcast(ctx context.Context, id, hex string, timeout time.Dur
wg.Add(1)
go func(provider txBroadcastProvider) {
defer wg.Done()
broadcastToProvider(provider, id,
c, ctxWithCancel, ctx, timeout,
broadcastToProvider(ctxWithCancel, ctx, provider, id, c, timeout,
resultsChannel, status)
}(broadcastProvider)
}
Expand All @@ -88,7 +87,7 @@ func (c *Client) broadcast(ctx context.Context, id, hex string, timeout time.Dur
}
}

func createActiveProviders(c *Client, txId, txHex string) []txBroadcastProvider {
func createActiveProviders(c *Client, txID, txHex string) []txBroadcastProvider {
providers := make([]txBroadcastProvider, 0, 10)

if shouldBroadcastWithMAPI(c) {
Expand All @@ -97,18 +96,18 @@ func createActiveProviders(c *Client, txId, txHex string) []txBroadcastProvider
continue
}

pvdr := mapiBroadcastProvider{miner: miner, txId: txId, txHex: txHex}
pvdr := mapiBroadcastProvider{miner: miner, txID: txID, txHex: txHex}
providers = append(providers, &pvdr)
}
}

if shouldBroadcastToWhatsOnChain(c) {
pvdr := whatsOnChainBroadcastProvider{txId: txId, txHex: txHex}
pvdr := whatsOnChainBroadcastProvider{txID: txID, txHex: txHex}
providers = append(providers, &pvdr)
}

if shouldBroadcastToNowNodes(c) {
pvdr := nowNodesBroadcastProvider{uniqueID: txId, txID: txId, txHex: txHex}
pvdr := nowNodesBroadcastProvider{uniqueID: txID, txID: txID, txHex: txHex}
providers = append(providers, &pvdr)
}

Expand All @@ -129,8 +128,8 @@ func shouldBroadcastToNowNodes(c *Client) bool {
c.NowNodes() != nil // Only if NowNodes is loaded (requires API key)
}

func broadcastToProvider(provider txBroadcastProvider, txId string,
c *Client, ctx, fallbackCtx context.Context, fallbackTimeout time.Duration,
func broadcastToProvider(ctx, fallbackCtx context.Context, provider txBroadcastProvider, txID string,
c *Client, fallbackTimeout time.Duration,
resultsChannel chan broadcastResult, status *broadcastStatus,
) {
bErr := provider.broadcast(ctx, c)
Expand All @@ -139,7 +138,7 @@ func broadcastToProvider(provider txBroadcastProvider, txId string,
// check in Mempool as fallback - if transaction is there -> GREAT SUCCESS
// Check error response for "questionable errors"/(TX FAILURE)
if doesErrorContain(bErr.Error(), broadcastQuestionableErrors) {
bErr = checkInMempool(fallbackCtx, c, txId, bErr.Error(), fallbackTimeout)
bErr = checkInMempool(fallbackCtx, c, txID, bErr.Error(), fallbackTimeout)
}

if bErr != nil {
Expand Down
18 changes: 9 additions & 9 deletions chainstate/broadcast_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ type txBroadcastProvider interface {
// mAPI provider
type mapiBroadcastProvider struct {
miner *Miner
txId, txHex string
txID, txHex string
}

func (provider mapiBroadcastProvider) getName() string {
return provider.miner.Miner.Name
}

func (provider mapiBroadcastProvider) broadcast(ctx context.Context, c *Client) error {
return broadcastMAPI(ctx, c, provider.miner.Miner, provider.txId, provider.txHex)
return broadcastMAPI(ctx, c, provider.miner.Miner, provider.txID, provider.txHex)
}

// broadcastMAPI will broadcast a transaction to a miner using mAPI
Expand All @@ -50,7 +50,7 @@ func broadcastMAPI(ctx context.Context, client ClientInterface, miner *minercraf

// Something went wrong - got back an id that does not match
if resp == nil || !strings.EqualFold(resp.Results.TxID, id) {
return incorrectTxIdReturnedErr(resp.Results.TxID, id)
return incorrectTxIDReturnedErr(resp.Results.TxID, id)
}

// mAPI success of broadcast
Expand All @@ -71,15 +71,15 @@ func broadcastMAPI(ctx context.Context, client ClientInterface, miner *minercraf

// WhatsOnChain provider
type whatsOnChainBroadcastProvider struct {
txId, txHex string
txID, txHex string
}

func (provider whatsOnChainBroadcastProvider) getName() string {
return ProviderWhatsOnChain
}

func (provider whatsOnChainBroadcastProvider) broadcast(ctx context.Context, c *Client) error {
return broadcastWhatsOnChain(ctx, c, provider.txId, provider.txHex)
return broadcastWhatsOnChain(ctx, c, provider.txID, provider.txHex)
}

// broadcastWhatsOnChain will broadcast a transaction to WhatsOnChain
Expand All @@ -98,7 +98,7 @@ func broadcastWhatsOnChain(ctx context.Context, client ClientInterface, id, hex

// Something went wrong - got back an id that does not match
if !strings.EqualFold(txID, id) {
return incorrectTxIdReturnedErr(txID, id)
return incorrectTxIDReturnedErr(txID, id)
}

// Success
Expand Down Expand Up @@ -137,7 +137,7 @@ func broadcastNowNodes(ctx context.Context, client ClientInterface, uniqueID, tx

// Something went wrong - got back an id that does not match
if !strings.EqualFold(result.Result, txID) {
return incorrectTxIdReturnedErr(result.Result, txID)
return incorrectTxIDReturnedErr(result.Result, txID)
}

// Success
Expand All @@ -146,6 +146,6 @@ func broadcastNowNodes(ctx context.Context, client ClientInterface, uniqueID, tx

////

func incorrectTxIdReturnedErr(actualTxId, expectedTxId string) error {
return fmt.Errorf("returned tx id [%s] does not match given tx id [%s]", actualTxId, expectedTxId)
func incorrectTxIDReturnedErr(actualTxID, expectedTxID string) error {
return fmt.Errorf("returned tx id [%s] does not match given tx id [%s]", actualTxID, expectedTxID)
}
4 changes: 2 additions & 2 deletions chainstate/broadcast_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ func doesErrorContain(err string, messages []string) bool {
return false
}

func debugLog(c ClientInterface, txId, msg string) {
c.DebugLog(fmt.Sprintf("[txId: %s]: %s", txId, msg))
func debugLog(c ClientInterface, txID, msg string) {
c.DebugLog(fmt.Sprintf("[txID: %s]: %s", txID, msg))
}

0 comments on commit d876c0b

Please sign in to comment.