44from graphenebase .objects import GrapheneObject , isArgsThisClass
55from graphenebase .objects import Operation as GrapheneOperation
66from graphenebase .types import (
7+ Bool ,
78 Bytes ,
89 Int16 ,
910 Map ,
1011 Static_variant ,
1112 String ,
13+ Uint8 ,
1214 Uint16 ,
1315 Uint32 ,
1416 Uint64 ,
@@ -117,13 +119,124 @@ def __init__(self, *args, **kwargs):
117119
118120class ChainPropertiesVariant (Static_variant ):
119121 def __init__ (self , props ):
120- version = 3
121- data = ChainProperties (** props )
122+ # Pick the versioned_chain_properties variant (index == C++ static_variant
123+ # index) from the fields present. HF14/Onix (chain_properties_pm) = 5,
124+ # HF13 (chain_properties_hf13) = 4, HF9 (chain_properties_hf9) = 3.
125+ if "pm_oracle_registration_fee" in props :
126+ version = 5
127+ data = ChainPropertiesPm (** props )
128+ elif "distribution_epoch_length" in props :
129+ version = 4
130+ data = ChainPropertiesHf13 (** props )
131+ else :
132+ version = 3
133+ data = ChainProperties (** props )
122134
123135 super ().__init__ (data , version )
124136
125137
138+ def _chain_properties_hf9_items (kwargs ):
139+ """Fields shared by chain_properties_hf9 (variant 3) and all later versions,
140+ in the exact FC_REFLECT order (binary layout is consensus-critical)."""
141+ return [
142+ # initial, version 0
143+ ("account_creation_fee" , Amount (kwargs ["account_creation_fee" ])),
144+ ("maximum_block_size" , Uint32 (kwargs ["maximum_block_size" ])),
145+ ("create_account_delegation_ratio" , Uint32 (kwargs ["create_account_delegation_ratio" ])),
146+ ("create_account_delegation_time" , Uint32 (kwargs ["create_account_delegation_time" ])),
147+ ("min_delegation" , Amount (kwargs ["min_delegation" ])),
148+ ("min_curation_percent" , Uint16 (kwargs ["min_curation_percent" ])),
149+ ("max_curation_percent" , Uint16 (kwargs ["max_curation_percent" ])),
150+ ("bandwidth_reserve_percent" , Uint16 (kwargs ["bandwidth_reserve_percent" ])),
151+ ("bandwidth_reserve_below" , Amount (kwargs ["bandwidth_reserve_below" ])),
152+ ("flag_energy_additional_cost" , Uint16 (kwargs ["flag_energy_additional_cost" ])),
153+ ("vote_accounting_min_rshares" , Uint32 (kwargs ["vote_accounting_min_rshares" ])),
154+ ("committee_request_approve_min_percent" , Uint16 (kwargs ["committee_request_approve_min_percent" ])),
155+ # chain_properties_hf4, version 1
156+ ("inflation_validator_percent" , Uint16 (kwargs ["inflation_validator_percent" ])),
157+ ("inflation_ratio_committee_vs_reward_fund" , Uint16 (kwargs ["inflation_ratio_committee_vs_reward_fund" ])),
158+ ("inflation_recalc_period" , Uint32 (kwargs ["inflation_recalc_period" ])),
159+ # chain_properties_hf6: version 2
160+ ("data_operations_cost_additional_bandwidth" , Uint32 (kwargs ["data_operations_cost_additional_bandwidth" ])),
161+ ("validator_miss_penalty_percent" , Uint16 (kwargs ["validator_miss_penalty_percent" ])),
162+ ("validator_miss_penalty_duration" , Uint32 (kwargs ["validator_miss_penalty_duration" ])),
163+ # chain_properties_hf9: version 3
164+ ("create_invite_min_balance" , Amount (kwargs ["create_invite_min_balance" ])),
165+ ("committee_create_request_fee" , Amount (kwargs ["committee_create_request_fee" ])),
166+ ("create_paid_subscription_fee" , Amount (kwargs ["create_paid_subscription_fee" ])),
167+ ("account_on_sale_fee" , Amount (kwargs ["account_on_sale_fee" ])),
168+ ("subaccount_on_sale_fee" , Amount (kwargs ["subaccount_on_sale_fee" ])),
169+ ("validator_declaration_fee" , Amount (kwargs ["validator_declaration_fee" ])),
170+ ("withdraw_intervals" , Uint16 (kwargs ["withdraw_intervals" ])),
171+ ]
172+
173+
174+ def _chain_properties_hf13_items (kwargs ):
175+ """hf9 + chain_properties_hf13 (variant 4)."""
176+ return _chain_properties_hf9_items (kwargs ) + [
177+ ("distribution_epoch_length" , Uint32 (kwargs ["distribution_epoch_length" ])),
178+ ]
179+
180+
181+ def _chain_properties_pm_items (kwargs ):
182+ """hf13 + HF14/Onix chain_properties_pm (variant 5) governance params.
183+ Order/types mirror FC_REFLECT_DERIVED(chain_properties_pm) exactly."""
184+ return _chain_properties_hf13_items (kwargs ) + [
185+ ("pm_oracle_registration_fee" , Amount (kwargs ["pm_oracle_registration_fee" ])),
186+ ("pm_min_oracle_insurance" , Amount (kwargs ["pm_min_oracle_insurance" ])),
187+ ("pm_market_creation_fee" , Amount (kwargs ["pm_market_creation_fee" ])),
188+ ("pm_min_liquidity" , Amount (kwargs ["pm_min_liquidity" ])),
189+ ("pm_max_outcomes" , Uint8 (kwargs ["pm_max_outcomes" ])),
190+ ("pm_max_market_duration" , Uint32 (kwargs ["pm_max_market_duration" ])),
191+ ("pm_max_oracle_fee_percent" , Uint16 (kwargs ["pm_max_oracle_fee_percent" ])),
192+ ("pm_oracle_accept_window_sec" , Uint32 (kwargs ["pm_oracle_accept_window_sec" ])),
193+ ("pm_listing_min_coverage_percent" , Uint16 (kwargs ["pm_listing_min_coverage_percent" ])),
194+ ("pm_betting_min_coverage_percent" , Uint16 (kwargs ["pm_betting_min_coverage_percent" ])),
195+ ("pm_default_time_penalty_percent" , Uint16 (kwargs ["pm_default_time_penalty_percent" ])),
196+ ("pm_max_time_penalty" , Uint32 (kwargs ["pm_max_time_penalty" ])),
197+ ("pm_dispute_fee" , Amount (kwargs ["pm_dispute_fee" ])),
198+ ("pm_dispute_grace_sec" , Uint32 (kwargs ["pm_dispute_grace_sec" ])),
199+ ("pm_oracle_dispute_response_sec" , Uint32 (kwargs ["pm_oracle_dispute_response_sec" ])),
200+ ("pm_dispute_auto_close_sec" , Uint32 (kwargs ["pm_dispute_auto_close_sec" ])),
201+ ("pm_dispute_vote_period_sec" , Uint32 (kwargs ["pm_dispute_vote_period_sec" ])),
202+ ("pm_dispute_approve_min_percent" , Uint16 (kwargs ["pm_dispute_approve_min_percent" ])),
203+ ("pm_oracle_penalty_percent" , Uint16 (kwargs ["pm_oracle_penalty_percent" ])),
204+ ("pm_no_contest_penalty_percent" , Uint16 (kwargs ["pm_no_contest_penalty_percent" ])),
205+ ("pm_dispute_reward_multiplier" , Uint32 (kwargs ["pm_dispute_reward_multiplier" ])),
206+ ("pm_batch_epoch_blocks" , Uint32 (kwargs ["pm_batch_epoch_blocks" ])),
207+ ("pm_reveal_window_blocks" , Uint32 (kwargs ["pm_reveal_window_blocks" ])),
208+ ("pm_commit_no_reveal_penalty_percent" , Uint16 (kwargs ["pm_commit_no_reveal_penalty_percent" ])),
209+ ("pm_min_batch_bet" , Amount (kwargs ["pm_min_batch_bet" ])),
210+ ("pm_commit_reveal_enabled" , Bool (bool (kwargs ["pm_commit_reveal_enabled" ]))),
211+ ("pm_processing_cap_per_block" , Uint32 (kwargs ["pm_processing_cap_per_block" ])),
212+ ("pm_lazy_pool_enabled" , Bool (bool (kwargs ["pm_lazy_pool_enabled" ]))),
213+ ("pm_lazy_alloc_percent" , Uint16 (kwargs ["pm_lazy_alloc_percent" ])),
214+ ("pm_lazy_max_total_alloc_percent" , Uint16 (kwargs ["pm_lazy_max_total_alloc_percent" ])),
215+ ("pm_lazy_lock_sec" , Uint32 (kwargs ["pm_lazy_lock_sec" ])),
216+ ("pm_lazy_recall_step_percent" , Uint16 (kwargs ["pm_lazy_recall_step_percent" ])),
217+ ("pm_lazy_emergency_penalty_percent" , Uint16 (kwargs ["pm_lazy_emergency_penalty_percent" ])),
218+ ("pm_lazy_min_liquidity_fee_percent" , Uint16 (kwargs ["pm_lazy_min_liquidity_fee_percent" ])),
219+ ("pm_leverage_enabled" , Bool (bool (kwargs ["pm_leverage_enabled" ]))),
220+ ("pm_leverage_fund_percent" , Uint16 (kwargs ["pm_leverage_fund_percent" ])),
221+ ("pm_leverage_max_per_position_bp" , Uint16 (kwargs ["pm_leverage_max_per_position_bp" ])),
222+ ("pm_leverage_pool_profit_percent" , Uint16 (kwargs ["pm_leverage_pool_profit_percent" ])),
223+ ("pm_leverage_safety_margin_percent" , Uint16 (kwargs ["pm_leverage_safety_margin_percent" ])),
224+ ("pm_leverage_max_slippage_percent" , Uint16 (kwargs ["pm_leverage_max_slippage_percent" ])),
225+ ("pm_leverage_min_market_liquidity" , Amount (kwargs ["pm_leverage_min_market_liquidity" ])),
226+ ("pm_leverage_max_position_ratio_percent" , Uint16 (kwargs ["pm_leverage_max_position_ratio_percent" ])),
227+ ("pm_leverage_expiration_buffer_sec" , Uint32 (kwargs ["pm_leverage_expiration_buffer_sec" ])),
228+ ("pm_leverage_m_factor_percent" , Uint16 (kwargs ["pm_leverage_m_factor_percent" ])),
229+ ("pm_leverage_funding_rate_ppm_per_day" , Uint32 (kwargs ["pm_leverage_funding_rate_ppm_per_day" ])),
230+ ("pm_conversion_profit_cost_percent" , Uint16 (kwargs ["pm_conversion_profit_cost_percent" ])),
231+ ("pm_closed_market_retention_sec" , Uint32 (kwargs ["pm_closed_market_retention_sec" ])),
232+ ]
233+
234+
126235class ChainProperties (GrapheneObject ):
236+ """versioned_chain_properties variant 3 (chain_properties_hf9)."""
237+
238+ _items = staticmethod (_chain_properties_hf9_items )
239+
127240 def __init__ (self , * args , ** kwargs ):
128241 if isArgsThisClass (self , args ):
129242 self .data = args [0 ].data
@@ -137,50 +250,19 @@ def __init__(self, *args, **kwargs):
137250 context = "chain_properties_update" ,
138251 )
139252
140- super ().__init__ (
141- OrderedDict (
142- [
143- # initial, version 0
144- ("account_creation_fee" , Amount (kwargs ["account_creation_fee" ])),
145- ("maximum_block_size" , Uint32 (kwargs ["maximum_block_size" ])),
146- ("create_account_delegation_ratio" , Uint32 (kwargs ["create_account_delegation_ratio" ])),
147- ("create_account_delegation_time" , Uint32 (kwargs ["create_account_delegation_time" ])),
148- ("min_delegation" , Amount (kwargs ["min_delegation" ])),
149- ("min_curation_percent" , Uint16 (kwargs ["min_curation_percent" ])),
150- ("max_curation_percent" , Uint16 (kwargs ["max_curation_percent" ])),
151- ("bandwidth_reserve_percent" , Uint16 (kwargs ["bandwidth_reserve_percent" ])),
152- ("bandwidth_reserve_below" , Amount (kwargs ["bandwidth_reserve_below" ])),
153- ("flag_energy_additional_cost" , Uint16 (kwargs ["flag_energy_additional_cost" ])),
154- ("vote_accounting_min_rshares" , Uint32 (kwargs ["vote_accounting_min_rshares" ])),
155- (
156- "committee_request_approve_min_percent" ,
157- Uint16 (kwargs ["committee_request_approve_min_percent" ]),
158- ),
159- # chain_properties_hf4, version 1
160- ("inflation_validator_percent" , Uint16 (kwargs ["inflation_validator_percent" ])),
161- (
162- "inflation_ratio_committee_vs_reward_fund" ,
163- Uint16 (kwargs ["inflation_ratio_committee_vs_reward_fund" ]),
164- ),
165- ("inflation_recalc_period" , Uint32 (kwargs ["inflation_recalc_period" ])),
166- # chain_properties_hf6: version 2
167- (
168- "data_operations_cost_additional_bandwidth" ,
169- Uint32 (kwargs ["data_operations_cost_additional_bandwidth" ]),
170- ),
171- ("validator_miss_penalty_percent" , Uint16 (kwargs ["validator_miss_penalty_percent" ])),
172- ("validator_miss_penalty_duration" , Uint32 (kwargs ["validator_miss_penalty_duration" ])),
173- # chain_properties_hf9: version 3
174- ("create_invite_min_balance" , Amount (kwargs ["create_invite_min_balance" ])),
175- ("committee_create_request_fee" , Amount (kwargs ["committee_create_request_fee" ])),
176- ("create_paid_subscription_fee" , Amount (kwargs ["create_paid_subscription_fee" ])),
177- ("account_on_sale_fee" , Amount (kwargs ["account_on_sale_fee" ])),
178- ("subaccount_on_sale_fee" , Amount (kwargs ["subaccount_on_sale_fee" ])),
179- ("validator_declaration_fee" , Amount (kwargs ["validator_declaration_fee" ])),
180- ("withdraw_intervals" , Uint16 (kwargs ["withdraw_intervals" ])),
181- ]
182- )
183- )
253+ super ().__init__ (OrderedDict (self ._items (kwargs )))
254+
255+
256+ class ChainPropertiesHf13 (ChainProperties ):
257+ """versioned_chain_properties variant 4 (chain_properties_hf13)."""
258+
259+ _items = staticmethod (_chain_properties_hf13_items )
260+
261+
262+ class ChainPropertiesPm (ChainProperties ):
263+ """versioned_chain_properties variant 5 (chain_properties_pm, HF14/Onix)."""
264+
265+ _items = staticmethod (_chain_properties_pm_items )
184266
185267
186268class Op_wrapper (GrapheneObject ):
0 commit comments