Skip to content

Commit

Permalink
feat: TX voting procedures attribute support
Browse files Browse the repository at this point in the history
This adds support for decoding and retrieving Conway voting procedures
from a TX

Fixes #343
  • Loading branch information
agaffney committed May 14, 2024
1 parent d54d92a commit e4fadbb
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ledger/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ func (t AllegraTransaction) Withdrawals() map[*Address]uint64 {
return t.Body.Withdrawals()
}

func (t AllegraTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}

func (t AllegraTransaction) Metadata() *cbor.Value {
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 @@ -288,6 +288,10 @@ func (t AlonzoTransaction) Withdrawals() map[*Address]uint64 {
return t.Body.Withdrawals()
}

func (t AlonzoTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}

func (t AlonzoTransaction) Metadata() *cbor.Value {
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 @@ -464,6 +464,10 @@ func (t BabbageTransaction) Withdrawals() map[*Address]uint64 {
return t.Body.Withdrawals()
}

func (t BabbageTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}

func (t BabbageTransaction) Metadata() *cbor.Value {
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 @@ -200,6 +200,11 @@ func (t *ByronTransaction) Withdrawals() map[*Address]uint64 {
return nil
}

func (t *ByronTransaction) VotingProcedures() VotingProcedures {
// No voting procedures in Byron
return nil
}

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

type ConwayTransactionBody struct {
BabbageTransactionBody
VotingProcedures *cbor.Value `cbor:"19,keyasint,omitempty"`
ProposalProcedures *cbor.Value `cbor:"20,keyasint,omitempty"`
CurrentTreasuryValue int64 `cbor:"21,keyasint,omitempty"`
Donation uint64 `cbor:"22,keyasint,omitempty"`
TxVotingProcedures VotingProcedures `cbor:"19,keyasint,omitempty"`
ProposalProcedures *cbor.Value `cbor:"20,keyasint,omitempty"`
CurrentTreasuryValue int64 `cbor:"21,keyasint,omitempty"`
Donation uint64 `cbor:"22,keyasint,omitempty"`
}

func (b *ConwayTransactionBody) UnmarshalCBOR(cborData []byte) error {
return b.UnmarshalCbor(cborData, b)
}

func (b *ConwayTransactionBody) VotingProcedures() VotingProcedures {
return b.TxVotingProcedures
}

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

const (
VoterTypeConstitutionalCommitteeHotKeyHash uint8 = 0
VoterTypeConstitutionalCommitteeHotScriptHash uint8 = 1
VoterTypeDRepKeyHash uint8 = 2
VoterTypeDRepScriptHash uint8 = 3
VoterTypeStakingPoolKeyHash uint8 = 4
)

type Voter struct {
cbor.StructAsArray
Type uint8
Hash [28]byte
}

const (
GovVoteNo uint8 = 0
GovVoteYes uint8 = 1
GovVoteAbstain uint8 = 2
)

type VotingProcedure struct {
cbor.StructAsArray
Vote uint8
Anchor *GovAnchor
}

type GovAnchor struct {
cbor.StructAsArray
Url string
DataHash [32]byte
}

type GovActionId struct {
cbor.StructAsArray
TransactionId [32]byte
GovActionIdx uint32
}

type ConwayTransaction struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand Down Expand Up @@ -184,6 +229,10 @@ func (t ConwayTransaction) Withdrawals() map[*Address]uint64 {
return t.Body.Withdrawals()
}

func (t ConwayTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}

func (t ConwayTransaction) Metadata() *cbor.Value {
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 @@ -195,6 +195,10 @@ func (t MaryTransaction) Withdrawals() map[*Address]uint64 {
return t.Body.Withdrawals()
}

func (t MaryTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}

func (t MaryTransaction) Metadata() *cbor.Value {
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 @@ -244,6 +244,11 @@ func (b *ShelleyTransactionBody) Withdrawals() map[*Address]uint64 {
return b.TxWithdrawals
}

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

func (b *ShelleyTransactionBody) Utxorpc() *utxorpc.Tx {
var txi []*utxorpc.TxInput
var txo []*utxorpc.TxOutput
Expand Down Expand Up @@ -402,6 +407,10 @@ func (t ShelleyTransaction) Withdrawals() map[*Address]uint64 {
return t.Body.Withdrawals()
}

func (t ShelleyTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}

func (t ShelleyTransaction) Metadata() *cbor.Value {
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 @@ -46,6 +46,7 @@ type TransactionBody interface {
TotalCollateral() uint64
Certificates() []Certificate
Withdrawals() map[*Address]uint64
VotingProcedures() VotingProcedures
Utxorpc() *utxorpc.Tx
}

Expand Down

0 comments on commit e4fadbb

Please sign in to comment.