Skip to content

Commit df19e63

Browse files
committed
Minor refactor changes
1 parent 422ddc9 commit df19e63

16 files changed

+22
-35
lines changed

Readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ For the moment, we have contract wrappers for:
111111
- StableToken
112112
- Validators
113113

114+
To create object of contract wrapper you shold set one of those contract names as a parameter to function `BaseWrapper.create_and_get_contract_by_name(...)`
115+
114116
## A Note About Contract Addresses
115117

116118
Celo Core Contracts addresses, can be obtained by looking at the `Registry` contract.

celo_sdk/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
registry,
33
wallet,
44
tests,
5+
kit,
56
)

celo_sdk/contracts/AccountsWrapper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from celo_sdk.registry import Registry
88
from celo_sdk.utils import hash_utils
99

10-
from eth_keys.datatypes import PublicKey
1110
from web3 import Web3
1211

1312

celo_sdk/contracts/AttestationsWrapper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from celo_sdk.contracts.base_wrapper import BaseWrapper
1111
from celo_sdk.registry import Registry
1212
from celo_sdk.utils import attestations_utils
13+
from celo_sdk.celo_account.messages import encode_defunct
1314

1415

1516
class Attestations(BaseWrapper):
@@ -248,6 +249,7 @@ def complete(self, identifier: str, account: str, issuer: str, code: str) -> str
248249
attestation_signer = accounts_contract.get_attestation_signer(issuer)
249250

250251
message = self.web3.soliditySha3(['bytes32', 'address'], [identifier, account]).hex()
252+
message = encode_defunct(hexstr=message)
251253
signer_address = Account.recoverHash(message, signature=code)
252254

253255
if signer_address != attestation_signer:
@@ -277,6 +279,7 @@ def find_matching_issuer(self, identifier: str, account: str, code: str, issuers
277279
"""
278280
accounts_contract = self.create_and_get_contract_by_name('Accounts')
279281
message = self.web3.soliditySha3(['bytes32', 'address'], [identifier, account]).hex()
282+
message = encode_defunct(hexstr=message)
280283
signer_address = Account.recoverHash(message, signature=code)
281284

282285
for issuer in issuers:
@@ -395,6 +398,7 @@ def validate_attestation_code(self, identifier: str, account: str, issuer: str,
395398
attestation_signer = accounts_contract.get_attestation_signer(issuer)
396399

397400
message = self.web3.soliditySha3(['bytes32', 'address'], [identifier, account]).hex()
401+
message = encode_defunct(hexstr=message)
398402
signer_address = Account.recoverHash(message, signature=code)
399403

400404
if signer_address != attestation_signer:

celo_sdk/contracts/BlockchainParametersWrapper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import sys
22

3-
from eth_keys.datatypes import PublicKey
43
from web3 import Web3
54

65
from celo_sdk.contracts.base_wrapper import BaseWrapper

celo_sdk/contracts/GovernanceWrapper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import time
32
from typing import List
43

celo_sdk/contracts/LockedGoldWrapper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import time
32
from typing import List
43

celo_sdk/contracts/MultiSigWrapper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import time
32
from typing import List
43

celo_sdk/contracts/ReleaseGoldWrapper.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from web3 import Web3
77

88
from celo_sdk.contracts.base_wrapper import BaseWrapper
9+
from celo_sdk.celo_account.account import Account
10+
from celo_sdk.celo_account.messages import encode_defunct
911
from celo_sdk.registry import Registry
1012
from celo_sdk.utils import hash_utils
1113

@@ -563,7 +565,7 @@ def authorize_vote_signer(self, signer: str, signature: 'Signature') -> str:
563565
Transaction hash
564566
"""
565567
func_call = self._contract.functions.authorizeVoteSigner(
566-
signer, signature.v, signature.r, signature.s)
568+
signer, signature.v, self.web3.toBytes(signature.r), self.web3.toBytes(signature.s))
567569

568570
return self.__wallet.send_transaction(func_call)
569571

@@ -588,8 +590,8 @@ def authorize_validator_signer(self, signer: str, proof_of_signing_key_possessio
588590
message = self.web3.soliditySha3(['address'], [account]).hex()
589591
prefixed_msg = hash_utils.hash_message_with_prefix(
590592
self.web3, message)
591-
pub_key = PublicKey.recover_from_msg_hash(
592-
prefixed_msg, proof_of_signing_key_possession).to_hex()
593+
prefixed_msg = encode_defunct(hexstr=prefixed_msg)
594+
pub_key = Account.recover_hash_to_pub(prefixed_msg, vrs=proof_of_signing_key_possession.vrs).to_hex()
593595
func_call = self._contract.functions.authorizeValidatorSignerWithPublicKey(
594596
signer, proof_of_signing_key_possession.v, self.web3.toBytes(proof_of_signing_key_possession.r), self.web3.toBytes(proof_of_signing_key_possession.s), pub_key)
595597

@@ -622,8 +624,8 @@ def authorize_validator_signer_and_bls(self, signer: str, proof_of_signing_key_p
622624
account = self.__wallet.active_account.address
623625
message = self.web3.soliditySha3(['address'], [account]).hex()
624626
prefixed_msg = hash_utils.hash_message_with_prefix(self.web3, message)
625-
pub_key = PublicKey.recover_from_msg_hash(
626-
prefixed_msg, proof_of_signing_key_possession).to_hex()
627+
prefixed_msg = encode_defunct(hexstr=prefixed_msg)
628+
pub_key = Account.recover_hash_to_pub(prefixed_msg, vrs=proof_of_signing_key_possession.vrs).to_hex()
627629
func_call = self._contract.functions.authorizeValidatorSignerWithKeys(
628630
signer, proof_of_signing_key_possession.v, self.web3.toBytes(proof_of_signing_key_possession.r), self.web3.toBytes(proof_of_signing_key_possession.s), pub_key, bls_pub_key, bls_pop)
629631

celo_sdk/contracts/ReserveWrapper.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import sys
2-
import time
31
from typing import List
42

5-
from eth_keys.datatypes import PublicKey
63
from web3 import Web3
74

85
from celo_sdk.contracts.base_wrapper import BaseWrapper

0 commit comments

Comments
 (0)