Skip to content

Commit

Permalink
feat: TX current treasury value attribute (#641)
Browse files Browse the repository at this point in the history
This adds a method for retrieving the current treasury value attribute from a TX

Fixes #626
  • Loading branch information
agaffney authored May 20, 2024
1 parent 86c47ea commit e4d1ad8
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ This is not an exhaustive list of existing and planned features, but it covers t
- [X] Reference inputs
- [X] Voting procedures
- [X] Proposal procedures
- [ ] Current treasury value
- [X] Current treasury value
- [ ] Donation
- [ ] Testing
- [X] Test framework for mocking Ouroboros conversations
Expand Down
4 changes: 4 additions & 0 deletions ledger/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ func (t AllegraTransaction) ProposalProcedures() []ProposalProcedure {
return t.Body.ProposalProcedures()
}

func (t AllegraTransaction) CurrentTreasuryValue() int64 {
return t.Body.CurrentTreasuryValue()
}

func (t AllegraTransaction) Metadata() *cbor.LazyValue {
return t.TxMetadata
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ func (t AlonzoTransaction) ProposalProcedures() []ProposalProcedure {
return t.Body.ProposalProcedures()
}

func (t AlonzoTransaction) CurrentTreasuryValue() int64 {
return t.Body.CurrentTreasuryValue()
}

func (t AlonzoTransaction) Metadata() *cbor.LazyValue {
return t.TxMetadata
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ func (t BabbageTransaction) ProposalProcedures() []ProposalProcedure {
return t.Body.ProposalProcedures()
}

func (t BabbageTransaction) CurrentTreasuryValue() int64 {
return t.Body.CurrentTreasuryValue()
}

func (t BabbageTransaction) Metadata() *cbor.LazyValue {
return t.TxMetadata
}
Expand Down
5 changes: 5 additions & 0 deletions ledger/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ func (t *ByronTransaction) ProposalProcedures() []ProposalProcedure {
return nil
}

func (t *ByronTransaction) CurrentTreasuryValue() int64 {
// No current treasury value in Byron
return 0
}

func (t *ByronTransaction) Metadata() *cbor.LazyValue {
return t.Attributes
}
Expand Down
16 changes: 12 additions & 4 deletions ledger/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ func (h *ConwayBlockHeader) Era() Era {

type ConwayTransactionBody struct {
BabbageTransactionBody
TxVotingProcedures VotingProcedures `cbor:"19,keyasint,omitempty"`
TxProposalProcedures []ProposalProcedure `cbor:"20,keyasint,omitempty"`
CurrentTreasuryValue int64 `cbor:"21,keyasint,omitempty"`
Donation uint64 `cbor:"22,keyasint,omitempty"`
TxVotingProcedures VotingProcedures `cbor:"19,keyasint,omitempty"`
TxProposalProcedures []ProposalProcedure `cbor:"20,keyasint,omitempty"`
TxCurrentTreasuryValue int64 `cbor:"21,keyasint,omitempty"`
Donation uint64 `cbor:"22,keyasint,omitempty"`
}

func (b *ConwayTransactionBody) UnmarshalCBOR(cborData []byte) error {
Expand All @@ -139,6 +139,10 @@ func (b *ConwayTransactionBody) ProposalProcedures() []ProposalProcedure {
return b.TxProposalProcedures
}

func (b *ConwayTransactionBody) CurrentTreasuryValue() int64 {
return b.TxCurrentTreasuryValue
}

// VotingProcedures is a convenience type to avoid needing to duplicate the full type definition everywhere
type VotingProcedures map[*Voter]map[*GovActionId]VotingProcedure

Expand Down Expand Up @@ -397,6 +401,10 @@ func (t ConwayTransaction) ProposalProcedures() []ProposalProcedure {
return t.Body.ProposalProcedures()
}

func (t ConwayTransaction) CurrentTreasuryValue() int64 {
return t.Body.CurrentTreasuryValue()
}

func (t ConwayTransaction) Metadata() *cbor.LazyValue {
return t.TxMetadata
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ func (t MaryTransaction) ProposalProcedures() []ProposalProcedure {
return t.Body.ProposalProcedures()
}

func (t MaryTransaction) CurrentTreasuryValue() int64 {
return t.Body.CurrentTreasuryValue()
}

func (t MaryTransaction) Metadata() *cbor.LazyValue {
return t.TxMetadata
}
Expand Down
9 changes: 9 additions & 0 deletions ledger/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ func (b *ShelleyTransactionBody) ProposalProcedures() []ProposalProcedure {
return nil
}

func (b *ShelleyTransactionBody) CurrentTreasuryValue() int64 {
// No current treasury value in Shelley
return 0
}

func (b *ShelleyTransactionBody) Utxorpc() *utxorpc.Tx {
var txi []*utxorpc.TxInput
var txo []*utxorpc.TxOutput
Expand Down Expand Up @@ -464,6 +469,10 @@ func (t ShelleyTransaction) ProposalProcedures() []ProposalProcedure {
return t.Body.ProposalProcedures()
}

func (t ShelleyTransaction) CurrentTreasuryValue() int64 {
return t.Body.CurrentTreasuryValue()
}

func (t ShelleyTransaction) Metadata() *cbor.LazyValue {
return t.TxMetadata
}
Expand Down
1 change: 1 addition & 0 deletions ledger/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type TransactionBody interface {
ScriptDataHash() *Blake2b256
VotingProcedures() VotingProcedures
ProposalProcedures() []ProposalProcedure
CurrentTreasuryValue() int64
Utxorpc() *utxorpc.Tx
}

Expand Down

0 comments on commit e4d1ad8

Please sign in to comment.