viz-python-lib 1.2.1__py3-none-any.whl → 1.3.0__py3-none-any.whl
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.
- viz/blockchain.py +14 -3
- viz/validator.py +44 -0
- viz/viz.py +3 -3
- viz/witness.py +16 -30
- {viz_python_lib-1.2.1.dist-info → viz_python_lib-1.3.0.dist-info}/METADATA +1 -1
- {viz_python_lib-1.2.1.dist-info → viz_python_lib-1.3.0.dist-info}/RECORD +15 -13
- vizapi/consts.py +10 -10
- vizapi/exceptions.py +6 -0
- vizapi/noderpc.py +73 -19
- vizbase/objects.py +11 -4
- vizbase/operationids.py +15 -7
- vizbase/operations.py +41 -3
- vizbase/validator_compat.py +82 -0
- {viz_python_lib-1.2.1.dist-info → viz_python_lib-1.3.0.dist-info}/WHEEL +0 -0
- {viz_python_lib-1.2.1.dist-info → viz_python_lib-1.3.0.dist-info}/licenses/LICENSE.txt +0 -0
viz/blockchain.py
CHANGED
|
@@ -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': '
|
|
151
|
+
'type': 'validator_reward',
|
|
142
152
|
'timestamp': '2020-05-29T19:07:48',
|
|
143
153
|
'block_num': 1,
|
|
144
154
|
'trx_id': '0000000000000000000000000000000000000000',
|
|
145
|
-
'
|
|
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': ['
|
|
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
|
|
viz/validator.py
ADDED
|
@@ -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
|
viz/viz.py
CHANGED
|
@@ -742,14 +742,14 @@ class Client(AbstractGrapheneChain):
|
|
|
742
742
|
pass
|
|
743
743
|
|
|
744
744
|
# TODO: Methods to implement:
|
|
745
|
-
# -
|
|
745
|
+
# - validator_update
|
|
746
746
|
# - chain_properties_update
|
|
747
747
|
# - allow / disallow
|
|
748
748
|
# - update_memo_key
|
|
749
|
-
# -
|
|
749
|
+
# - approve_validator / disapprove_validator
|
|
750
750
|
# - account_metadata
|
|
751
751
|
# - proposal_create / proposal_update / proposal_delete
|
|
752
|
-
# -
|
|
752
|
+
# - validator_proxy
|
|
753
753
|
# - recover-related methods
|
|
754
754
|
# - escrow-related methods
|
|
755
755
|
# - worker create / cancel / vote
|
viz/witness.py
CHANGED
|
@@ -1,36 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"""
|
|
2
|
+
Deprecated module: use viz.validator instead.
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
"""
|
|
6
8
|
|
|
9
|
+
import warnings
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
class Witness(GrapheneWitness):
|
|
10
|
-
"""
|
|
11
|
-
Read data about a witness in the chain.
|
|
11
|
+
from .validator import Validator, Validators
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
warnings.warn(
|
|
14
|
+
"viz.witness is deprecated; import from viz.validator instead",
|
|
15
|
+
DeprecationWarning,
|
|
16
|
+
stacklevel=2,
|
|
17
|
+
)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
self.type_ids = [6, 2]
|
|
19
|
+
Witness = Validator
|
|
20
|
+
Witnesses = Validators
|
|
21
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
|
|
22
|
+
__all__ = ["Witness", "Witnesses"]
|
|
@@ -2,7 +2,7 @@ viz/__init__.py,sha256=zZLRKB2iD1XkOhD9zHglX-q6shGvWyek5v-ZHa_Q4x8,46
|
|
|
2
2
|
viz/account.py,sha256=21MaPOWAbJJt9n971ytZJVAIvBBDD6NRZ5O3ANgLCAg,10865
|
|
3
3
|
viz/amount.py,sha256=6LoUfr4E9mOmWlRC0Smy9vKfUt0Hhdx7qH1C7mlEF70,5683
|
|
4
4
|
viz/block.py,sha256=aoCq3zOYyoI_6OmW4imQKVk0Tcn32YrrIOJJZfcGqY0,1093
|
|
5
|
-
viz/blockchain.py,sha256=
|
|
5
|
+
viz/blockchain.py,sha256=jLHp9nhYn07dRBUl7t_8O9FTedivW_CtwruIF1Icih4,9264
|
|
6
6
|
viz/blockchainobject.py,sha256=_pwnJMDj6wmPGdxgc43iu2t_4yNozY7i0c_IeIgooUU,386
|
|
7
7
|
viz/converter.py,sha256=Bty4Av7k-fAhHZZA54M5cDYO4c3ufgl0cnjklp1G5pk,1101
|
|
8
8
|
viz/exceptions.py,sha256=yMJ0-TxS0bn2vkH8P4Mkd33CDbKqrioqwYogOfWtORI,428
|
|
@@ -11,23 +11,25 @@ viz/memo.py,sha256=8EsbCw99m2GAR6D7wW8l4em6RpKoF4cKJ-FO3fN12E8,3831
|
|
|
11
11
|
viz/storage.py,sha256=EMPZmUirQ2m8ZMxMcCKTS7kIxqcezCAdl92E6TyGGv0,600
|
|
12
12
|
viz/transactionbuilder.py,sha256=m42aPGkCHGlMmVCv8tR3AE5pz1uuYZWt8K_S33up7ng,6164
|
|
13
13
|
viz/utils.py,sha256=4OkRq2DoefAtS2gbRLPolJ6pUN9oP56guyro8NfGzUE,1078
|
|
14
|
-
viz/
|
|
14
|
+
viz/validator.py,sha256=1dq1xUxP2ytoBY31ch3CxcrK4UPLc5Fdw8iTEt0UbdI,1402
|
|
15
|
+
viz/viz.py,sha256=4WNA1Ui00gGQp3eZ5FddzGx_mSZK5z6DetXLMC1aCL8,28955
|
|
15
16
|
viz/wallet.py,sha256=rD1L2LSdP0GaDn4UY13fQP-gyswIzsOnWP2O6rT5Fic,361
|
|
16
|
-
viz/witness.py,sha256=
|
|
17
|
+
viz/witness.py,sha256=g2mMCplyrKAThHLynmmEBQ-9vcdRc0ts0CcoFd7i2rg,519
|
|
17
18
|
vizapi/__init__.py,sha256=1mfkBk0riiobfZ00LKex4r8dDlCv4rU9kX7VMAUzQY4,49
|
|
18
|
-
vizapi/consts.py,sha256=
|
|
19
|
-
vizapi/exceptions.py,sha256=
|
|
20
|
-
vizapi/noderpc.py,sha256=
|
|
19
|
+
vizapi/consts.py,sha256=Lcg-xwYvz3Hvslb5TZAYURAMFYaJjwcpPT78YYSlhpc,4857
|
|
20
|
+
vizapi/exceptions.py,sha256=JfD1NL68ntRb4vAMhRQQWPk1UJ52RH93swJA2au2FFI,984
|
|
21
|
+
vizapi/noderpc.py,sha256=mz7z5PCMT9ANBAVR-gD87rfdYUE1Xwc02PNrP2Wrcjk,7790
|
|
21
22
|
vizbase/__init__.py,sha256=TyuPogcL9AGGSDrJq_iIcKclvsn0ZoPhBpXFMjbGsH4,186
|
|
22
23
|
vizbase/account.py,sha256=QTu8WukItc_HN6G76MMO6IfS0iY18NWXmamXzt3AG5g,3183
|
|
23
24
|
vizbase/chains.py,sha256=3_JFSb7C453G-r80SKjELEbuqyqBe-lgfr3D7hvu9nY,480
|
|
24
25
|
vizbase/exceptions.py,sha256=dm76Hj5tMoaKOTPJvTue1y8LuP3zfI8P_1BDBFyJVwM,87
|
|
25
26
|
vizbase/memo.py,sha256=artQmLtKp-b_ZtoUj02GGd1_IaLPbWEJyHw2OWC008U,3929
|
|
26
|
-
vizbase/objects.py,sha256=
|
|
27
|
-
vizbase/operationids.py,sha256=
|
|
28
|
-
vizbase/operations.py,sha256=
|
|
27
|
+
vizbase/objects.py,sha256=qFLVNtIzRLijCBQG8ChF4Z7VHP9mKL4-wcoYTJgHgSg,7761
|
|
28
|
+
vizbase/operationids.py,sha256=RuvmwSn9v_un3xlpXL5G4BwsZ9O0aVadba30mr-wLag,2796
|
|
29
|
+
vizbase/operations.py,sha256=pUobmLdXNEbnRNQDa5wX8HdsNthKkteyT8yM6gg0-RM,18338
|
|
29
30
|
vizbase/signedtransactions.py,sha256=KZuWGmzA-Lamq6VadEESDTsRl7ECpscThj6wIu47d78,665
|
|
30
|
-
|
|
31
|
-
viz_python_lib-1.
|
|
32
|
-
viz_python_lib-1.
|
|
33
|
-
viz_python_lib-1.
|
|
31
|
+
vizbase/validator_compat.py,sha256=RuhaW3ZFh5eGZ74nGtEek35o5cOuQ9VBGXoPial5Dho,2962
|
|
32
|
+
viz_python_lib-1.3.0.dist-info/METADATA,sha256=HJcpOlLyXs3USd4bMsL2cG0d614YPKFjjSG2baQgdhM,4577
|
|
33
|
+
viz_python_lib-1.3.0.dist-info/WHEEL,sha256=EGEvSphFYqXKs23-kQBeyNoJP1nrT8ZJKQoi5p5DYL8,88
|
|
34
|
+
viz_python_lib-1.3.0.dist-info/licenses/LICENSE.txt,sha256=Nl1SGZTRwbvAko1uTG4FLQMol_feVwxCWnqCTQtf8No,1211
|
|
35
|
+
viz_python_lib-1.3.0.dist-info/RECORD,,
|
vizapi/consts.py
CHANGED
|
@@ -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
|
-
"
|
|
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": "
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
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",
|
vizapi/exceptions.py
CHANGED
vizapi/noderpc.py
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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 "{
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
"""
|
vizbase/objects.py
CHANGED
|
@@ -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
|
-
("
|
|
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
|
-
("
|
|
165
|
-
("
|
|
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
|
-
("
|
|
179
|
+
("validator_declaration_fee", Amount(kwargs["validator_declaration_fee"])),
|
|
173
180
|
("withdraw_intervals", Uint16(kwargs["withdraw_intervals"])),
|
|
174
181
|
]
|
|
175
182
|
)
|
vizbase/operationids.py
CHANGED
|
@@ -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
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
95
|
+
"validator_reward",
|
|
88
96
|
"receive_award",
|
|
89
97
|
"benefactor_award",
|
|
90
98
|
"paid_subscription_action",
|
vizbase/operations.py
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
("
|
|
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
|
|
File without changes
|
|
File without changes
|