Skip to content

Commit

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

Fixes #344
  • Loading branch information
agaffney committed May 15, 2024
1 parent a82fa14 commit 296a6b1
Showing 1 changed file with 148 additions and 4 deletions.
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 Down Expand Up @@ -176,6 +176,150 @@ 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 cert
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()
Cbor() []byte
Utxorpc() *utxorpc.Certificate
}

/*
proposal_procedures = nonempty_oset<proposal_procedure>
gov_action =
[ parameter_change_action
// hard_fork_initiation_action
// treasury_withdrawals_action
// no_confidence
// update_committee
// new_constitution
// info_action
]
policy_hash = scripthash
parameter_change_action = (0, gov_action_id / null, protocol_param_update, policy_hash / null)
hard_fork_initiation_action = (1, gov_action_id / null, protocol_version)
treasury_withdrawals_action = (2, { reward_account => coin }, policy_hash / null)
no_confidence = (3, gov_action_id / null)
update_committee = (4, gov_action_id / null, set<committee_cold_credential>, { committee_cold_credential => epoch }, unit_interval)
new_constitution = (5, gov_action_id / null, constitution)
constitution =
[ anchor
, scripthash / null
]
info_action = 6
*/

type ParameterChangeGovAction struct {
// TODO
}

func (a ParameterChangeGovAction) isGovAction() {}

type HardForkInitiationGovAction struct {
// TODO
}

func (a HardForkInitiationGovAction) isGovAction() {}

type TreasuryWithdrawalGovAction struct {
// TODO
}

func (a TreasuryWithdrawalGovAction) isGovAction() {}

type NoConfidenceGovAction struct {
// TODO
}

func (a NoConfidenceGovAction) isGovAction() {}

type UpdateCommitteeGovAction struct {
// TODO
}

func (a UpdateCommitteeGovAction) isGovAction() {}

type NewConstitutionGovAction struct {
// TODO
}

func (a NewConstitutionGovAction) isGovAction() {}

type InfoGovAction struct {
// TODO
}

func (a InfoGovAction) isGovAction() {}

type ConwayTransaction struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand Down

0 comments on commit 296a6b1

Please sign in to comment.