viz-python-lib 1.2.2__tar.gz → 1.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/PKG-INFO +1 -1
  2. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/pyproject.toml +1 -1
  3. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/blockchain.py +14 -3
  4. viz_python_lib-1.3.0/viz/validator.py +44 -0
  5. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/viz.py +3 -3
  6. viz_python_lib-1.3.0/viz/witness.py +22 -0
  7. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/vizapi/consts.py +10 -10
  8. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/vizapi/exceptions.py +6 -0
  9. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/vizapi/noderpc.py +73 -19
  10. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/vizbase/objects.py +11 -4
  11. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/vizbase/operationids.py +15 -7
  12. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/vizbase/operations.py +41 -3
  13. viz_python_lib-1.3.0/vizbase/validator_compat.py +82 -0
  14. viz_python_lib-1.2.2/viz/witness.py +0 -36
  15. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/LICENSE.txt +0 -0
  16. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/README.md +0 -0
  17. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/__init__.py +0 -0
  18. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/account.py +0 -0
  19. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/amount.py +0 -0
  20. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/block.py +0 -0
  21. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/blockchainobject.py +0 -0
  22. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/converter.py +0 -0
  23. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/exceptions.py +0 -0
  24. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/instance.py +0 -0
  25. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/memo.py +0 -0
  26. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/storage.py +0 -0
  27. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/transactionbuilder.py +0 -0
  28. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/utils.py +0 -0
  29. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/viz/wallet.py +0 -0
  30. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/vizapi/__init__.py +0 -0
  31. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/vizbase/__init__.py +0 -0
  32. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/vizbase/account.py +0 -0
  33. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/vizbase/chains.py +0 -0
  34. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/vizbase/exceptions.py +0 -0
  35. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/vizbase/memo.py +0 -0
  36. {viz_python_lib-1.2.2 → viz_python_lib-1.3.0}/vizbase/signedtransactions.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: viz-python-lib
3
- Version: 1.2.2
3
+ Version: 1.3.0
4
4
  Summary: Python library for VIZ blockchain
5
5
  License: MIT
6
6
  License-File: LICENSE.txt
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "viz-python-lib"
7
- version = "1.2.2"
7
+ version = "1.3.0"
8
8
  description = "Python library for VIZ blockchain"
9
9
  authors = ["Vladimir Kamarzin <vvk@vvk.pp.ru>", "Vladimir Babin <vovababin@gmail.com>"]
10
10
  license = "MIT"
@@ -6,11 +6,21 @@ from collections.abc import Iterator
6
6
  from graphenecommon.blockchain import Blockchain as GrapheneBlockchain
7
7
 
8
8
  from vizbase import operationids
9
+ from vizbase.validator_compat import OP_NAME_ALIASES
9
10
 
10
11
  from .block import Block
11
12
  from .instance import BlockchainInstance
12
13
 
13
14
 
15
+ def _canonical_filter(filter_by):
16
+ """Translate deprecated witness_* op names to validator_*; pass through others."""
17
+ if filter_by is None:
18
+ return None
19
+ if isinstance(filter_by, str):
20
+ return OP_NAME_ALIASES.get(filter_by, filter_by)
21
+ return [OP_NAME_ALIASES.get(name, name) for name in filter_by]
22
+
23
+
14
24
  @BlockchainInstance.inject
15
25
  class Blockchain(GrapheneBlockchain):
16
26
  """
@@ -138,11 +148,11 @@ class Blockchain(GrapheneBlockchain):
138
148
 
139
149
  {
140
150
  '_id': 'e2fabb498706edfccd1114921f05d95e8fd64e4c',
141
- 'type': 'witness_reward',
151
+ 'type': 'validator_reward',
142
152
  'timestamp': '2020-05-29T19:07:48',
143
153
  'block_num': 1,
144
154
  'trx_id': '0000000000000000000000000000000000000000',
145
- 'witness': 'committee',
155
+ 'validator': 'committee',
146
156
  'shares': '0.032999 SHARES',
147
157
  }
148
158
 
@@ -157,7 +167,7 @@ class Blockchain(GrapheneBlockchain):
157
167
  'op_in_trx': 0,
158
168
  'virtual_op': 1,
159
169
  'timestamp': '2020-05-29T19:28:08',
160
- 'op': ['witness_reward', {'witness': 'committee', 'shares': '0.032999 SHARES'}],
170
+ 'op': ['validator_reward', {'validator': 'committee', 'shares': '0.032999 SHARES'}],
161
171
  }
162
172
 
163
173
 
@@ -175,6 +185,7 @@ class Blockchain(GrapheneBlockchain):
175
185
  'memo': 'test stream',
176
186
  }
177
187
  """
188
+ filter_by = _canonical_filter(filter_by)
178
189
  if filter_by is None:
179
190
  filter_by = []
180
191
 
@@ -0,0 +1,44 @@
1
+ from graphenecommon.witness import Witness as GrapheneWitness
2
+ from graphenecommon.witness import Witnesses as GrapheneWitnesses
3
+
4
+ from .account import Account
5
+ from .instance import BlockchainInstance
6
+
7
+
8
+ @BlockchainInstance.inject
9
+ class Validator(GrapheneWitness):
10
+ """
11
+ Read data about a validator in the chain.
12
+
13
+ :param str account_name: Name of the validator
14
+ :param viz blockchain_instance: Client() instance to use when
15
+ accesing a RPC
16
+
17
+ .. note::
18
+ Inherits from graphenecommon.witness.Witness. Once graphenecommon
19
+ migrates its terminology, this parent can be swapped to the
20
+ validator-named equivalent.
21
+ """
22
+
23
+ def define_classes(self):
24
+ self.account_class = Account
25
+ self.type_ids = [6, 2]
26
+
27
+
28
+ @BlockchainInstance.inject
29
+ class Validators(GrapheneWitnesses):
30
+ """
31
+ Obtain a list of **active** validators and the current schedule.
32
+
33
+ :param bool only_active: (False) Only return validators that are
34
+ actively producing blocks
35
+ :param viz blockchain_instance: Client() instance to use when
36
+ accesing a RPC
37
+ """
38
+
39
+ def define_classes(self):
40
+ self.account_class = Account
41
+ # graphenecommon contract: parent asserts self.witness_class.
42
+ self.witness_class = Validator
43
+ # Forward-compat for a future graphenecommon migration. Harmless today.
44
+ self.validator_class = Validator
@@ -742,14 +742,14 @@ class Client(AbstractGrapheneChain):
742
742
  pass
743
743
 
744
744
  # TODO: Methods to implement:
745
- # - witness_update
745
+ # - validator_update
746
746
  # - chain_properties_update
747
747
  # - allow / disallow
748
748
  # - update_memo_key
749
- # - approve_witness / disapprove_witness
749
+ # - approve_validator / disapprove_validator
750
750
  # - account_metadata
751
751
  # - proposal_create / proposal_update / proposal_delete
752
- # - witness_proxy
752
+ # - validator_proxy
753
753
  # - recover-related methods
754
754
  # - escrow-related methods
755
755
  # - worker create / cancel / vote
@@ -0,0 +1,22 @@
1
+ """
2
+ Deprecated module: use viz.validator instead.
3
+
4
+ This shim re-exports Validator/Validators under their old witness names
5
+ to preserve backward compatibility during the witness -> validator
6
+ terminology migration. Remove during Phase C cleanup.
7
+ """
8
+
9
+ import warnings
10
+
11
+ from .validator import Validator, Validators
12
+
13
+ warnings.warn(
14
+ "viz.witness is deprecated; import from viz.validator instead",
15
+ DeprecationWarning,
16
+ stacklevel=2,
17
+ )
18
+
19
+ Witness = Validator
20
+ Witnesses = Validators
21
+
22
+ __all__ = ["Witness", "Witnesses"]
@@ -58,7 +58,7 @@ API = {
58
58
  "debug_push_blocks": "debug_node",
59
59
  "debug_push_json_blocks": "debug_node",
60
60
  "debug_pop_block": "debug_node",
61
- "debug_get_witness_schedule": "debug_node",
61
+ "debug_get_validator_schedule": "debug_node",
62
62
  "debug_get_hardfork_property_object": "debug_node",
63
63
  "debug_set_hardfork": "debug_node",
64
64
  "debug_has_hardfork": "debug_node",
@@ -97,15 +97,15 @@ API = {
97
97
  "get_blog_authors": "follow",
98
98
  "get_inbox": "private_message",
99
99
  "get_outbox": "private_message",
100
- "get_miner_queue": "witness_api",
101
- "get_witnesses_by_counted_vote": "witness_api",
102
- "get_active_witnesses": "witness_api",
103
- "get_witness_schedule": "witness_api",
104
- "get_witnesses": "witness_api",
105
- "get_witness_by_account": "witness_api",
106
- "get_witnesses_by_vote": "witness_api",
107
- "get_witness_count": "witness_api",
108
- "lookup_witness_accounts": "witness_api",
100
+ "get_miner_queue": "validator_api",
101
+ "get_validators_by_counted_vote": "validator_api",
102
+ "get_active_validators": "validator_api",
103
+ "get_validator_schedule": "validator_api",
104
+ "get_validators": "validator_api",
105
+ "get_validator_by_account": "validator_api",
106
+ "get_validators_by_vote": "validator_api",
107
+ "get_validator_count": "validator_api",
108
+ "lookup_validator_accounts": "validator_api",
109
109
  "get_account": "custom_protocol_api",
110
110
  "test_api_a": "test_api",
111
111
  "test_api_b": "test_api",
@@ -36,3 +36,9 @@ class ReadLockFail(RPCError):
36
36
 
37
37
  class UnknownNetwork(RPCError):
38
38
  pass
39
+
40
+
41
+ class NoSuchMethod(RPCError):
42
+ """Raised when the node reports the requested method is not available on the API."""
43
+
44
+ pass
@@ -1,4 +1,5 @@
1
1
  import logging
2
+ import warnings
2
3
  from threading import Lock
3
4
 
4
5
  from grapheneapi.api import Api as GrapheneApi
@@ -7,12 +8,16 @@ from grapheneapi.rpc import Rpc as GrapheneRpc
7
8
  from grapheneapi.websocket import Websocket as GrapheneWebsocket
8
9
 
9
10
  from vizbase.chains import KNOWN_CHAINS
11
+ from vizbase.validator_compat import API_METHOD_ALIASES
10
12
 
11
13
  from . import exceptions
12
14
  from .consts import API
13
15
 
14
16
  log = logging.getLogger(__name__)
15
17
 
18
+ # Reverse map for runtime fallback: new method name -> old method name.
19
+ _REVERSE_API_METHOD = {new: old for old, new in API_METHOD_ALIASES.items()}
20
+
16
21
 
17
22
  class NodeRPC(GrapheneApi):
18
23
  """
@@ -48,6 +53,7 @@ class NodeRPC(GrapheneApi):
48
53
  raise
49
54
 
50
55
  msg = exceptions.decode_rpc_error_msg(error)
56
+ msg_lower = msg.lower()
51
57
  if (
52
58
  msg.startswith("Missing Active Authority")
53
59
  or msg.startswith("Missing Master Authority")
@@ -57,6 +63,8 @@ class NodeRPC(GrapheneApi):
57
63
  raise exceptions.MissingRequiredAuthority(msg)
58
64
  elif msg == "Unable to acquire READ lock":
59
65
  raise exceptions.ReadLockFail(msg)
66
+ elif "could not find method" in msg_lower or "method not found" in msg_lower or "no such method" in msg_lower:
67
+ raise exceptions.NoSuchMethod(msg)
60
68
  elif msg:
61
69
  raise exceptions.UnhandledRPCError(msg)
62
70
  else:
@@ -102,43 +110,89 @@ class Rpc(GrapheneRpc):
102
110
  """
103
111
  This class is responsible for making RPC queries.
104
112
 
105
- Original graphene chains (like Bitshares) uses api_id in "params", while Golos and VIZ uses api name here.
113
+ Phase A of the witness -> validator migration: inbound calls using old
114
+ method names are translated to new names with a DeprecationWarning.
115
+ On a NoSuchMethod error against the new method, the dispatcher falls
116
+ back to the old method on `witness_api` and caches the result so
117
+ subsequent calls skip the new-name attempt.
106
118
  """
107
119
 
108
120
  def __init__(self, *args, **kwargs):
109
121
  super().__init__(*args, **kwargs)
122
+ # None = unknown; True = node only knows witness_api; False = new names confirmed.
123
+ self._uses_legacy_witness_api: bool | None = None
110
124
 
111
125
  def __getattr__(self, name):
112
126
  """Map all methods to RPC calls and pass through the arguments."""
113
127
 
114
128
  def method(*args, **kwargs):
115
- api = kwargs.get("api", API.get(name))
129
+ # Inbound translation: if caller used a deprecated witness_* name,
130
+ # translate to the validator_* equivalent and warn.
131
+ canonical_name = API_METHOD_ALIASES.get(name, name)
132
+ if canonical_name != name:
133
+ warnings.warn(
134
+ f"API method '{name}' is deprecated; use '{canonical_name}' instead",
135
+ DeprecationWarning,
136
+ stacklevel=2,
137
+ )
138
+
139
+ api = kwargs.get("api", API.get(canonical_name))
116
140
  if not api:
117
- raise exceptions.NoSuchAPI(f'Cannot find API for you request "{name}"')
141
+ raise exceptions.NoSuchAPI(f'Cannot find API for you request "{canonical_name}"')
118
142
 
119
143
  # Fix wrong api name hardcoded in graphenecommon.TransactionBuilder
120
144
  if api == "network_broadcast":
121
145
  api = "network_broadcast_api"
122
146
 
123
- query = {
124
- "method": "call",
125
- "params": [api, name, list(args)],
126
- "jsonrpc": "2.0",
127
- "id": self.get_request_id(),
128
- }
129
- log.debug(query)
130
- while True:
131
- try:
132
- response = self.rpcexec(query)
133
- message = self.parse_response(response)
134
- except exceptions.ReadLockFail:
135
- pass
136
- else:
137
- break
138
- return message
147
+ # If the node is known to only speak witness_api, skip new-name attempt.
148
+ if self._uses_legacy_witness_api and canonical_name in _REVERSE_API_METHOD:
149
+ return self._call_legacy(canonical_name, list(args))
150
+
151
+ return self._call_with_fallback(api, canonical_name, list(args))
139
152
 
140
153
  return method
141
154
 
155
+ def _call_legacy(self, canonical_name: str, params_args: list) -> object:
156
+ old_name = _REVERSE_API_METHOD[canonical_name]
157
+ return self._do_call("witness_api", old_name, params_args)
158
+
159
+ def _call_with_fallback(self, api: str, canonical_name: str, params_args: list) -> object:
160
+ try:
161
+ result = self._do_call(api, canonical_name, params_args)
162
+ except exceptions.NoSuchMethod:
163
+ if canonical_name not in _REVERSE_API_METHOD:
164
+ raise
165
+ if self._uses_legacy_witness_api is None:
166
+ warnings.warn(
167
+ "Node responded on witness_api; upgrade recommended",
168
+ DeprecationWarning,
169
+ stacklevel=4,
170
+ )
171
+ self._uses_legacy_witness_api = True
172
+ return self._call_legacy(canonical_name, params_args)
173
+ else:
174
+ if self._uses_legacy_witness_api is None:
175
+ self._uses_legacy_witness_api = False
176
+ return result
177
+
178
+ def _do_call(self, api: str, name: str, params_args: list) -> object:
179
+ query = {
180
+ "method": "call",
181
+ "params": [api, name, params_args],
182
+ "jsonrpc": "2.0",
183
+ "id": self.get_request_id(),
184
+ }
185
+ log.debug(query)
186
+ while True:
187
+ try:
188
+ response = self.rpcexec(query)
189
+ message = self.parse_response(response)
190
+ except exceptions.ReadLockFail:
191
+ pass
192
+ else:
193
+ break
194
+ return message
195
+
142
196
 
143
197
  class Websocket(GrapheneWebsocket, Rpc):
144
198
  """
@@ -18,6 +18,7 @@ from .account import PublicKey
18
18
  from .chains import DEFAULT_PREFIX, PRECISIONS
19
19
  from .exceptions import AssetUnknown
20
20
  from .operationids import operations
21
+ from .validator_compat import CHAIN_PROPS_FIELD_ALIASES, translate_kwargs
21
22
 
22
23
 
23
24
  class Operation(GrapheneOperation):
@@ -130,6 +131,12 @@ class ChainProperties(GrapheneObject):
130
131
  if len(args) == 1 and len(kwargs) == 0:
131
132
  kwargs = args[0]
132
133
 
134
+ kwargs = translate_kwargs(
135
+ kwargs,
136
+ CHAIN_PROPS_FIELD_ALIASES,
137
+ context="chain_properties_update",
138
+ )
139
+
133
140
  super().__init__(
134
141
  OrderedDict(
135
142
  [
@@ -150,7 +157,7 @@ class ChainProperties(GrapheneObject):
150
157
  Uint16(kwargs["committee_request_approve_min_percent"]),
151
158
  ),
152
159
  # chain_properties_hf4, version 1
153
- ("inflation_witness_percent", Uint16(kwargs["inflation_witness_percent"])),
160
+ ("inflation_validator_percent", Uint16(kwargs["inflation_validator_percent"])),
154
161
  (
155
162
  "inflation_ratio_committee_vs_reward_fund",
156
163
  Uint16(kwargs["inflation_ratio_committee_vs_reward_fund"]),
@@ -161,15 +168,15 @@ class ChainProperties(GrapheneObject):
161
168
  "data_operations_cost_additional_bandwidth",
162
169
  Uint32(kwargs["data_operations_cost_additional_bandwidth"]),
163
170
  ),
164
- ("witness_miss_penalty_percent", Uint16(kwargs["witness_miss_penalty_percent"])),
165
- ("witness_miss_penalty_duration", Uint32(kwargs["witness_miss_penalty_duration"])),
171
+ ("validator_miss_penalty_percent", Uint16(kwargs["validator_miss_penalty_percent"])),
172
+ ("validator_miss_penalty_duration", Uint32(kwargs["validator_miss_penalty_duration"])),
166
173
  # chain_properties_hf9: version 3
167
174
  ("create_invite_min_balance", Amount(kwargs["create_invite_min_balance"])),
168
175
  ("committee_create_request_fee", Amount(kwargs["committee_create_request_fee"])),
169
176
  ("create_paid_subscription_fee", Amount(kwargs["create_paid_subscription_fee"])),
170
177
  ("account_on_sale_fee", Amount(kwargs["account_on_sale_fee"])),
171
178
  ("subaccount_on_sale_fee", Amount(kwargs["subaccount_on_sale_fee"])),
172
- ("witness_declaration_fee", Amount(kwargs["witness_declaration_fee"])),
179
+ ("validator_declaration_fee", Amount(kwargs["validator_declaration_fee"])),
173
180
  ("withdraw_intervals", Uint16(kwargs["withdraw_intervals"])),
174
181
  ]
175
182
  )
@@ -1,3 +1,5 @@
1
+ from .validator_compat import OP_NAME_ALIASES
2
+
1
3
  #: Operation ids
2
4
  # Note: take operations from libraries/protocol/include/graphene/protocol/operations.hpp
3
5
  # Beware to keep operations order!
@@ -8,9 +10,9 @@ OPS = [
8
10
  "transfer_to_vesting",
9
11
  "withdraw_vesting",
10
12
  "account_update",
11
- "witness_update",
12
- "account_witness_vote",
13
- "account_witness_proxy",
13
+ "validator_update",
14
+ "account_validator_vote",
15
+ "account_validator_proxy",
14
16
  "delete_content",
15
17
  "custom",
16
18
  "set_withdraw_vesting_route",
@@ -32,7 +34,7 @@ OPS = [
32
34
  "curation_reward",
33
35
  "content_reward",
34
36
  "fill_vesting_withdraw",
35
- "shutdown_witness",
37
+ "shutdown_validator",
36
38
  "hardfork",
37
39
  "content_payout_update",
38
40
  "content_benefactor_reward",
@@ -44,7 +46,7 @@ OPS = [
44
46
  "committee_approve_request",
45
47
  "committee_payout_request",
46
48
  "committee_pay_request",
47
- "witness_reward",
49
+ "validator_reward",
48
50
  "create_invite",
49
51
  "claim_invite_balance",
50
52
  "invite_registration",
@@ -69,13 +71,19 @@ OPS = [
69
71
  ]
70
72
  operations = {o: OPS.index(o) for o in OPS}
71
73
 
74
+ # Phase A dual-support: register old op names as aliases pointing to the
75
+ # same integer ID. Lookup by either old or new name returns the same id.
76
+ # Remove these alias entries during Phase C cleanup.
77
+ for _old, _new in OP_NAME_ALIASES.items():
78
+ operations[_old] = operations[_new]
79
+
72
80
  # libraries/protocol/include/graphene/protocol/chain_virtual_operations.hpp
73
81
  VIRTUAL_OPS = [
74
82
  "author_reward",
75
83
  "curation_reward",
76
84
  "content_reward",
77
85
  "fill_vesting_withdraw",
78
- "shutdown_witness",
86
+ "shutdown_validator",
79
87
  "hardfork",
80
88
  "content_payout_update",
81
89
  "content_benefactor_reward",
@@ -84,7 +92,7 @@ VIRTUAL_OPS = [
84
92
  "committee_approve_request",
85
93
  "committee_payout_request",
86
94
  "committee_pay_request",
87
- "witness_reward",
95
+ "validator_reward",
88
96
  "receive_award",
89
97
  "benefactor_award",
90
98
  "paid_subscription_action",
@@ -1,4 +1,5 @@
1
1
  import json
2
+ import warnings
2
3
  from collections import OrderedDict
3
4
 
4
5
  from graphenebase.types import (
@@ -22,11 +23,37 @@ from .objects import (
22
23
  Permission,
23
24
  isArgsThisClass,
24
25
  )
26
+ from .validator_compat import OP_FIELD_ALIASES, translate_kwargs
25
27
 
26
28
  # You can find operations definitions in
27
29
  # libraries/protocol/include/graphene/protocol/chain_operations.hpp
28
30
 
29
31
 
32
+ class _DeprecatedAlias:
33
+ """Warn once-per-process on first instantiation of a deprecated class name."""
34
+
35
+ _warned: set[str] = set()
36
+
37
+ @classmethod
38
+ def make(cls, old_name: str, new_class: type) -> type:
39
+ warned = cls._warned
40
+
41
+ class _Alias(new_class):
42
+ def __init__(self, *args, **kwargs):
43
+ if old_name not in warned:
44
+ warnings.warn(
45
+ f"{old_name} is deprecated; use {new_class.__name__} instead",
46
+ DeprecationWarning,
47
+ stacklevel=2,
48
+ )
49
+ warned.add(old_name)
50
+ super().__init__(*args, **kwargs)
51
+
52
+ _Alias.__name__ = old_name
53
+ _Alias.__qualname__ = old_name
54
+ return _Alias
55
+
56
+
30
57
  class Account_create(GrapheneObject):
31
58
  def __init__(self, *args, **kwargs):
32
59
  if isArgsThisClass(self, args):
@@ -268,7 +295,7 @@ class Set_withdraw_vesting_route(GrapheneObject):
268
295
  )
269
296
 
270
297
 
271
- class Witness_update(GrapheneObject):
298
+ class Validator_update(GrapheneObject):
272
299
  def __init__(self, *args, **kwargs):
273
300
  if isArgsThisClass(self, args):
274
301
  self.data = args[0].data
@@ -310,18 +337,23 @@ class Versioned_chain_properties_update(GrapheneObject):
310
337
  super().__init__(OrderedDict([("owner", String(kwargs["owner"])), ("props", props)]))
311
338
 
312
339
 
313
- class Account_witness_vote(GrapheneObject):
340
+ class Account_validator_vote(GrapheneObject):
314
341
  def __init__(self, *args, **kwargs):
315
342
  if isArgsThisClass(self, args):
316
343
  self.data = args[0].data
317
344
  else:
318
345
  if len(args) == 1 and len(kwargs) == 0:
319
346
  kwargs = args[0]
347
+ kwargs = translate_kwargs(
348
+ kwargs,
349
+ OP_FIELD_ALIASES["account_validator_vote"],
350
+ context="Account_validator_vote",
351
+ )
320
352
  super().__init__(
321
353
  OrderedDict(
322
354
  [
323
355
  ("account", String(kwargs["account"])),
324
- ("witness", String(kwargs["witness"])),
356
+ ("validator", String(kwargs["validator"])),
325
357
  ("approve", Bool(bool(kwargs["approve"]))),
326
358
  ]
327
359
  )
@@ -450,3 +482,9 @@ class Custom(GrapheneObject):
450
482
  ]
451
483
  )
452
484
  )
485
+
486
+
487
+ # Deprecated witness-named aliases. Subclasses that warn once per process
488
+ # on first instantiation. Remove during Phase C cleanup.
489
+ Witness_update = _DeprecatedAlias.make("Witness_update", Validator_update)
490
+ Account_witness_vote = _DeprecatedAlias.make("Account_witness_vote", Account_validator_vote)
@@ -0,0 +1,82 @@
1
+ """
2
+ Witness -> Validator migration compatibility layer.
3
+
4
+ Single source of truth for old -> new name translation. When the migration
5
+ is complete (Phase C), delete this file and remove all imports from it.
6
+ """
7
+
8
+ import warnings
9
+
10
+ # Wire-format op name aliases (old -> new).
11
+ OP_NAME_ALIASES = {
12
+ "witness_update": "validator_update",
13
+ "account_witness_vote": "account_validator_vote",
14
+ "account_witness_proxy": "account_validator_proxy",
15
+ "shutdown_witness": "shutdown_validator",
16
+ "witness_reward": "validator_reward",
17
+ }
18
+
19
+ # JSON-RPC API method aliases (old -> new).
20
+ API_METHOD_ALIASES = {
21
+ "get_active_witnesses": "get_active_validators",
22
+ "get_witness_schedule": "get_validator_schedule",
23
+ "get_witnesses": "get_validators",
24
+ "get_witness_by_account": "get_validator_by_account",
25
+ "get_witnesses_by_vote": "get_validators_by_vote",
26
+ "get_witnesses_by_counted_vote": "get_validators_by_counted_vote",
27
+ "get_witness_count": "get_validator_count",
28
+ "lookup_witness_accounts": "lookup_validator_accounts",
29
+ "debug_get_witness_schedule": "debug_get_validator_schedule",
30
+ }
31
+
32
+ # Chain-properties field aliases (old -> new). Applies to chain_properties_hf4/hf6/hf9.
33
+ CHAIN_PROPS_FIELD_ALIASES = {
34
+ "inflation_witness_percent": "inflation_validator_percent",
35
+ "witness_miss_penalty_percent": "validator_miss_penalty_percent",
36
+ "witness_miss_penalty_duration": "validator_miss_penalty_duration",
37
+ "witness_declaration_fee": "validator_declaration_fee",
38
+ }
39
+
40
+ # Per-op kwarg field aliases (old -> new), keyed by canonical new op name.
41
+ OP_FIELD_ALIASES = {
42
+ "account_validator_vote": {"witness": "validator"},
43
+ "validator_reward": {"witness": "validator"}, # virtual op; reserved for future use
44
+ }
45
+
46
+
47
+ def translate_kwargs(kwargs: dict, alias_map: dict, *, context: str) -> dict:
48
+ """
49
+ Return a copy of `kwargs` with old keys renamed to new keys per `alias_map`.
50
+
51
+ Emits one DeprecationWarning per old key found, citing `context`.
52
+ If both old and new keys are present, the new value wins and the old
53
+ key triggers a warning.
54
+ """
55
+ out = dict(kwargs)
56
+ for old, new in alias_map.items():
57
+ if old in out:
58
+ warnings.warn(
59
+ f"{context}: '{old}' is deprecated; use '{new}' instead",
60
+ DeprecationWarning,
61
+ stacklevel=3,
62
+ )
63
+ if new not in out:
64
+ out[new] = out.pop(old)
65
+ else:
66
+ out.pop(old)
67
+ return out
68
+
69
+
70
+ def pick(obj, *keys, default=None):
71
+ """
72
+ Return obj[k] for the first k in `keys` that exists; else `default`.
73
+
74
+ Used at response-read sites to tolerate both old (witness_*) and new
75
+ (validator_*) field names. Call with new key first, old key second.
76
+ """
77
+ for k in keys:
78
+ if isinstance(obj, dict) and k in obj:
79
+ return obj[k]
80
+ if not isinstance(obj, dict) and hasattr(obj, k):
81
+ return getattr(obj, k)
82
+ return default
@@ -1,36 +0,0 @@
1
- from graphenecommon.witness import Witness as GrapheneWitness
2
- from graphenecommon.witness import Witnesses as GrapheneWitnesses
3
-
4
- from .account import Account
5
- from .instance import BlockchainInstance
6
-
7
-
8
- @BlockchainInstance.inject
9
- class Witness(GrapheneWitness):
10
- """
11
- Read data about a witness in the chain.
12
-
13
- :param str account_name: Name of the witness
14
- :param viz blockchain_instance: Client() instance to use when
15
- accesing a RPC
16
- """
17
-
18
- def define_classes(self):
19
- self.account_class = Account
20
- self.type_ids = [6, 2]
21
-
22
-
23
- @BlockchainInstance.inject
24
- class Witnesses(GrapheneWitnesses):
25
- """
26
- Obtain a list of **active** witnesses and the current schedule.
27
-
28
- :param bool only_active: (False) Only return witnesses that are
29
- actively producing blocks
30
- :param viz blockchain_instance: Client() instance to use when
31
- accesing a RPC
32
- """
33
-
34
- def define_classes(self):
35
- self.account_class = Account
36
- self.witness_class = Witness
File without changes