Skip to content

Commit 0a58cdb

Browse files
committed
fn: rename chanutils packge to fn
In this commit, we rename the chanutils package to be just `fn`. This is shorter so means we'll run into the line limit less. The package also now contains general generic functions, so this new name matches better.
1 parent f5b31f3 commit 0a58cdb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+215
-231
lines changed

address/book.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/btcsuite/btcd/wire"
1212
"github.com/lightninglabs/lndclient"
1313
"github.com/lightninglabs/taproot-assets/asset"
14-
"github.com/lightninglabs/taproot-assets/chanutils"
1514
"github.com/lightninglabs/taproot-assets/commitment"
15+
"github.com/lightninglabs/taproot-assets/fn"
1616
"github.com/lightningnetwork/lnd/keychain"
1717
)
1818

@@ -150,23 +150,23 @@ type Book struct {
150150

151151
// subscribers is a map of components that want to be notified on new
152152
// address events, keyed by their subscription ID.
153-
subscribers map[uint64]*chanutils.EventReceiver[*AddrWithKeyInfo]
153+
subscribers map[uint64]*fn.EventReceiver[*AddrWithKeyInfo]
154154

155155
// subscriberMtx guards the subscribers map and access to the
156156
// subscriptionID.
157157
subscriberMtx sync.Mutex
158158
}
159159

160160
// A compile-time assertion to make sure Book satisfies the
161-
// chanutils.EventPublisher interface.
162-
var _ chanutils.EventPublisher[*AddrWithKeyInfo, QueryParams] = (*Book)(nil)
161+
// fn.EventPublisher interface.
162+
var _ fn.EventPublisher[*AddrWithKeyInfo, QueryParams] = (*Book)(nil)
163163

164164
// NewBook creates a new Book instance from the config.
165165
func NewBook(cfg BookConfig) *Book {
166166
return &Book{
167167
cfg: cfg,
168168
subscribers: make(
169-
map[uint64]*chanutils.EventReceiver[*AddrWithKeyInfo],
169+
map[uint64]*fn.EventReceiver[*AddrWithKeyInfo],
170170
),
171171
}
172172
}
@@ -392,7 +392,7 @@ func (b *Book) CompleteEvent(ctx context.Context, event *Event,
392392
// marker onward existing items should be delivered on startup. If deliverFrom
393393
// is nil/zero/empty then all existing items will be delivered.
394394
func (b *Book) RegisterSubscriber(
395-
receiver *chanutils.EventReceiver[*AddrWithKeyInfo],
395+
receiver *fn.EventReceiver[*AddrWithKeyInfo],
396396
deliverExisting bool, deliverFrom QueryParams) error {
397397

398398
b.subscriberMtx.Lock()
@@ -427,7 +427,7 @@ func (b *Book) RegisterSubscriber(
427427
// RemoveSubscriber removes the given subscriber and also stops it from
428428
// processing events.
429429
func (b *Book) RemoveSubscriber(
430-
subscriber *chanutils.EventReceiver[*AddrWithKeyInfo]) error {
430+
subscriber *fn.EventReceiver[*AddrWithKeyInfo]) error {
431431

432432
b.subscriberMtx.Lock()
433433
defer b.subscriberMtx.Unlock()

cmd/tapd/main.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"runtime/pprof"
88

99
"github.com/jessevdk/go-flags"
10-
"github.com/lightninglabs/taproot-assets/chanutils"
10+
"github.com/lightninglabs/taproot-assets/fn"
1111
"github.com/lightninglabs/taproot-assets/tapcfg"
1212
"github.com/lightningnetwork/lnd/signal"
1313
)
@@ -62,9 +62,7 @@ func main() {
6262
// This concurrent error queue can be used by every component that can
6363
// raise runtime errors. Using a queue will prevent us from blocking on
6464
// sending errors to it, as long as the queue is running.
65-
errQueue := chanutils.NewConcurrentQueue[error](
66-
chanutils.DefaultQueueSize,
67-
)
65+
errQueue := fn.NewConcurrentQueue[error](fn.DefaultQueueSize)
6866
errQueue.Start()
6967
defer errQueue.Stop()
7068

commitment/asset.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"github.com/btcsuite/btcd/btcec/v2/schnorr"
1212
"github.com/lightninglabs/taproot-assets/asset"
13-
"github.com/lightninglabs/taproot-assets/chanutils"
13+
"github.com/lightninglabs/taproot-assets/fn"
1414
"github.com/lightninglabs/taproot-assets/mssmt"
1515
"golang.org/x/exp/maps"
1616
)
@@ -404,7 +404,7 @@ func (c *AssetCommitment) Copy() (*AssetCommitment, error) {
404404

405405
// First, we'll perform a deep copy of all the assets that this existing
406406
// commitment is committing to.
407-
newAssets := chanutils.CopyAll(maps.Values(c.Assets()))
407+
newAssets := fn.CopyAll(maps.Values(c.Assets()))
408408

409409
// Now that we have a deep copy of all the assets, we can just create a
410410
// brand-new commitment from the set of assets.

commitment/proof.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"io"
66

77
"github.com/lightninglabs/taproot-assets/asset"
8-
"github.com/lightninglabs/taproot-assets/chanutils"
8+
"github.com/lightninglabs/taproot-assets/fn"
99
"github.com/lightninglabs/taproot-assets/mssmt"
1010
"github.com/lightningnetwork/lnd/tlv"
1111
)
@@ -129,7 +129,7 @@ func (p Proof) DeriveByAssetInclusion(asset *asset.Asset) (*TapCommitment,
129129
)
130130
log.Tracef("Derived asset inclusion proof for asset_id=%v, "+
131131
"asset_commitment_key=%x, asset_commitment_leaf=%s",
132-
asset.ID(), chanutils.ByteSlice(asset.AssetCommitmentKey()),
132+
asset.ID(), fn.ByteSlice(asset.AssetCommitmentKey()),
133133
assetCommitmentLeaf.NodeHash())
134134

135135
return NewTapCommitmentWithRoot(

commitment/tap.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/btcsuite/btcd/chaincfg/chainhash"
1212
"github.com/btcsuite/btcd/txscript"
1313
"github.com/lightninglabs/taproot-assets/asset"
14-
"github.com/lightninglabs/taproot-assets/chanutils"
14+
"github.com/lightninglabs/taproot-assets/fn"
1515
"github.com/lightninglabs/taproot-assets/mssmt"
1616
"golang.org/x/exp/maps"
1717
)
@@ -378,7 +378,7 @@ func (c *TapCommitment) Copy() (*TapCommitment, error) {
378378
}
379379

380380
// Otherwise, we'll copy all the internal asset commitments.
381-
newAssetCommitments, err := chanutils.CopyAllErr(
381+
newAssetCommitments, err := fn.CopyAllErr(
382382
maps.Values(c.assetCommitments),
383383
)
384384
if err != nil {

chanutils/concurrency.go renamed to fn/concurrency.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chanutils
1+
package fn
22

33
import (
44
"context"

chanutils/concurrency_test.go renamed to fn/concurrency_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chanutils
1+
package fn
22

33
import (
44
"context"

chanutils/context_guard.go renamed to fn/context_guard.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chanutils
1+
package fn
22

33
import (
44
"context"

chanutils/errors.go renamed to fn/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chanutils
1+
package fn
22

33
import (
44
"context"

chanutils/errors_test.go renamed to fn/errors_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chanutils
1+
package fn
22

33
import (
44
"context"

chanutils/events.go renamed to fn/events.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chanutils
1+
package fn
22

33
import (
44
"fmt"

chanutils/func.go renamed to fn/func.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chanutils
1+
package fn
22

33
import "fmt"
44

chanutils/iter.go renamed to fn/iter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chanutils
1+
package fn
22

33
// ForEachErr will iterate through all items in the passed slice, calling the
44
// function f on each slice. If a call to f fails, then the function returns an

chanutils/memory.go renamed to fn/memory.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chanutils
1+
package fn
22

33
// Ptr returns the pointer of the given value. This is useful in instances
44
// where a function returns the value, but a pointer is wanted. Without this,

chanutils/queue.go renamed to fn/queue.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chanutils
1+
package fn
22

33
import (
44
"container/list"

chanutils/recv.go renamed to fn/recv.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chanutils
1+
package fn
22

33
import (
44
"fmt"

chanutils/send.go renamed to fn/send.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chanutils
1+
package fn
22

33
// SendOrQuit attempts to and a message through channel c. If this succeeds,
44
// then bool is returned. Otherwise if a quit signal is received first, then

chanutils/set.go renamed to fn/set.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package chanutils
1+
package fn
22

33
import "golang.org/x/exp/maps"
44

itest/assertions.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/btcsuite/btcd/txscript"
1313
"github.com/btcsuite/btcd/wire"
1414
"github.com/lightninglabs/taproot-assets/asset"
15-
"github.com/lightninglabs/taproot-assets/chanutils"
15+
"github.com/lightninglabs/taproot-assets/fn"
1616
"github.com/lightninglabs/taproot-assets/proof"
1717
"github.com/lightninglabs/taproot-assets/taprpc"
1818
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
@@ -688,7 +688,7 @@ func assertUniverseRootsEqual(t *testing.T, a, b *unirpc.AssetRootResponse) {
688688
// same set of asset IDs are being tracked.
689689
uniKeys := maps.Keys(a.UniverseRoots)
690690
require.Equal(t, len(a.UniverseRoots), len(b.UniverseRoots))
691-
require.True(t, chanutils.All(uniKeys, func(key string) bool {
691+
require.True(t, fn.All(uniKeys, func(key string) bool {
692692
_, ok := b.UniverseRoots[key]
693693
return ok
694694
}))
@@ -805,7 +805,7 @@ func assertUniverseAssetStats(t *testing.T, node *tapdHarness,
805805
require.Len(t, assetStats.AssetStats, len(assetIDs))
806806

807807
for _, assetStat := range assetStats.AssetStats {
808-
found := chanutils.Any(assetIDs, func(id []byte) bool {
808+
found := fn.Any(assetIDs, func(id []byte) bool {
809809
return bytes.Equal(assetStat.AssetId, id)
810810
})
811811
require.True(t, found)

itest/assets_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010

1111
"github.com/btcsuite/btcd/chaincfg/chainhash"
12-
"github.com/lightninglabs/taproot-assets/chanutils"
12+
"github.com/lightninglabs/taproot-assets/fn"
1313
"github.com/lightninglabs/taproot-assets/proof"
1414
"github.com/lightninglabs/taproot-assets/taprpc"
1515
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
@@ -469,7 +469,7 @@ func testMintAssetNameCollisionError(t *harnessTest) {
469469

470470
return batch.Assets[0].AssetType == taprpc.AssetType_COLLECTIBLE
471471
}
472-
batchCollide, err := chanutils.First(allBatches, isCollidingBatch)
472+
batchCollide, err := fn.First(allBatches, isCollidingBatch)
473473
require.NoError(t.t, err)
474474

475475
require.Len(t.t, batchCollide.Assets, 1)

itest/multi_asset_group_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"testing"
88

99
"github.com/lightninglabs/taproot-assets/asset"
10-
"github.com/lightninglabs/taproot-assets/chanutils"
10+
"github.com/lightninglabs/taproot-assets/fn"
1111
"github.com/lightninglabs/taproot-assets/taprpc"
1212
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
1313
"github.com/stretchr/testify/require"
@@ -91,7 +91,7 @@ func testMintMultiAssetGroups(t *harnessTest) {
9191

9292
// We need to fetch the minted group anchor asset, which includes the
9393
// genesis information used to compute the tweak for the group key.
94-
normalAnchor, err := chanutils.First(
94+
normalAnchor, err := fn.First(
9595
mintedBatch, func(asset *taprpc.Asset) bool {
9696
return matchingName(asset, issuableAssets[0].Asset.Name)
9797
},
@@ -104,7 +104,7 @@ func testMintMultiAssetGroups(t *harnessTest) {
104104
normalAnchor.AssetGroup.TweakedGroupKey,
105105
)
106106

107-
collectAnchor, err := chanutils.First(
107+
collectAnchor, err := fn.First(
108108
mintedBatch, func(asset *taprpc.Asset) bool {
109109
return matchingName(asset, issuableAssets[1].Asset.Name)
110110
},
@@ -130,7 +130,7 @@ func testMintMultiAssetGroups(t *harnessTest) {
130130
require.NoError(t.t, secondTapd.stop(true))
131131
}()
132132

133-
normalMember, err := chanutils.First(
133+
normalMember, err := fn.First(
134134
mintedBatch, func(asset *taprpc.Asset) bool {
135135
return asset.Amount == normalAnchor.Amount/2
136136
},
@@ -175,7 +175,7 @@ func testMintMultiAssetGroups(t *harnessTest) {
175175
)
176176
return isNotAnchor && isGrouped
177177
}
178-
collectMember, err := chanutils.First(mintedBatch, isCollectGroupMember)
178+
collectMember, err := fn.First(mintedBatch, isCollectGroupMember)
179179
require.NoError(t.t, err)
180180

181181
collectMemberGenInfo := collectMember.AssetGenesis

itest/universe_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"io"
99

1010
"github.com/btcsuite/btcd/btcec/v2/schnorr"
11-
"github.com/lightninglabs/taproot-assets/chanutils"
11+
"github.com/lightninglabs/taproot-assets/fn"
1212
"github.com/lightninglabs/taproot-assets/taprpc"
1313
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
1414
"github.com/lightningnetwork/lnd/lntest/wait"
@@ -116,10 +116,9 @@ func testUniverseSync(t *harnessTest) {
116116
// Finally, we'll ensure that the universe keys and leaves matches for
117117
// both parties.
118118
uniRoots := maps.Values(universeRoots.UniverseRoots)
119-
uniIDs := chanutils.Map(uniRoots,
120-
func(root *unirpc.UniverseRoot) *unirpc.ID {
121-
return root.Id
122-
},
119+
uniIDs := fn.Map(uniRoots, func(root *unirpc.UniverseRoot) *unirpc.ID {
120+
return root.Id
121+
},
123122
)
124123
assertUniverseKeysEqual(t.t, uniIDs, t.tapd, bob)
125124
assertUniverseLeavesEqual(t.t, uniIDs, t.tapd, bob)

mssmt/proof.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"errors"
55
"fmt"
66

7-
"github.com/lightninglabs/taproot-assets/chanutils"
7+
"github.com/lightninglabs/taproot-assets/fn"
88
)
99

1010
var (
@@ -89,7 +89,7 @@ func (p *CompressedProof) Decompress() (*Proof, error) {
8989
nodes := make([]Node, len(p.Bits))
9090

9191
// The number of 0 bits should match the number of pre-populated nodes.
92-
numExpectedNodes := chanutils.Reduce(p.Bits, func(count int, bit bool) int {
92+
numExpectedNodes := fn.Reduce(p.Bits, func(count int, bit bool) int {
9393
if !bit {
9494
return count + 1
9595
}

0 commit comments

Comments
 (0)