Skip to content

Commit

Permalink
feat: TX script data hash attribute (#632)
Browse files Browse the repository at this point in the history
This adds a method for retrieving the script data hash from a TX

Fixes #337
  • Loading branch information
agaffney authored May 16, 2024
1 parent 4ffacfe commit 3f73561
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 @@ -186,6 +186,10 @@ func (t AllegraTransaction) AssetMint() *MultiAsset[MultiAssetTypeMint] {
return t.Body.AssetMint()
}

func (t AllegraTransaction) ScriptDataHash() *Blake2b256 {
return t.Body.ScriptDataHash()
}

func (t AllegraTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}
Expand Down
10 changes: 9 additions & 1 deletion ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type AlonzoTransactionBody struct {
ProtocolParamUpdates map[Blake2b224]AlonzoProtocolParameterUpdate
Epoch uint64
} `cbor:"6,keyasint,omitempty"`
ScriptDataHash Blake2b256 `cbor:"11,keyasint,omitempty"`
TxScriptDataHash *Blake2b256 `cbor:"11,keyasint,omitempty"`
TxCollateral []ShelleyTransactionInput `cbor:"13,keyasint,omitempty"`
TxRequiredSigners []Blake2b224 `cbor:"14,keyasint,omitempty"`
NetworkId uint8 `cbor:"15,keyasint,omitempty"`
Expand Down Expand Up @@ -159,6 +159,10 @@ func (b *AlonzoTransactionBody) RequiredSigners() []Blake2b224 {
return b.TxRequiredSigners[:]
}

func (b *AlonzoTransactionBody) ScriptDataHash() *Blake2b256 {
return b.TxScriptDataHash
}

type AlonzoTransactionOutput struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand Down Expand Up @@ -300,6 +304,10 @@ func (t AlonzoTransaction) AssetMint() *MultiAsset[MultiAssetTypeMint] {
return t.Body.AssetMint()
}

func (t AlonzoTransaction) ScriptDataHash() *Blake2b256 {
return t.Body.ScriptDataHash()
}

func (t AlonzoTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ func (t BabbageTransaction) Withdrawals() map[*Address]uint64 {
return t.Body.Withdrawals()
}

func (t BabbageTransaction) ScriptDataHash() *Blake2b256 {
return t.Body.ScriptDataHash()
}

func (t BabbageTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}
Expand Down
5 changes: 5 additions & 0 deletions ledger/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ func (t *ByronTransaction) AssetMint() *MultiAsset[MultiAssetTypeMint] {
return nil
}

func (t *ByronTransaction) ScriptDataHash() *Blake2b256 {
// No script data hash in Byron
return nil
}

func (t *ByronTransaction) VotingProcedures() VotingProcedures {
// No voting procedures 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 @@ -377,6 +377,10 @@ func (t ConwayTransaction) AssetMint() *MultiAsset[MultiAssetTypeMint] {
return t.Body.AssetMint()
}

func (t ConwayTransaction) ScriptDataHash() *Blake2b256 {
return t.Body.ScriptDataHash()
}

func (t ConwayTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ func (t MaryTransaction) AssetMint() *MultiAsset[MultiAssetTypeMint] {
return t.Body.AssetMint()
}

func (t MaryTransaction) ScriptDataHash() *Blake2b256 {
return t.Body.ScriptDataHash()
}

func (t MaryTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}
Expand Down
13 changes: 11 additions & 2 deletions ledger/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,17 @@ func (b *ShelleyTransactionBody) AssetMint() *MultiAsset[MultiAssetTypeMint] {
return nil
}

func (t *ShelleyTransactionBody) VotingProcedures() VotingProcedures {
func (b *ShelleyTransactionBody) ScriptDataHash() *Blake2b256 {
// No script data hash in Shelley
return nil
}

func (b *ShelleyTransactionBody) VotingProcedures() VotingProcedures {
// No voting procedures in Shelley
return nil
}

func (t *ShelleyTransactionBody) ProposalProcedures() []ProposalProcedure {
func (b *ShelleyTransactionBody) ProposalProcedures() []ProposalProcedure {
// No proposal procedures in Shelley
return nil
}
Expand Down Expand Up @@ -430,6 +435,10 @@ func (t ShelleyTransaction) AssetMint() *MultiAsset[MultiAssetTypeMint] {
return t.Body.AssetMint()
}

func (t ShelleyTransaction) ScriptDataHash() *Blake2b256 {
return t.Body.ScriptDataHash()
}

func (t ShelleyTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}
Expand Down
1 change: 1 addition & 0 deletions ledger/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type TransactionBody interface {
Withdrawals() map[*Address]uint64
RequiredSigners() []Blake2b224
AssetMint() *MultiAsset[MultiAssetTypeMint]
ScriptDataHash() *Blake2b256
VotingProcedures() VotingProcedures
ProposalProcedures() []ProposalProcedure
Utxorpc() *utxorpc.Tx
Expand Down

0 comments on commit 3f73561

Please sign in to comment.