Skip to content

Commit

Permalink
chore: move ProtocolParametersUpdate() to TransactionBody interface (#…
Browse files Browse the repository at this point in the history
…658)

Fixes #603
  • Loading branch information
agaffney authored Jun 12, 2024
1 parent abad687 commit 3f47cef
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 44 deletions.
16 changes: 10 additions & 6 deletions ledger/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ func (b *AllegraTransactionBody) ValidityIntervalStart() uint64 {
return b.TxValidityIntervalStart
}

func (b *AllegraTransactionBody) ProtocolParametersUpdate() map[Blake2b224]any {
updateMap := make(map[Blake2b224]any)
for k, v := range b.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
}

type AllegraTransaction struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand Down Expand Up @@ -238,12 +246,8 @@ func (t AllegraTransaction) Produced() []TransactionOutput {
return t.Outputs()
}

func (t *AllegraTransaction) ProtocolParametersUpdate() map[Blake2b224]any {
updateMap := make(map[Blake2b224]any)
for k, v := range t.Body.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
func (t AllegraTransaction) ProtocolParametersUpdate() map[Blake2b224]any {
return t.Body.ProtocolParametersUpdate()
}

func (t *AllegraTransaction) Cbor() []byte {
Expand Down
20 changes: 12 additions & 8 deletions ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ func (b *AlonzoTransactionBody) Outputs() []TransactionOutput {
return ret
}

func (b *AlonzoTransactionBody) ProtocolParametersUpdate() map[Blake2b224]any {
updateMap := make(map[Blake2b224]any)
for k, v := range b.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
}

func (b *AlonzoTransactionBody) Collateral() []TransactionInput {
ret := []TransactionInput{}
for _, collateral := range b.TxCollateral {
Expand Down Expand Up @@ -289,6 +297,10 @@ func (t AlonzoTransaction) ValidityIntervalStart() uint64 {
return t.Body.ValidityIntervalStart()
}

func (t AlonzoTransaction) ProtocolParametersUpdate() map[Blake2b224]any {
return t.Body.ProtocolParametersUpdate()
}

func (t AlonzoTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}
Expand Down Expand Up @@ -370,14 +382,6 @@ func (t AlonzoTransaction) Produced() []TransactionOutput {
}
}

func (t *AlonzoTransaction) ProtocolParametersUpdate() map[Blake2b224]any {
updateMap := make(map[Blake2b224]any)
for k, v := range t.Body.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
}

func (t *AlonzoTransaction) Cbor() []byte {
// Return stored CBOR if we have any
cborData := t.DecodeStoreCbor.Cbor()
Expand Down
20 changes: 12 additions & 8 deletions ledger/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ func (b *BabbageTransactionBody) Outputs() []TransactionOutput {
return ret
}

func (b *BabbageTransactionBody) ProtocolParametersUpdate() map[Blake2b224]any {
updateMap := make(map[Blake2b224]any)
for k, v := range b.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
}

func (b *BabbageTransactionBody) ReferenceInputs() []TransactionInput {
ret := []TransactionInput{}
for _, input := range b.TxReferenceInputs {
Expand Down Expand Up @@ -455,6 +463,10 @@ func (t BabbageTransaction) ValidityIntervalStart() uint64 {
return t.Body.ValidityIntervalStart()
}

func (t BabbageTransaction) ProtocolParametersUpdate() map[Blake2b224]any {
return t.Body.ProtocolParametersUpdate()
}

func (t BabbageTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}
Expand Down Expand Up @@ -538,14 +550,6 @@ func (t BabbageTransaction) Produced() []TransactionOutput {
}
}

func (t *BabbageTransaction) ProtocolParametersUpdate() map[Blake2b224]any {
updateMap := make(map[Blake2b224]any)
for k, v := range t.Body.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
}

func (t *BabbageTransaction) Cbor() []byte {
// Return stored CBOR if we have any
cborData := t.DecodeStoreCbor.Cbor()
Expand Down
20 changes: 12 additions & 8 deletions ledger/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ func (b *ConwayTransactionBody) UnmarshalCBOR(cborData []byte) error {
return b.UnmarshalCbor(cborData, b)
}

func (b *ConwayTransactionBody) ProtocolParametersUpdate() map[Blake2b224]any {
updateMap := make(map[Blake2b224]any)
for k, v := range b.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
}

func (b *ConwayTransactionBody) VotingProcedures() VotingProcedures {
return b.TxVotingProcedures
}
Expand Down Expand Up @@ -357,6 +365,10 @@ func (t ConwayTransaction) ValidityIntervalStart() uint64 {
return t.Body.ValidityIntervalStart()
}

func (t ConwayTransaction) ProtocolParametersUpdate() map[Blake2b224]any {
return t.Body.ProtocolParametersUpdate()
}

func (t ConwayTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}
Expand Down Expand Up @@ -440,14 +452,6 @@ func (t ConwayTransaction) Produced() []TransactionOutput {
}
}

func (t *ConwayTransaction) ProtocolParametersUpdate() map[Blake2b224]any {
updateMap := make(map[Blake2b224]any)
for k, v := range t.Body.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
}

func (t *ConwayTransaction) Cbor() []byte {
// Return stored CBOR if we have any
cborData := t.DecodeStoreCbor.Cbor()
Expand Down
20 changes: 12 additions & 8 deletions ledger/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ func (b *MaryTransactionBody) Outputs() []TransactionOutput {
return ret
}

func (b *MaryTransactionBody) ProtocolParametersUpdate() map[Blake2b224]any {
updateMap := make(map[Blake2b224]any)
for k, v := range b.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
}

func (b *MaryTransactionBody) AssetMint() *MultiAsset[MultiAssetTypeMint] {
return b.TxMint
}
Expand Down Expand Up @@ -179,6 +187,10 @@ func (t MaryTransaction) ValidityIntervalStart() uint64 {
return t.Body.ValidityIntervalStart()
}

func (t MaryTransaction) ProtocolParametersUpdate() map[Blake2b224]any {
return t.Body.ProtocolParametersUpdate()
}

func (t MaryTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}
Expand Down Expand Up @@ -251,14 +263,6 @@ func (t MaryTransaction) Produced() []TransactionOutput {
return t.Outputs()
}

func (t *MaryTransaction) ProtocolParametersUpdate() map[Blake2b224]any {
updateMap := make(map[Blake2b224]any)
for k, v := range t.Body.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
}

func (t *MaryTransaction) Cbor() []byte {
// Return stored CBOR if we have any
cborData := t.DecodeStoreCbor.Cbor()
Expand Down
14 changes: 9 additions & 5 deletions ledger/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ func (b *ShelleyTransactionBody) ValidityIntervalStart() uint64 {
return 0
}

func (b *ShelleyTransactionBody) ProtocolParametersUpdate() map[Blake2b224]any {
updateMap := make(map[Blake2b224]any)
for k, v := range b.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
}

func (b *ShelleyTransactionBody) ReferenceInputs() []TransactionInput {
return []TransactionInput{}
}
Expand Down Expand Up @@ -503,11 +511,7 @@ func (t ShelleyTransaction) Utxorpc() *utxorpc.Tx {
}

func (t *ShelleyTransaction) ProtocolParametersUpdate() map[Blake2b224]any {
updateMap := make(map[Blake2b224]any)
for k, v := range t.Body.Update.ProtocolParamUpdates {
updateMap[k] = v
}
return updateMap
return t.Body.ProtocolParametersUpdate()
}

func (t *ShelleyTransaction) Cbor() []byte {
Expand Down
2 changes: 1 addition & 1 deletion ledger/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type Transaction interface {
IsValid() bool
Consumed() []TransactionInput
Produced() []TransactionOutput
ProtocolParametersUpdate() map[Blake2b224]any
}

type TransactionBody interface {
Expand All @@ -40,6 +39,7 @@ type TransactionBody interface {
Inputs() []TransactionInput
Outputs() []TransactionOutput
TTL() uint64
ProtocolParametersUpdate() map[Blake2b224]any
ValidityIntervalStart() uint64
ReferenceInputs() []TransactionInput
Collateral() []TransactionInput
Expand Down

0 comments on commit 3f47cef

Please sign in to comment.