예제 #1
0
        public async Task <bool> BuyTokens([FromBody] TokenCredits credits)
        {
            TokenContract token = new TokenContract();
            await token.Transfer(credits.Tokens);

            return(true);
        }
예제 #2
0
        public async Task <bool> DeductTokens([FromBody] TokenCredits credits)
        {
            TokenContract token = new TokenContract();
            await token.Deduct(credits.Tokens);

            return(true);
        }
예제 #3
0
        public async Task <EthContractData> CreateToken()
        {
            TokenContract token = new TokenContract();
            await token.RegisterContract();

            return(Globals.TokenEthData);
        }
예제 #4
0
        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);
        }
예제 #5
0
 public static IEnumerable <TokenContract> EnumerateTokenContracts(this DataCache snapshot, ProtocolSettings settings)
 {
     foreach (var(contractHash, standard) in TokenContract.Enumerate(snapshot))
     {
         if (TryLoadTokenInfo(contractHash, snapshot, settings, out var info))
         {
             yield return(new TokenContract(info.symbol, info.decimals, contractHash, standard));
         }
     }
예제 #6
0
 DataContracts.TokenContract IMapSvs.AuthenicateUser(Credentials creds)
 {
     if (creds.User == null || creds.Password == null)
     {
         throw new WebFaultException <string>("Please provide user name and password.", System.Net.HttpStatusCode.BadRequest);
     }
     else
     {
         using (BAL.MemberAuthentication objAuth = new BAL.MemberAuthentication())
         {
             if (objAuth.AuthenticateUser(creds))
             {
                 DataContracts.TokenContract objToken = new TokenContract();
                 objToken = objAuth.GenerateToken(creds.User);
                 return(objToken);
             }
             else
             {
                 throw new WebFaultException <string>("Invalid user name or password.", System.Net.HttpStatusCode.Unauthorized);
             }
         }
     }
 }
예제 #7
0
        private async void OnTokenContractTextChanged(object sender, TextChangedEventArgs args)
        {
            if (!String.IsNullOrEmpty(args.NewTextValue))
            {
                if (!TokenContractHint.IsVisible)
                {
                    TokenContractHint.IsVisible = true;

                    _ = TokenContractHint.FadeTo(1, 500, Easing.Linear);
                    _ = TokenContract.TranslateTo(0, 10, 500, Easing.CubicOut);
                    _ = TokenContractHint.TranslateTo(0, -15, 500, Easing.CubicOut);
                }
            }
            else
            {
                await Task.WhenAll(
                    TokenContractHint.FadeTo(0, 500, Easing.Linear),
                    TokenContract.TranslateTo(0, 0, 500, Easing.CubicOut),
                    TokenContractHint.TranslateTo(0, -10, 500, Easing.CubicOut)
                    );

                TokenContractHint.IsVisible = false;
            }
        }
예제 #8
0
        public JObject GetNep17Balances(JArray @params)
        {
            var address = AsScriptHash(@params[0]);

            using var snapshot = neoSystem.GetSnapshot();

            // collect the non-zero balances of all the deployed Nep17 contracts for the specified account
            var addressBalances = TokenContract.Enumerate(snapshot)
                                  .Where(c => c.standard == TokenStandard.Nep17)
                                  .Select(c => (
                                              scriptHash: c.scriptHash,
                                              balance: snapshot.GetNep17Balance(c.scriptHash, address, neoSystem.Settings)))
                                  .Where(t => !t.balance.IsZero)
                                  .ToList();

            // collect the last block index a transfer occurred for all account balances
            var updateIndexes = new Dictionary <UInt160, uint>();

            if (addressBalances.Count > 0)
            {
                var notifications = PersistencePlugin.GetNotifications(
                    storageProvider,
                    SeekDirection.Backward,
                    addressBalances.Select(b => b.scriptHash).ToHashSet(),
                    TRANSFER);

                foreach (var(blockIndex, _, notification) in notifications)
                {
                    // iterate backwards thru the notifications looking for all the Transfer events from a contract
                    // in assets where a Transfer event hasn't already been recorded
                    if (!updateIndexes.ContainsKey(notification.ScriptHash))
                    {
                        var transfer = TransferNotificationRecord.Create(notification);
                        if (transfer is not null &&
                            (transfer.From == address || transfer.To == address))
                        {
                            // if the specified account was the sender or receiver of the current transfer,
                            // record the update index. Stop the iteration if indexes for all the assets are
                            // have been recorded
                            updateIndexes.Add(notification.ScriptHash, blockIndex);
                            if (updateIndexes.Count == addressBalances.Count)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            var balances = new JArray();

            for (int i = 0; i < addressBalances.Count; i++)
            {
                var(scriptHash, balance) = addressBalances[i];
                var lastUpdatedBlock = updateIndexes.TryGetValue(scriptHash, out var _index) ? _index : 0;

                balances.Add(new JObject
                {
                    ["assethash"]        = scriptHash.ToString(),
                    ["amount"]           = balance.ToString(),
                    ["lastupdatedblock"] = lastUpdatedBlock,
                });
            }

            return(new JObject
            {
                ["address"] = address.ToAddress(neoSystem.Settings.AddressVersion),
                ["balance"] = balances,
            });
        }
예제 #9
0
        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);
        }
예제 #10
0
        internal Chain CreateChain(Address owner, string name, Chain parentChain, Block parentBlock)
        {
            if (parentChain == null || parentBlock == null)
            {
                return(null);
            }

            if (owner != GenesisAddress)
            {
                if (parentChain.Level < 2)
                {
                    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;

            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, new[] { tokenContract, gasContract, contract }, _logger, parentChain, parentBlock);

            lock (_chains)
            {
                _chains[name] = chain;
            }

            return(chain);
        }
예제 #11
0
        public async Task <bool> Kill()
        {
            TokenContract token = new TokenContract();

            return(await token.Kill());
        }
예제 #12
0
 private void OnTokenContractEntryTapped(object sender, EventArgs args)
 {
     TokenContract.Focus();
 }
예제 #13
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 public ContractInfoRegistry()
     : base(new[] { TokenContract.Create(), FaucetContract.Create() })
 {
 }
예제 #14
0
 // CreateTokenContract
 public async Task <TokenContract> CreateTokenContract(TokenContract tokenContract)
 {
     return(await this.Post <TokenContract>("tokens", tokenContract));
 }