public static async Task CreateMissingIdentities( MySqlConnection connection, Web3 cl, int blockchainId, BlockchainType blockchain, BlockchainNetwork network) { var eth = new EthApiService(cl.Client); var allIdentitiesCreated = connection .Query <OTContract_Profile_IdentityCreated>(@"select * from OTContract_Profile_IdentityCreated IC WHERE IC.NewIdentity not in (SELECT OTIdentity.Identity FROM OTIdentity WHERE BlockchainID = @BlockchainID) AND IC.BlockchainID = @blockchainID", new { blockchainId = blockchainId }) .ToArray(); foreach (var identity in allIdentitiesCreated) { var ercContract = new Contract(eth, AbiHelper.GetContractAbi(ContractTypeEnum.ERC725, blockchain, network), identity.NewIdentity); var otVersionFunction = ercContract.GetFunction("otVersion"); var value = await otVersionFunction.CallAsync <BigInteger>(); await OTIdentity.Insert(connection, new OTIdentity { TransactionHash = identity.TransactionHash, Identity = identity.NewIdentity, Version = (int)value, BlockchainID = blockchainId }); } //This only happens due to missing blockchain events (only happened in December 2018) var profilesCreatedWithoutIdentities = connection.Query( @"select TransactionHash, Profile from otcontract_profile_profilecreated WHERE Profile not in (select otidentity.Identity from otidentity WHERE BlockchainID = @blockchainID) AND BlockchainID = @blockchainID", new { blockchainId = blockchainId }).ToArray(); foreach (var profilesCreatedWithoutIdentity in profilesCreatedWithoutIdentities) { string hash = profilesCreatedWithoutIdentity.TransactionHash; string identity = profilesCreatedWithoutIdentity.Profile; var ercContract = new Contract(eth, AbiHelper.GetContractAbi(ContractTypeEnum.ERC725, blockchain, network), identity); var otVersionFunction = ercContract.GetFunction("otVersion"); var value = await otVersionFunction.CallAsync <BigInteger>(); await OTIdentity.Insert(connection, new OTIdentity { TransactionHash = hash, Identity = identity, Version = (int)value, BlockchainID = blockchainId }); } }