示例#1
0
        public void Copy(IIndexable other)
        {
            var otherLuchador = (Luchador)other;

            this.ID    = otherLuchador.ID;
            this.Owner = otherLuchador.Owner;
            this.data  = otherLuchador.data;
        }
示例#2
0
        public static Luchador FromData(BigInteger id, Address owner, NachoWrestler data)
        {
            var luchador = new Luchador(id)
            {
                Data = data, Owner = owner
            };

            return(luchador);
        }
示例#3
0
        public static Luchador FromData(BigInteger n, Address owner, NachoWrestler data)
        {
            var luchador = new Luchador(n)
            {
                data = data
            };

            return(luchador);
        }
示例#4
0
        public static Luchador FromGenes(BigInteger n, byte[] genes)
        {
            var luchador = new Luchador(n);
            var data     = new NachoWrestler {
                genes = genes
            };

            luchador.data = data;
            return(luchador);
        }
示例#5
0
        public ChainSimulator(KeyPair ownerKey, int seed, Logger logger = null)
        {
            this.Logger = logger != null ? logger : new DummyLogger();

            _owner     = ownerKey;
            this.Nexus = new Nexus();

            CurrentTime = new DateTime(2018, 8, 26);

            if (!Nexus.CreateGenesisBlock("simnet", _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.FuelTokenSymbol, _owner.Address);

            if (localBalance < oneFuel)
            {
                throw new Exception("Funds missing oops");
            }

            var nachoAddress = Address.FromText("PGasVpbFYdu7qERihCsR22nTDQp1JwVAjfuJ38T8NtrCB");
            var nachoFuel    = UnitConversion.ToBigInteger(5, Nexus.FuelTokenDecimals);
            var nachoChain   = Nexus.FindChainByName("nacho");

            var appsChain = Nexus.FindChainByName("apps");

            BeginBlock();
            GenerateSideChainSend(_owner, Nexus.FuelTokenSymbol, Nexus.RootChain, _owner.Address, appsChain, oneFuel, 0);
            GenerateSideChainSend(_owner, Nexus.FuelTokenSymbol, Nexus.RootChain, nachoAddress, nachoChain, nachoFuel, 9999);
            GenerateSideChainSend(_owner, Nexus.FuelTokenSymbol, Nexus.RootChain, Address.FromText("P27j1vgY1cjVYPnPDqjAVvqtxMmK9qjYvqz99EFp8vrPQ"), nachoChain, nachoFuel, 9999);
            var blockTx = EndBlock().First();

            BeginBlock();
            GenerateSideChainSettlement(_owner, Nexus.RootChain, appsChain, blockTx.Hash);
            GenerateSideChainSettlement(_owner, Nexus.RootChain, nachoChain, blockTx.Hash);
            EndBlock();

            BeginBlock();
            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, Constants.NACHO_SYMBOL, "Nachomen", 0, 0, TokenFlags.Transferable);
            GenerateToken(_owner, Constants.WRESTLER_SYMBOL, "Nachomen Luchador", 0, 0, TokenFlags.Transferable);
            GenerateToken(_owner, Constants.ITEM_SYMBOL, "Nachomen Item", 0, 0, TokenFlags.Transferable);
            EndBlock();

            var market = Nexus.FindChainByName("market");

            BeginBlock();

            var nachoSymbol = "NACHO";

            RandomSpreadNFT(nachoSymbol, 150);

            GenerateSetTokenMetadata(_owner, nachoSymbol, "details", "https://nacho.men/luchador/*");
            GenerateSetTokenMetadata(_owner, nachoSymbol, "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;
                TokenContent info;
                try
                {
                    info = Nexus.GetNFT(nachoSymbol, ID);
                }
                catch
                {
                    continue;
                }

                var chain = Nexus.FindChainByAddress(info.CurrentChain);
                if (chain == null)
                {
                    continue;
                }

                var nftOwner = chain.GetTokenOwner(nachoSymbol, 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.FuelTokenSymbol, 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, nachoSymbol, sale.Value, UnitConversion.ToBigInteger(100 + 5 * _rnd.Next() % 50, Nexus.FuelTokenDecimals));
            }
            EndBlock();

            BeginBlock();

            var newWrestler = new NachoWrestler()
            {
                auctionID          = 0,
                battleCount        = 0,
                comments           = new string[0],
                currentMojo        = 10,
                experience         = 10000,
                flags              = WrestlerFlags.None,
                genes              = new byte[] { 115, 169, 73, 21, 111, 3, 174, 90, 137, 58 }, //"Piece, 115, 169, 73, 21, 111, 3, 174, 90, 137, 58"
                gymBoostAtk        = byte.MaxValue,
                gymBoostDef        = byte.MaxValue,
                gymBoostStamina    = byte.MaxValue,
                gymTime            = 0,
                itemID             = 0,
                location           = WrestlerLocation.None,
                maskOverrideCheck  = byte.MaxValue,
                maskOverrideID     = byte.MaxValue,
                maskOverrideRarity = byte.MaxValue,
                maxMojo            = 10,
                mojoTime           = 0,
                moveOverrides      = new byte[0],
                nickname           = "testname",
                owner              = nachoAddress,
                perfumeTime        = 0,
                praticeLevel       = PraticeLevel.Gold,
                roomTime           = 0,
                score              = 0,
                stakeAmount        = 0,
                trainingStat       = StatKind.None,
                ua1 = byte.MaxValue,
                ua2 = byte.MaxValue,
                ua3 = byte.MaxValue,
                us1 = byte.MaxValue,
                us2 = byte.MaxValue,
                us3 = byte.MaxValue
            };

            var wrestlerBytes = newWrestler.Serialize();

            GenerateNft(_owner, nachoAddress, nachoSymbol, new byte[0], wrestlerBytes);

            EndBlock();
        }