public SmartContract FindContract(string contractName) { Throw.IfNullOrEmpty(contractName, nameof(contractName)); if (_contractCache.ContainsKey(contractName)) { return(_contractCache[contractName]); } SmartContract contract; switch (contractName) { case "nexus": contract = new NexusContract(); break; case "consensus": contract = new ConsensusContract(); break; case "governance": contract = new GovernanceContract(); break; case "account": contract = new AccountContract(); break; case "friends": contract = new FriendContract(); break; case "exchange": contract = new ExchangeContract(); break; case "market": contract = new MarketContract(); break; case "energy": contract = new EnergyContract(); break; case "token": contract = new TokenContract(); break; case "swap": contract = new SwapContract(); break; case "gas": contract = new GasContract(); break; case "relay": contract = new RelayContract(); break; case "storage": contract = new StorageContract(); break; case "vault": contract = new VaultContract(); break; case "bank": contract = new BankContract(); break; case "apps": contract = new AppsContract(); break; case "dex": contract = new ExchangeContract(); break; case "nacho": contract = new NachoContract(); break; case "casino": contract = new CasinoContract(); break; default: throw new Exception("Unknown contract: " + contractName); } _contractCache[contractName] = contract; return(contract); }
internal Chain CreateChain(Address owner, string name, Chain parentChain, Block parentBlock) { if (name != RootChainName) { if (parentChain == null || parentBlock == null) { return(null); } } if (!Chain.ValidateName(name)) { return(null); } // check if already exists something with that name var temp = FindChainByName(name); if (temp != null) { return(null); } SmartContract contract; switch (name) { case "privacy": contract = new PrivacyContract(); break; case "storage": contract = new StorageContract(); break; case "vault": contract = new VaultContract(); break; case "bank": contract = new BankContract(); break; case "apps": contract = new AppsContract(); break; case "dex": contract = new ExchangeContract(); break; case "market": contract = new MarketContract(); break; case "energy": contract = new EnergyContract(); break; case "nacho": contract = new NachoContract(); break; case "casino": contract = new CasinoContract(); break; default: { var sb = new ScriptBuilder(); contract = new CustomContract(sb.ToScript(), null); // TODO break; } } var tokenContract = new TokenContract(); var gasContract = new GasContract(); var chain = new Chain(this, name, _logger); chain.Initialize(new[] { tokenContract, gasContract, contract }); // add to persisent list of chains var chainList = this.Chains.ToList(); chainList.Add(name); this.Chains = chainList; // add address and name mapping this._vars.Set(ChainAddressMapKey + chain.Address.Text, Encoding.UTF8.GetBytes(chain.Name)); this._vars.Set(ChainNameMapKey + chain.Name, chain.Address.PublicKey); if (parentChain != null) { this._vars.Set(ChainParentNameKey + chain.Name, Encoding.UTF8.GetBytes(parentChain.Name)); this._vars.Set(ChainParentBlockKey + chain.Name, parentBlock.Hash.ToByteArray()); } _chainCache[chain.Name] = chain; return(chain); }