diff --git a/cbor/cbor.go b/cbor/cbor.go index 7b53273f..9dcf5df9 100644 --- a/cbor/cbor.go +++ b/cbor/cbor.go @@ -64,7 +64,7 @@ func (d *DecodeStoreCbor) SetCbor(cborData []byte) { } // Cbor returns the original CBOR for the object -func (d *DecodeStoreCbor) Cbor() []byte { +func (d DecodeStoreCbor) Cbor() []byte { return d.cborData } diff --git a/ledger/allegra/allegra.go b/ledger/allegra/allegra.go index 82b4ac4c..df13f6bd 100644 --- a/ledger/allegra/allegra.go +++ b/ledger/allegra/allegra.go @@ -148,12 +148,12 @@ func (b *AllegraTransactionBody) ValidityIntervalStart() uint64 { return b.TxValidityIntervalStart } -func (b *AllegraTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any { - updateMap := make(map[common.Blake2b224]any) +func (b *AllegraTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) { + updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate) for k, v := range b.Update.ProtocolParamUpdates { updateMap[k] = v } - return updateMap + return b.Update.Epoch, updateMap } type AllegraTransaction struct { @@ -278,8 +278,8 @@ func (t AllegraTransaction) Produced() []common.Utxo { return ret } -func (t AllegraTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any { - return t.Body.ProtocolParametersUpdate() +func (t AllegraTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) { + return t.Body.ProtocolParameterUpdates() } func (t *AllegraTransaction) Cbor() []byte { diff --git a/ledger/alonzo/alonzo.go b/ledger/alonzo/alonzo.go index 23c69294..cef02a49 100644 --- a/ledger/alonzo/alonzo.go +++ b/ledger/alonzo/alonzo.go @@ -166,12 +166,12 @@ func (b *AlonzoTransactionBody) Outputs() []common.TransactionOutput { return ret } -func (b *AlonzoTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any { - updateMap := make(map[common.Blake2b224]any) +func (b *AlonzoTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) { + updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate) for k, v := range b.Update.ProtocolParamUpdates { updateMap[k] = v } - return updateMap + return b.Update.Epoch, updateMap } func (b *AlonzoTransactionBody) Collateral() []common.TransactionInput { @@ -349,8 +349,8 @@ func (t AlonzoTransaction) ValidityIntervalStart() uint64 { return t.Body.ValidityIntervalStart() } -func (t AlonzoTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any { - return t.Body.ProtocolParametersUpdate() +func (t AlonzoTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) { + return t.Body.ProtocolParameterUpdates() } func (t AlonzoTransaction) ReferenceInputs() []common.TransactionInput { diff --git a/ledger/babbage/babbage.go b/ledger/babbage/babbage.go index 04f3a8b4..35143c98 100644 --- a/ledger/babbage/babbage.go +++ b/ledger/babbage/babbage.go @@ -220,12 +220,12 @@ func (b *BabbageTransactionBody) Outputs() []common.TransactionOutput { return ret } -func (b *BabbageTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any { - updateMap := make(map[common.Blake2b224]any) +func (b *BabbageTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) { + updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate) for k, v := range b.Update.ProtocolParamUpdates { updateMap[k] = v } - return updateMap + return b.Update.Epoch, updateMap } func (b *BabbageTransactionBody) ReferenceInputs() []common.TransactionInput { @@ -523,8 +523,8 @@ func (t BabbageTransaction) ValidityIntervalStart() uint64 { return t.Body.ValidityIntervalStart() } -func (t BabbageTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any { - return t.Body.ProtocolParametersUpdate() +func (t BabbageTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) { + return t.Body.ProtocolParameterUpdates() } func (t BabbageTransaction) ReferenceInputs() []common.TransactionInput { @@ -685,6 +685,7 @@ type BabbageProtocolParameters struct { } type BabbageProtocolParameterUpdate struct { + cbor.DecodeStoreCbor MinFeeA uint `cbor:"0,keyasint"` MinFeeB uint `cbor:"1,keyasint"` MaxBlockBodySize uint `cbor:"2,keyasint"` @@ -713,6 +714,12 @@ type BabbageProtocolParameterUpdate struct { MaxCollateralInputs uint `cbor:"24,keyasint"` } +func (BabbageProtocolParameterUpdate) IsProtocolParameterUpdate() {} + +func (u *BabbageProtocolParameterUpdate) UnmarshalCBOR(data []byte) error { + return u.UnmarshalCbor(data, u) +} + func NewBabbageBlockFromCbor(data []byte) (*BabbageBlock, error) { var babbageBlock BabbageBlock if _, err := cbor.Decode(data, &babbageBlock); err != nil { diff --git a/ledger/byron/byron.go b/ledger/byron/byron.go index 51af843f..79a1f470 100644 --- a/ledger/byron/byron.go +++ b/ledger/byron/byron.go @@ -297,13 +297,10 @@ func (t *ByronTransaction) Utxorpc() *utxorpc.Tx { return &utxorpc.Tx{} } -func (t *ByronTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any { - // TODO: Implement this add missing Body TransactionBody - updateMap := make(map[common.Blake2b224]any) - // for k, v := range t.Body.Update.ProtocolParamUpdates { - // updateMap[k] = v - // } - return updateMap +func (t *ByronTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) { + // No protocol parameter updates in Byron + updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate) + return 0, updateMap } type ByronTransactionInput struct { diff --git a/ledger/common/pparams.go b/ledger/common/pparams.go new file mode 100644 index 00000000..2a6ac564 --- /dev/null +++ b/ledger/common/pparams.go @@ -0,0 +1,20 @@ +// Copyright 2024 Blink Labs Software +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package common + +type ProtocolParameterUpdate interface { + IsProtocolParameterUpdate() + Cbor() []byte +} diff --git a/ledger/common/tx.go b/ledger/common/tx.go index ae36457b..6edc0e6e 100644 --- a/ledger/common/tx.go +++ b/ledger/common/tx.go @@ -36,7 +36,7 @@ type TransactionBody interface { Inputs() []TransactionInput Outputs() []TransactionOutput TTL() uint64 - ProtocolParametersUpdate() map[Blake2b224]any + ProtocolParameterUpdates() (uint64, map[Blake2b224]ProtocolParameterUpdate) ValidityIntervalStart() uint64 ReferenceInputs() []TransactionInput Collateral() []TransactionInput diff --git a/ledger/conway/conway.go b/ledger/conway/conway.go index c59916a8..50864ad5 100644 --- a/ledger/conway/conway.go +++ b/ledger/conway/conway.go @@ -203,12 +203,12 @@ func (b *ConwayTransactionBody) UnmarshalCBOR(cborData []byte) error { return b.UnmarshalCbor(cborData, b) } -func (b *ConwayTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any { - updateMap := make(map[common.Blake2b224]any) +func (b *ConwayTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) { + updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate) for k, v := range b.Update.ProtocolParamUpdates { updateMap[k] = v } - return updateMap + return b.Update.Epoch, updateMap } func (b *ConwayTransactionBody) VotingProcedures() common.VotingProcedures { @@ -339,8 +339,8 @@ func (t ConwayTransaction) ValidityIntervalStart() uint64 { return t.Body.ValidityIntervalStart() } -func (t ConwayTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any { - return t.Body.ProtocolParametersUpdate() +func (t ConwayTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) { + return t.Body.ProtocolParameterUpdates() } func (t ConwayTransaction) ReferenceInputs() []common.TransactionInput { diff --git a/ledger/mary/mary.go b/ledger/mary/mary.go index 62be60f8..2708a0c7 100644 --- a/ledger/mary/mary.go +++ b/ledger/mary/mary.go @@ -156,12 +156,12 @@ func (b *MaryTransactionBody) Outputs() []common.TransactionOutput { return ret } -func (b *MaryTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any { - updateMap := make(map[common.Blake2b224]any) +func (b *MaryTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) { + updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate) for k, v := range b.Update.ProtocolParamUpdates { updateMap[k] = v } - return updateMap + return b.Update.Epoch, updateMap } func (b *MaryTransactionBody) AssetMint() *common.MultiAsset[common.MultiAssetTypeMint] { @@ -210,8 +210,8 @@ func (t MaryTransaction) ValidityIntervalStart() uint64 { return t.Body.ValidityIntervalStart() } -func (t MaryTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any { - return t.Body.ProtocolParametersUpdate() +func (t MaryTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) { + return t.Body.ProtocolParameterUpdates() } func (t MaryTransaction) ReferenceInputs() []common.TransactionInput { diff --git a/ledger/shelley/shelley.go b/ledger/shelley/shelley.go index 501fe412..f96f88df 100644 --- a/ledger/shelley/shelley.go +++ b/ledger/shelley/shelley.go @@ -237,12 +237,12 @@ func (b *ShelleyTransactionBody) ValidityIntervalStart() uint64 { return 0 } -func (b *ShelleyTransactionBody) ProtocolParametersUpdate() map[common.Blake2b224]any { - updateMap := make(map[common.Blake2b224]any) +func (b *ShelleyTransactionBody) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) { + updateMap := make(map[common.Blake2b224]common.ProtocolParameterUpdate) for k, v := range b.Update.ProtocolParamUpdates { updateMap[k] = v } - return updateMap + return b.Update.Epoch, updateMap } func (b *ShelleyTransactionBody) ReferenceInputs() []common.TransactionInput { @@ -554,8 +554,8 @@ func (t ShelleyTransaction) Utxorpc() *utxorpc.Tx { return t.Body.Utxorpc() } -func (t *ShelleyTransaction) ProtocolParametersUpdate() map[common.Blake2b224]any { - return t.Body.ProtocolParametersUpdate() +func (t *ShelleyTransaction) ProtocolParameterUpdates() (uint64, map[common.Blake2b224]common.ProtocolParameterUpdate) { + return t.Body.ProtocolParameterUpdates() } func (t *ShelleyTransaction) Cbor() []byte { @@ -606,6 +606,7 @@ type ShelleyProtocolParameters struct { } type ShelleyProtocolParameterUpdate struct { + cbor.DecodeStoreCbor MinFeeA uint `cbor:"0,keyasint"` MinFeeB uint `cbor:"1,keyasint"` MaxBlockBodySize uint `cbor:"2,keyasint"` @@ -628,6 +629,12 @@ type ShelleyProtocolParameterUpdate struct { MinUtxoValue uint `cbor:"15,keyasint"` } +func (ShelleyProtocolParameterUpdate) IsProtocolParameterUpdate() {} + +func (u *ShelleyProtocolParameterUpdate) UnmarshalCBOR(data []byte) error { + return u.UnmarshalCbor(data, u) +} + const ( NonceType0 = 0 NonceType1 = 1