Skip to content
Merged
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
14 changes: 11 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ issues:
max-issues-per-linter: 0
max-same-issues: 0
linters:
disable:
- asasalint
- depguard
- recvcheck
- unparam
enable:
- errcheck
- gosimple
Expand All @@ -12,12 +17,15 @@ linters:
- staticcheck
- unused
# Defaults above ours below
disable:
- asasalint
- recvcheck
- copyloopvar
- usestdlibvars
- whitespace
presets:
- bugs
- format
- import
- performance
- unused
#linters-settings:
# errcheck:
# check-type-assertions: true
Expand Down
6 changes: 4 additions & 2 deletions cbor/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ const (
type RawMessage = _cbor.RawMessage

// Alias for Tag for convenience
type Tag = _cbor.Tag
type RawTag = _cbor.RawTag
type (
Tag = _cbor.Tag
RawTag = _cbor.RawTag
)

// Useful for embedding and easier to remember
type StructAsArray struct {
Expand Down
6 changes: 4 additions & 2 deletions cbor/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ func DecodeById(
return ret, nil
}

var decodeGenericTypeCache = map[reflect.Type]reflect.Type{}
var decodeGenericTypeCacheMutex sync.RWMutex
var (
decodeGenericTypeCache = map[reflect.Type]reflect.Type{}
decodeGenericTypeCacheMutex sync.RWMutex
)

// DecodeGeneric decodes the specified CBOR into the destination object without using the
// destination object's UnmarshalCBOR() function
Expand Down
6 changes: 4 additions & 2 deletions cbor/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ func Encode(data interface{}) ([]byte, error) {
return buf.Bytes(), err
}

var encodeGenericTypeCache = map[reflect.Type]reflect.Type{}
var encodeGenericTypeCacheMutex sync.RWMutex
var (
encodeGenericTypeCache = map[reflect.Type]reflect.Type{}
encodeGenericTypeCacheMutex sync.RWMutex
)

// EncodeGeneric encodes the specified object to CBOR without using the source object's
// MarshalCBOR() function
Expand Down
1 change: 0 additions & 1 deletion cbor/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ func generateAstJsonMap[T map[any]any | Map](v T) ([]byte, error) {
strings.Join(tmpItems, ","),
)
return []byte(tmpJson), nil

}

type Constructor struct {
Expand Down
5 changes: 2 additions & 3 deletions cmd/gouroboros/mem_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ import (
"fmt"
"log"
"net/http"
// #nosec G108
_ "net/http/pprof"
"os"
"runtime"
"runtime/pprof"
"time"

// #nosec G108
_ "net/http/pprof"

ouroboros "github.com/blinklabs-io/gouroboros"
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/gouroboros/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (

type serverFlags struct {
flagset *flag.FlagSet
//txFile string
// txFile string
}

func newServerFlags() *serverFlags {
f := &serverFlags{
flagset: flag.NewFlagSet("server", flag.ExitOnError),
}
//f.flagset.StringVar(&f.txFile, "tx-file", "", "path to the transaction file to submit")
// f.flagset.StringVar(&f.txFile, "tx-file", "", "path to the transaction file to submit")
return f
}

Expand Down
10 changes: 6 additions & 4 deletions cmd/tx-submission/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ type txSubmissionFlags struct {
rawTxFile string
}

var txBytes []byte
var txHash [32]byte
var sentTx bool
var doneChan chan any
var (
txBytes []byte
txHash [32]byte
sentTx bool
doneChan chan any
)

func main() {
// Parse commandline
Expand Down
12 changes: 7 additions & 5 deletions ledger/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import "github.com/blinklabs-io/gouroboros/ledger/allegra"
// to keep existing code working after a refactor of the ledger package

// Allegra types
type AllegraBlock = allegra.AllegraBlock
type AllegraTransaction = allegra.AllegraTransaction
type AllegraTransactionBody = allegra.AllegraTransactionBody
type AllegraProtocolParameters = allegra.AllegraProtocolParameters
type AllegraProtocolParameterUpdate = allegra.AllegraProtocolParameterUpdate
type (
AllegraBlock = allegra.AllegraBlock
AllegraTransaction = allegra.AllegraTransaction
AllegraTransactionBody = allegra.AllegraTransactionBody
AllegraProtocolParameters = allegra.AllegraProtocolParameters
AllegraProtocolParameterUpdate = allegra.AllegraProtocolParameterUpdate
)

// Allegra constants
const (
Expand Down
11 changes: 4 additions & 7 deletions ledger/allegra/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/gouroboros/ledger/shelley"

utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

Expand All @@ -36,12 +35,10 @@ const (
TxTypeAllegra = 2
)

var (
EraAllegra = common.Era{
Id: EraIdAllegra,
Name: EraNameAllegra,
}
)
var EraAllegra = common.Era{
Id: EraIdAllegra,
Name: EraNameAllegra,
}

func init() {
common.RegisterEra(EraAllegra)
Expand Down
18 changes: 10 additions & 8 deletions ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import "github.com/blinklabs-io/gouroboros/ledger/alonzo"
// to keep existing code working after a refactor of the ledger package

// Alonzo types
type AlonzoBlock = alonzo.AlonzoBlock
type AlonzoBlockHeader = alonzo.AlonzoBlockHeader
type AlonzoTransaction = alonzo.AlonzoTransaction
type AlonzoTransactionBody = alonzo.AlonzoTransactionBody
type AlonzoTransactionOutput = alonzo.AlonzoTransactionOutput
type AlonzoTransactionWitnessSet = alonzo.AlonzoTransactionWitnessSet
type AlonzoProtocolParameters = alonzo.AlonzoProtocolParameters
type AlonzoProtocolParameterUpdate = alonzo.AlonzoProtocolParameterUpdate
type (
AlonzoBlock = alonzo.AlonzoBlock
AlonzoBlockHeader = alonzo.AlonzoBlockHeader
AlonzoTransaction = alonzo.AlonzoTransaction
AlonzoTransactionBody = alonzo.AlonzoTransactionBody
AlonzoTransactionOutput = alonzo.AlonzoTransactionOutput
AlonzoTransactionWitnessSet = alonzo.AlonzoTransactionWitnessSet
AlonzoProtocolParameters = alonzo.AlonzoProtocolParameters
AlonzoProtocolParameterUpdate = alonzo.AlonzoProtocolParameterUpdate
)

// Alonzo constants
const (
Expand Down
14 changes: 5 additions & 9 deletions ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/gouroboros/ledger/mary"
"github.com/blinklabs-io/gouroboros/ledger/shelley"

utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

Expand All @@ -38,12 +37,10 @@ const (
TxTypeAlonzo = 4
)

var (
EraAlonzo = common.Era{
Id: EraIdAlonzo,
Name: EraNameAlonzo,
}
)
var EraAlonzo = common.Era{
Id: EraIdAlonzo,
Name: EraNameAlonzo,
}

func init() {
common.RegisterEra(EraAlonzo)
Expand Down Expand Up @@ -169,7 +166,6 @@ func (b *AlonzoTransactionBody) UnmarshalCBOR(cborData []byte) error {
func (b *AlonzoTransactionBody) Outputs() []common.TransactionOutput {
ret := []common.TransactionOutput{}
for _, output := range b.TxOutputs {

ret = append(ret, &output)
}
return ret
Expand Down Expand Up @@ -277,7 +273,7 @@ func (o AlonzoTransactionOutput) Utxorpc() *utxorpc.TxOutput {
if o.Assets() != nil {
tmpAssets := o.Assets()
for _, policyId := range tmpAssets.Policies() {
var ma = &utxorpc.Multiasset{
ma := &utxorpc.Multiasset{
PolicyId: policyId.Bytes(),
}
for _, assetName := range tmpAssets.Assets(policyId) {
Expand Down
3 changes: 1 addition & 2 deletions ledger/alonzo/pparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ package alonzo
import (
"math"

cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/gouroboros/ledger/mary"
cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

type AlonzoProtocolParameters struct {
Expand Down
18 changes: 10 additions & 8 deletions ledger/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import "github.com/blinklabs-io/gouroboros/ledger/babbage"
// to keep existing code working after a refactor of the ledger package

// Babbage types
type BabbageBlock = babbage.BabbageBlock
type BabbageBlockHeader = babbage.BabbageBlockHeader
type BabbageTransaction = babbage.BabbageTransaction
type BabbageTransactionBody = babbage.BabbageTransactionBody
type BabbageTransactionOutput = babbage.BabbageTransactionOutput
type BabbageTransactionWitnessSet = babbage.BabbageTransactionWitnessSet
type BabbageProtocolParameters = babbage.BabbageProtocolParameters
type BabbageProtocolParameterUpdate = babbage.BabbageProtocolParameterUpdate
type (
BabbageBlock = babbage.BabbageBlock
BabbageBlockHeader = babbage.BabbageBlockHeader
BabbageTransaction = babbage.BabbageTransaction
BabbageTransactionBody = babbage.BabbageTransactionBody
BabbageTransactionOutput = babbage.BabbageTransactionOutput
BabbageTransactionWitnessSet = babbage.BabbageTransactionWitnessSet
BabbageProtocolParameters = babbage.BabbageProtocolParameters
BabbageProtocolParameterUpdate = babbage.BabbageProtocolParameterUpdate
)

// Babbage constants
const (
Expand Down
15 changes: 5 additions & 10 deletions ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/gouroboros/ledger/mary"
"github.com/blinklabs-io/gouroboros/ledger/shelley"

utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

Expand All @@ -40,12 +39,10 @@ const (
TxTypeBabbage = 5
)

var (
EraBabbage = common.Era{
Id: EraIdBabbage,
Name: EraNameBabbage,
}
)
var EraBabbage = common.Era{
Id: EraIdBabbage,
Name: EraNameBabbage,
}

func init() {
common.RegisterEra(EraBabbage)
Expand Down Expand Up @@ -228,7 +225,6 @@ func (b *BabbageTransactionBody) UnmarshalCBOR(cborData []byte) error {
func (b *BabbageTransactionBody) Outputs() []common.TransactionOutput {
ret := []common.TransactionOutput{}
for _, output := range b.TxOutputs {

ret = append(ret, &output)
}
return ret
Expand All @@ -245,7 +241,6 @@ func (b *BabbageTransactionBody) ProtocolParameterUpdates() (uint64, map[common.
func (b *BabbageTransactionBody) ReferenceInputs() []common.TransactionInput {
ret := []common.TransactionInput{}
for _, input := range b.TxReferenceInputs {

ret = append(ret, &input)
}
return ret
Expand Down Expand Up @@ -458,7 +453,7 @@ func (o BabbageTransactionOutput) Utxorpc() *utxorpc.TxOutput {
if o.Assets() != nil {
tmpAssets := o.Assets()
for _, policyId := range tmpAssets.Policies() {
var ma = &utxorpc.Multiasset{
ma := &utxorpc.Multiasset{
PolicyId: policyId.Bytes(),
}
for _, assetName := range tmpAssets.Assets(policyId) {
Expand Down
3 changes: 1 addition & 2 deletions ledger/babbage/pparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ package babbage
import (
"math"

cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/alonzo"
"github.com/blinklabs-io/gouroboros/ledger/common"
cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

// BabbageProtocolParameters represents the current Babbage protocol parameters as seen in local-state-query
Expand Down
3 changes: 2 additions & 1 deletion ledger/babbage/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func UtxoValidateCollateralContainsNonAda(
}
totalCollateral += utxo.Output.Amount()
totalAssets.Add(utxo.Output.Assets())
if utxo.Output.Assets() == nil || len(utxo.Output.Assets().Policies()) == 0 {
if utxo.Output.Assets() == nil ||
len(utxo.Output.Assets().Policies()) == 0 {
continue
}
badOutputs = append(badOutputs, utxo.Output)
Expand Down
4 changes: 2 additions & 2 deletions ledger/babbage/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,14 +1113,14 @@ func TestUtxoValidateCollateralContainsNonAda(t *testing.T) {
}
tmpMultiAsset := common.NewMultiAsset[common.MultiAssetTypeOutput](
map[common.Blake2b224]map[cbor.ByteString]uint64{
common.Blake2b224Hash([]byte("abcd")): map[cbor.ByteString]uint64{
common.Blake2b224Hash([]byte("abcd")): {
cbor.NewByteString([]byte("efgh")): 123,
},
},
)
tmpZeroMultiAsset := common.NewMultiAsset[common.MultiAssetTypeOutput](
map[common.Blake2b224]map[cbor.ByteString]uint64{
common.Blake2b224Hash([]byte("abcd")): map[cbor.ByteString]uint64{
common.Blake2b224Hash([]byte("abcd")): {
cbor.NewByteString([]byte("efgh")): 0,
},
},
Expand Down
6 changes: 4 additions & 2 deletions ledger/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (
)

// Compatibility aliases
type Block = common.Block
type BlockHeader = common.BlockHeader
type (
Block = common.Block
BlockHeader = common.BlockHeader
)

func NewBlockFromCbor(blockType uint, data []byte) (Block, error) {
switch blockType {
Expand Down
Loading