Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ linters:
- "prealloc" # Finds slice declarations that could potentially be pre-allocated.
- "predeclared" # Find code that shadows one of Go's predeclared identifiers.
- "promlinter" # Check Prometheus metrics naming via promlint.
# TODO: enable revive - when bored, run 'golangci-lint run -Erevive' and fix issues
# - "revive" # Miscellaneous linter
- "revive" # Miscellaneous linter
- "staticcheck" # Runs staticcheck.
- "sqlclosecheck" # Checks that sql.Rows, sql.Stmt, sqlx.NamedStmt, pgx.Query are closed.
- "rowserrcheck" # Checks whether Rows.Err of rows is checked successfully.
Expand Down
30 changes: 15 additions & 15 deletions api/tbcapi/tbcapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ const (
CmdUTXOsByAddressRequest = "tbcapi-utxos-by-address-request"
CmdUTXOsByAddressResponse = "tbcapi-utxos-by-address-response"

CmdTxByIdRawRequest = "tbcapi-tx-by-id-raw-request"
CmdTxByIdRawResponse = "tbcapi-tx-by-id-raw-response"
CmdTxByIDRawRequest = "tbcapi-tx-by-id-raw-request"
CmdTxByIDRawResponse = "tbcapi-tx-by-id-raw-response"

CmdTxByIdRequest = "tbcapi-tx-by-id-request"
CmdTxByIdResponse = "tbcapi-tx-by-id-response"
CmdTxByIDRequest = "tbcapi-tx-by-id-request"
CmdTxByIDResponse = "tbcapi-tx-by-id-response"

CmdTxBroadcastRequest = "tbcapi-tx-broadcast-request"
CmdTxBroadcastResponse = "tbcapi-tx-broadcast-response"
Expand Down Expand Up @@ -173,7 +173,7 @@ type Tx struct {

// UTXO represents a Bitcoin unspent transaction output.
type UTXO struct {
TxId chainhash.Hash `json:"tx_id"`
TxID chainhash.Hash `json:"tx_id"`
Value btcutil.Amount `json:"value"`
OutIndex uint32 `json:"out_index"`
}
Expand Down Expand Up @@ -296,20 +296,20 @@ type UTXOsByAddressResponse struct {
Error *protocol.Error `json:"error,omitempty"`
}

type TxByIdRawRequest struct {
type TxByIDRawRequest struct {
TxID chainhash.Hash `json:"tx_id"`
}

type TxByIdRawResponse struct {
type TxByIDRawResponse struct {
Tx api.ByteSlice `json:"tx"`
Error *protocol.Error `json:"error,omitempty"`
}

type TxByIdRequest struct {
type TxByIDRequest struct {
TxID chainhash.Hash `json:"tx_id"`
}

type TxByIdResponse struct {
type TxByIDResponse struct {
Tx *Tx `json:"tx"`
Error *protocol.Error `json:"error,omitempty"`
}
Expand Down Expand Up @@ -444,8 +444,8 @@ type MempoolUtxosRequest struct {

// MempoolUTXO is an output from an unconfirmed mempool transaction.
type MempoolUTXO struct {
// TxId is the transaction hash containing this output.
TxId chainhash.Hash `json:"tx_id"`
// TxID is the transaction hash containing this output.
TxID chainhash.Hash `json:"tx_id"`

// Value is the output amount in satoshis.
Value btcutil.Amount `json:"value"`
Expand Down Expand Up @@ -608,10 +608,10 @@ var commands = map[protocol.Command]reflect.Type{
CmdUTXOsByAddressRawResponse: reflect.TypeFor[UTXOsByAddressRawResponse](),
CmdUTXOsByAddressRequest: reflect.TypeFor[UTXOsByAddressRequest](),
CmdUTXOsByAddressResponse: reflect.TypeFor[UTXOsByAddressResponse](),
CmdTxByIdRawRequest: reflect.TypeFor[TxByIdRawRequest](),
CmdTxByIdRawResponse: reflect.TypeFor[TxByIdRawResponse](),
CmdTxByIdRequest: reflect.TypeFor[TxByIdRequest](),
CmdTxByIdResponse: reflect.TypeFor[TxByIdResponse](),
CmdTxByIDRawRequest: reflect.TypeFor[TxByIDRawRequest](),
CmdTxByIDRawResponse: reflect.TypeFor[TxByIDRawResponse](),
CmdTxByIDRequest: reflect.TypeFor[TxByIDRequest](),
CmdTxByIDResponse: reflect.TypeFor[TxByIDResponse](),
CmdTxBroadcastRequest: reflect.TypeFor[TxBroadcastRequest](),
CmdTxBroadcastResponse: reflect.TypeFor[TxBroadcastResponse](),
CmdTxBroadcastRawRequest: reflect.TypeFor[TxBroadcastRawRequest](),
Expand Down
12 changes: 6 additions & 6 deletions bitcoin/wallet/gozer/blockstream/blockstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (bs *blockstreamGozer) BroadcastTx(ctx context.Context, tx *wire.MsgTx) (*c
return txidHash, nil
}

func (bs *blockstreamGozer) UtxosByAddress(ctx context.Context, filterMempool bool, addr btcutil.Address, start, count uint) ([]*tbcapi.UTXO, error) {
func (bs *blockstreamGozer) UtxosByAddress(ctx context.Context, _ bool, addr btcutil.Address, _, _ uint) ([]*tbcapi.UTXO, error) {
u := fmt.Sprintf("%v/address/%v/utxo", bs.url, addr)
utxos, err := httpclient.Request(ctx, "GET", u, nil)
if err != nil {
Expand All @@ -171,7 +171,7 @@ func (bs *blockstreamGozer) UtxosByAddress(ctx context.Context, filterMempool bo
BlockTime int64 `json:"block_time"`
}
type utxosJSON struct {
TxId chainhash.Hash `json:"txid"`
TxID chainhash.Hash `json:"txid"`
Vout uint32 `json:"vout"`
Value btcutil.Amount `json:"value"`
Status statusJSON `json:"status"`
Expand All @@ -188,7 +188,7 @@ func (bs *blockstreamGozer) UtxosByAddress(ctx context.Context, filterMempool bo
continue
}
urv = append(urv, &tbcapi.UTXO{
TxId: v.TxId,
TxID: v.TxID,
OutIndex: v.Vout,
Value: v.Value,
})
Expand All @@ -201,13 +201,13 @@ func (bs *blockstreamGozer) MempoolUtxos(_ context.Context, _ []api.ByteSlice) (
return nil, errors.New("mempool utxos not supported by blockstream")
}

func (bs *blockstreamGozer) BlocksByL2AbrevHashes(ctx context.Context, hashes []chainhash.Hash) *gozer.BlocksByL2AbrevHashesResponse {
func (bs *blockstreamGozer) BlocksByL2AbrevHashes(_ context.Context, _ []chainhash.Hash) *gozer.BlocksByL2AbrevHashesResponse {
return &gozer.BlocksByL2AbrevHashesResponse{
Error: protocol.Errorf("not supported yet"),
}
}

func (bs *blockstreamGozer) KeystonesByHeight(ctx context.Context, height uint32, depth int) (*gozer.KeystonesByHeightResponse, error) {
func (bs *blockstreamGozer) KeystonesByHeight(_ context.Context, _ uint32, _ int) (*gozer.KeystonesByHeightResponse, error) {
err := errors.New("not supported yet")
return &gozer.KeystonesByHeightResponse{
Error: protocol.Errorf("%v", err),
Expand All @@ -218,7 +218,7 @@ func (bs *blockstreamGozer) KeystonesByHeight(ctx context.Context, height uint32
// TxByID is a stub — blockstream support for transaction lookup is
// not yet implemented. The only consumer today is ectoplasm which
// uses tbcGozer.
func (bs *blockstreamGozer) TxByID(ctx context.Context, txid *chainhash.Hash) (*tbcapi.Tx, error) {
func (bs *blockstreamGozer) TxByID(_ context.Context, _ *chainhash.Hash) (*tbcapi.Tx, error) {
// Blockstream exposes GET /tx/{txid}/hex and GET /tx/{txid},
// either of which could be mapped onto *tbcapi.Tx. Left as
// a stub here because the only consumer today is ectoplasm
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/wallet/gozer/blockstream/blockstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/hemilabs/heminetwork/v2/bitcoin/wallet/gozer"
)

func mockHttpServer() *httptest.Server {
func mockHTTPServer() *httptest.Server {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fakeHash := "00000000c5cbf1fcdc75539ac75fe8a98417976e548197355b3e5f6c4e884a17"
switch {
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestBlockstreamGozer(t *testing.T) {
defer cancel()

// use mock http server rather than blockstream api
ts := mockHttpServer()
ts := mockHTTPServer()
defer ts.Close()

// can't use Run() for custom urls
Expand Down
10 changes: 5 additions & 5 deletions bitcoin/wallet/gozer/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func TestFilterSpent(t *testing.T) {
h3 := chainhash.HashH([]byte("tx3"))

utxos := []*tbcapi.MempoolUTXO{
{TxId: h1, OutIndex: 0, Value: 1000},
{TxId: h1, OutIndex: 1, Value: 2000},
{TxId: h2, OutIndex: 0, Value: 3000},
{TxId: h3, OutIndex: 0, Value: 4000},
{TxID: h1, OutIndex: 0, Value: 1000},
{TxID: h1, OutIndex: 1, Value: 2000},
{TxID: h2, OutIndex: 0, Value: 3000},
{TxID: h3, OutIndex: 0, Value: 4000},
}

t.Run("no spent", func(t *testing.T) {
Expand All @@ -38,7 +38,7 @@ func TestFilterSpent(t *testing.T) {
t.Fatalf("got %d, want 3", len(result))
}
for _, u := range result {
if u.TxId == h1 && u.OutIndex == 0 {
if u.TxID == h1 && u.OutIndex == 0 {
t.Fatal("spent utxo should be excluded")
}
}
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/wallet/gozer/gozer.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ type KeystonesByHeightResponse struct {
Error *protocol.Error `json:"error,omitempty"`
}

// FilterSpent removes mempool UTXOs whose outpoint (TxId:OutIndex)
// FilterSpent removes mempool UTXOs whose outpoint (TxID:OutIndex)
// appears in the spent set. Use this to exclude outputs that have
// been spent by another mempool transaction (CPFP chains).
func FilterSpent(utxos []*tbcapi.MempoolUTXO, spent []tbcapi.OutPoint) []*tbcapi.MempoolUTXO {
Expand All @@ -163,7 +163,7 @@ func FilterSpent(utxos []*tbcapi.MempoolUTXO, spent []tbcapi.OutPoint) []*tbcapi
}
var out []*tbcapi.MempoolUTXO
for _, u := range utxos {
if _, ok := set[op{Hash: u.TxId, Index: u.OutIndex}]; ok {
if _, ok := set[op{Hash: u.TxID, Index: u.OutIndex}]; ok {
continue
}
out = append(out, u)
Expand Down
10 changes: 5 additions & 5 deletions bitcoin/wallet/gozer/tbcgozer/tbcgozer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ type tbcGozer struct {

var _ gozer.Gozer = (*tbcGozer)(nil)

func New(tbcUrl string) gozer.Gozer {
func New(tbcURL string) gozer.Gozer {
return &tbcGozer{
url: tbcUrl,
url: tbcURL,
cmdCh: make(chan tbcCmd, DefaultCommandQueueDepth),
}
}
Expand Down Expand Up @@ -162,16 +162,16 @@ func (t *tbcGozer) TxByID(ctx context.Context, txid *chainhash.Hash) (*tbcapi.Tx
if txid == nil {
return nil, errors.New("txid is nil")
}
req := &tbcapi.TxByIdRequest{TxID: *txid}
req := &tbcapi.TxByIDRequest{TxID: *txid}

res, err := t.callTBC(ctx, DefaultRequestTimeout, req)
if err != nil {
return nil, err
}

resp, ok := res.(*tbcapi.TxByIdResponse)
resp, ok := res.(*tbcapi.TxByIDResponse)
if !ok {
return nil, fmt.Errorf("not a TxByIdResponse: %T", res)
return nil, fmt.Errorf("not a TxByIDResponse: %T", res)
}

if resp.Error != nil {
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TransactionCreate(locktime uint32, amount btcutil.Amount, satsPerByte float
tx.LockTime = locktime
prevOuts := make(PrevOuts, len(utxoList))
for _, utxo := range utxoList {
outpoint := wire.NewOutPoint(&utxo.TxId, utxo.OutIndex)
outpoint := wire.NewOutPoint(&utxo.TxID, utxo.OutIndex)
tx.AddTxIn(wire.NewTxIn(outpoint, script, nil))
prevOuts[outpoint.String()] = wire.NewTxOut(int64(utxo.Value), script)
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func PoPTransactionCreate(l2keystone *hemi.L2Keystone, locktime uint32, satsPerB
// Assemble transaction
tx := wire.NewMsgTx(2) // Latest supported version
tx.LockTime = locktime
outpoint := wire.NewOutPoint(&utxo.TxId, utxo.OutIndex)
outpoint := wire.NewOutPoint(&utxo.TxID, utxo.OutIndex)
tx.AddTxIn(wire.NewTxIn(outpoint, script, nil))

// Return previous outs to caller so that they can be signed.
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/wallet/wallet_pop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func newPoPFixture(t *testing.T) *popFixture {

fundHash := chainhash.DoubleHashH([]byte("pop-regression-funding-txid-000"))
utxo := &tbcapi.UTXO{
TxId: fundHash,
TxID: fundHash,
OutIndex: 0,
Value: btcutil.Amount(500000),
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/btctool/btctool.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func parseBlockFromHex(blk string) (*btcutil.Block, error) {
return b, nil
}

func parseBlock(ctx context.Context, filename string) (*btcutil.Block, error) {
func parseBlock(_ context.Context, filename string) (*btcutil.Block, error) {
heb, err := os.ReadFile(filename)
if err != nil {
return nil, err
Expand Down Expand Up @@ -149,7 +149,7 @@ func (p *peer) read() (wire.Message, error) {
return msg, err
}

func (p *peer) handshake(ctx context.Context) error {
func (p *peer) handshake(_ context.Context) error {
// 1. send our version
// 2. receive version
// 3. send sendaddrv2
Expand Down Expand Up @@ -257,7 +257,7 @@ func handleInv(p *peer, msg *wire.MsgInv) {
}
}

func handleBlock(p *peer, msg *wire.MsgBlock) {
func handleBlock(_ *peer, msg *wire.MsgBlock) {
fmt.Printf("handle block: %v txs %v\n", msg.Header.BlockHash(),
len(msg.Transactions))
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/hemictl/hemictl.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ func tbcdb(pctx context.Context, flags []string) error {
return fmt.Errorf("chainhash: %w", err)
}

bh, err := s.BlockHashByTxId(ctx, *chtxid)
bh, err := s.BlockHashByTxID(ctx, *chtxid)
if err != nil {
return fmt.Errorf("block by txid: %w", err)
}
Expand All @@ -635,7 +635,7 @@ func tbcdb(pctx context.Context, flags []string) error {
return fmt.Errorf("chainhash: %w", err)
}

tx, err := s.TxById(ctx, *chtxid)
tx, err := s.TxByID(ctx, *chtxid)
if err != nil {
return fmt.Errorf("block by txid: %w", err)
}
Expand All @@ -651,7 +651,7 @@ func tbcdb(pctx context.Context, flags []string) error {
return fmt.Errorf("chainhash: %w", err)
}

si, err := s.SpentOutputsByTxId(ctx, *chtxid)
si, err := s.SpentOutputsByTxID(ctx, *chtxid)
if err != nil {
return fmt.Errorf("spend outputs by txid: %w", err)
}
Expand All @@ -670,7 +670,7 @@ func tbcdb(pctx context.Context, flags []string) error {
return fmt.Errorf("chainhash: %w", err)
}

si, err := s.SpentOutputsByTxId(ctx, *chtxid)
si, err := s.SpentOutputsByTxID(ctx, *chtxid)
if err != nil {
return fmt.Errorf("spend outputs by txid: %w", err)
}
Expand All @@ -687,8 +687,8 @@ func tbcdb(pctx context.Context, flags []string) error {
if err != nil {
return err
}
txIdBytes := [32]byte(chtxid.CloneBytes())
op := tbcd.NewOutpoint(txIdBytes, uint32(idx))
txIDBytes := [32]byte(chtxid.CloneBytes())
op := tbcd.NewOutpoint(txIDBytes, uint32(idx))
// copy(h[:], chtxid[:])
// op := tbcd.NewOutpoint(h, uint32(idx))
sh, err := s.ScriptHashByOutpoint(ctx, op)
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type MyConfig struct {
}

var (
cfg = MyConfig{}
cm CfgMap = CfgMap{
cfg = MyConfig{}
cm = CfgMap{
"STRING": Config{
Value: &cfg.IamString,
DefaultValue: "default",
Expand Down
2 changes: 1 addition & 1 deletion database/level/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (l *Database) openRawDB(name string, blockSize int64) error {
return nil
}

func New(ctx context.Context, cfg *Config) (*Database, error) {
func New(_ context.Context, cfg *Config) (*Database, error) {
log.Tracef("New")
defer log.Tracef("New exit")

Expand Down
Loading