示例#1
0
        public async Task can_add_data_asset()
        {
            Keccak id = await providerService.AddDataAssetAsync("test-asset", "Testing", new UInt256(10), DataAssetUnitType.Unit, 1, 10, new DataAssetRules(new DataAssetRule(10)));

            var addedDataAsset = dataAssetRepository.GetAsync(id);

            Assert.IsNotNull(addedDataAsset);
        }
        public async Task <ResultWrapper <Keccak> > ndm_addDataAsset(DataAssetForRpc dataAsset)
        {
            if (dataAsset.UnitPrice == null)
            {
                throw new InvalidDataException("Data asset is missing unit price.");
            }

            if (dataAsset.UnitType == null)
            {
                throw new InvalidDataException("Data asset is missing unit type.");
            }

            if (dataAsset.Rules == null)
            {
                throw new InvalidDataException("Data asset is missing basic rules definitions.");
            }

            if (dataAsset.Description == null)
            {
                throw new InvalidDataException("Data asset is missing description.");
            }

            if (dataAsset.Name == null)
            {
                throw new InvalidDataException("Data asset is missing name.");
            }

            if (dataAsset.Rules.Expiry == null)
            {
                throw new InvalidDataException("Data asset is missing expiry rule.");
            }

            Keccak?id = await _providerService.AddDataAssetAsync(dataAsset.Name,
                                                                 dataAsset.Description, (UInt256)dataAsset.UnitPrice,
                                                                 Enum.Parse <DataAssetUnitType>(dataAsset.UnitType, true),
                                                                 dataAsset.MinUnits, dataAsset.MaxUnits,
                                                                 new DataAssetRules(new DataAssetRule((UInt256)dataAsset.Rules.Expiry.Value),
                                                                                    dataAsset.Rules.UpfrontPayment is null
                        ? null
                        : new DataAssetRule((UInt256)dataAsset.Rules.UpfrontPayment.Value)),
                                                                 dataAsset.File, dataAsset.Data,
                                                                 string.IsNullOrWhiteSpace(dataAsset.QueryType)
                                                                 ?QueryType.Stream
                                                                 : Enum.Parse <QueryType>(dataAsset.QueryType, true),
                                                                 dataAsset.TermsAndConditions, dataAsset.KycRequired ?? false, dataAsset.Plugin);

            return(id is null
                ? ResultWrapper <Keccak> .Fail($"Data asset: '{dataAsset.Name}' already exists.")
                : ResultWrapper <Keccak> .Success(id));
        }