Repository navigation
Expand file tree
/
Copy pathprotocolvote_privkey.py
More file actions
183 lines (146 loc) · 5.6 KB
/
Copy pathprotocolvote_privkey.py
File metadata and controls
183 lines (146 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
from radix_engine_toolkit import *
from typing import Tuple
import secrets
import requests
import json
import bech32
import ecdsa
import hashlib
import time
from cryptography.hazmat.primitives.serialization import pkcs12
from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat, NoEncryption
from cryptography.hazmat.backends import default_backend
from ecdsa.curves import SECP256k1
from ecdsa.util import sigencode_der
from getpass import getpass
#network id is 0x01 for mainnet, or 0x02 for Stokenet
network_id = 0x01
private_key_bytes_ret: bytes = <ENTER PRIVATE KEY BYTES HERE>
private_key_ret: PrivateKey = PrivateKey.new_ed25519(list(private_key_bytes_ret))
public_key: PublicKey = private_key_ret.public_key()
account: Address = derive_virtual_account_address_from_public_key(
public_key, network_id
)
def random_nonce() -> int:
"""
Generates a random secure random number between 0 and 0xFFFFFFFF (u32::MAX)
"""
return secrets.randbelow(0xFFFFFFFF)
SOURCE_ACCOUNT: str = (
account.as_str()
)
print("Please ensure your Validator owner badge is in this account and there is at least 10XRD present:",SOURCE_ACCOUNT)
# The address of the validator on the Babylon network. This address will be used
# to determine the non-fungible local id of the validator owner badge.
BABYLON_VALIDATOR_ADDRESS: str = ("validator_rdx1sds4prpgf0p25pu458fg468nw9rtwqdawwg9w45hgf0t95yd3ncs09")
print("Validator Babylon Address :",BABYLON_VALIDATOR_ADDRESS)
def validator_owner_badge_non_fungible_local_id(
validator_address: Address,
) -> NonFungibleLocalId:
"""
Gets the non-fungible local id of owner badge associated with the given
validator address
"""
if validator_address.entity_type() != EntityType.GLOBAL_VALIDATOR:
raise ValueError("The address passed is not a validator address")
return NonFungibleLocalId.BYTES(validator_address.bytes()) # type: ignore
validator_address: Address = Address(BABYLON_VALIDATOR_ADDRESS)
owner_badge_resource_address: Address = known_addresses(
validator_address.network_id()
).resource_addresses.validator_owner_badge
owner_badge_local_id: NonFungibleLocalId = (
validator_owner_badge_non_fungible_local_id(validator_address)
)
address_book: KnownAddresses = known_addresses(network_id)
xrd_address: Address = address_book.resource_addresses.xrd
owner_badge: str = ("resource_rdx1nfxxxxxxxxxxvdrwnrxxxxxxxxx004365253834xxxxxxxxxvdrwnr")
print('\n')
manifest: TransactionManifest = (
ManifestBuilder()
.call_method(
ManifestBuilderAddress.STATIC(Address(SOURCE_ACCOUNT)),
"lock_fee",
[ManifestBuilderValue.DECIMAL_VALUE(Decimal("10"))],
)
.call_method(
ManifestBuilderAddress.STATIC(Address(SOURCE_ACCOUNT)),
"create_proof_of_non_fungibles",
[
ManifestBuilderValue.ADDRESS_VALUE(
ManifestBuilderAddress.STATIC(Address(owner_badge))
),
ManifestBuilderValue.ARRAY_VALUE(
ManifestBuilderValueKind.NON_FUNGIBLE_LOCAL_ID_VALUE,
[
ManifestBuilderValue.NON_FUNGIBLE_LOCAL_ID_VALUE(
owner_badge_local_id
)
],
),
],
)
.call_method(
ManifestBuilderAddress.STATIC(Address(BABYLON_VALIDATOR_ADDRESS)),
"signal_protocol_update_readiness",
[ManifestBuilderValue.STRING_VALUE("86894b9104afb73a000000bottlenose")],
)
.build(network_id)
)
# Validating the manifest instructions statically, an exception is raised if
# the manifest contains static errors.
print(manifest.instructions().as_str())
manifest.statically_validate()
urlint = "https://mainnet.radixdlt.com/statistics/validators/uptime"
headers = {"Content-Type": "application/json; charset=utf-8"}
dataint = {
"validator_addresses": [
BABYLON_VALIDATOR_ADDRESS
]
}
response = requests.post(urlint, json=dataint)
response_dict = response.json()
current_epoch = response_dict["ledger_state"]["epoch"]
end_epoch = int(current_epoch) + int(5)
print ("Start Epoch: ",current_epoch)
print ("End Epoch: ",end_epoch)
print('\n')
header: TransactionHeader = TransactionHeader(
network_id=network_id,
start_epoch_inclusive=current_epoch,
end_epoch_exclusive=end_epoch,
nonce=random_nonce(),
notary_public_key=public_key,
notary_is_signatory=True,
tip_percentage=0,
)
transaction: NotarizedTransaction = (
TransactionBuilder()
.header(header)
.manifest(manifest)
.sign_with_private_key(private_key_ret)
.notarize_with_private_key(private_key_ret)
)
# Ensure that the transaction is statically valid - if the validation fails an
# exception will be raised.
transaction.statically_validate(ValidationConfig.default(network_id))
print(f"Transaction Hash: {transaction.intent_hash().as_str()}")
print('\n')
url = "https://mainnet.radixdlt.com/transaction/submit"
headers = {"Content-Type": "application/json; charset=utf-8"}
data2 = {
"notarized_transaction_hex": bytearray(transaction.compile()).hex()
}
response = requests.post(url, json=data2)
print("Status Code", response.status_code)
print('\n')
time.sleep(5)
urlstatus = "https://mainnet.radixdlt.com/transaction/status"
headers = {"Content-Type": "application/json; charset=utf-8"}
data3 = {
"intent_hash": transaction.intent_hash().as_str()
}
response = requests.post(urlstatus, json=data3)
print("Status Code", response.status_code)
print('\n')
response_dict = response.json()
print(json.dumps(response_dict, indent=4))