Skip to content

Commit

Permalink
feat: TX total collateral support (#622)
Browse files Browse the repository at this point in the history
This provides a method for returning the total collateral of a
transaction

Fixes #341
  • Loading branch information
agaffney authored May 14, 2024
1 parent cf212da commit e72fabc
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ledger/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ func (t AllegraTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}

func (t AllegraTransaction) TotalCollateral() uint64 {
return t.Body.TotalCollateral()
}

func (t AllegraTransaction) Certificates() []Certificate {
return t.Body.Certificates()
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ func (t AlonzoTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}

func (t AlonzoTransaction) TotalCollateral() uint64 {
return t.Body.TotalCollateral()
}

func (t AlonzoTransaction) Certificates() []Certificate {
return t.Body.Certificates()
}
Expand Down
10 changes: 9 additions & 1 deletion ledger/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ type BabbageTransactionBody struct {
Epoch uint64
} `cbor:"6,keyasint,omitempty"`
TxCollateralReturn *BabbageTransactionOutput `cbor:"16,keyasint,omitempty"`
TotalCollateral uint64 `cbor:"17,keyasint,omitempty"`
TxTotalCollateral uint64 `cbor:"17,keyasint,omitempty"`
TxReferenceInputs []ShelleyTransactionInput `cbor:"18,keyasint,omitempty"`
}

Expand Down Expand Up @@ -218,6 +218,10 @@ func (b *BabbageTransactionBody) CollateralReturn() TransactionOutput {
return b.TxCollateralReturn
}

func (b *BabbageTransactionBody) TotalCollateral() uint64 {
return b.TxTotalCollateral
}

func (b *BabbageTransactionBody) Utxorpc() *utxorpc.Tx {
var txi, txri []*utxorpc.TxInput
var txo []*utxorpc.TxOutput
Expand Down Expand Up @@ -448,6 +452,10 @@ func (t BabbageTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}

func (t BabbageTransaction) TotalCollateral() uint64 {
return t.Body.TotalCollateral()
}

func (t BabbageTransaction) Certificates() []Certificate {
return t.Body.Certificates()
}
Expand Down
2 changes: 1 addition & 1 deletion ledger/babbage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestBabbageBlockTransactions(t *testing.T) {

for i := 0; i < txsCount; i++ {
b.TransactionBodies[i] = BabbageTransactionBody{
TotalCollateral: 1 << i,
TxTotalCollateral: 1 << i,
}
b.TransactionWitnessSets[i] = BabbageTransactionWitnessSet{
AlonzoTransactionWitnessSet: AlonzoTransactionWitnessSet{
Expand Down
5 changes: 5 additions & 0 deletions ledger/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ func (t *ByronTransaction) CollateralReturn() TransactionOutput {
return nil
}

func (t *ByronTransaction) TotalCollateral() uint64 {
// No collateral in Byron
return 0
}

func (t *ByronTransaction) Certificates() []Certificate {
// No certificates in Byron
return nil
Expand Down
4 changes: 4 additions & 0 deletions ledger/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ func (t ConwayTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}

func (t ConwayTransaction) TotalCollateral() uint64 {
return t.Body.TotalCollateral()
}

func (t ConwayTransaction) Certificates() []Certificate {
return t.Body.Certificates()
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ func (t MaryTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}

func (t MaryTransaction) TotalCollateral() uint64 {
return t.Body.TotalCollateral()
}

func (t MaryTransaction) Certificates() []Certificate {
return t.Body.Certificates()
}
Expand Down
9 changes: 9 additions & 0 deletions ledger/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ func (b *ShelleyTransactionBody) CollateralReturn() TransactionOutput {
return nil
}

func (b *ShelleyTransactionBody) TotalCollateral() uint64 {
// No collateral in Shelley
return 0
}

func (b *ShelleyTransactionBody) Certificates() []Certificate {
ret := make([]Certificate, len(b.TxCertificates))
for i, cert := range b.TxCertificates {
Expand Down Expand Up @@ -384,6 +389,10 @@ func (t ShelleyTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}

func (t ShelleyTransaction) TotalCollateral() uint64 {
return t.Body.TotalCollateral()
}

func (t ShelleyTransaction) Certificates() []Certificate {
return t.Body.Certificates()
}
Expand Down
1 change: 1 addition & 0 deletions ledger/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type TransactionBody interface {
ReferenceInputs() []TransactionInput
Collateral() []TransactionInput
CollateralReturn() TransactionOutput
TotalCollateral() uint64
Certificates() []Certificate
Utxorpc() *utxorpc.Tx
}
Expand Down

0 comments on commit e72fabc

Please sign in to comment.