-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use automatic generation of contracts (#15)
* A bit of tidying up, adding type hinting and better naming * Refactor with contractsService * Created TransactionService, 🔥 credentialregistry * Public key example with new service * Remove the last hardcoded contract function files * Improving examples, adding a node envvar, more to come * Clean old tests * Updated CHANGELOG * Updating README with relevant information * Added codebeautifier link * Fixing typos * Remove old hardcoded addresses * Make it easy to change parser * Adding a new TODO * Get addresses from contracts * Remove config example from root directory * delegated calls testing * Examples working fine * CHANGELOG updated
- Loading branch information
1 parent
65f05e3
commit 7a161f7
Showing
34 changed files
with
574 additions
and
1,881 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[run] | ||
branch = true | ||
omit = */tests/* | ||
omit = */tests/*,*/examples/* | ||
source = . | ||
|
||
[report] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
alastria_identity/examples/alastria_contract_config_generation.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from alastria_identity.services import IdentityConfigBuilder, ContractParser | ||
|
||
|
||
def main(): | ||
# We generate the config based on the markdown url | ||
CONTRACTS_INFO_URL = 'https://raw.githubusercontent.com/alastria/alastria-identity/master/contracts/ContractInfo.md' | ||
builder = IdentityConfigBuilder( | ||
contracts_info_url=CONTRACTS_INFO_URL, | ||
parser_class=ContractParser | ||
) | ||
config = builder.generate() | ||
|
||
# This is the format of the config | ||
# We'll use config['functions'] for the TransactionService | ||
print(config) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
from web3 import Web3 | ||
|
||
from alastria_identity.services import ( | ||
ContractsService, IdentityConfigBuilder, ContractParser) | ||
|
||
|
||
def main(): | ||
# We generate the config based on the markdown | ||
CONTRACTS_INFO_URL = 'https://raw.githubusercontent.com/alastria/alastria-identity/master/contracts/ContractInfo.md' | ||
builder = IdentityConfigBuilder( | ||
contracts_info_url=CONTRACTS_INFO_URL, | ||
parser_class=ContractParser | ||
) | ||
config = builder.generate() | ||
|
||
# We instantiate the contract service | ||
ALASTRIA_IDENTITY_MANAGER_CONTRACT_NAME = 'AlastriaIdentityManager' | ||
PROVIDER_NODE_URL = os.environ.get( | ||
'PROVIDER_NODE_URL', 'https://127.0.0.1/rpc') | ||
|
||
endpoint = Web3(Web3.HTTPProvider(PROVIDER_NODE_URL)) | ||
|
||
contract_service = ContractsService(config) | ||
alastria_identity_manager_contract = contract_service.get_contract_handler( | ||
ALASTRIA_IDENTITY_MANAGER_CONTRACT_NAME, endpoint) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
46 changes: 46 additions & 0 deletions
46
alastria_identity/examples/create_alastria_identity_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
|
||
from web3 import Web3 | ||
|
||
from alastria_identity.services import ( | ||
IdentityConfigBuilder, ContractParser, TransactionService) | ||
from alastria_identity.types import Transaction | ||
|
||
|
||
def main(): | ||
# We generate the config based on the markdown url | ||
CONTRACTS_INFO_URL = 'https://raw.githubusercontent.com/alastria/alastria-identity/master/contracts/ContractInfo.md' | ||
builder = IdentityConfigBuilder( | ||
contracts_info_url=CONTRACTS_INFO_URL, | ||
parser_class=ContractParser | ||
) | ||
config = builder.generate() | ||
|
||
PROVIDER_NODE_URL = os.environ.get( | ||
'PROVIDER_NODE_URL', 'https://127.0.0.1/rpc') | ||
web3_instance = Web3(Web3.HTTPProvider(PROVIDER_NODE_URL)) | ||
|
||
# Non delegated call | ||
PUBLIC_KEY = os.environ.get('PUBLIC_KEY', 'mykey') | ||
|
||
transaction_service = TransactionService( | ||
config, | ||
'AlastriaPublicKeyRegistry', | ||
web3_instance) | ||
transaction_response: Transaction = transaction_service.generate_transaction( | ||
'addKey', | ||
[PUBLIC_KEY] | ||
) | ||
|
||
transaction_service = TransactionService( | ||
config, | ||
'AlastriaIdentityManager', | ||
web3_instance) | ||
transaction_response: Transaction = transaction_service.generate_transaction( | ||
'createAlastriaIdentity', | ||
[transaction_response.data] | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
|
||
from web3 import Web3 | ||
|
||
from alastria_identity.services import ( | ||
IdentityConfigBuilder, ContractParser, TransactionService) | ||
|
||
|
||
def main(): | ||
# We generate the config based on the markdown url | ||
CONTRACTS_INFO_URL = os.environ.get( | ||
'CONTRACTS_INFO_URL', | ||
'https://raw.githubusercontent.com/alastria/alastria-identity/master/contracts/ContractInfo.md') | ||
builder = IdentityConfigBuilder( | ||
contracts_info_url=CONTRACTS_INFO_URL, | ||
parser_class=ContractParser | ||
) | ||
config = builder.generate() | ||
|
||
# Non delegated call | ||
PROVIDER_NODE_URL = os.environ.get( | ||
'PROVIDER_NODE_URL', 'https://127.0.0.1/rpc') | ||
web3_endpoint = Web3(Web3.HTTPProvider(PROVIDER_NODE_URL)) | ||
|
||
transaction_service = TransactionService( | ||
config, 'AlastriaCredentialRegistry', web3_endpoint) | ||
|
||
subject_status, issuer_status = 1, 1 | ||
transaction_service.generate_transaction( | ||
'getCredentialStatus', [subject_status, issuer_status]) | ||
|
||
issuer_credential_hash, status = b'dummy', 1 | ||
transaction_service.enable_delegated_call().generate_transaction( | ||
'updateCredentialStatus', [issuer_credential_hash, status]) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
|
||
from web3 import Web3 | ||
|
||
from alastria_identity.services import ( | ||
IdentityConfigBuilder, ContractParser, TransactionService) | ||
from alastria_identity.types import NetworkDid | ||
|
||
|
||
def main(): | ||
# We generate the config based on the markdown url | ||
CONTRACTS_INFO_URL = 'https://raw.githubusercontent.com/alastria/alastria-identity/master/contracts/ContractInfo.md' | ||
builder = IdentityConfigBuilder( | ||
contracts_info_url=CONTRACTS_INFO_URL, | ||
parser_class=ContractParser | ||
) | ||
config = builder.generate() | ||
|
||
# Non delegated call | ||
PROVIDER_NODE_URL = os.environ.get( | ||
'PROVIDER_NODE_URL', 'https://127.0.0.1/rpc') | ||
web3_endpoint = Web3(Web3.HTTPProvider(PROVIDER_NODE_URL)) | ||
|
||
transaction_service = TransactionService( | ||
config, | ||
'AlastriaIdentityManager', | ||
web3_endpoint) | ||
|
||
SIGN_DID = os.environ.get( | ||
'SIGN_DID', | ||
'did:ala:quor:redT:ee2d1fe7b0d4571155c93497a7a9bde56fb87b40') | ||
|
||
# We can use NetworkDid to get the proxy_address out of a did | ||
sign_address = NetworkDid.from_did(SIGN_DID).proxy_address | ||
checksum = Web3.toChecksumAddress(sign_address) | ||
|
||
transaction_service.enable_delegated_call().generate_transaction( | ||
'prepareAlastriaID', [checksum]) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
33 changes: 33 additions & 0 deletions
33
alastria_identity/examples/presentation_registry_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
|
||
from web3 import Web3 | ||
|
||
from alastria_identity.services import ( | ||
IdentityConfigBuilder, ContractParser, TransactionService) | ||
|
||
|
||
def main(): | ||
# We generate the config based on the markdown url | ||
CONTRACTS_INFO_URL = 'https://raw.githubusercontent.com/alastria/alastria-identity/master/contracts/ContractInfo.md' | ||
builder = IdentityConfigBuilder( | ||
contracts_info_url=CONTRACTS_INFO_URL, | ||
parser_class=ContractParser | ||
) | ||
config = builder.generate() | ||
|
||
# Non delegated call | ||
PROVIDER_NODE_URL = os.environ.get( | ||
'PROVIDER_NODE_URL', 'https://127.0.0.1/rpc') | ||
web3_endpoint = Web3(Web3.HTTPProvider(PROVIDER_NODE_URL)) | ||
|
||
transaction_service = TransactionService( | ||
config, | ||
'AlastriaPresentationRegistry', | ||
web3_endpoint) | ||
|
||
receiver_presentation_hash, status = b'myhash', 1 | ||
transaction_service.enable_delegated_call().generate_transaction( | ||
'updateReceiverPresentation', [receiver_presentation_hash, status]) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
|
||
from web3 import Web3 | ||
|
||
from alastria_identity.services import ( | ||
IdentityConfigBuilder, ContractParser, TransactionService) | ||
|
||
|
||
def main(): | ||
# We generate the config based on the markdown url | ||
CONTRACTS_INFO_URL = 'https://raw.githubusercontent.com/alastria/alastria-identity/master/contracts/ContractInfo.md' | ||
builder = IdentityConfigBuilder( | ||
contracts_info_url=CONTRACTS_INFO_URL, | ||
parser_class=ContractParser | ||
) | ||
config = builder.generate() | ||
|
||
# Non delegated call | ||
PROVIDER_NODE_URL = os.environ.get( | ||
'PROVIDER_NODE_URL', 'https://127.0.0.1/rpc') | ||
web3_endpoint = Web3(Web3.HTTPProvider(PROVIDER_NODE_URL)) | ||
|
||
transaction_service = TransactionService( | ||
config, | ||
'AlastriaPublicKeyRegistry', | ||
web3_endpoint) | ||
|
||
subject_address = Web3.toChecksumAddress('0xee2d1fe7b0d4571155c93497a7a9bde56fb87b40') | ||
public_key = b'12345' | ||
transaction_service.generate_transaction( | ||
'getPublicKeyStatus', [subject_address, public_key]) | ||
|
||
transaction_service.enable_delegated_call().generate_transaction( | ||
'deletePublicKey', [subject_address]) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class ContractNameError(Exception): pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,6 @@ | ||
from .config_builder import IdentityConfigBuilder | ||
from .contracts import ( | ||
IDENTITY_MANAGER_ADDRESS, | ||
ContractsService, | ||
PUBLIC_KEY_REGISTRY_ADDRESS, | ||
PRESENTATION_REGISTRY_ADDRESS, | ||
CREDENTIAL_REGISTRY_ADDRESS | ||
) | ||
from .credential_registry import CredentialRegistryService | ||
from .contracts import ContractsService | ||
from .identity import UserIdentityService | ||
from .identity_manager import IdentityManagerService | ||
from .parsers import ContractParser | ||
from .presentation_registry import PresentationRegistryService | ||
from .tokens import TokenService | ||
from .public_key import PublicKeyService | ||
from .transaction_service import TransactionService |
Oops, something went wrong.