Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: TX proposal procedures attribute #629

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ledger/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ func (t AllegraTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}

func (t AllegraTransaction) ProposalProcedures() []ProposalProcedure {
return t.Body.ProposalProcedures()
}

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 @@ -292,6 +292,10 @@ func (t AlonzoTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}

func (t AlonzoTransaction) ProposalProcedures() []ProposalProcedure {
return t.Body.ProposalProcedures()
}

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 @@ -468,6 +468,10 @@ func (t BabbageTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}

func (t BabbageTransaction) ProposalProcedures() []ProposalProcedure {
return t.Body.ProposalProcedures()
}

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 @@ -205,6 +205,11 @@ func (t *ByronTransaction) VotingProcedures() VotingProcedures {
return nil
}

func (t *ByronTransaction) ProposalProcedures() []ProposalProcedure {
// No proposal procedures in Byron
return nil
}

func (t *ByronTransaction) Metadata() *cbor.Value {
return t.Attributes
}
Expand Down
152 changes: 148 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"`
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"`
TxProposalProcedures []ProposalProcedure `cbor:"20,keyasint,omitempty"`
CurrentTreasuryValue int64 `cbor:"21,keyasint,omitempty"`
Donation uint64 `cbor:"22,keyasint,omitempty"`
}

func (b *ConwayTransactionBody) UnmarshalCBOR(cborData []byte) error {
Expand All @@ -135,6 +135,10 @@ func (b *ConwayTransactionBody) VotingProcedures() VotingProcedures {
return b.TxVotingProcedures
}

func (b *ConwayTransactionBody) ProposalProcedures() []ProposalProcedure {
return b.TxProposalProcedures
}

// 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 @@ -176,6 +180,142 @@ type GovActionId struct {
GovActionIdx uint32
}

type ProposalProcedure struct {
cbor.StructAsArray
Deposit uint64
RewardAccount Address
GovAction GovActionWrapper
Anchor GovAnchor
}

const (
GovActionTypeParameterChange = 0
GovActionTypeHardForkInitiation = 1
GovActionTypeTreasuryWithdrawal = 2
GovActionTypeNoConfidence = 3
GovActionTypeUpdateCommittee = 4
GovActionTypeNewConstitution = 5
GovActionTypeInfo = 6
)

type GovActionWrapper struct {
Type uint
Action GovAction
}

func (g *GovActionWrapper) UnmarshalCBOR(data []byte) error {
// Determine action type
actionType, err := cbor.DecodeIdFromList(data)
if err != nil {
return err
}
var tmpAction GovAction
switch actionType {
case GovActionTypeParameterChange:
tmpAction = &ParameterChangeGovAction{}
case GovActionTypeHardForkInitiation:
tmpAction = &HardForkInitiationGovAction{}
case GovActionTypeTreasuryWithdrawal:
tmpAction = &TreasuryWithdrawalGovAction{}
case GovActionTypeNoConfidence:
tmpAction = &NoConfidenceGovAction{}
case GovActionTypeUpdateCommittee:
tmpAction = &UpdateCommitteeGovAction{}
case GovActionTypeNewConstitution:
tmpAction = &NewConstitutionGovAction{}
case GovActionTypeInfo:
tmpAction = &InfoGovAction{}
default:
return fmt.Errorf("unknown governance action type: %d", actionType)
}
// Decode action
if _, err := cbor.Decode(data, tmpAction); err != nil {
return err
}
g.Type = uint(actionType)
g.Action = tmpAction
return nil
}

func (g *GovActionWrapper) MarshalCBOR() ([]byte, error) {
return cbor.Encode(g.Action)
}

type GovAction interface {
isGovAction()
}

type ParameterChangeGovAction struct {
cbor.StructAsArray
Type uint
ActionId *GovActionId
ParamUpdate BabbageProtocolParameterUpdate // TODO: use Conway params update type
PolicyHash []byte
}

func (a ParameterChangeGovAction) isGovAction() {}

type HardForkInitiationGovAction struct {
cbor.StructAsArray
Type uint
ActionId *GovActionId
ProtocolVersion struct {
cbor.StructAsArray
Major uint
Minor uint
}
}

func (a HardForkInitiationGovAction) isGovAction() {}

type TreasuryWithdrawalGovAction struct {
cbor.StructAsArray
Type uint
Withdrawals map[*Address]uint64
PolicyHash []byte
}

func (a TreasuryWithdrawalGovAction) isGovAction() {}

type NoConfidenceGovAction struct {
cbor.StructAsArray
Type uint
ActionId *GovActionId
}

func (a NoConfidenceGovAction) isGovAction() {}

type UpdateCommitteeGovAction struct {
cbor.StructAsArray
Type uint
ActionId *GovActionId
Credentials []StakeCredential
CredEpochs map[*StakeCredential]uint
Unknown cbor.Rat
}

func (a UpdateCommitteeGovAction) isGovAction() {}

type NewConstitutionGovAction struct {
cbor.StructAsArray
Type uint
ActionId *GovActionId
Constitution struct {
cbor.StructAsArray
Anchor GovAnchor
ScriptHash []byte
}
}

func (a NewConstitutionGovAction) isGovAction() {}

type InfoGovAction struct {
cbor.StructAsArray
Type uint
}

func (a InfoGovAction) isGovAction() {}

type ConwayTransaction struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand Down Expand Up @@ -233,6 +373,10 @@ func (t ConwayTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}

func (t ConwayTransaction) ProposalProcedures() []ProposalProcedure {
return t.Body.ProposalProcedures()
}

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 @@ -199,6 +199,10 @@ func (t MaryTransaction) VotingProcedures() VotingProcedures {
return t.Body.VotingProcedures()
}

func (t MaryTransaction) ProposalProcedures() []ProposalProcedure {
return t.Body.ProposalProcedures()
}

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 @@ -249,6 +249,11 @@ func (t *ShelleyTransactionBody) VotingProcedures() VotingProcedures {
return nil
}

func (t *ShelleyTransactionBody) ProposalProcedures() []ProposalProcedure {
// No proposal procedures in Shelley
return nil
}

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

func (t ShelleyTransaction) ProposalProcedures() []ProposalProcedure {
return t.Body.ProposalProcedures()
}

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 @@ -47,6 +47,7 @@ type TransactionBody interface {
Certificates() []Certificate
Withdrawals() map[*Address]uint64
VotingProcedures() VotingProcedures
ProposalProcedures() []ProposalProcedure
Utxorpc() *utxorpc.Tx
}

Expand Down