Exemple #1
0
        public async Task <IActionResult> Add([FromBody] AssetExtendedInfo assetInfo)
        {
            assetInfo = Mapper.Map <AssetExtendedInfo>(await _assetExtendedInfoService.AddAsync(assetInfo));

            return(Created
                   (
                       uri:   $"api/v2/asset-extended-infos/{assetInfo.Id}",
                       value: assetInfo
                   ));
        }
Exemple #2
0
        public async Task <IAsset> CreateAssetForErc20TokenAsync(string tokenAddress)
        {
            var erc20Token = Mapper.Map <Erc20Token>(await _erc20TokenService.GetByTokenAddressAsync(tokenAddress));

            if (!string.IsNullOrEmpty(erc20Token.AssetId))
            {
                throw new InvalidOperationException($"Asset for the token with specified address [{tokenAddress}] already exists.");
            }

            if (!string.IsNullOrEmpty(erc20Token.TokenTotalSupply) && !BigInteger.TryParse(erc20Token.TokenTotalSupply, out var _))
            {
                throw new InvalidOperationException($"Specified token supply [{erc20Token.TokenTotalSupply}] is not valid BigInteger.");
            }

            // Creating asset
            var asset = Mapper.Map <Asset>(_assetService.CreateDefault());
            var blockchainAndDisplayIds = await GetBlockchainAndDisplayIdsAsync(erc20Token);

            var tokenDecimals = erc20Token.TokenDecimals ?? 0;

            asset.Accuracy          = GetAssetAccuracy(tokenDecimals);
            asset.AssetAddress      = string.Empty;
            asset.Blockchain        = Blockchain.Ethereum;
            asset.BlockChainId      = blockchainAndDisplayIds.BlockchainId;
            asset.BlockChainAssetId = erc20Token.Address;
            asset.DisplayId         = blockchainAndDisplayIds.DisplayId;
            asset.Id              = Guid.NewGuid().ToString();
            asset.IsDisabled      = true;
            asset.IsTradable      = false;
            asset.MultiplierPower = tokenDecimals;
            asset.Name            = GetAssetName(erc20Token);
            asset.Symbol          = erc20Token.TokenSymbol;
            asset.Type            = AssetType.Erc20Token;

            asset = Mapper.Map <Asset>(await _assetService.AddAsync(asset));

            // Creating extended info
            var assetExtendedInfo = Mapper.Map <AssetExtendedInfo>(_assetExtendedInfoService.CreateDefault());

            assetExtendedInfo.Id            = asset.Id;
            assetExtendedInfo.NumberOfCoins = GetNumberOfCoins(erc20Token);


            await _assetExtendedInfoService.AddAsync(assetExtendedInfo);

            // Updating token
            erc20Token.AssetId = asset.Id;

            await _erc20TokenService.UpdateAsync(erc20Token);


            return(asset);
        }