예제 #1
0
        public DataAsset Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            try
            {
                rlpStream.ReadSequenceLength();
                Keccak            id                 = rlpStream.DecodeKeccak();
                string            name               = rlpStream.DecodeString();
                string            description        = rlpStream.DecodeString();
                UInt256           unitPrice          = rlpStream.DecodeUInt256();
                DataAssetUnitType unitType           = (DataAssetUnitType)rlpStream.DecodeInt();
                uint              minUnits           = rlpStream.DecodeUInt();
                uint              maxUnits           = rlpStream.DecodeUInt();
                DataAssetRules    rules              = Serialization.Rlp.Rlp.Decode <DataAssetRules>(rlpStream);
                DataAssetProvider provider           = Serialization.Rlp.Rlp.Decode <DataAssetProvider>(rlpStream);
                string            file               = rlpStream.DecodeString();
                QueryType         queryType          = (QueryType)rlpStream.DecodeInt();
                DataAssetState    state              = (DataAssetState)rlpStream.DecodeInt();
                string            termsAndConditions = rlpStream.DecodeString();
                bool              kycRequired        = rlpStream.DecodeBool();
                string            plugin             = rlpStream.DecodeString();

                return(new DataAsset(id, name, description, unitPrice, unitType, minUnits, maxUnits,
                                     rules, provider, file, queryType, state, termsAndConditions, kycRequired, plugin));
            }
            catch (Exception e)
            {
                throw new RlpException($"{nameof(DataAsset)} could not be deserialized", e);
            }
        }
예제 #2
0
 public Task SendDataAssetStateChangedAsync(Keccak id, string name, DataAssetState state)
 => _notifier.NotifyAsync(new Notification("data_asset_state_changed",
                                           new
 {
     id,
     name,
     state = state.ToString()
 }));
 public void SendDataAssetStateChanged(Keccak assetId, DataAssetState state)
 {
     if (Logger.IsTrace)
     {
         Logger.Trace($"{Session.RemoteNodeId} NDM sending: dataassetstatechanged");
     }
     Send(new DataAssetStateChangedMessage(assetId, state));
 }
예제 #4
0
        public void SetState(DataAssetState state)
        {
            if (State == state || State == DataAssetState.Archived)
            {
                return;
            }

            State = state;
        }
        public DataAssetStateChangedMessage Deserialize(byte[] bytes)
        {
            RlpStream context = bytes.AsRlpStream();

            context.ReadSequenceLength();
            Keccak?        dataAssetId = context.DecodeKeccak();
            DataAssetState state       = (DataAssetState)context.DecodeInt();

            return(new DataAssetStateChangedMessage(dataAssetId, state));
        }
예제 #6
0
        public void ChangeState(Keccak dataAssetId, DataAssetState state)
        {
            if (!_discoveredDataAssets.TryGetValue(dataAssetId, out var dataAsset))
            {
                return;
            }

            dataAsset.SetState(state);
            _consumerNotifier.SendDataAssetStateChangedAsync(dataAssetId, dataAsset.Name, state);
            if (_logger.IsInfo)
            {
                _logger.Info($"Changed the discovered data asset: '{dataAssetId}' state to: '{state}'.");
            }
        }
예제 #7
0
 public void ChangeDataAssetState(Keccak dataAssetId, DataAssetState state)
 => _dataAssetService.ChangeState(dataAssetId, state);
예제 #8
0
        public DataAsset(Keccak id, string name, string description, UInt256 unitPrice,
                         DataAssetUnitType unitType, uint minUnits, uint maxUnits, DataAssetRules rules,
                         DataAssetProvider provider, string file = null, QueryType queryType          = QueryType.Stream,
                         DataAssetState state = DataAssetState.Unpublished, string termsAndConditions = null,
                         bool kycRequired     = false, string plugin = null)
        {
            if (provider == null || string.IsNullOrWhiteSpace(provider.Name) || provider.Address == null)
            {
                throw new ArgumentException("Invalid data asset provider.", nameof(provider));
            }

            if (id == Keccak.Zero)
            {
                throw new ArgumentException("Invalid data asset id.", nameof(id));
            }

            if (string.IsNullOrWhiteSpace(name) || name.Length > 100)
            {
                throw new ArgumentException("Invalid data asset name.", nameof(name));
            }

            if (string.IsNullOrWhiteSpace(description) || description.Length > 256)
            {
                throw new ArgumentException("Invalid data asset description.", nameof(description));
            }

            if (termsAndConditions?.Length > 10000)
            {
                throw new ArgumentException("Invalid terms and conditions (over 10000 chars).", nameof(description));
            }

            if (rules is null)
            {
                throw new ArgumentException($"Missing rules.", nameof(rules));
            }

            if (rules.Expiry is null && rules.Expiry.Value <= 0)
            {
                throw new ArgumentException($"Invalid expiry rule value: {rules.Expiry}.", nameof(rules.Expiry));
            }

            if (!(rules.UpfrontPayment is null) && rules.UpfrontPayment.Value > minUnits)
            {
                throw new ArgumentException($"Min units ({minUnits}) cannot be lower than upfront payment value" +
                                            $" ({rules.UpfrontPayment.Value}).", nameof(minUnits));
            }

            Provider           = provider;
            State              = state;
            Id                 = id;
            Name               = name;
            Description        = description;
            UnitPrice          = unitPrice;
            UnitType           = unitType;
            QueryType          = queryType;
            MinUnits           = minUnits;
            MaxUnits           = maxUnits;
            Rules              = rules;
            Provider           = provider;
            File               = file;
            State              = state;
            TermsAndConditions = termsAndConditions;
            KycRequired        = kycRequired;
            SetState(state);
            SetPlugin(plugin);
        }
 public DataAssetStateChangedMessage(Keccak dataAssetId, DataAssetState state)
 {
     DataAssetId = dataAssetId;
     State       = state;
 }