Skip to content

Commit b97f175

Browse files
committed
add ppos and pip
1 parent a95697b commit b97f175

File tree

16 files changed

+501
-1676
lines changed

16 files changed

+501
-1676
lines changed

.idea/inspectionProfiles/Project_Default.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client_sdk_python/admin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def stopWS(self):
6060
return self.web3.manager.request_blocking("admin_stopWS", [])
6161

6262
def getProgramVersion(self):
63-
return self.web3.manager.request_blocking("admin_getProgramVersion",[])
63+
return self.web3.manager.request_blocking("admin_getProgramVersion", [])
6464

6565
def getSchnorrNIZKProve(self):
66-
return self.web3.manager.request_blocking("admin_getSchnorrNIZKProve", [])
66+
return self.web3.manager.request_blocking("admin_getSchnorrNIZKProve", [])

client_sdk_python/eth.py

+8
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,14 @@ def generateGasPrice(self, transaction_params=None):
409409
def setGasPriceStrategy(self, gas_price_strategy):
410410
self.gasPriceStrategy = gas_price_strategy
411411

412+
# add to platon
413+
def analyzeReceiptByHash(self, tx_hash):
414+
receipt = self.waitForTransactionReceipt(tx_hash)
415+
return self.analyzeReceipt(receipt)
416+
417+
def analyzeReceipt(self, transaction_receipt):
418+
return self.web3.analyzeReceipt(transaction_receipt)
419+
412420

413421
class PlatON(Eth):
414422
pass

client_sdk_python/main.py

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
to_int,
6161
to_hex,
6262
to_text,
63+
analyze,
6364
)
6465
from client_sdk_python.utils.normalizers import (
6566
abi_ens_resolver,
@@ -106,6 +107,8 @@ class Web3:
106107
toWei = staticmethod(to_wei)
107108
fromWei = staticmethod(from_wei)
108109

110+
analyzeReceipt = staticmethod(analyze)
111+
109112
# Address Utility
110113
isAddress = staticmethod(is_address)
111114
isChecksumAddress = staticmethod(is_checksum_address)

client_sdk_python/pip.py

+234
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
import json
2+
import rlp
3+
4+
from hexbytes import HexBytes
5+
from client_sdk_python.module import (
6+
Module,
7+
)
8+
from client_sdk_python.utils.encoding import parse_str
9+
from client_sdk_python.utils.transactions import send_obj_transaction
10+
from client_sdk_python.eth import Eth
11+
12+
13+
class Pip(Module):
14+
pip_address = "0x1000000000000000000000000000000000000005"
15+
gas_price = ""
16+
chain_id = 101
17+
need_analyze = True
18+
platon = Eth(Module)
19+
20+
def submitText(self, verifier, pip_id, pri_key, from_address, gas_price=None, gas=None, nonce=None):
21+
data = rlp.encode([rlp.encode(int(2000)), rlp.encode(bytes.fromhex(verifier)),
22+
rlp.encode(pip_id)])
23+
return send_obj_transaction(self, data, from_address, self.pip_address, gas_price, gas, 0, pri_key, nonce)
24+
25+
def submitVersion(self, verifier, pip_id, new_version, end_voting_rounds, pri_key,
26+
from_address, gas_price=None, gas=None, nonce=None):
27+
28+
data = rlp.encode([rlp.encode(int(2001)), rlp.encode(bytes.fromhex(verifier)),
29+
rlp.encode(pip_id), rlp.encode(int(new_version)), rlp.encode(int(end_voting_rounds))])
30+
return send_obj_transaction(self, data, from_address, self.pip_address, gas_price, gas, 0, pri_key, nonce)
31+
32+
def submitParam(self, verifier, url, end_voting_block, param_name, current_value, new_value,
33+
privatekey=None, from_address=None, gasPrice=None, gas=None):
34+
'''
35+
提交参数提案
36+
:param verifier: 64bytes
37+
:param githubID: string
38+
:param topic: string
39+
:param desc: string
40+
:param url: string
41+
:param end_voting_block: uint64
42+
:param param_name:string
43+
:param from_address:
44+
:param gasPrice:
45+
:param gas:
46+
:return:
47+
'''
48+
to_address = "0x1000000000000000000000000000000000000005"
49+
data = rlp.encode([rlp.encode(int(2002)), rlp.encode(bytes.fromhex(verifier)),
50+
rlp.encode(url), rlp.encode(int(end_voting_block)),
51+
rlp.encode(param_name), rlp.encode(str(currentValue)), rlp.encode(str(new_value))])
52+
return send_obj_transaction(self, data, from_address, self.pip_address, gas_price, gas, 0, pri_key, nonce)
53+
54+
def vote(self, verifier, proposalID, option, programVersion, versionSign, from_address=None, gasPrice=None,
55+
gas=None, privatekey=None):
56+
'''
57+
给提案投票
58+
:param verifier: 64bytes
59+
:param proposalID: common.Hash
60+
:param option: VoteOption
61+
:param from_address:
62+
:param gasPrice:
63+
:param gas:
64+
:return:
65+
'''
66+
if proposalID[:2] == '0x':
67+
proposalID = proposalID[2:]
68+
if versionSign[:2] == '0x':
69+
versionSign = versionSign[2:]
70+
data = rlp.encode([rlp.encode(int(2003)), rlp.encode(bytes.fromhex(verifier)),
71+
rlp.encode(bytes.fromhex(proposalID)), rlp.encode(option), rlp.encode(int(programVersion)),
72+
rlp.encode(bytes.fromhex(versionSign))])
73+
return send_obj_transaction(self, data, from_address, self.pip_address, gas_price, gas, 0, pri_key, nonce)
74+
75+
def declareVersion(self, activeNode, version, versionSign, privatekey=None, from_address=None, gasPrice=None,
76+
gas=None):
77+
'''
78+
版本声明
79+
:param activeNode: 64bytes
80+
:param version: uint
81+
:param from_address:
82+
:param gasPrice:
83+
:param gas:
84+
:return:
85+
'''
86+
to_address = "0x1000000000000000000000000000000000000005"
87+
if versionSign[0:2] == '0x':
88+
versionSign = versionSign[2:]
89+
data = rlp.encode([rlp.encode(int(2004)), rlp.encode(bytes.fromhex(activeNode)),
90+
rlp.encode(int(version)), rlp.encode(bytes.fromhex(versionSign))])
91+
return send_obj_transaction(self, data, from_address, self.pip_address, gas_price, gas, 0, pri_key, nonce)
92+
93+
def getProposal(self, proposalID):
94+
'''
95+
查询提案
96+
:param proposalID: common.Hash
97+
:return:
98+
'''
99+
if proposalID[:2] == '0x':
100+
proposalID = proposalID[2:]
101+
to_address = "0x1000000000000000000000000000000000000005"
102+
data = rlp.encode([rlp.encode(int(2100)), rlp.encode(bytes.fromhex(proposalID))])
103+
recive = self.platon.call({
104+
"from": self.address,
105+
"to": to_address,
106+
"data": data
107+
})
108+
recive = str(recive, encoding="utf8")
109+
recive = json.loads(recive)
110+
return recive
111+
112+
def getTallyResult(self, proposalID):
113+
'''
114+
查询提案结果
115+
:param proposalID: common.Hash
116+
:param from_address:
117+
:param gasPrice:
118+
:param gas:
119+
:return:
120+
'''
121+
if proposalID[:2] == '0x':
122+
proposalID = proposalID[2:]
123+
data = rlp.encode([rlp.encode(int(2101)), rlp.encode(bytes.fromhex(proposalID))])
124+
to_address = "0x1000000000000000000000000000000000000005"
125+
recive = self.platon.call({
126+
"from": self.address,
127+
"to": to_address,
128+
"data": data
129+
})
130+
recive = str(recive, encoding="utf8")
131+
recive = json.loads(recive)
132+
return recive
133+
134+
def getAccuVerifiersCount(self, proposalID, blockHash):
135+
'''
136+
查询提案的累积可投票人数
137+
:param proposalID: common.Hash
138+
:param from_address:
139+
:param gasPrice:
140+
:param gas:
141+
:return:
142+
'''
143+
if proposalID[:2] == '0x':
144+
proposalID = proposalID[2:]
145+
if blockHash[:2] == '0x':
146+
blockHash = blockHash[2:]
147+
data = rlp.encode(
148+
[rlp.encode(int(2105)), rlp.encode(bytes.fromhex(proposalID)), rlp.encode(bytes.fromhex(blockHash))])
149+
to_address = "0x1000000000000000000000000000000000000005"
150+
recive = self.platon.call({
151+
"from": self.address,
152+
"to": to_address,
153+
"data": data
154+
})
155+
recive = str(recive, encoding="utf8")
156+
recive = json.loads(recive)
157+
return recive
158+
159+
def listProposal(self):
160+
'''
161+
查询提案列表
162+
:return:
163+
'''
164+
data = rlp.encode([rlp.encode(int(2102))])
165+
to_address = "0x1000000000000000000000000000000000000005"
166+
recive = self.platon.call({
167+
"from": self.address,
168+
"to": to_address,
169+
"data": data
170+
})
171+
recive = str(recive, encoding="utf8")
172+
recive = json.loads(recive)
173+
return recive
174+
175+
def getActiveVersion(self):
176+
"""
177+
查询节点的链生效版本
178+
"""
179+
data = rlp.encode([rlp.encode(int(2103))])
180+
to_address = "0x1000000000000000000000000000000000000005"
181+
recive = self.platon.call({
182+
"from": self.address,
183+
"to": to_address,
184+
"data": data
185+
})
186+
recive = str(recive, encoding="utf8")
187+
recive = json.loads(recive)
188+
# print(recive)
189+
return recive
190+
191+
def getProgramVersion(self):
192+
"""
193+
查询节点代码版本
194+
"""
195+
data = rlp.encode([rlp.encode(int(2104))])
196+
to_address = "0x1000000000000000000000000000000000000005"
197+
recive = self.platon.call({
198+
"from": self.address,
199+
"to": to_address,
200+
"data": data
201+
})
202+
recive = str(recive, encoding="utf8")
203+
recive = json.loads(recive)
204+
# print(recive)
205+
return recive
206+
207+
def listParam(self):
208+
"""
209+
查询可治理参数列表
210+
"""
211+
data = rlp.encode([rlp.encode(int(2105))])
212+
to_address = "0x1000000000000000000000000000000000000005"
213+
recive = self.platon.call({
214+
"from": self.address,
215+
"to": to_address,
216+
"data": data
217+
})
218+
recive = str(recive, encoding="utf8")
219+
recive = json.loads(recive)
220+
# print(recive)
221+
return recive
222+
223+
def submitCancel(self, verifier, pIDID, endVotingRounds, tobeCanceledProposalID, pri_key=None,
224+
from_address=None, gas_price=None, gas=None):
225+
226+
if tobeCanceledProposalID[:2] == '0x':
227+
tobeCanceledProposalID = tobeCanceledProposalID[2:]
228+
to_address = "0x1000000000000000000000000000000000000005"
229+
print(pIDID, endVotingRounds, tobeCanceledProposalID)
230+
data = rlp.encode([rlp.encode(int(2005)), rlp.encode(bytes.fromhex(verifier)),
231+
rlp.encode(pIDID), rlp.encode(int(endVotingRounds)),
232+
rlp.encode(bytes.fromhex(tobeCanceledProposalID))])
233+
234+
return send_obj_transaction(self, data, from_address, self.pip_address, gas_price, gas, 0, pri_key, nonce)

0 commit comments

Comments
 (0)