示例#1
0
        APIResultCodes DiscountTokenGenesis()
        {
            _DiscountTokenBlock = CreateDiscountTokenGenesisBlock(_FirstGenesisBlock);
            var authorizer = new NewTokenAuthorizer(serviceAccount, accountCollection);

            return(authorizer.Authorize <TokenGenesisBlock>(ref _DiscountTokenBlock));
        }
 public void SaveTokenInfo(TokenGenesisBlock tokenGewnesisBlock)
 {
     if (tokenGewnesisBlock != null && GetTokenInfo(tokenGewnesisBlock.Ticker) == null)
     {
         _tokeninfo.Add(tokenGewnesisBlock);
     }
 }
示例#3
0
 public void SaveTokenInfo(TokenGenesisBlock tokenGewnesisBlock)
 {
     if (tokenGewnesisBlock != null && GetTokenInfo(tokenGewnesisBlock.Ticker) == null)
     {
         GetTokenInfoCollection().Insert(tokenGewnesisBlock);
     }
 }
示例#4
0
 public async Task <AuthorizationAPIResult> CreateTokenAsync(TokenGenesisBlock tokenBlock)
 {
     if (!CheckServiceStatus())
     {
         return(null);
     }
     return(await _trans.CreateTokenAsync(tokenBlock));
 }
示例#5
0
        async Task <AuthorizationAPIResult> INodeAPI.CreateToken(TokenGenesisBlock block)
        {
            var request = new CreateTokenRequest()
            {
                CreateTokenJson = Json(block)
            };
            var result = await CreateTokenAsync(request);

            return(ToAAR(result));
        }
示例#6
0
        public async Task <AuthorizationAPIResult> CreateTokenAsync(TokenGenesisBlock tokenBlock)
        {
            var result = new AuthorizationAPIResult();

            //// filter the names -- not needed because authorizer control it
            //if (tokenBlock.DomainName.ToLower().StartsWith("lyra")
            //    || tokenBlock.Ticker.ToLower().StartsWith("lyra"))
            //{
            //    result.ResultCode = APIResultCodes.NameUnavailable;
            //    return result;
            //}

            return(await Pre_PrepareAsync(tokenBlock).ConfigureAwait(false));
        }
        // check if NFT instance with this serial number already exists to avoid duplicate serial numbers
        protected async Task <bool> WasNFTInstanceIssuedAsync(DagSystem sys, TokenGenesisBlock token_block, string SerialNumber)
        {
            var non_fungible_tokens = await sys.Storage.GetIssuedNFTInstancesAsync(GetOnlySendBlocks : true, token_block.AccountID, token_block.Ticker);

            if (non_fungible_tokens == null)
            {
                return(false);
            }
            foreach (var nft in non_fungible_tokens)
            {
                if (nft.SerialNumber == SerialNumber)
                {
                    return(true);
                }
            }
            return(false);
        }
        public async Task <AuthorizationAPIResult> CreateToken(TokenGenesisBlock tokenBlock)
        {
            var result = new AuthorizationAPIResult();

            // filter the names
            if (tokenBlock.DomainName.ToLower().StartsWith("lyra") ||
                tokenBlock.Ticker.ToLower().StartsWith("lyra"))
            {
                result.ResultCode = APIResultCodes.NameUnavailable;
                return(result);
            }

            return(await Pre_PrepareAsync(tokenBlock, async (b) =>
            {
                var feeResult = await ProcessTokenGenerationFee(b as TokenGenesisBlock);
                return feeResult.block;
            }).ConfigureAwait(false));
        }
示例#9
0
        TokenGenesisBlock CreateDiscountTokenGenesisBlock(TransactionBlock previousBlock)
        {
            var TokenGenerationFee = serviceAccount.GetLastServiceBlock().TokenGenerationFee;

            TokenGenesisBlock tokenBlock = new TokenGenesisBlock
            {
                Ticker          = "Custom.DISC",
                DomainName      = "Custom",
                Description     = "DISCOUNT NONFUNGIBLE TOKEN TEST",
                Precision       = 2,
                IsFinalSupply   = false,
                AccountID       = AccountId1,
                Balances        = new Dictionary <string, decimal>(),
                ServiceHash     = string.Empty,
                Fee             = TokenGenerationFee,
                FeeType         = AuthorizationFeeTypes.Regular,
                IsNonFungible   = true,
                NonFungibleKey  = AccountId1,
                NonFungibleType = NonFungibleTokenTypes.LoyaltyDiscount,
                RenewalDate     = DateTime.Now.Add(TimeSpan.FromDays(365)),
            };

            var transaction = new TransactionInfo()
            {
                TokenCode = "Custom.DISC", Amount = 100000
            };

            tokenBlock.Balances.Add(transaction.TokenCode, transaction.Amount); // This is current supply in atomic units (1,000,000.00)
            tokenBlock.Balances.Add(LyraGlobal.OFFICIALTICKERCODE, previousBlock.Balances[LyraGlobal.OFFICIALTICKERCODE] - TokenGenerationFee);

            tokenBlock.InitializeBlock(previousBlock, PrivateKey1, AccountId1);

            //tokenBlock.Signature = Signatures.GetSignature(PrivateKey1, tokenBlock.Hash);

            return(tokenBlock);
        }
示例#10
0
 public async Task <AuthorizationAPIResult> CreateToken(TokenGenesisBlock tokenBlock)
 {
     CheckSyncState();
     return(await _trans.CreateToken(tokenBlock));
 }
        async Task <(APIResultCodes result, TransactionBlock block)> ProcessTokenGenerationFee(TokenGenesisBlock tokenBlock)
        {
            if (tokenBlock.Fee != BlockChain.Singleton.GetLastServiceBlock().TokenGenerationFee)
            {
                return(APIResultCodes.InvalidFeeAmount, null);
            }

            return(await ProcessFee(tokenBlock.Hash, tokenBlock.Fee));
        }
 // must be overriden and implemented in both send and receive authorizers as they have very different logic
 protected virtual async Task <APIResultCodes> ValidateCollectibleNFTAsync(DagSystem sys, TransactionBlock send_or_receice_block, TokenGenesisBlock token_block)
 {
     return(await Task.FromResult(APIResultCodes.Success));
 }
示例#13
0
 public Task <bool> DoesAccountHaveCollectibleNFTInstanceAsync(string owner_account_id, TokenGenesisBlock token_block, string serial_number)
 {
     return(StopWatcher.TrackAsync(() => _store.DoesAccountHaveCollectibleNFTInstanceAsync(owner_account_id, token_block, serial_number), StopWatcher.GetCurrentMethod()));
 }
示例#14
0
        protected override async Task <APIResultCodes> ValidateCollectibleNFTAsync(DagSystem sys, TransactionBlock send_or_receice_block, TokenGenesisBlock token_block)
        {
            if (send_or_receice_block.NonFungibleToken.Denomination != 1)
            {
                return(APIResultCodes.InvalidCollectibleNFTDenomination);
            }

            if (string.IsNullOrEmpty(send_or_receice_block.NonFungibleToken.SerialNumber))
            {
                return(APIResultCodes.InvalidCollectibleNFTSerialNumber);
            }

            bool nft_instance_exists = await WasNFTInstanceIssuedAsync(sys, token_block, send_or_receice_block.NonFungibleToken.SerialNumber);

            bool is_there_a_token = await sys.Storage.DoesAccountHaveCollectibleNFTInstanceAsync(send_or_receice_block.AccountID, token_block, send_or_receice_block.NonFungibleToken.SerialNumber);

            if (nft_instance_exists) // this is a transfer of existing instance to another account
            {
                if (!is_there_a_token && send_or_receice_block.AccountID == token_block.AccountID)
                {
                    return(APIResultCodes.DuplicateNFTCollectibleSerialNumber);
                }

                if (!is_there_a_token && send_or_receice_block.AccountID != token_block.AccountID)
                {
                    return(APIResultCodes.InsufficientFunds);
                }
            }
            else // otherwise, this is an attempt to issue a new instance
            {
                // Only the owner of the genesis token block can issue a new instance of NFT
                if (send_or_receice_block.AccountID != token_block.AccountID)
                {
                    return(APIResultCodes.NFTCollectibleSerialNumberDoesNotExist);
                }
            }

            return(APIResultCodes.Success);
        }
 public async Task <AuthorizationAPIResult> CreateToken(TokenGenesisBlock block)
 {
     return(await PostBlock("CreateToken", block));
 }
        public async Task <AuthorizationAPIResult> CreateTokenAsync(
            string tokenName,
            string domainName,
            string description,
            sbyte precision,
            decimal supply,
            bool isFinalSupply,
            string owner,               // shop name
            string address,             // shop URL
            string currency,            // USD
            ContractTypes contractType, // reward or discount or custom
            Dictionary <string, string> tags)
        {
            if (string.IsNullOrWhiteSpace(domainName))
            {
                domainName = "Custom";
            }

            string ticker = domainName + "/" + tokenName;

            var blockresult = await _node.GetLastServiceBlockAsync();

            if (blockresult.ResultCode != APIResultCodes.Success)
            {
                return new AuthorizationAPIResult()
                       {
                           ResultCode = blockresult.ResultCode
                       }
            }
            ;

            ServiceBlock lastServiceBlock = blockresult.GetBlock() as ServiceBlock;

            TransactionBlock latestBlock = await GetLatestBlockAsync();

            if (latestBlock == null || latestBlock.Balances[LyraGlobal.OFFICIALTICKERCODE] < lastServiceBlock.TokenGenerationFee.ToBalanceLong())
            {
                //throw new Exception("Insufficent funds");
                return(new AuthorizationAPIResult()
                {
                    ResultCode = APIResultCodes.InsufficientFunds
                });
            }

            var svcBlockResult = await _node.GetLastServiceBlockAsync();

            if (svcBlockResult.ResultCode != APIResultCodes.Success)
            {
                throw new Exception("Unable to get latest service block.");
            }

            // initiate test coins
            TokenGenesisBlock tokenBlock = new TokenGenesisBlock
            {
                Ticker        = ticker,
                DomainName    = domainName,
                Description   = description,
                Precision     = precision,
                IsFinalSupply = isFinalSupply,
                //CustomFee = 0,
                //CustomFeeAccountId = string.Empty,
                AccountID    = AccountId,
                Balances     = new Dictionary <string, long>(),
                ServiceHash  = svcBlockResult.GetBlock().Hash,
                Fee          = lastServiceBlock.TokenGenerationFee,
                FeeCode      = LyraGlobal.OFFICIALTICKERCODE,
                FeeType      = AuthorizationFeeTypes.Regular,
                Owner        = owner,
                Address      = address,
                Currency     = currency,
                Tags         = tags,
                RenewalDate  = DateTime.UtcNow.Add(TimeSpan.FromDays(3650)),
                ContractType = contractType,
                VoteFor      = latestBlock.VoteFor
            };
            // TO DO - set service hash

            //var transaction = new TransactionInfo() { TokenCode = ticker, Amount = supply * (long)Math.Pow(10, precision) };
            var transaction = new TransactionInfo()
            {
                TokenCode = ticker, Amount = supply
            };

            tokenBlock.Balances.Add(transaction.TokenCode, transaction.Amount.ToBalanceLong()); // This is current supply in atomic units (1,000,000.00)
            tokenBlock.Balances.Add(LyraGlobal.OFFICIALTICKERCODE, latestBlock.Balances[LyraGlobal.OFFICIALTICKERCODE] - lastServiceBlock.TokenGenerationFee.ToBalanceLong());
            //tokenBlock.Transaction = transaction;
            // transfer unchanged token balances from the previous block
            foreach (var balance in latestBlock.Balances)
            {
                if (!(tokenBlock.Balances.ContainsKey(balance.Key)))
                {
                    tokenBlock.Balances.Add(balance.Key, balance.Value);
                }
            }

            await tokenBlock.InitializeBlockAsync(latestBlock, _signer);

            //tokenBlock.Signature = Signatures.GetSignature(PrivateKey, tokenBlock.Hash);

            var result = await _trans.CreateTokenAsync(tokenBlock);

            if (result.ResultCode == APIResultCodes.Success)
            {
                LastBlock = tokenBlock;
            }
            else
            {
                LastBlock = null;
            }

            return(result);
        }
示例#17
0
 public void SaveTokenInfo(TokenGenesisBlock tokenGewnesisBlock)
 {
     throw new ApplicationException("Not supported");
 }