diff --git a/ledger/allegra/rules.go b/ledger/allegra/rules.go index 96831e18..5af2b6bf 100644 --- a/ledger/allegra/rules.go +++ b/ledger/allegra/rules.go @@ -35,7 +35,12 @@ var UtxoValidationRules = []common.UtxoValidationRuleFunc{ } // UtxoValidateOutsideValidityIntervalUtxo ensures that the current tip slot has reached the specified validity interval -func UtxoValidateOutsideValidityIntervalUtxo(tx common.Transaction, slot uint64, _ common.LedgerState, _ common.ProtocolParameters) error { +func UtxoValidateOutsideValidityIntervalUtxo( + tx common.Transaction, + slot uint64, + _ common.LedgerState, + _ common.ProtocolParameters, +) error { validityIntervalStart := tx.ValidityIntervalStart() if validityIntervalStart == 0 || slot >= validityIntervalStart { return nil @@ -46,54 +51,119 @@ func UtxoValidateOutsideValidityIntervalUtxo(tx common.Transaction, slot uint64, } } -func UtxoValidateInputSetEmptyUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateInputSetEmptyUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { return shelley.UtxoValidateInputSetEmptyUtxo(tx, slot, ls, pp) } -func UtxoValidateFeeTooSmallUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateFeeTooSmallUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { tmpPparams, ok := pp.(*AllegraProtocolParameters) if !ok { return fmt.Errorf("pparams are not expected type") } - return shelley.UtxoValidateFeeTooSmallUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters) + return shelley.UtxoValidateFeeTooSmallUtxo( + tx, + slot, + ls, + &tmpPparams.ShelleyProtocolParameters, + ) } -func UtxoValidateBadInputsUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateBadInputsUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { return shelley.UtxoValidateBadInputsUtxo(tx, slot, ls, pp) } -func UtxoValidateWrongNetwork(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateWrongNetwork( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { return shelley.UtxoValidateWrongNetwork(tx, slot, ls, pp) } -func UtxoValidateWrongNetworkWithdrawal(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateWrongNetworkWithdrawal( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { return shelley.UtxoValidateWrongNetworkWithdrawal(tx, slot, ls, pp) } -func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateValueNotConservedUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { tmpPparams, ok := pp.(*AllegraProtocolParameters) if !ok { return fmt.Errorf("pparams are not expected type") } - return shelley.UtxoValidateValueNotConservedUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters) + return shelley.UtxoValidateValueNotConservedUtxo( + tx, + slot, + ls, + &tmpPparams.ShelleyProtocolParameters, + ) } -func UtxoValidateOutputTooSmallUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateOutputTooSmallUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { tmpPparams, ok := pp.(*AllegraProtocolParameters) if !ok { return fmt.Errorf("pparams are not expected type") } - return shelley.UtxoValidateOutputTooSmallUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters) + return shelley.UtxoValidateOutputTooSmallUtxo( + tx, + slot, + ls, + &tmpPparams.ShelleyProtocolParameters, + ) } -func UtxoValidateOutputBootAddrAttrsTooBig(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateOutputBootAddrAttrsTooBig( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { return shelley.UtxoValidateOutputBootAddrAttrsTooBig(tx, slot, ls, pp) } -func UtxoValidateMaxTxSizeUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateMaxTxSizeUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { tmpPparams, ok := pp.(*AllegraProtocolParameters) if !ok { return fmt.Errorf("pparams are not expected type") } - return shelley.UtxoValidateMaxTxSizeUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters) + return shelley.UtxoValidateMaxTxSizeUtxo( + tx, + slot, + ls, + &tmpPparams.ShelleyProtocolParameters, + ) } diff --git a/ledger/allegra/rules_test.go b/ledger/allegra/rules_test.go index 4121161d..1f2dc283 100644 --- a/ledger/allegra/rules_test.go +++ b/ledger/allegra/rules_test.go @@ -36,7 +36,9 @@ func (ls testLedgerState) NetworkId() uint { return ls.networkId } -func (ls testLedgerState) UtxoById(id common.TransactionInput) (common.Utxo, error) { +func (ls testLedgerState) UtxoById( + id common.TransactionInput, +) (common.Utxo, error) { for _, tmpUtxo := range ls.utxos { if id.Index() != tmpUtxo.Id.Index() { continue @@ -383,8 +385,12 @@ func TestUtxoValidateBadInputsUtxo(t *testing.T) { } func TestUtxoValidateWrongNetwork(t *testing.T) { - testCorrectNetworkAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd") - testWrongNetworkAddr, _ := common.NewAddress("addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07") + testCorrectNetworkAddr, _ := common.NewAddress( + "addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd", + ) + testWrongNetworkAddr, _ := common.NewAddress( + "addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07", + ) testTx := &allegra.AllegraTransaction{ Body: allegra.AllegraTransactionBody{ ShelleyTransactionBody: shelley.ShelleyTransactionBody{ @@ -451,8 +457,12 @@ func TestUtxoValidateWrongNetwork(t *testing.T) { } func TestUtxoValidateWrongNetworkWithdrawal(t *testing.T) { - testCorrectNetworkAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd") - testWrongNetworkAddr, _ := common.NewAddress("addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07") + testCorrectNetworkAddr, _ := common.NewAddress( + "addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd", + ) + testWrongNetworkAddr, _ := common.NewAddress( + "addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07", + ) testTx := &allegra.AllegraTransaction{ Body: allegra.AllegraTransactionBody{ ShelleyTransactionBody: shelley.ShelleyTransactionBody{ @@ -696,7 +706,9 @@ func TestUtxoValidateOutputTooSmallUtxo(t *testing.T) { } func TestUtxoValidateOutputBootAddrAttrsTooBig(t *testing.T) { - testGoodAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd") + testGoodAddr, _ := common.NewAddress( + "addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd", + ) // Generate random pubkey testBadAddrPubkey := make([]byte, 28) if _, err := rand.Read(testBadAddrPubkey); err != nil { diff --git a/ledger/alonzo/alonzo.go b/ledger/alonzo/alonzo.go index af52cdb3..b89bc487 100644 --- a/ledger/alonzo/alonzo.go +++ b/ledger/alonzo/alonzo.go @@ -322,7 +322,10 @@ func (r AlonzoRedeemers) Indexes(tag common.RedeemerTag) []uint { return ret } -func (r AlonzoRedeemers) Value(index uint, tag common.RedeemerTag) (cbor.LazyValue, common.RedeemerExUnits) { +func (r AlonzoRedeemers) Value( + index uint, + tag common.RedeemerTag, +) (cbor.LazyValue, common.RedeemerExUnits) { for _, redeemer := range r { if redeemer.Tag == tag && uint(redeemer.Index) == index { return redeemer.Data, redeemer.ExUnits diff --git a/ledger/alonzo/pparams.go b/ledger/alonzo/pparams.go index 44e19a6c..fbd6ddcf 100644 --- a/ledger/alonzo/pparams.go +++ b/ledger/alonzo/pparams.go @@ -122,27 +122,27 @@ func (p *AlonzoProtocolParameters) Utxorpc() *cardano.PParams { if p.A0.Num().Int64() > math.MaxInt32 || p.A0.Denom().Int64() < 0 || p.A0.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.Rho.Num().Int64() > math.MaxInt32 || p.Rho.Denom().Int64() < 0 || p.Rho.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.Tau.Num().Int64() > math.MaxInt32 || p.Tau.Denom().Int64() < 0 || p.Tau.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.ExecutionCosts.MemPrice.Num().Int64() > math.MaxInt32 || p.ExecutionCosts.MemPrice.Denom().Int64() < 0 || p.ExecutionCosts.MemPrice.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.ExecutionCosts.StepPrice.Num().Int64() > math.MaxInt32 || p.ExecutionCosts.StepPrice.Denom().Int64() < 0 || p.ExecutionCosts.StepPrice.Denom().Int64() > math.MaxUint32 { - return nil + return nil } // #nosec G115 return &cardano.PParams{ diff --git a/ledger/babbage/pparams.go b/ledger/babbage/pparams.go index 3bb27669..ee117043 100644 --- a/ledger/babbage/pparams.go +++ b/ledger/babbage/pparams.go @@ -161,27 +161,27 @@ func (p *BabbageProtocolParameters) Utxorpc() *cardano.PParams { if p.A0.Num().Int64() > math.MaxInt32 || p.A0.Denom().Int64() < 0 || p.A0.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.Rho.Num().Int64() > math.MaxInt32 || p.Rho.Denom().Int64() < 0 || p.Rho.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.Tau.Num().Int64() > math.MaxInt32 || p.Tau.Denom().Int64() < 0 || p.Tau.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.ExecutionCosts.MemPrice.Num().Int64() > math.MaxInt32 || p.ExecutionCosts.MemPrice.Denom().Int64() < 0 || p.ExecutionCosts.MemPrice.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.ExecutionCosts.StepPrice.Num().Int64() > math.MaxInt32 || p.ExecutionCosts.StepPrice.Denom().Int64() < 0 || p.ExecutionCosts.StepPrice.Denom().Int64() > math.MaxUint32 { - return nil + return nil } // #nosec G115 return &cardano.PParams{ diff --git a/ledger/conway/conway.go b/ledger/conway/conway.go index b5100ee9..dc80ae8f 100644 --- a/ledger/conway/conway.go +++ b/ledger/conway/conway.go @@ -200,7 +200,10 @@ func (r ConwayRedeemers) Indexes(tag common.RedeemerTag) []uint { return ret } -func (r ConwayRedeemers) Value(index uint, tag common.RedeemerTag) (cbor.LazyValue, common.RedeemerExUnits) { +func (r ConwayRedeemers) Value( + index uint, + tag common.RedeemerTag, +) (cbor.LazyValue, common.RedeemerExUnits) { redeemer, ok := r.Redeemers[ConwayRedeemerKey{ Tag: tag, Index: uint32(index), // #nosec G115 diff --git a/ledger/conway/pparams.go b/ledger/conway/pparams.go index 6e03d842..e82fa0d8 100644 --- a/ledger/conway/pparams.go +++ b/ledger/conway/pparams.go @@ -64,27 +64,27 @@ func (p *ConwayProtocolParameters) Utxorpc() *cardano.PParams { if p.A0.Num().Int64() > math.MaxInt32 || p.A0.Denom().Int64() < 0 || p.A0.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.Rho.Num().Int64() > math.MaxInt32 || p.Rho.Denom().Int64() < 0 || p.Rho.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.Tau.Num().Int64() > math.MaxInt32 || p.Tau.Denom().Int64() < 0 || p.Tau.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.ExecutionCosts.MemPrice.Num().Int64() > math.MaxInt32 || p.ExecutionCosts.MemPrice.Denom().Int64() < 0 || p.ExecutionCosts.MemPrice.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.ExecutionCosts.StepPrice.Num().Int64() > math.MaxInt32 || p.ExecutionCosts.StepPrice.Denom().Int64() < 0 || p.ExecutionCosts.StepPrice.Denom().Int64() > math.MaxUint32 { - return nil + return nil } // #nosec G115 return &cardano.PParams{ diff --git a/ledger/mary/rules.go b/ledger/mary/rules.go index 1ecb3320..badc7cac 100644 --- a/ledger/mary/rules.go +++ b/ledger/mary/rules.go @@ -42,7 +42,12 @@ var UtxoValidationRules = []common.UtxoValidationRuleFunc{ } // UtxoValidateOutputTooBigUtxo ensures that transaction output values are not too large -func UtxoValidateOutputTooBigUtxo(tx common.Transaction, slot uint64, _ common.LedgerState, _ common.ProtocolParameters) error { +func UtxoValidateOutputTooBigUtxo( + tx common.Transaction, + slot uint64, + _ common.LedgerState, + _ common.ProtocolParameters, +) error { var badOutputs []common.TransactionOutput for _, txOutput := range tx.Outputs() { tmpOutput, ok := txOutput.(*MaryTransactionOutput) @@ -66,58 +71,128 @@ func UtxoValidateOutputTooBigUtxo(tx common.Transaction, slot uint64, _ common.L } } -func UtxoValidateOutsideValidityIntervalUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateOutsideValidityIntervalUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { return allegra.UtxoValidateOutsideValidityIntervalUtxo(tx, slot, ls, pp) } -func UtxoValidateInputSetEmptyUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateInputSetEmptyUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { return shelley.UtxoValidateInputSetEmptyUtxo(tx, slot, ls, pp) } -func UtxoValidateFeeTooSmallUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateFeeTooSmallUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { tmpPparams, ok := pp.(*MaryProtocolParameters) if !ok { return fmt.Errorf("pparams are not expected type") } - return shelley.UtxoValidateFeeTooSmallUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters) + return shelley.UtxoValidateFeeTooSmallUtxo( + tx, + slot, + ls, + &tmpPparams.ShelleyProtocolParameters, + ) } -func UtxoValidateBadInputsUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateBadInputsUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { return shelley.UtxoValidateBadInputsUtxo(tx, slot, ls, pp) } -func UtxoValidateWrongNetwork(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateWrongNetwork( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { return shelley.UtxoValidateWrongNetwork(tx, slot, ls, pp) } -func UtxoValidateWrongNetworkWithdrawal(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateWrongNetworkWithdrawal( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { return shelley.UtxoValidateWrongNetworkWithdrawal(tx, slot, ls, pp) } -func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateValueNotConservedUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { tmpPparams, ok := pp.(*MaryProtocolParameters) if !ok { return fmt.Errorf("pparams are not expected type") } - return shelley.UtxoValidateValueNotConservedUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters) + return shelley.UtxoValidateValueNotConservedUtxo( + tx, + slot, + ls, + &tmpPparams.ShelleyProtocolParameters, + ) } -func UtxoValidateOutputTooSmallUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateOutputTooSmallUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { tmpPparams, ok := pp.(*MaryProtocolParameters) if !ok { return fmt.Errorf("pparams are not expected type") } - return shelley.UtxoValidateOutputTooSmallUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters) + return shelley.UtxoValidateOutputTooSmallUtxo( + tx, + slot, + ls, + &tmpPparams.ShelleyProtocolParameters, + ) } -func UtxoValidateOutputBootAddrAttrsTooBig(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateOutputBootAddrAttrsTooBig( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { return shelley.UtxoValidateOutputBootAddrAttrsTooBig(tx, slot, ls, pp) } -func UtxoValidateMaxTxSizeUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateMaxTxSizeUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { tmpPparams, ok := pp.(*MaryProtocolParameters) if !ok { return fmt.Errorf("pparams are not expected type") } - return shelley.UtxoValidateMaxTxSizeUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters) + return shelley.UtxoValidateMaxTxSizeUtxo( + tx, + slot, + ls, + &tmpPparams.ShelleyProtocolParameters, + ) } diff --git a/ledger/mary/rules_test.go b/ledger/mary/rules_test.go index 0bc1421b..f6ba0a3e 100644 --- a/ledger/mary/rules_test.go +++ b/ledger/mary/rules_test.go @@ -38,7 +38,9 @@ func (ls testLedgerState) NetworkId() uint { return ls.networkId } -func (ls testLedgerState) UtxoById(id common.TransactionInput) (common.Utxo, error) { +func (ls testLedgerState) UtxoById( + id common.TransactionInput, +) (common.Utxo, error) { for _, tmpUtxo := range ls.utxos { if id.Index() != tmpUtxo.Id.Index() { continue @@ -395,8 +397,12 @@ func TestUtxoValidateBadInputsUtxo(t *testing.T) { } func TestUtxoValidateWrongNetwork(t *testing.T) { - testCorrectNetworkAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd") - testWrongNetworkAddr, _ := common.NewAddress("addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07") + testCorrectNetworkAddr, _ := common.NewAddress( + "addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd", + ) + testWrongNetworkAddr, _ := common.NewAddress( + "addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07", + ) testTx := &mary.MaryTransaction{ Body: mary.MaryTransactionBody{ TxOutputs: []mary.MaryTransactionOutput{ @@ -463,8 +469,12 @@ func TestUtxoValidateWrongNetwork(t *testing.T) { } func TestUtxoValidateWrongNetworkWithdrawal(t *testing.T) { - testCorrectNetworkAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd") - testWrongNetworkAddr, _ := common.NewAddress("addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07") + testCorrectNetworkAddr, _ := common.NewAddress( + "addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd", + ) + testWrongNetworkAddr, _ := common.NewAddress( + "addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07", + ) testTx := &mary.MaryTransaction{ Body: mary.MaryTransactionBody{ AllegraTransactionBody: allegra.AllegraTransactionBody{ @@ -546,7 +556,10 @@ func TestUtxoValidateValueNotConservedUtxo(t *testing.T) { TxFee: testFee, TxInputs: shelley.NewShelleyTransactionInputSet( []shelley.ShelleyTransactionInput{ - shelley.NewShelleyTransactionInput(testInputTxId, 0), + shelley.NewShelleyTransactionInput( + testInputTxId, + 0, + ), }, ), }, @@ -731,7 +744,9 @@ func TestUtxoValidateOutputTooBigUtxo(t *testing.T) { cbor.NewByteString(tmpAssetName): 1, } } - tmpBadMultiAsset := common.NewMultiAsset[common.MultiAssetTypeOutput](tmpBadAssets) + tmpBadMultiAsset := common.NewMultiAsset[common.MultiAssetTypeOutput]( + tmpBadAssets, + ) var testOutputValueBad = mary.MaryTransactionOutputValue{ Amount: 1234567, Assets: &tmpBadMultiAsset, @@ -797,7 +812,9 @@ func TestUtxoValidateOutputTooBigUtxo(t *testing.T) { } func TestUtxoValidateOutputBootAddrAttrsTooBig(t *testing.T) { - testGoodAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd") + testGoodAddr, _ := common.NewAddress( + "addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd", + ) // Generate random pubkey testBadAddrPubkey := make([]byte, 28) if _, err := rand.Read(testBadAddrPubkey); err != nil { diff --git a/ledger/shelley/pparams.go b/ledger/shelley/pparams.go index adb308a5..46c1f1da 100644 --- a/ledger/shelley/pparams.go +++ b/ledger/shelley/pparams.go @@ -164,17 +164,17 @@ func (p *ShelleyProtocolParameters) Utxorpc() *cardano.PParams { if p.A0.Num().Int64() > math.MaxInt32 || p.A0.Denom().Int64() < 0 || p.A0.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.Rho.Num().Int64() > math.MaxInt32 || p.Rho.Denom().Int64() < 0 || p.Rho.Denom().Int64() > math.MaxUint32 { - return nil + return nil } if p.Tau.Num().Int64() > math.MaxInt32 || p.Tau.Denom().Int64() < 0 || p.Tau.Denom().Int64() > math.MaxUint32 { - return nil + return nil } // #nosec G115 return &cardano.PParams{ diff --git a/ledger/shelley/rules.go b/ledger/shelley/rules.go index 002fa262..25f6a3ed 100644 --- a/ledger/shelley/rules.go +++ b/ledger/shelley/rules.go @@ -35,7 +35,12 @@ var UtxoValidationRules = []common.UtxoValidationRuleFunc{ } // UtxoValidateTimeToLive ensures that the current tip slot is not after the specified TTL value -func UtxoValidateTimeToLive(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateTimeToLive( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { ttl := tx.TTL() if ttl == 0 || ttl >= slot { return nil @@ -47,7 +52,12 @@ func UtxoValidateTimeToLive(tx common.Transaction, slot uint64, ls common.Ledger } // UtxoValidateInputSetEmptyUtxo ensures that the input set is not empty -func UtxoValidateInputSetEmptyUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateInputSetEmptyUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { if len(tx.Inputs()) > 0 { return nil } @@ -55,7 +65,12 @@ func UtxoValidateInputSetEmptyUtxo(tx common.Transaction, slot uint64, ls common } // UtxoValidateFeeTooSmallUtxo ensures that the fee is at least the calculated minimum -func UtxoValidateFeeTooSmallUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateFeeTooSmallUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { minFee, err := MinFeeTx(tx, pp) if err != nil { return err @@ -70,7 +85,12 @@ func UtxoValidateFeeTooSmallUtxo(tx common.Transaction, slot uint64, ls common.L } // UtxoValidateBadInputsUtxo ensures that all inputs are present in the ledger state (have not been spent) -func UtxoValidateBadInputsUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateBadInputsUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { var badInputs []common.TransactionInput for _, tmpInput := range tx.Inputs() { _, err := ls.UtxoById(tmpInput) @@ -87,7 +107,12 @@ func UtxoValidateBadInputsUtxo(tx common.Transaction, slot uint64, ls common.Led } // UtxoValidateWrongNetwork ensures that all output addresses use the correct network ID -func UtxoValidateWrongNetwork(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateWrongNetwork( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { networkId := ls.NetworkId() var badAddrs []common.Address for _, tmpOutput := range tx.Outputs() { @@ -107,7 +132,12 @@ func UtxoValidateWrongNetwork(tx common.Transaction, slot uint64, ls common.Ledg } // UtxoValidateWrongNetworkWithdrawal ensures that all withdrawal addresses use the correct network ID -func UtxoValidateWrongNetworkWithdrawal(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateWrongNetworkWithdrawal( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { networkId := ls.NetworkId() var badAddrs []common.Address for addr := range tx.Withdrawals() { @@ -126,7 +156,12 @@ func UtxoValidateWrongNetworkWithdrawal(tx common.Transaction, slot uint64, ls c } // UtxoValidateValueNotConservedUtxo ensures that the consumed value equals the produced value -func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateValueNotConservedUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { // Calculate consumed value // consumed = value from input(s) + withdrawals + refunds(?) var consumedValue uint64 @@ -158,7 +193,12 @@ func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls co } // UtxoValidateOutputTooSmallUtxo ensures that outputs have at least the minimum value -func UtxoValidateOutputTooSmallUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateOutputTooSmallUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { minCoin, err := MinCoinTxOut(tx, pp) if err != nil { return err @@ -178,7 +218,12 @@ func UtxoValidateOutputTooSmallUtxo(tx common.Transaction, slot uint64, ls commo } // UtxoValidateOutputBootAddrAttrsTooBig ensures that bootstrap (Byron) addresses don't have attributes that are too large -func UtxoValidateOutputBootAddrAttrsTooBig(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateOutputBootAddrAttrsTooBig( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { var badOutputs []common.TransactionOutput for _, tmpOutput := range tx.Outputs() { addr := tmpOutput.Address() @@ -204,7 +249,12 @@ func UtxoValidateOutputBootAddrAttrsTooBig(tx common.Transaction, slot uint64, l } // UtxoValidateMaxTxSizeUtxo ensures that a transaction does not exceed the max size -func UtxoValidateMaxTxSizeUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error { +func UtxoValidateMaxTxSizeUtxo( + tx common.Transaction, + slot uint64, + ls common.LedgerState, + pp common.ProtocolParameters, +) error { tmpPparams, ok := pp.(*ShelleyProtocolParameters) if !ok { return fmt.Errorf("pparams are not expected type") @@ -223,18 +273,26 @@ func UtxoValidateMaxTxSizeUtxo(tx common.Transaction, slot uint64, ls common.Led } // MinFeeTx calculates the minimum required fee for a transaction based on protocol parameters -func MinFeeTx(tx common.Transaction, pparams common.ProtocolParameters) (uint64, error) { +func MinFeeTx( + tx common.Transaction, + pparams common.ProtocolParameters, +) (uint64, error) { tmpPparams, ok := pparams.(*ShelleyProtocolParameters) if !ok { return 0, fmt.Errorf("pparams are not expected type") } txBytes := tx.Cbor() - minFee := uint64((tmpPparams.MinFeeA * uint(len(txBytes))) + tmpPparams.MinFeeB) + minFee := uint64( + (tmpPparams.MinFeeA * uint(len(txBytes))) + tmpPparams.MinFeeB, + ) return minFee, nil } // MinCoinTxOut calculates the minimum coin for a transaction output based on protocol parameters -func MinCoinTxOut(_ common.Transaction, pparams common.ProtocolParameters) (uint64, error) { +func MinCoinTxOut( + _ common.Transaction, + pparams common.ProtocolParameters, +) (uint64, error) { tmpPparams, ok := pparams.(*ShelleyProtocolParameters) if !ok { return 0, fmt.Errorf("pparams are not expected type") diff --git a/ledger/shelley/rules_test.go b/ledger/shelley/rules_test.go index 9fa833e3..030cfc87 100644 --- a/ledger/shelley/rules_test.go +++ b/ledger/shelley/rules_test.go @@ -35,7 +35,9 @@ func (ls testLedgerState) NetworkId() uint { return ls.networkId } -func (ls testLedgerState) UtxoById(id common.TransactionInput) (common.Utxo, error) { +func (ls testLedgerState) UtxoById( + id common.TransactionInput, +) (common.Utxo, error) { for _, tmpUtxo := range ls.utxos { if id.Index() != tmpUtxo.Id.Index() { continue @@ -376,8 +378,12 @@ func TestUtxoValidateBadInputsUtxo(t *testing.T) { } func TestUtxoValidateWrongNetwork(t *testing.T) { - testCorrectNetworkAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd") - testWrongNetworkAddr, _ := common.NewAddress("addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07") + testCorrectNetworkAddr, _ := common.NewAddress( + "addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd", + ) + testWrongNetworkAddr, _ := common.NewAddress( + "addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07", + ) testTx := &shelley.ShelleyTransaction{ Body: shelley.ShelleyTransactionBody{ TxOutputs: []shelley.ShelleyTransactionOutput{ @@ -442,8 +448,12 @@ func TestUtxoValidateWrongNetwork(t *testing.T) { } func TestUtxoValidateWrongNetworkWithdrawal(t *testing.T) { - testCorrectNetworkAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd") - testWrongNetworkAddr, _ := common.NewAddress("addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07") + testCorrectNetworkAddr, _ := common.NewAddress( + "addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd", + ) + testWrongNetworkAddr, _ := common.NewAddress( + "addr_test1qqx80sj9nwxdnglmzdl95v2k40d9422au0klwav8jz2dj985v0wma0mza32f8z6pv2jmkn7cen50f9vn9jmp7dd0njcqqpce07", + ) testTx := &shelley.ShelleyTransaction{ Body: shelley.ShelleyTransactionBody{ TxWithdrawals: map[*common.Address]uint64{}, @@ -679,7 +689,9 @@ func TestUtxoValidateOutputTooSmallUtxo(t *testing.T) { } func TestUtxoValidateOutputBootAddrAttrsTooBig(t *testing.T) { - testGoodAddr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd") + testGoodAddr, _ := common.NewAddress( + "addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd", + ) // Generate random pubkey testBadAddrPubkey := make([]byte, 28) if _, err := rand.Read(testBadAddrPubkey); err != nil { diff --git a/ledger/shelley/shelley.go b/ledger/shelley/shelley.go index abccde62..5c90ba09 100644 --- a/ledger/shelley/shelley.go +++ b/ledger/shelley/shelley.go @@ -363,7 +363,9 @@ type ShelleyTransactionInputSet struct { items []ShelleyTransactionInput } -func NewShelleyTransactionInputSet(items []ShelleyTransactionInput) ShelleyTransactionInputSet { +func NewShelleyTransactionInputSet( + items []ShelleyTransactionInput, +) ShelleyTransactionInputSet { s := ShelleyTransactionInputSet{ items: items, } diff --git a/ledger/tx_test.go b/ledger/tx_test.go index be6d3e8f..27f0c81c 100644 --- a/ledger/tx_test.go +++ b/ledger/tx_test.go @@ -41,7 +41,11 @@ func TestDetermineTransactionType(t *testing.T) { t.Fatalf("unexpected error: %s", err) } if tmpTxType != testDef.expectedTxType { - t.Fatalf("did not get expected TX type: got %d, wanted %d", tmpTxType, testDef.expectedTxType) + t.Fatalf( + "did not get expected TX type: got %d, wanted %d", + tmpTxType, + testDef.expectedTxType, + ) } } }