Skip to content

Commit 3f73561

Browse files
authored
feat: TX script data hash attribute (#632)
This adds a method for retrieving the script data hash from a TX Fixes #337
1 parent 4ffacfe commit 3f73561

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
@@ -186,6 +186,10 @@ func (t AllegraTransaction) AssetMint() *MultiAsset[MultiAssetTypeMint] {
186186
return t.Body.AssetMint()
187187
}
188188

189+
func (t AllegraTransaction) ScriptDataHash() *Blake2b256 {
190+
return t.Body.ScriptDataHash()
191+
}
192+
189193
func (t AllegraTransaction) VotingProcedures() VotingProcedures {
190194
return t.Body.VotingProcedures()
191195
}

ledger/alonzo.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ type AlonzoTransactionBody struct {
128128
ProtocolParamUpdates map[Blake2b224]AlonzoProtocolParameterUpdate
129129
Epoch uint64
130130
} `cbor:"6,keyasint,omitempty"`
131-
ScriptDataHash Blake2b256 `cbor:"11,keyasint,omitempty"`
131+
TxScriptDataHash *Blake2b256 `cbor:"11,keyasint,omitempty"`
132132
TxCollateral []ShelleyTransactionInput `cbor:"13,keyasint,omitempty"`
133133
TxRequiredSigners []Blake2b224 `cbor:"14,keyasint,omitempty"`
134134
NetworkId uint8 `cbor:"15,keyasint,omitempty"`
@@ -159,6 +159,10 @@ func (b *AlonzoTransactionBody) RequiredSigners() []Blake2b224 {
159159
return b.TxRequiredSigners[:]
160160
}
161161

162+
func (b *AlonzoTransactionBody) ScriptDataHash() *Blake2b256 {
163+
return b.TxScriptDataHash
164+
}
165+
162166
type AlonzoTransactionOutput struct {
163167
cbor.StructAsArray
164168
cbor.DecodeStoreCbor
@@ -300,6 +304,10 @@ func (t AlonzoTransaction) AssetMint() *MultiAsset[MultiAssetTypeMint] {
300304
return t.Body.AssetMint()
301305
}
302306

307+
func (t AlonzoTransaction) ScriptDataHash() *Blake2b256 {
308+
return t.Body.ScriptDataHash()
309+
}
310+
303311
func (t AlonzoTransaction) VotingProcedures() VotingProcedures {
304312
return t.Body.VotingProcedures()
305313
}

ledger/babbage.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ func (t BabbageTransaction) Withdrawals() map[*Address]uint64 {
464464
return t.Body.Withdrawals()
465465
}
466466

467+
func (t BabbageTransaction) ScriptDataHash() *Blake2b256 {
468+
return t.Body.ScriptDataHash()
469+
}
470+
467471
func (t BabbageTransaction) VotingProcedures() VotingProcedures {
468472
return t.Body.VotingProcedures()
469473
}

ledger/byron.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ func (t *ByronTransaction) AssetMint() *MultiAsset[MultiAssetTypeMint] {
210210
return nil
211211
}
212212

213+
func (t *ByronTransaction) ScriptDataHash() *Blake2b256 {
214+
// No script data hash in Byron
215+
return nil
216+
}
217+
213218
func (t *ByronTransaction) VotingProcedures() VotingProcedures {
214219
// No voting procedures in Byron
215220
return nil

ledger/conway.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ func (t ConwayTransaction) AssetMint() *MultiAsset[MultiAssetTypeMint] {
377377
return t.Body.AssetMint()
378378
}
379379

380+
func (t ConwayTransaction) ScriptDataHash() *Blake2b256 {
381+
return t.Body.ScriptDataHash()
382+
}
383+
380384
func (t ConwayTransaction) VotingProcedures() VotingProcedures {
381385
return t.Body.VotingProcedures()
382386
}

ledger/mary.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ func (t MaryTransaction) AssetMint() *MultiAsset[MultiAssetTypeMint] {
207207
return t.Body.AssetMint()
208208
}
209209

210+
func (t MaryTransaction) ScriptDataHash() *Blake2b256 {
211+
return t.Body.ScriptDataHash()
212+
}
213+
210214
func (t MaryTransaction) VotingProcedures() VotingProcedures {
211215
return t.Body.VotingProcedures()
212216
}

ledger/shelley.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,17 @@ func (b *ShelleyTransactionBody) AssetMint() *MultiAsset[MultiAssetTypeMint] {
254254
return nil
255255
}
256256

257-
func (t *ShelleyTransactionBody) VotingProcedures() VotingProcedures {
257+
func (b *ShelleyTransactionBody) ScriptDataHash() *Blake2b256 {
258+
// No script data hash in Shelley
259+
return nil
260+
}
261+
262+
func (b *ShelleyTransactionBody) VotingProcedures() VotingProcedures {
258263
// No voting procedures in Shelley
259264
return nil
260265
}
261266

262-
func (t *ShelleyTransactionBody) ProposalProcedures() []ProposalProcedure {
267+
func (b *ShelleyTransactionBody) ProposalProcedures() []ProposalProcedure {
263268
// No proposal procedures in Shelley
264269
return nil
265270
}
@@ -430,6 +435,10 @@ func (t ShelleyTransaction) AssetMint() *MultiAsset[MultiAssetTypeMint] {
430435
return t.Body.AssetMint()
431436
}
432437

438+
func (t ShelleyTransaction) ScriptDataHash() *Blake2b256 {
439+
return t.Body.ScriptDataHash()
440+
}
441+
433442
func (t ShelleyTransaction) VotingProcedures() VotingProcedures {
434443
return t.Body.VotingProcedures()
435444
}

ledger/tx.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type TransactionBody interface {
4848
Withdrawals() map[*Address]uint64
4949
RequiredSigners() []Blake2b224
5050
AssetMint() *MultiAsset[MultiAssetTypeMint]
51+
ScriptDataHash() *Blake2b256
5152
VotingProcedures() VotingProcedures
5253
ProposalProcedures() []ProposalProcedure
5354
Utxorpc() *utxorpc.Tx

0 commit comments

Comments
 (0)