Skip to content

Commit 161a36c

Browse files
authored
feat: TX collateral return support (#604)
This adds support for returning the collateral return value (if any) decoded from the transaction body Fixes #340
1 parent 0e01b91 commit 161a36c

File tree

8 files changed

+42
-3
lines changed

8 files changed

+42
-3
lines changed

ledger/allegra.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ func (t AllegraTransaction) ReferenceInputs() []TransactionInput {
158158
return t.Body.ReferenceInputs()
159159
}
160160

161+
func (t AllegraTransaction) CollateralReturn() TransactionOutput {
162+
return t.Body.CollateralReturn()
163+
}
164+
161165
func (t AllegraTransaction) Metadata() *cbor.Value {
162166
return t.TxMetadata
163167
}

ledger/alonzo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ func (t AlonzoTransaction) ReferenceInputs() []TransactionInput {
260260
return t.Body.ReferenceInputs()
261261
}
262262

263+
func (t AlonzoTransaction) CollateralReturn() TransactionOutput {
264+
return t.Body.CollateralReturn()
265+
}
266+
263267
func (t AlonzoTransaction) Metadata() *cbor.Value {
264268
return t.TxMetadata
265269
}

ledger/babbage.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ type BabbageTransactionBody struct {
181181
ProtocolParamUpdates map[Blake2b224]BabbageProtocolParameterUpdate
182182
Epoch uint64
183183
} `cbor:"6,keyasint,omitempty"`
184-
CollateralReturn BabbageTransactionOutput `cbor:"16,keyasint,omitempty"`
185-
TotalCollateral uint64 `cbor:"17,keyasint,omitempty"`
186-
TxReferenceInputs []ShelleyTransactionInput `cbor:"18,keyasint,omitempty"`
184+
TxCollateralReturn *BabbageTransactionOutput `cbor:"16,keyasint,omitempty"`
185+
TotalCollateral uint64 `cbor:"17,keyasint,omitempty"`
186+
TxReferenceInputs []ShelleyTransactionInput `cbor:"18,keyasint,omitempty"`
187187
}
188188

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

211+
func (b *BabbageTransactionBody) CollateralReturn() TransactionOutput {
212+
return b.TxCollateralReturn
213+
}
214+
211215
func (b *BabbageTransactionBody) Utxorpc() *utxorpc.Tx {
212216
var txi, txri []*utxorpc.TxInput
213217
var txo []*utxorpc.TxOutput
@@ -430,6 +434,10 @@ func (t BabbageTransaction) ReferenceInputs() []TransactionInput {
430434
return t.Body.ReferenceInputs()
431435
}
432436

437+
func (t BabbageTransaction) CollateralReturn() TransactionOutput {
438+
return t.Body.CollateralReturn()
439+
}
440+
433441
func (t BabbageTransaction) Metadata() *cbor.Value {
434442
return t.TxMetadata
435443
}

ledger/byron.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ func (t *ByronTransaction) ReferenceInputs() []TransactionInput {
175175
return nil
176176
}
177177

178+
func (t *ByronTransaction) CollateralReturn() TransactionOutput {
179+
// No collateral in Byron
180+
return nil
181+
}
182+
178183
func (t *ByronTransaction) Metadata() *cbor.Value {
179184
return t.Attributes
180185
}

ledger/conway.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ func (t ConwayTransaction) ReferenceInputs() []TransactionInput {
164164
return t.Body.ReferenceInputs()
165165
}
166166

167+
func (t ConwayTransaction) CollateralReturn() TransactionOutput {
168+
return t.Body.CollateralReturn()
169+
}
170+
167171
func (t ConwayTransaction) Metadata() *cbor.Value {
168172
return t.TxMetadata
169173
}

ledger/mary.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ func (t MaryTransaction) ReferenceInputs() []TransactionInput {
175175
return t.Body.ReferenceInputs()
176176
}
177177

178+
func (t MaryTransaction) CollateralReturn() TransactionOutput {
179+
return t.Body.CollateralReturn()
180+
}
181+
178182
func (t MaryTransaction) Metadata() *cbor.Value {
179183
return t.TxMetadata
180184
}

ledger/shelley.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ func (b *ShelleyTransactionBody) ReferenceInputs() []TransactionInput {
221221
return []TransactionInput{}
222222
}
223223

224+
func (b *ShelleyTransactionBody) CollateralReturn() TransactionOutput {
225+
// No collateral in Shelley
226+
return nil
227+
}
228+
224229
func (b *ShelleyTransactionBody) Utxorpc() *utxorpc.Tx {
225230
var txi []*utxorpc.TxInput
226231
var txo []*utxorpc.TxOutput
@@ -359,6 +364,10 @@ func (t ShelleyTransaction) ReferenceInputs() []TransactionInput {
359364
return t.Body.ReferenceInputs()
360365
}
361366

367+
func (t ShelleyTransaction) CollateralReturn() TransactionOutput {
368+
return t.Body.CollateralReturn()
369+
}
370+
362371
func (t ShelleyTransaction) Metadata() *cbor.Value {
363372
return t.TxMetadata
364373
}

ledger/tx.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type TransactionBody interface {
4040
TTL() uint64
4141
ReferenceInputs() []TransactionInput
4242
Utxorpc() *utxorpc.Tx
43+
CollateralReturn() TransactionOutput
4344
}
4445

4546
type TransactionInput interface {

0 commit comments

Comments
 (0)