public IAPIResult GetToken([APIParameter("Token symbol to obtain info", "SOUL")] string symbol) { var token = Nexus.FindTokenBySymbol(symbol); if (token == null) { return(new ErrorResult() { error = "invalid token" }); } var result = FillToken(token); return(result); }
public ChainSimulator(KeyPair ownerKey, int seed, int cacheSize, Logger logger = null) { this.Logger = logger != null ? logger : new DummyLogger(); _owner = ownerKey; this.Nexus = new Nexus("simnet", ownerKey.Address, cacheSize); CurrentTime = new DateTime(2018, 8, 26); if (!Nexus.CreateGenesisBlock(_owner, CurrentTime)) { throw new ChainException("Genesis block failure"); } this.bankChain = Nexus.FindChainByName("bank"); _rnd = new System.Random(seed); _keys.Add(_owner); var oneFuel = UnitConversion.ToBigInteger(1, Nexus.FuelTokenDecimals); var localBalance = Nexus.RootChain.GetTokenBalance(Nexus.FuelToken, _owner.Address); if (localBalance < oneFuel) { throw new Exception("Funds missing oops"); } var appsChain = Nexus.FindChainByName("apps"); BeginBlock(); GenerateSideChainSend(_owner, Nexus.FuelToken, Nexus.RootChain, _owner.Address, appsChain, oneFuel, 0); var blockTx = EndBlock().First(); BeginBlock(); GenerateSideChainSettlement(_owner, Nexus.RootChain, appsChain, blockTx.Hash); GenerateChain(_owner, Nexus.RootChain, "dex"); GenerateChain(_owner, Nexus.RootChain, "market"); EndBlock(); BeginBlock(); GenerateAppRegistration(_owner, "nachomen", "https://nacho.men", "Collect, train and battle against other players in Nacho Men!"); GenerateAppRegistration(_owner, "mystore", "https://my.store", "The future of digital content distribution!"); GenerateAppRegistration(_owner, "nftbazar", "https://nft.bazar", "A decentralized NFT market"); GenerateToken(_owner, "NACHO", "Nachomen", 0, 0, TokenFlags.Transferable); EndBlock(); var market = Nexus.FindChainByName("market"); BeginBlock(); var nacho = Nexus.FindTokenBySymbol("NACHO"); RandomSpreadNFT(nacho, 150); GenerateSetTokenMetadata(_owner, nacho, "details", "https://nacho.men/luchador/*"); GenerateSetTokenMetadata(_owner, nacho, "viewer", "https://nacho.men/luchador/body/*"); EndBlock(); var nftSales = new List <KeyValuePair <KeyPair, BigInteger> >(); BeginBlock(); for (int i = 1; i < 7; i++) { BigInteger ID = i + 100; var info = Nexus.GetNFT(nacho, ID); if (info == null) { continue; } var chain = Nexus.FindChainByAddress(info.CurrentChain); if (chain == null) { continue; } var nftOwner = chain.GetTokenOwner(nacho, ID); if (nftOwner == Address.Null) { continue; } foreach (var key in _keys) { if (key.Address == nftOwner) { nftSales.Add(new KeyValuePair <KeyPair, BigInteger>(key, ID)); // send some gas to the sellers GenerateTransfer(_owner, key.Address, Nexus.RootChain, Nexus.FuelToken, UnitConversion.ToBigInteger(0.01m, Nexus.FuelTokenDecimals)); } } } EndBlock(); BeginBlock(); foreach (var sale in nftSales) { // TODO this later should be the market chain instead of root GenerateNftSale(sale.Key, Nexus.RootChain, nacho, sale.Value, UnitConversion.ToBigInteger(100 + 5 * _rnd.Next() % 50, Nexus.FuelTokenDecimals)); } EndBlock(); }