Skip to content

Commit a0d78a9

Browse files
authored
feat: TX collateral inputs support (#605)
This adds support for returning the collateral inputs (if any) from a transaction body. Fixes #338
1 parent 161a36c commit a0d78a9

File tree

8 files changed

+45
-2
lines changed

8 files changed

+45
-2
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) Collateral() []TransactionInput {
162+
return t.Body.Collateral()
163+
}
164+
161165
func (t AllegraTransaction) CollateralReturn() TransactionOutput {
162166
return t.Body.CollateralReturn()
163167
}

ledger/alonzo.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ type AlonzoTransactionBody struct {
129129
Epoch uint64
130130
} `cbor:"6,keyasint,omitempty"`
131131
ScriptDataHash Blake2b256 `cbor:"11,keyasint,omitempty"`
132-
Collateral []ShelleyTransactionInput `cbor:"13,keyasint,omitempty"`
132+
TxCollateral []ShelleyTransactionInput `cbor:"13,keyasint,omitempty"`
133133
RequiredSigners []Blake2b224 `cbor:"14,keyasint,omitempty"`
134134
NetworkId uint8 `cbor:"15,keyasint,omitempty"`
135135
}
@@ -147,6 +147,14 @@ func (b *AlonzoTransactionBody) Outputs() []TransactionOutput {
147147
return ret
148148
}
149149

150+
func (b *AlonzoTransactionBody) Collateral() []TransactionInput {
151+
ret := []TransactionInput{}
152+
for _, collateral := range b.TxCollateral {
153+
ret = append(ret, collateral)
154+
}
155+
return ret
156+
}
157+
150158
type AlonzoTransactionOutput struct {
151159
cbor.StructAsArray
152160
cbor.DecodeStoreCbor
@@ -260,6 +268,10 @@ func (t AlonzoTransaction) ReferenceInputs() []TransactionInput {
260268
return t.Body.ReferenceInputs()
261269
}
262270

271+
func (t AlonzoTransaction) Collateral() []TransactionInput {
272+
return t.Body.Collateral()
273+
}
274+
263275
func (t AlonzoTransaction) CollateralReturn() TransactionOutput {
264276
return t.Body.CollateralReturn()
265277
}

ledger/babbage.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ func (t BabbageTransaction) ReferenceInputs() []TransactionInput {
434434
return t.Body.ReferenceInputs()
435435
}
436436

437+
func (t BabbageTransaction) Collateral() []TransactionInput {
438+
return t.Body.Collateral()
439+
}
440+
437441
func (t BabbageTransaction) CollateralReturn() TransactionOutput {
438442
return t.Body.CollateralReturn()
439443
}

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) Collateral() []TransactionInput {
179+
// No collateral in Byron
180+
return nil
181+
}
182+
178183
func (t *ByronTransaction) CollateralReturn() TransactionOutput {
179184
// No collateral in Byron
180185
return nil

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) Collateral() []TransactionInput {
168+
return t.Body.Collateral()
169+
}
170+
167171
func (t ConwayTransaction) CollateralReturn() TransactionOutput {
168172
return t.Body.CollateralReturn()
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) Collateral() []TransactionInput {
179+
return t.Body.Collateral()
180+
}
181+
178182
func (t MaryTransaction) CollateralReturn() TransactionOutput {
179183
return t.Body.CollateralReturn()
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) Collateral() []TransactionInput {
225+
// No collateral in Shelley
226+
return nil
227+
}
228+
224229
func (b *ShelleyTransactionBody) CollateralReturn() TransactionOutput {
225230
// No collateral in Shelley
226231
return nil
@@ -364,6 +369,10 @@ func (t ShelleyTransaction) ReferenceInputs() []TransactionInput {
364369
return t.Body.ReferenceInputs()
365370
}
366371

372+
func (t ShelleyTransaction) Collateral() []TransactionInput {
373+
return t.Body.Collateral()
374+
}
375+
367376
func (t ShelleyTransaction) CollateralReturn() TransactionOutput {
368377
return t.Body.CollateralReturn()
369378
}

ledger/tx.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ type TransactionBody interface {
3939
Outputs() []TransactionOutput
4040
TTL() uint64
4141
ReferenceInputs() []TransactionInput
42-
Utxorpc() *utxorpc.Tx
42+
Collateral() []TransactionInput
4343
CollateralReturn() TransactionOutput
44+
Utxorpc() *utxorpc.Tx
4445
}
4546

4647
type TransactionInput interface {

0 commit comments

Comments
 (0)