Skip to content

Commit

Permalink
feat: TX collateral return support (#604)
Browse files Browse the repository at this point in the history
This adds support for returning the collateral return value (if any)
decoded from the transaction body

Fixes #340
  • Loading branch information
agaffney authored May 2, 2024
1 parent 0e01b91 commit 161a36c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ledger/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ func (t AllegraTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}

func (t AllegraTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}

func (t AllegraTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ func (t AlonzoTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}

func (t AlonzoTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}

func (t AlonzoTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}
Expand Down
14 changes: 11 additions & 3 deletions ledger/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ type BabbageTransactionBody struct {
ProtocolParamUpdates map[Blake2b224]BabbageProtocolParameterUpdate
Epoch uint64
} `cbor:"6,keyasint,omitempty"`
CollateralReturn BabbageTransactionOutput `cbor:"16,keyasint,omitempty"`
TotalCollateral uint64 `cbor:"17,keyasint,omitempty"`
TxReferenceInputs []ShelleyTransactionInput `cbor:"18,keyasint,omitempty"`
TxCollateralReturn *BabbageTransactionOutput `cbor:"16,keyasint,omitempty"`
TotalCollateral uint64 `cbor:"17,keyasint,omitempty"`
TxReferenceInputs []ShelleyTransactionInput `cbor:"18,keyasint,omitempty"`
}

func (b *BabbageTransactionBody) UnmarshalCBOR(cborData []byte) error {
Expand All @@ -208,6 +208,10 @@ func (b *BabbageTransactionBody) ReferenceInputs() []TransactionInput {
return ret
}

func (b *BabbageTransactionBody) CollateralReturn() TransactionOutput {
return b.TxCollateralReturn
}

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

func (t BabbageTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}

func (t BabbageTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}
Expand Down
5 changes: 5 additions & 0 deletions ledger/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ func (t *ByronTransaction) ReferenceInputs() []TransactionInput {
return nil
}

func (t *ByronTransaction) CollateralReturn() TransactionOutput {
// No collateral in Byron
return nil
}

func (t *ByronTransaction) Metadata() *cbor.Value {
return t.Attributes
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ func (t ConwayTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}

func (t ConwayTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}

func (t ConwayTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ func (t MaryTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}

func (t MaryTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}

func (t MaryTransaction) Metadata() *cbor.Value {
return t.TxMetadata
}
Expand Down
9 changes: 9 additions & 0 deletions ledger/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ func (b *ShelleyTransactionBody) ReferenceInputs() []TransactionInput {
return []TransactionInput{}
}

func (b *ShelleyTransactionBody) CollateralReturn() TransactionOutput {
// No collateral in Shelley
return nil
}

func (b *ShelleyTransactionBody) Utxorpc() *utxorpc.Tx {
var txi []*utxorpc.TxInput
var txo []*utxorpc.TxOutput
Expand Down Expand Up @@ -359,6 +364,10 @@ func (t ShelleyTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}

func (t ShelleyTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}

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

type TransactionInput interface {
Expand Down

0 comments on commit 161a36c

Please sign in to comment.