Skip to content

Commit

Permalink
feat: TX collateral inputs support (#605)
Browse files Browse the repository at this point in the history
This adds support for returning the collateral inputs (if any) from a
transaction body.

Fixes #338
  • Loading branch information
agaffney authored May 2, 2024
1 parent 161a36c commit a0d78a9
Show file tree
Hide file tree
Showing 8 changed files with 45 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 @@ -158,6 +158,10 @@ func (t AllegraTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}

func (t AllegraTransaction) Collateral() []TransactionInput {
return t.Body.Collateral()
}

func (t AllegraTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}
Expand Down
14 changes: 13 additions & 1 deletion ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ type AlonzoTransactionBody struct {
Epoch uint64
} `cbor:"6,keyasint,omitempty"`
ScriptDataHash Blake2b256 `cbor:"11,keyasint,omitempty"`
Collateral []ShelleyTransactionInput `cbor:"13,keyasint,omitempty"`
TxCollateral []ShelleyTransactionInput `cbor:"13,keyasint,omitempty"`
RequiredSigners []Blake2b224 `cbor:"14,keyasint,omitempty"`
NetworkId uint8 `cbor:"15,keyasint,omitempty"`
}
Expand All @@ -147,6 +147,14 @@ func (b *AlonzoTransactionBody) Outputs() []TransactionOutput {
return ret
}

func (b *AlonzoTransactionBody) Collateral() []TransactionInput {
ret := []TransactionInput{}
for _, collateral := range b.TxCollateral {
ret = append(ret, collateral)
}
return ret
}

type AlonzoTransactionOutput struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand Down Expand Up @@ -260,6 +268,10 @@ func (t AlonzoTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}

func (t AlonzoTransaction) Collateral() []TransactionInput {
return t.Body.Collateral()
}

func (t AlonzoTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ func (t BabbageTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}

func (t BabbageTransaction) Collateral() []TransactionInput {
return t.Body.Collateral()
}

func (t BabbageTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}
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) Collateral() []TransactionInput {
// No collateral in Byron
return nil
}

func (t *ByronTransaction) CollateralReturn() TransactionOutput {
// No collateral 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 @@ -164,6 +164,10 @@ func (t ConwayTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}

func (t ConwayTransaction) Collateral() []TransactionInput {
return t.Body.Collateral()
}

func (t ConwayTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}
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) Collateral() []TransactionInput {
return t.Body.Collateral()
}

func (t MaryTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}
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) Collateral() []TransactionInput {
// No collateral in Shelley
return nil
}

func (b *ShelleyTransactionBody) CollateralReturn() TransactionOutput {
// No collateral in Shelley
return nil
Expand Down Expand Up @@ -364,6 +369,10 @@ func (t ShelleyTransaction) ReferenceInputs() []TransactionInput {
return t.Body.ReferenceInputs()
}

func (t ShelleyTransaction) Collateral() []TransactionInput {
return t.Body.Collateral()
}

func (t ShelleyTransaction) CollateralReturn() TransactionOutput {
return t.Body.CollateralReturn()
}
Expand Down
3 changes: 2 additions & 1 deletion ledger/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ type TransactionBody interface {
Outputs() []TransactionOutput
TTL() uint64
ReferenceInputs() []TransactionInput
Utxorpc() *utxorpc.Tx
Collateral() []TransactionInput
CollateralReturn() TransactionOutput
Utxorpc() *utxorpc.Tx
}

type TransactionInput interface {
Expand Down

0 comments on commit a0d78a9

Please sign in to comment.