From 7903a996d02b513ecdc481b18a544ade421c9977 Mon Sep 17 00:00:00 2001 From: Alexander Sukhachev Date: Fri, 16 Feb 2024 19:00:15 +0500 Subject: [PATCH] updated the code according to code review notes Signed-off-by: Alexander Sukhachev --- config.json | 44 ---- examples/migration/besu-config.json | 26 -- examples/migration/src/ledger.rs | 103 ++++---- network/config.json | 42 ++++ smart_contracts/demos/utils/actor.ts | 33 +-- smart_contracts/scripts/genesis/config.ts | 235 ------------------ .../genesis/contracts/accountControl.ts | 5 +- .../contracts/credentialDefinitionRegistry.ts | 5 +- .../genesis/contracts/ethereumDidRegistry.ts | 5 +- .../contracts/legacyMappingRegistry.ts | 5 +- .../scripts/genesis/contracts/roleControl.ts | 5 +- .../genesis/contracts/schemaRegistry.ts | 5 +- .../genesis/contracts/upgradeControl.ts | 5 +- .../genesis/contracts/validatorControl.ts | 5 +- smart_contracts/scripts/genesis/generate.ts | 22 +- smart_contracts/scripts/genesis/helpers.ts | 153 +++++++++++- smart_contracts/utils/common.ts | 36 ++- vdr/src/client/client.rs | 150 ++++++----- vdr/src/contracts/auth/role_control.rs | 10 +- .../cl/credential_definition_registry.rs | 6 +- vdr/src/contracts/cl/schema_registry.rs | 6 +- vdr/src/contracts/did/did_ethr_registry.rs | 14 +- .../migration/legacy_mapping_registry.rs | 10 +- .../contracts/network/validator_control.rs | 8 +- vdr/src/types/transaction.rs | 6 +- vdr/wasm/demo/node/src/main.ts | 10 +- vdr/wrappers/python/demo/test.py | 10 +- 27 files changed, 427 insertions(+), 537 deletions(-) delete mode 100644 config.json delete mode 100644 examples/migration/besu-config.json create mode 100644 network/config.json delete mode 100644 smart_contracts/scripts/genesis/config.ts diff --git a/config.json b/config.json deleted file mode 100644 index 1558a890..00000000 --- a/config.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "contracts": { - "did_validator": { - "spec_path": "smart_contracts/artifacts/contracts/did/DidValidator.sol/DidValidator.json", - "address": "0x0000000000000000000000000000000000002222" - }, - - "cred_def_registry": { - "spec_path": "smart_contracts/artifacts/contracts/cl/CredentialDefinitionRegistry.sol/CredentialDefinitionRegistry.json", - "address": "0x0000000000000000000000000000000000004444" - }, - "schema_registry": { - "spec_path": "smart_contracts/artifacts/contracts/cl/SchemaRegistry.sol/SchemaRegistry.json", - "address": "0x0000000000000000000000000000000000005555" - }, - "role_control": { - "spec_path": "smart_contracts/artifacts/contracts/auth/RoleControl.sol/RoleControl.json", - "address": "0x0000000000000000000000000000000000006666" - }, - "validator_control": { - "spec_path": "smart_contracts/artifacts/contracts/network/ValidatorControl.sol/ValidatorControl.json", - "address": "0x0000000000000000000000000000000000007777" - }, - "account_control": { - "spec_path": "smart_contracts/artifacts/contracts/auth/AccountControl.sol/AccountControl.json", - "address": "0x0000000000000000000000000000000000008888" - }, - "upgrade_control": { - "spec_path": "smart_contracts/artifacts/contracts/upgrade/UpgradeControl.sol/UpgradeControl.json", - "address": "0x0000000000000000000000000000000000009999" - }, - "legacy_mapping_registry": { - "spec_path": "smart_contracts/artifacts/contracts/migration/LegacyMappingRegistry.sol/LegacyMappingRegistry.json", - "address": "0x0000000000000000000000000000000000019999" - }, - "ethereum_did_registry": { - "spec_path": "smart_contracts/artifacts/contracts/did/EthereumExtDidRegistry.sol/EthereumExtDidRegistry.json", - "address": "0x0000000000000000000000000000000000003333" - } - } -} - - - diff --git a/examples/migration/besu-config.json b/examples/migration/besu-config.json deleted file mode 100644 index 69a6e224..00000000 --- a/examples/migration/besu-config.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "chainId": 1337, - "nodeAddress": "http://127.0.0.1:8545", - "contracts": { - "didRegistry": { - "address": "0x0000000000000000000000000000000000003333", - "path": "../../smart_contracts/artifacts/contracts/did/EthereumExtDidRegistry.sol/EthereumExtDidRegistry.json" - }, - "schemaRegistry": { - "address": "0x0000000000000000000000000000000000005555", - "path": "../../smart_contracts/artifacts/contracts/cl/SchemaRegistry.sol/SchemaRegistry.json" - }, - "credentialDefinitionRegistry": { - "address": "0x0000000000000000000000000000000000004444", - "path": "../../smart_contracts/artifacts/contracts/cl/CredentialDefinitionRegistry.sol/CredentialDefinitionRegistry.json" - }, - "roleControl": { - "address": "0x0000000000000000000000000000000000006666", - "path": "../../smart_contracts/artifacts/contracts/auth/RoleControl.sol/RoleControl.json" - }, - "legacyMappingRegistry": { - "address": "0x0000000000000000000000000000000000019999", - "path": "../../smart_contracts/artifacts/contracts/migration/LegacyMappingRegistry.sol/LegacyMappingRegistry.json" - } - } -} diff --git a/examples/migration/src/ledger.rs b/examples/migration/src/ledger.rs index 4355d06c..5994854e 100644 --- a/examples/migration/src/ledger.rs +++ b/examples/migration/src/ledger.rs @@ -208,17 +208,33 @@ struct BesuConfig { #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] struct BesuContracts { - did_registry: BesuContractConfig, + did_validator: BesuContractConfig, + cred_def_registry: BesuContractConfig, schema_registry: BesuContractConfig, - credential_definition_registry: BesuContractConfig, role_control: BesuContractConfig, + validator_control: BesuContractConfig, + account_control: BesuContractConfig, + upgrade_control: BesuContractConfig, legacy_mapping_registry: BesuContractConfig, + ethereum_did_registry: BesuContractConfig, } #[derive(Serialize, Deserialize)] -struct BesuContractConfig { +#[serde(rename_all = "camelCase")] +pub struct BesuContractConfig { address: String, - path: String, + spec_path: String, +} + +fn build_contract_path(contract_path: &str) -> String { + let mut cur_dir = env::current_dir().unwrap(); + cur_dir.push("../../"); // project root directory + cur_dir.push(contract_path); + fs::canonicalize(&cur_dir) + .unwrap() + .to_str() + .unwrap() + .to_string() } impl BesuLedger { @@ -226,60 +242,39 @@ impl BesuLedger { pub const CHAIN_ID: u64 = 1337; pub const NODE_ADDRESS: &'static str = "http://127.0.0.1:8545"; - fn build_contract_path(contract_path: &str) -> String { - let mut cur_dir = env::current_dir().unwrap(); - cur_dir.push("../../"); // project root directory - cur_dir.push(contract_path); - fs::canonicalize(&cur_dir) - .unwrap() - .to_str() - .unwrap() - .to_string() - } - fn contracts() -> Vec { - let mut conf_json_path = env::current_dir().unwrap(); - conf_json_path.push("../../config.json"); - - let json_content = fs::read_to_string(conf_json_path).expect("config file reading failed"); - let conf: Value = serde_json::from_str(&json_content).expect("config file parsing failed"); - - let contracts_conf = conf - .get("contracts").expect("'contracts' must be in the config file") - .as_object().expect("'contracts' is expected to be an object"); - - - let result: Vec<_> = contracts_conf - .iter() - .filter(|(contract_name,_)| { - let cn = contract_name.as_str(); - let contracts = [ - "did_registry", "cred_def_registry", "schema_registry", - "role_control", "legacy_mapping_registry" - ]; - contracts.contains(cn) - }) - .map(|(_,contract_conf)| { - let addr = contract_conf - .get("address").expect("'address' not found in the contract config") - .as_str().expect("'address' must be a string"); - - let spec = contract_conf - .get("spec_path").expect("'spec_path' not found in the contract config") - .as_str().expect("'spec_path' must be a string"); - - ContractConfig { - address: String::from(addr), - spec_path: Some(build_contract_path(spec)), - spec: None, - } - }).collect(); - - return result; + fn contracts(contracts: &BesuContracts) -> Vec { + vec![ + ContractConfig { + address: contracts.ethereum_did_registry.address.to_string(), + spec_path: Some(build_contract_path(contracts.ethereum_did_registry.spec_path.as_str())), + spec: None, + }, + ContractConfig { + address: contracts.schema_registry.address.to_string(), + spec_path: Some(build_contract_path(contracts.schema_registry.spec_path.as_str())), + spec: None, + }, + ContractConfig { + address: contracts.cred_def_registry.address.to_string(), + spec_path: Some(build_contract_path(contracts.cred_def_registry.spec_path.as_str())), + spec: None, + }, + ContractConfig { + address: contracts.role_control.address.to_string(), + spec_path: Some(build_contract_path(contracts.role_control.spec_path.as_str())), + spec: None, + }, + ContractConfig { + address: contracts.legacy_mapping_registry.address.to_string(), + spec_path: Some(build_contract_path(contracts.legacy_mapping_registry.spec_path.as_str())), + spec: None, + }, + ] } pub async fn new() -> BesuLedger { - let file = fs::File::open("besu-config.json").expect("Unable to open besu config file"); + let file = fs::File::open("../../network/config.json").expect("Unable to open besu config file"); let config: BesuConfig = serde_json::from_reader(file).expect("Unable to parse besu config file"); diff --git a/network/config.json b/network/config.json new file mode 100644 index 00000000..d2d9a69e --- /dev/null +++ b/network/config.json @@ -0,0 +1,42 @@ +{ + "chainId": 1337, + "nodeAddress": "http://127.0.0.1:8545", + "contracts": { + "didValidator": { + "specPath": "smart_contracts/artifacts/contracts/did/DidValidator.sol/DidValidator.json", + "address": "0x0000000000000000000000000000000000002222" + }, + "credDefRegistry": { + "specPath": "smart_contracts/artifacts/contracts/cl/CredentialDefinitionRegistry.sol/CredentialDefinitionRegistry.json", + "address": "0x0000000000000000000000000000000000004444" + }, + "schemaRegistry": { + "specPath": "smart_contracts/artifacts/contracts/cl/SchemaRegistry.sol/SchemaRegistry.json", + "address": "0x0000000000000000000000000000000000005555" + }, + "roleControl": { + "specPath": "smart_contracts/artifacts/contracts/auth/RoleControl.sol/RoleControl.json", + "address": "0x0000000000000000000000000000000000006666" + }, + "validatorControl": { + "specPath": "smart_contracts/artifacts/contracts/network/ValidatorControl.sol/ValidatorControl.json", + "address": "0x0000000000000000000000000000000000007777" + }, + "accountControl": { + "specPath": "smart_contracts/artifacts/contracts/auth/AccountControl.sol/AccountControl.json", + "address": "0x0000000000000000000000000000000000008888" + }, + "upgradeControl": { + "specPath": "smart_contracts/artifacts/contracts/upgrade/UpgradeControl.sol/UpgradeControl.json", + "address": "0x0000000000000000000000000000000000009999" + }, + "legacyMappingRegistry": { + "specPath": "smart_contracts/artifacts/contracts/migration/LegacyMappingRegistry.sol/LegacyMappingRegistry.json", + "address": "0x0000000000000000000000000000000000019999" + }, + "ethereumDidRegistry": { + "specPath": "smart_contracts/artifacts/contracts/did/EthereumExtDidRegistry.sol/EthereumExtDidRegistry.json", + "address": "0x0000000000000000000000000000000000003333" + } + } +} diff --git a/smart_contracts/demos/utils/actor.ts b/smart_contracts/demos/utils/actor.ts index f5124582..377da97c 100644 --- a/smart_contracts/demos/utils/actor.ts +++ b/smart_contracts/demos/utils/actor.ts @@ -1,5 +1,4 @@ -import { readFileSync } from 'fs' -import { resolve } from 'path' +import { readBesuConfig } from '../../utils' import { RoleControl, SchemaRegistry, @@ -24,18 +23,19 @@ export class Actor { } public async init() { - const addresses = this.readContractsAddresses() + const besuConfig = readBesuConfig() + const contracts = besuConfig.contracts - this.roleControl = await new RoleControl(this.account).getInstance(addresses['role_control']) - this.validatorControl = await new ValidatorControl(this.account).getInstance(addresses['validator_control']) + this.roleControl = await new RoleControl(this.account).getInstance(contracts.roleControl.address) + this.validatorControl = await new ValidatorControl(this.account).getInstance(contracts.validatorControl.address) this.ethereumDIDRegistry = await new EthereumExtDidRegistry(this.account).getInstance( - addresses['ethereum_did_registry'], + contracts.ethereumDidRegistry.address, ) - this.schemaRegistry = await new SchemaRegistry(this.account).getInstance(addresses['schema_registry']) + this.schemaRegistry = await new SchemaRegistry(this.account).getInstance(contracts.schemaRegistry.address) this.credentialDefinitionRegistry = await new CredentialDefinitionRegistry(this.account).getInstance( - addresses['cred_def_registry'], + contracts.credDefRegistry.address, ) - this.upgradeControl = await new UpgradeControl(this.account).getInstance(addresses['upgrade_control']) + this.upgradeControl = await new UpgradeControl(this.account).getInstance(contracts.upgradeControl.address) return this } @@ -54,19 +54,4 @@ export class Actor { public get didDocument() { return this.account.didDocument } - - private readContractsAddresses(): { [key: string]: string } { - const configPath = resolve('..', 'config.json') - - const data = readFileSync(configPath, 'utf8') - const contracts = JSON.parse(data).contracts - - const result = {} - - for (const contractName of Object.keys(contracts)) { - result[contractName] = contracts[contractName].address - } - - return result - } } diff --git a/smart_contracts/scripts/genesis/config.ts b/smart_contracts/scripts/genesis/config.ts deleted file mode 100644 index 3c6204f2..00000000 --- a/smart_contracts/scripts/genesis/config.ts +++ /dev/null @@ -1,235 +0,0 @@ -import { readFileSync } from 'fs' -import { resolve } from 'path' - -import { - AccountControlConfig, - CredentialDefinitionsConfig, - EthereumDidRegistryConfig, - LegacyMappingRegistryConfig, - RolesConfig, - SchemasConfig, - ValidatorsConfig, -} from './contracts' -import { UpgradeControlConfig } from './contracts/upgradeControl' - -export const compiledContractsFolder = 'compiled-contracts' -export const inFile = 'config.json' -export const outFile = 'ContractsGenesis.json' - -export interface Config { - accountControl: AccountControlConfig - credentialDefinitionRegistry: CredentialDefinitionsConfig - ethereumDidRegistry: EthereumDidRegistryConfig - roleControl: RolesConfig - schemaRegistry: SchemasConfig - upgradeControl: UpgradeControlConfig - validatorControl: ValidatorsConfig - legacyMapping: LegacyMappingRegistryConfig -} - -const contractsAddresses: { [key: string]: string } = {} - -export function readContractsConfig() { - const configPath = resolve('..', inFile) - - const data = readFileSync(configPath, 'utf8') - const parsed_data = JSON.parse(data) - const contracts = parsed_data.contracts - - for (const key of Object.keys(contracts)) { - contractsAddresses[key] = contracts[key].address - } -} - -function getContractAddress(contractName: string): string { - if (Object.keys(contractsAddresses).length === 0) { - throw new Error("the 'readContractsConfig()' function must be called") - } - - if (contractsAddresses[contractName] === undefined) { - throw new Error(`contract '${contractName}' not found`) - } - - return contractsAddresses[contractName] -} - -export const config: Config = { - get ethereumDidRegistry(): EthereumDidRegistryConfig { - return { - name: 'EthereumExtDidRegistry', - address: getContractAddress('ethereum_did_registry'), - description: 'Ethereum registry for ERC-1056 ethr did methods', - } - }, - - get accountControl(): AccountControlConfig { - return { - name: 'AccountControl', - address: getContractAddress('account_control'), - description: 'Account permissioning smart contract', - data: { - roleControlContractAddress: getContractAddress('role_control'), - upgradeControlAddress: getContractAddress('upgrade_control'), - }, - } - }, - - get credentialDefinitionRegistry(): CredentialDefinitionsConfig { - return { - name: 'CredentialDefinitionRegistry', - address: getContractAddress('cred_def_registry'), - description: 'Smart contract to manage credential definitions', - data: { - credentialDefinitions: [], - ethereumDidRegistry: getContractAddress('ethereum_did_registry'), - schemaRegistryAddress: getContractAddress('schema_registry'), - upgradeControlAddress: getContractAddress('upgrade_control'), - }, - } - }, - - get indyDidValidator(): IndyDidValidatorConfig { - return { - name: 'IndyDidValidator', - address: getContractAddress('did_validator'), - description: 'Library to validate DID', - } - }, - - get indyDidRegistry(): IndyDidRegistryConfig { - return { - name: 'IndyDidRegistry', - address: getContractAddress('did_registry'), - description: 'Smart contract to manage DIDs', - libraries: { 'contracts/did/IndyDidValidator.sol:IndyDidValidator': getContractAddress('did_validator') }, - data: { - dids: [], - upgradeControlAddress: getContractAddress('upgrade_control'), - }, - } - }, - - get ethereumDidRegistry(): EthereumDidRegistryConfig { - return { - name: 'EthereumExtDidRegistry', - address: getContractAddress('ethereum_did_registry'), - description: 'Ethereum registry for ERC-1056 ethr did methods', - } - }, - - get roleControl(): RolesConfig { - return { - name: 'RoleControl', - address: getContractAddress('role_control'), - description: 'Smart contract to manage account roles', - data: { - accounts: [ - { - account: '0xfe3b557e8fb62b89f4916b721be55ceb828dbd73', - role: 1, - }, - { - account: '0x627306090abaB3A6e1400e9345bC60c78a8BEf57', - role: 1, - }, - { - account: '0xf17f52151EbEF6C7334FAD080c5704D77216b732', - role: 1, - }, - { - account: '0xf0e2db6c8dc6c681bb5d6ad121a107f300e9b2b5', - role: 1, - }, - { - account: '0xca843569e3427144cead5e4d5999a3d0ccf92b8e', - role: 1, - }, - ], - roleOwners: { - '1': '1', - '2': '1', - '3': '1', - }, - }, - } - }, - - get schemaRegistry(): SchemasConfig { - return { - name: 'SchemaRegistry', - address: getContractAddress('schema_registry'), - description: 'Smart contract to manage schemas', - data: { - schemas: [], - ethereumDidRegistry: getContractAddress('ethereum_did_registry'), - upgradeControlAddress: getContractAddress('upgrade_control'), - }, - } - }, - - get universalDidResolver(): UniversalDidResolverConfig { - return { - name: 'UniversalDidResolver', - address: getContractAddress('universal_did_resolver'), - description: 'Smart contract to resolve DIDs from various DID registries', - data: { - etheriumDidRegistryAddress: getContractAddress('ethereum_did_registry'), - didRegistryAddress: getContractAddress('did_registry'), - upgradeControlAddress: getContractAddress('upgrade_control'), - }, - } - }, - - get upgradeControl(): UpgradeControlConfig { - return { - name: 'UpgradeControl', - address: getContractAddress('upgrade_control'), - description: 'Smart contract to manage proxy contract upgrades', - data: { - roleControlContractAddress: getContractAddress('role_control'), - }, - } - }, - - get validatorControl(): ValidatorsConfig { - return { - name: 'ValidatorControl', - address: getContractAddress('validator_control'), - description: 'Smart contract to manage validator nodes', - data: { - validators: [ - { - account: '0xed9d02e382b34818e88b88a309c7fe71e65f419d', - validator: '0x93917cadbace5dfce132b991732c6cda9bcc5b8a', - }, - { - account: '0xb30f304642de3fee4365ed5cd06ea2e69d3fd0ca', - validator: '0x27a97c9aaf04f18f3014c32e036dd0ac76da5f18', - }, - { - account: '0x0886328869e4e1f401e1052a5f4aae8b45f42610', - validator: '0xce412f988377e31f4d0ff12d74df73b51c42d0ca', - }, - { - account: '0xf48de4a0c2939e62891f3c6aca68982975477e45', - validator: '0x98c1334496614aed49d2e81526d089f7264fed9c', - }, - ], - roleControlContractAddress: getContractAddress('role_control'), - upgradeControlAddress: getContractAddress('upgrade_control'), - }, - } - }, - - get legacyMapping(): LegacyMappingRegistryConfig { - return { - name: 'LegacyMappingRegistry', - address: getContractAddress('legacy_mapping_registry'), - description: 'Smart contract to store mapping of legacy identifiers to new one', - data: { - ethereumDidRegistry: contractsAddresses.ethereumDidRegistry, - upgradeControlAddress: contractsAddresses.upgradeControl, - }, - } - }, -} diff --git a/smart_contracts/scripts/genesis/contracts/accountControl.ts b/smart_contracts/scripts/genesis/contracts/accountControl.ts index 46c58fd2..1bfc0536 100644 --- a/smart_contracts/scripts/genesis/contracts/accountControl.ts +++ b/smart_contracts/scripts/genesis/contracts/accountControl.ts @@ -1,5 +1,4 @@ import { padLeft } from 'web3-utils' -import { config } from '../config' import { ContractConfig } from '../contractConfig' import { buildProxySection, slots } from '../helpers' @@ -10,8 +9,8 @@ export interface AccountControlConfig extends ContractConfig { } } -export function accountControl() { - const { name, address, description, data } = config.accountControl +export function accountControl(config: AccountControlConfig) { + const { name, address, description, data } = config const storage: any = {} // address of upgrade control contact stored in slot 1 diff --git a/smart_contracts/scripts/genesis/contracts/credentialDefinitionRegistry.ts b/smart_contracts/scripts/genesis/contracts/credentialDefinitionRegistry.ts index bd3cd55a..7676518f 100644 --- a/smart_contracts/scripts/genesis/contracts/credentialDefinitionRegistry.ts +++ b/smart_contracts/scripts/genesis/contracts/credentialDefinitionRegistry.ts @@ -1,5 +1,4 @@ import { padLeft } from 'web3-utils' -import { config } from '../config' import { ContractConfig } from '../contractConfig' import { buildProxySection, slots } from '../helpers' @@ -12,8 +11,8 @@ export interface CredentialDefinitionsConfig extends ContractConfig { } } -export function credentialDefinitionRegistry() { - const { name, address, description, data } = config.credentialDefinitionRegistry +export function credentialDefinitionRegistry(config: CredentialDefinitionsConfig) { + const { name, address, description, data } = config const storage: any = {} // address of upgrade control contact stored in slot 0 diff --git a/smart_contracts/scripts/genesis/contracts/ethereumDidRegistry.ts b/smart_contracts/scripts/genesis/contracts/ethereumDidRegistry.ts index 87e3f365..4e530e33 100644 --- a/smart_contracts/scripts/genesis/contracts/ethereumDidRegistry.ts +++ b/smart_contracts/scripts/genesis/contracts/ethereumDidRegistry.ts @@ -1,11 +1,10 @@ -import { config } from '../config' import { ContractConfig } from '../contractConfig' import { buildProxySection } from '../helpers' export interface EthereumDidRegistryConfig extends ContractConfig {} -export function ethereumDidRegistry() { - const { name, address, description } = config.ethereumDidRegistry +export function ethereumDidRegistry(config: EthereumDidRegistryConfig) { + const { name, address, description } = config const storage: any = {} return buildProxySection(name, address, description, storage) diff --git a/smart_contracts/scripts/genesis/contracts/legacyMappingRegistry.ts b/smart_contracts/scripts/genesis/contracts/legacyMappingRegistry.ts index e0b72a78..261c4629 100644 --- a/smart_contracts/scripts/genesis/contracts/legacyMappingRegistry.ts +++ b/smart_contracts/scripts/genesis/contracts/legacyMappingRegistry.ts @@ -1,5 +1,4 @@ import { padLeft } from 'web3-utils' -import { config } from '../config' import { ContractConfig } from '../contractConfig' import { buildProxySection, slots } from '../helpers' @@ -10,8 +9,8 @@ export interface LegacyMappingRegistryConfig extends ContractConfig { } } -export function legacyMappingRegistry() { - const { name, address, description, data } = config.legacyMapping +export function legacyMappingRegistry(config: LegacyMappingRegistryConfig) { + const { name, address, description, data } = config const storage: any = {} // address of upgrade control contact stored in slot 0 diff --git a/smart_contracts/scripts/genesis/contracts/roleControl.ts b/smart_contracts/scripts/genesis/contracts/roleControl.ts index 377fc959..b40d678c 100644 --- a/smart_contracts/scripts/genesis/contracts/roleControl.ts +++ b/smart_contracts/scripts/genesis/contracts/roleControl.ts @@ -1,5 +1,4 @@ import { padLeft, sha3, toHex } from 'web3-utils' -import { config } from '../config' import { ContractConfig } from '../contractConfig' import { buildProxySection, slots } from '../helpers' @@ -11,8 +10,8 @@ export interface RolesConfig extends ContractConfig { } } -export function roleControl() { - const { name, address, description, data } = config.roleControl +export function roleControl(config: RolesConfig) { + const { name, address, description, data } = config const storage: any = {} // address of upgrade control contact stored in slot 0 diff --git a/smart_contracts/scripts/genesis/contracts/schemaRegistry.ts b/smart_contracts/scripts/genesis/contracts/schemaRegistry.ts index 187f2d9c..dc755e8e 100644 --- a/smart_contracts/scripts/genesis/contracts/schemaRegistry.ts +++ b/smart_contracts/scripts/genesis/contracts/schemaRegistry.ts @@ -1,5 +1,4 @@ import { padLeft } from 'web3-utils' -import { config } from '../config' import { ContractConfig } from '../contractConfig' import { buildProxySection, slots } from '../helpers' @@ -11,8 +10,8 @@ export interface SchemasConfig extends ContractConfig { } } -export function schemaRegistry() { - const { name, address, description, data } = config.schemaRegistry +export function schemaRegistry(config: SchemasConfig) { + const { name, address, description, data } = config const storage: any = {} // address of upgrade control contact stored in slot 0 diff --git a/smart_contracts/scripts/genesis/contracts/upgradeControl.ts b/smart_contracts/scripts/genesis/contracts/upgradeControl.ts index f91a551b..a6f4664d 100644 --- a/smart_contracts/scripts/genesis/contracts/upgradeControl.ts +++ b/smart_contracts/scripts/genesis/contracts/upgradeControl.ts @@ -1,5 +1,4 @@ import { padLeft } from 'web3-utils' -import { config } from '../config' import { ContractConfig } from '../contractConfig' import { buildProxySection, slots } from '../helpers' @@ -9,8 +8,8 @@ export interface UpgradeControlConfig extends ContractConfig { } } -export function upgradeControl() { - const { name, address, description, data } = config.upgradeControl +export function upgradeControl(config: UpgradeControlConfig) { + const { name, address, description, data } = config const storage: any = {} // address of upgrade control contact stored in slot 0 diff --git a/smart_contracts/scripts/genesis/contracts/validatorControl.ts b/smart_contracts/scripts/genesis/contracts/validatorControl.ts index 0e79081a..713c0eaa 100644 --- a/smart_contracts/scripts/genesis/contracts/validatorControl.ts +++ b/smart_contracts/scripts/genesis/contracts/validatorControl.ts @@ -1,6 +1,5 @@ import { BN } from 'bn.js' import { padLeft, sha3 } from 'web3-utils' -import { config } from '../config' import { ContractConfig } from '../contractConfig' import { buildProxySection, slots } from '../helpers' @@ -12,8 +11,8 @@ export interface ValidatorsConfig extends ContractConfig { } } -export function validatorControl() { - const { name, address, description, data } = config.validatorControl +export function validatorControl(config: ValidatorsConfig) { + const { name, address, description, data } = config const storage: any = {} // address of upgrade control contact stored in slot 0 diff --git a/smart_contracts/scripts/genesis/generate.ts b/smart_contracts/scripts/genesis/generate.ts index b9314e93..c08934e7 100644 --- a/smart_contracts/scripts/genesis/generate.ts +++ b/smart_contracts/scripts/genesis/generate.ts @@ -1,5 +1,4 @@ import { writeJson } from '../../utils' -import { outFile, readContractsConfig } from './config' import { accountControl, credentialDefinitionRegistry, @@ -10,21 +9,22 @@ import { upgradeControl, validatorControl, } from './contracts' +import { prepareConfig } from './helpers' function main() { - readContractsConfig() + const config = prepareConfig() const contracts = { - ...accountControl(), - ...roleControl(), - ...validatorControl(), - ...upgradeControl(), - ...ethereumDidRegistry(), - ...schemaRegistry(), - ...credentialDefinitionRegistry(), - ...legacyMappingRegistry(), + ...accountControl(config.accountControl), + ...roleControl(config.roleControl), + ...validatorControl(config.validatorControl), + ...upgradeControl(config.upgradeControl), + ...ethereumDidRegistry(config.ethereumDidRegistry), + ...schemaRegistry(config.schemaRegistry), + ...credentialDefinitionRegistry(config.credentialDefinitionRegistry), + ...legacyMappingRegistry(config.legacyMapping), } - writeJson(contracts, outFile) + writeJson(contracts, 'ContractsGenesis.json') } if (require.main === module) { diff --git a/smart_contracts/scripts/genesis/helpers.ts b/smart_contracts/scripts/genesis/helpers.ts index 6a5a049e..24b77f79 100644 --- a/smart_contracts/scripts/genesis/helpers.ts +++ b/smart_contracts/scripts/genesis/helpers.ts @@ -1,7 +1,18 @@ import * as fs from 'fs-extra' import path from 'path' import { padLeft, sha3 } from 'web3-utils' -import { compiledContractsFolder } from './config' +import { readBesuConfig } from '../../utils' + +import { + AccountControlConfig, + CredentialDefinitionsConfig, + EthereumDidRegistryConfig, + LegacyMappingRegistryConfig, + RolesConfig, + SchemasConfig, + ValidatorsConfig, +} from './contracts' +import { UpgradeControlConfig } from './contracts/upgradeControl' // tslint:disable-next-line: no-var-requires const linker = require('solc/linker') @@ -16,6 +27,7 @@ export const slots = { const proxyBytecode = readContractBytecode('ERC1967Proxy') const proxyImplmentationSlot = '360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' const initializableVersionSlot = 'f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00' +const compiledContractsFolder = 'compiled-contracts' export function computeContractAddress(name: string) { const bytecode = readContractBytecode(name) @@ -87,3 +99,142 @@ export function readContractBytecode(contractName: string) { 'utf8', ) } + +export interface ContractsConfigs { + accountControl: AccountControlConfig + credentialDefinitionRegistry: CredentialDefinitionsConfig + ethereumDidRegistry: EthereumDidRegistryConfig + roleControl: RolesConfig + schemaRegistry: SchemasConfig + upgradeControl: UpgradeControlConfig + validatorControl: ValidatorsConfig + legacyMapping: LegacyMappingRegistryConfig +} + +export function prepareConfig(): ContractsConfigs { + const contracts = readBesuConfig().contracts + + return { + accountControl: { + name: 'AccountControl', + address: contracts.accountControl.address, + description: 'Account permissioning smart contract', + data: { + roleControlContractAddress: contracts.roleControl.address, + upgradeControlAddress: contracts.upgradeControl.address, + }, + }, + + credentialDefinitionRegistry: { + name: 'CredentialDefinitionRegistry', + address: contracts.credDefRegistry.address, + description: 'Smart contract to manage credential definitions', + data: { + credentialDefinitions: [], + ethereumDidRegistry: contracts.ethereumDidRegistry.address, + schemaRegistryAddress: contracts.schemaRegistry.address, + upgradeControlAddress: contracts.upgradeControl.address, + }, + }, + + ethereumDidRegistry: { + name: 'EthereumExtDidRegistry', + address: contracts.ethereumDidRegistry.address, + description: 'Ethereum registry for ERC-1056 ethr did methods', + }, + + roleControl: { + name: 'RoleControl', + address: contracts.roleControl.address, + description: 'Smart contract to manage account roles', + data: { + accounts: [ + { + account: '0xfe3b557e8fb62b89f4916b721be55ceb828dbd73', + role: 1, + }, + { + account: '0x627306090abaB3A6e1400e9345bC60c78a8BEf57', + role: 1, + }, + { + account: '0xf17f52151EbEF6C7334FAD080c5704D77216b732', + role: 1, + }, + { + account: '0xf0e2db6c8dc6c681bb5d6ad121a107f300e9b2b5', + role: 1, + }, + { + account: '0xca843569e3427144cead5e4d5999a3d0ccf92b8e', + role: 1, + }, + ], + roleOwners: { + '1': '1', + '2': '1', + '3': '1', + }, + upgradeControlAddress: contracts.upgradeControl.address, + }, + }, + + schemaRegistry: { + name: 'SchemaRegistry', + address: contracts.schemaRegistry.address, + description: 'Smart contract to manage schemas', + data: { + schemas: [], + ethereumDidRegistry: contracts.ethereumDidRegistry.address, + upgradeControlAddress: contracts.upgradeControl.address, + }, + }, + + upgradeControl: { + name: 'UpgradeControl', + address: contracts.upgradeControl.address, + description: 'Smart contract to manage proxy contract upgrades', + data: { + roleControlContractAddress: contracts.roleControl.address, + }, + }, + + validatorControl: { + name: 'ValidatorControl', + address: contracts.validatorControl.address, + description: 'Smart contract to manage validator nodes', + data: { + validators: [ + { + account: '0xed9d02e382b34818e88b88a309c7fe71e65f419d', + validator: '0x93917cadbace5dfce132b991732c6cda9bcc5b8a', + }, + { + account: '0xb30f304642de3fee4365ed5cd06ea2e69d3fd0ca', + validator: '0x27a97c9aaf04f18f3014c32e036dd0ac76da5f18', + }, + { + account: '0x0886328869e4e1f401e1052a5f4aae8b45f42610', + validator: '0xce412f988377e31f4d0ff12d74df73b51c42d0ca', + }, + { + account: '0xf48de4a0c2939e62891f3c6aca68982975477e45', + validator: '0x98c1334496614aed49d2e81526d089f7264fed9c', + }, + ], + roleControlContractAddress: contracts.roleControl.address, + upgradeControlAddress: contracts.upgradeControl.address, + }, + }, + + legacyMapping: { + name: 'LegacyMappingRegistry', + address: contracts.legacyMappingRegistry.address, + description: 'Smart contract to store mapping of legacy identifiers to new one', + data: { + ethereumDidRegistry: contracts.ethereumDidRegistry.address, + upgradeControlAddress: contracts.upgradeControl.address, + }, + }, + } +} diff --git a/smart_contracts/utils/common.ts b/smart_contracts/utils/common.ts index 5a6d19a8..37207b0e 100644 --- a/smart_contracts/utils/common.ts +++ b/smart_contracts/utils/common.ts @@ -1,7 +1,41 @@ +import { readFileSync } from 'fs' +import { resolve } from 'path' + export function randomString(len: number = 6) { return (Math.random() + 1).toString(36).substring(len) } export function delay(ms: number) { - return new Promise((resolve) => setTimeout(resolve, ms)) + return new Promise((resolveFunc) => setTimeout(resolveFunc, ms)) +} + +export interface ContractConfig { + specPath: string + address: string +} + +export interface ContractsConfigs { + didValidator: ContractConfig + credDefRegistry: ContractConfig + schemaRegistry: ContractConfig + roleControl: ContractConfig + validatorControl: ContractConfig + accountControl: ContractConfig + upgradeControl: ContractConfig + legacyMappingRegistry: ContractConfig + ethereumDidRegistry: ContractConfig +} + +export interface BesuConfig { + chainId: number + nodeAddress: string + contracts: ContractsConfigs +} + +export function readBesuConfig(): BesuConfig { + const configPath = resolve('../network/config.json') + const data = readFileSync(configPath, 'utf8') + + // TODO: validate the file data structure + return JSON.parse(data) as BesuConfig } diff --git a/vdr/src/client/client.rs b/vdr/src/client/client.rs index 36057765..39b33488 100644 --- a/vdr/src/client/client.rs +++ b/vdr/src/client/client.rs @@ -3,6 +3,7 @@ use std::{ fmt::{Debug, Formatter}, }; use serde_json::Value; +use serde::{Deserialize, Serialize}; use log::warn; use log_derive::{logfn, logfn_inputs}; @@ -211,6 +212,35 @@ impl Debug for LedgerClient { } } +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct BesuConfig { + pub contracts: BesuContractsConfigs, +} + + +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct BesuContractsConfigs { + pub did_validator: BesuContractConfig, + pub cred_def_registry: BesuContractConfig, + pub schema_registry: BesuContractConfig, + pub role_control: BesuContractConfig, + pub validator_control: BesuContractConfig, + pub account_control: BesuContractConfig, + pub upgrade_control: BesuContractConfig, + pub legacy_mapping_registry: BesuContractConfig, + pub ethereum_did_registry: BesuContractConfig, +} + +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct BesuContractConfig { + pub address: Address, + pub spec_path: String, +} + + #[cfg(test)] pub mod test { use super::*; @@ -232,6 +262,9 @@ pub mod test { pub const INVALID_ADDRESS: &str = "123"; + pub static CONTRACTS_CONFIG: Lazy = + Lazy::new(|| read_contract_configs()); + pub static TRUSTEE_ACC: Lazy
= Lazy::new(|| Address::from("0xf0e2db6c8dc6c681bb5d6ad121a107f300e9b2b5")); @@ -249,84 +282,47 @@ pub mod test { .to_string() } - fn get_contract_conf(contract_name: &str) -> Option { - let mut conf_json_path = env::current_dir().unwrap(); - conf_json_path.push("../config.json"); - let json_content = fs::read_to_string(conf_json_path).expect("config file reading failed"); - let conf: Value = serde_json::from_str(&json_content).expect("config file parsing failed"); - - let contracts = conf - .get("contracts").expect("'contracts' must be in the config file") - .as_object().expect("'contracts' is expected to be an object"); + fn read_contract_configs() -> BesuContractsConfigs { + let file = fs::File::open("../network/config.json").expect("Unable to open besu config file"); + let config: BesuConfig = + serde_json::from_reader(file).expect("Unable to parse besu config file"); - match contracts.get(contract_name) { - Some(value) => { - return Some(value.clone()); - }, - None => { - return None; - } - } + config.contracts } - pub fn get_contract_address(contract_name: &str) -> Option
{ - match get_contract_conf(contract_name) { - Some(value) => { - let s = value - .get("address").expect("'address' not found in the contract config") - .as_str().expect("'address' must be a string"); - return Some(Address::from(s)); + fn contracts() -> Vec { + vec![ + ContractConfig { + address: CONTRACTS_CONFIG.schema_registry.address.to_string(), + spec_path: Some(build_contract_path(CONTRACTS_CONFIG.schema_registry.spec_path.as_str())), + spec: None, }, - None => { - return None; - } - } - } - - pub fn get_contract_spec_path(contract_name: &str) -> Option { - match get_contract_conf(contract_name) { - Some(value) => { - let s = value - .get("spec_path").expect("'spec_path' not found in the contract config") - .as_str().expect("'spec_path' must be a string"); - return Some(String::from(s)); + ContractConfig { + address: CONTRACTS_CONFIG.cred_def_registry.address.to_string(), + spec_path: Some(build_contract_path(CONTRACTS_CONFIG.cred_def_registry.spec_path.as_str())), + spec: None, }, - None => { - return None; - } - } - } - - fn contracts() -> Vec { - let mut conf_json_path = env::current_dir().unwrap(); - conf_json_path.push("../config.json"); - - let json_content = fs::read_to_string(conf_json_path).expect("config file reading failed"); - let conf: Value = serde_json::from_str(&json_content).expect("config file parsing failed"); - - let contracts_conf = conf - .get("contracts").expect("'contracts' must be in the config file") - .as_object().expect("'contracts' is expected to be an object"); - - let mut result = Vec::new(); - - for contract_conf in contracts_conf.values() { - let addr = contract_conf - .get("address").expect("'address' not found in the contract config") - .as_str().expect("'address' must be a string"); - - let spec = contract_conf - .get("spec_path").expect("'spec_path' not found in the contract config") - .as_str().expect("'spec_path' must be a string"); - - result.push(ContractConfig { - address: String::from(addr), - spec_path: Some(build_contract_path(spec)), + ContractConfig { + address: CONTRACTS_CONFIG.validator_control.address.to_string(), + spec_path: Some(build_contract_path(CONTRACTS_CONFIG.validator_control.spec_path.as_str())), spec: None, - }); - } - - return result; + }, + ContractConfig { + address: CONTRACTS_CONFIG.role_control.address.to_string(), + spec_path: Some(build_contract_path(CONTRACTS_CONFIG.role_control.spec_path.as_str())), + spec: None, + }, + ContractConfig { + address: CONTRACTS_CONFIG.ethereum_did_registry.address.to_string(), + spec_path: Some(build_contract_path(CONTRACTS_CONFIG.ethereum_did_registry.spec_path.as_str())), + spec: None, + }, + ContractConfig { + address: CONTRACTS_CONFIG.legacy_mapping_registry.address.to_string(), + spec_path: Some(build_contract_path(CONTRACTS_CONFIG.legacy_mapping_registry.spec_path.as_str())), + spec: None, + }, + ] } pub fn client() -> LedgerClient { @@ -389,7 +385,7 @@ pub mod test { #[rstest] #[case::invalid_contract_data(vec![ContractConfig { - address: get_contract_address("validator_control").unwrap().to_string(), + address: CONTRACTS_CONFIG.validator_control.address.to_string(), spec_path: None, spec: Some(ContractSpec { name: VALIDATOR_CONTROL_NAME.to_string(), @@ -397,20 +393,20 @@ pub mod test { }), }], VdrError::ContractInvalidInputData)] #[case::both_contract_path_and_spec_provided(vec![ContractConfig { - address: get_contract_address("validator_control").unwrap().to_string(), - spec_path: Some(build_contract_path(get_contract_spec_path("validator_control").unwrap().as_str())), + address: CONTRACTS_CONFIG.validator_control.address.to_string(), + spec_path: Some(build_contract_path(CONTRACTS_CONFIG.validator_control.spec_path.as_str())), spec: Some(ContractSpec { name: VALIDATOR_CONTROL_NAME.to_string(), abi: Value::Array(vec ! []), }), }], VdrError::ContractInvalidSpec("Either `spec_path` or `spec` must be provided".to_string()))] #[case::non_existent_spec_path(vec![ContractConfig { - address: get_contract_address("validator_control").unwrap().to_string(), + address: CONTRACTS_CONFIG.validator_control.address.to_string(), spec_path: Some(build_contract_path("")), spec: None, }], VdrError::ContractInvalidSpec("Unable to read contract spec file. Err: \"Is a directory (os error 21)\"".to_string()))] #[case::empty_contract_spec(vec![ContractConfig { - address: get_contract_address("validator_control").unwrap().to_string(), + address: CONTRACTS_CONFIG.validator_control.address.to_string(), spec_path: None, spec: None, }], VdrError::ContractInvalidSpec("Either `spec_path` or `spec` must be provided".to_string()))] diff --git a/vdr/src/contracts/auth/role_control.rs b/vdr/src/contracts/auth/role_control.rs index 84a75e26..19db18f3 100644 --- a/vdr/src/contracts/auth/role_control.rs +++ b/vdr/src/contracts/auth/role_control.rs @@ -158,7 +158,7 @@ pub mod test { use super::*; use crate::{ client::client::test::{ - mock_client, CHAIN_ID, DEFAULT_NONCE, TRUSTEE_ACC, get_contract_address + mock_client, CHAIN_ID, DEFAULT_NONCE, TRUSTEE_ACC, CONTRACTS_CONFIG, }, utils::init_env_logger, }; @@ -194,7 +194,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(TRUSTEE_ACC.clone()), - to: get_contract_address("role_control").unwrap(), + to: CONTRACTS_CONFIG.role_control.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: expected_data, @@ -227,7 +227,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(TRUSTEE_ACC.clone()), - to: get_contract_address("role_control").unwrap(), + to: CONTRACTS_CONFIG.role_control.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: expected_data, @@ -258,7 +258,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Read, from: None, - to: get_contract_address("role_control").unwrap(), + to: CONTRACTS_CONFIG.role_control.address.clone(), nonce: None, chain_id: CHAIN_ID, data: expected_data, @@ -306,7 +306,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Read, from: None, - to: get_contract_address("role_control").unwrap(), + to: CONTRACTS_CONFIG.role_control.address.clone(), nonce: None, chain_id: CHAIN_ID, data: expected_data, diff --git a/vdr/src/contracts/cl/credential_definition_registry.rs b/vdr/src/contracts/cl/credential_definition_registry.rs index 7a2a167b..b3e04cd2 100644 --- a/vdr/src/contracts/cl/credential_definition_registry.rs +++ b/vdr/src/contracts/cl/credential_definition_registry.rs @@ -266,7 +266,7 @@ pub mod test { use super::*; use crate::{ client::client::test::{ - mock_client, CHAIN_ID, DEFAULT_NONCE, TRUSTEE_ACC, get_contract_address + mock_client, CHAIN_ID, DEFAULT_NONCE, TRUSTEE_ACC, CONTRACTS_CONFIG, }, contracts::{ cl::types::{ @@ -307,7 +307,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(TRUSTEE_ACC.clone()), - to: get_contract_address("cred_def_registry").unwrap(), + to: CONTRACTS_CONFIG.cred_def_registry.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: vec![ @@ -387,7 +387,7 @@ pub mod test { .await .unwrap(); let expected_query = EventQuery { - address: get_contract_address("cred_def_registry").unwrap(), + address: CONTRACTS_CONFIG.cred_def_registry.address.clone(), from_block: None, to_block: None, event_signature: None, diff --git a/vdr/src/contracts/cl/schema_registry.rs b/vdr/src/contracts/cl/schema_registry.rs index d12dc1d7..d3aa79d3 100644 --- a/vdr/src/contracts/cl/schema_registry.rs +++ b/vdr/src/contracts/cl/schema_registry.rs @@ -256,7 +256,7 @@ pub mod test { use super::*; use crate::{ client::client::test::{ - mock_client, CHAIN_ID, DEFAULT_NONCE, TRUSTEE_ACC, get_contract_address + mock_client, CHAIN_ID, DEFAULT_NONCE, TRUSTEE_ACC, CONTRACTS_CONFIG, }, contracts::{ cl::types::schema::test::{schema, SCHEMA_ATTRIBUTES, SCHEMA_NAME, SCHEMA_VERSION}, @@ -282,7 +282,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(TRUSTEE_ACC.clone()), - to: get_contract_address("schema_registry").unwrap(), + to: CONTRACTS_CONFIG.schema_registry.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: vec![ @@ -344,7 +344,7 @@ pub mod test { .await .unwrap(); let expected_query = EventQuery { - address: get_contract_address("schema_registry").unwrap(), + address: CONTRACTS_CONFIG.schema_registry.address.clone(), from_block: None, to_block: None, event_signature: None, diff --git a/vdr/src/contracts/did/did_ethr_registry.rs b/vdr/src/contracts/did/did_ethr_registry.rs index ef124fa4..a447377f 100644 --- a/vdr/src/contracts/did/did_ethr_registry.rs +++ b/vdr/src/contracts/did/did_ethr_registry.rs @@ -877,7 +877,7 @@ pub mod test { use crate::{ client::client::test::{ mock_client, CHAIN_ID, DEFAULT_NONCE, IDENTITY_ACC, - TRUSTEE_ACC, get_contract_address + TRUSTEE_ACC, CONTRACTS_CONFIG, }, contracts::{ did::types::{ @@ -953,7 +953,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(IDENTITY_ACC.clone()), - to: get_contract_address("ethereum_did_registry").unwrap(), + to: CONTRACTS_CONFIG.ethereum_did_registry.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: vec![ @@ -989,7 +989,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(IDENTITY_ACC.clone()), - to: get_contract_address("ethereum_did_registry").unwrap(), + to: CONTRACTS_CONFIG.ethereum_did_registry.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: vec![ @@ -1027,7 +1027,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(IDENTITY_ACC.clone()), - to: get_contract_address("ethereum_did_registry").unwrap(), + to: CONTRACTS_CONFIG.ethereum_did_registry.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: vec![ @@ -1063,7 +1063,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(IDENTITY_ACC.clone()), - to: get_contract_address("ethereum_did_registry").unwrap(), + to: CONTRACTS_CONFIG.ethereum_did_registry.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: vec![ @@ -1099,7 +1099,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(IDENTITY_ACC.clone()), - to: get_contract_address("ethereum_did_registry").unwrap(), + to: CONTRACTS_CONFIG.ethereum_did_registry.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: vec![ @@ -1135,7 +1135,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(IDENTITY_ACC.clone()), - to: get_contract_address("ethereum_did_registry").unwrap(), + to: CONTRACTS_CONFIG.ethereum_did_registry.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: vec![ diff --git a/vdr/src/contracts/migration/legacy_mapping_registry.rs b/vdr/src/contracts/migration/legacy_mapping_registry.rs index a6ce9166..423aa61a 100644 --- a/vdr/src/contracts/migration/legacy_mapping_registry.rs +++ b/vdr/src/contracts/migration/legacy_mapping_registry.rs @@ -343,7 +343,7 @@ pub mod test { use super::*; use crate::{ client::client::test::{ - mock_client, CHAIN_ID, DEFAULT_NONCE, TRUSTEE_ACC, get_contract_address, + mock_client, CHAIN_ID, DEFAULT_NONCE, TRUSTEE_ACC, CONTRACTS_CONFIG, }, contracts::did::types::{did::DID, did_doc::test::ISSUER_ID}, }; @@ -374,7 +374,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(TRUSTEE_ACC.clone()), - to: get_contract_address("legacy_mapping_registry").unwrap(), + to: CONTRACTS_CONFIG.legacy_mapping_registry.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: vec![ @@ -411,7 +411,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Read, from: None, - to: get_contract_address("legacy_mapping_registry").unwrap(), + to: CONTRACTS_CONFIG.legacy_mapping_registry.address.clone(), nonce: None, chain_id: CHAIN_ID, data: vec![ @@ -447,7 +447,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(TRUSTEE_ACC.clone()), - to: get_contract_address("legacy_mapping_registry").unwrap(), + to: CONTRACTS_CONFIG.legacy_mapping_registry.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: vec![ @@ -494,7 +494,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Read, from: None, - to: get_contract_address("legacy_mapping_registry").unwrap(), + to: CONTRACTS_CONFIG.legacy_mapping_registry.address.clone(), nonce: None, chain_id: CHAIN_ID, data: vec![ diff --git a/vdr/src/contracts/network/validator_control.rs b/vdr/src/contracts/network/validator_control.rs index 5100c42f..42893961 100644 --- a/vdr/src/contracts/network/validator_control.rs +++ b/vdr/src/contracts/network/validator_control.rs @@ -108,7 +108,7 @@ pub mod test { use super::*; use crate::{ client::client::test::{ - mock_client, CHAIN_ID, DEFAULT_NONCE, TRUSTEE_ACC, get_contract_address + mock_client, CHAIN_ID, DEFAULT_NONCE, TRUSTEE_ACC, CONTRACTS_CONFIG, }, utils::init_env_logger, }; @@ -153,7 +153,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(TRUSTEE_ACC.clone()), - to: get_contract_address("validator_control").unwrap(), + to: CONTRACTS_CONFIG.validator_control.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: expected_data.into(), @@ -184,7 +184,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Write, from: Some(TRUSTEE_ACC.clone()), - to: get_contract_address("validator_control").unwrap(), + to: CONTRACTS_CONFIG.validator_control.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: expected_data.into(), @@ -209,7 +209,7 @@ pub mod test { let expected_transaction = Transaction { type_: TransactionType::Read, from: None, - to: get_contract_address("validator_control").unwrap(), + to: CONTRACTS_CONFIG.validator_control.address.clone(), nonce: None, chain_id: CHAIN_ID, data: encoded_method.into(), diff --git a/vdr/src/types/transaction.rs b/vdr/src/types/transaction.rs index 798b2286..08f66cc2 100644 --- a/vdr/src/types/transaction.rs +++ b/vdr/src/types/transaction.rs @@ -521,7 +521,7 @@ pub mod test { use crate::{ client::client::test::{ mock_client, CHAIN_ID, DEFAULT_NONCE, INVALID_ADDRESS, TRUSTEE_ACC, - get_contract_address, + CONTRACTS_CONFIG, }, contracts::network::test::{ ADD_VALIDATOR_METHOD, VALIDATOR_ADDRESS, VALIDATOR_CONTROL_NAME, VALIDATOR_LIST_BYTES, @@ -538,7 +538,7 @@ pub mod test { Transaction { type_: TransactionType::Write, from: Some(TRUSTEE_ACC.clone()), - to: get_contract_address("validator_control").unwrap(), + to: CONTRACTS_CONFIG.validator_control.address.clone(), nonce: Some(DEFAULT_NONCE.clone()), chain_id: CHAIN_ID, data: vec![], @@ -551,7 +551,7 @@ pub mod test { Transaction { type_: TransactionType::Read, from: None, - to: get_contract_address("validator_control").unwrap(), + to: CONTRACTS_CONFIG.validator_control.address.clone(), nonce: None, chain_id: CHAIN_ID, data: vec![], diff --git a/vdr/wasm/demo/node/src/main.ts b/vdr/wasm/demo/node/src/main.ts index 9631c0a0..f64b377c 100644 --- a/vdr/wasm/demo/node/src/main.ts +++ b/vdr/wasm/demo/node/src/main.ts @@ -28,22 +28,22 @@ function sign(message: Uint8Array, key: Uint8Array) { function readContractsConfigs(): {address: string, spec: string}[] { const projectRootPath = resolve('../../../..') - const configPath = `${projectRootPath}/config.json` + const configPath = `${projectRootPath}/network/config.json` const data = readFileSync(configPath, 'utf8') const parsed_data = JSON.parse(data) - const ethDidRegistry = parsed_data.contracts.ethereum_did_registry - const schemaRegistry = parsed_data.contracts.schema_registry + const ethDidRegistry = parsed_data.contracts.ethereumDidRegistry + const schemaRegistry = parsed_data.contracts.schemaRegistry return [ { address: ethDidRegistry.address as string, - spec: `${projectRootPath}/${ethDidRegistry.spec_path}` + spec: `${projectRootPath}/${ethDidRegistry.specPath}` }, { address: schemaRegistry.address as string, - spec: `${projectRootPath}/${schemaRegistry.spec_path}` + spec: `${projectRootPath}/${schemaRegistry.specPath}` } ] } diff --git a/vdr/wrappers/python/demo/test.py b/vdr/wrappers/python/demo/test.py index 2c29652c..38196052 100644 --- a/vdr/wrappers/python/demo/test.py +++ b/vdr/wrappers/python/demo/test.py @@ -32,16 +32,16 @@ async def demo(): cwd = os.getcwd() project_root = f"{cwd}/../../.." - with open(f"{project_root}/config.json") as f: + with open(f"{project_root}/network/config.json") as f: configs = json.loads(f.read()) - did_registry_contract = configs["contracts"]["did_registry"] + did_registry_contract = configs["contracts"]["ethereumDidRegistry"] did_contract_address = did_registry_contract["address"] - did_contract_spec_path = "{}/{}".format(project_root, did_registry_contract["spec_path"]) + did_contract_spec_path = "{}/{}".format(project_root, did_registry_contract["specPath"]) - schema_registry_contract = configs["contracts"]["schema_registry"] + schema_registry_contract = configs["contracts"]["schemaRegistry"] schema_contract_address = schema_registry_contract["address"] - schema_contract_spec_path = "{}/{}".format(project_root, schema_registry_contract["spec_path"]) + schema_contract_spec_path = "{}/{}".format(project_root, schema_registry_contract["specPath"]) print("1. Init client") contract_configs = [