Esempio n. 1
0
        public void CounterfeitArtefact(Artefact artefact)
        {
            Account.ForgetArtefact(artefact.Id);
            var counterfeit = new Artefact(artefact, Account.Id);

            OnCreatedArtefact(counterfeit);
        }
Esempio n. 2
0
        public void AddArtefact(Artefact artefact, AgentId ownerId)
        {
            if (!IsConnectedTo(ownerId))
            {
                return;
            }
            var newArtefact = new Artefact(artefact, ownerId);

            GetPeer(ownerId).AddArtefact(newArtefact);
            RememberArtefact(newArtefact);
        }
Esempio n. 3
0
 public void AddArtefact(Artefact artefact)
 {
     if (HasArtefact(artefact.Id))
     {
         throw new DuplicateKey <ArtefactId>(artefact.Id);
     }
     if (artefact.OwnerId != Id)
     {
         throw new ArgumentException("Cannot add artefact with othe owner");
     }
     _artefacts.Add(artefact.Id, artefact);
 }
Esempio n. 4
0
        public void EndorceArtefact(Artefact artefact)
        {
            if (artefact.OwnerId == default)
            {
                throw new ArgumentException("Tried to endorce artefact without owner");
            }
            var owner = ProducePeer(artefact.OwnerId);

            if (Account.KnowsArtefact(artefact.Id))
            {
                artefact = Account.GetArtefact(artefact.Id);
                if (owner.Id != artefact.OwnerId)
                {
                    throw new ArgumentException($"Tried to endorce artefact with invalid owner: {owner.Id}");
                }
            }
            else
            {
                Account.RememberArtefact(artefact);
            }
            Account.IncreaseTrust(owner.Id, ArtefactEndorcementTrustFactor);
            OnEndorcedArtefact(artefact);
        }
Esempio n. 5
0
 public Artefact(Artefact artefact, AgentId ownerId)
     : this(artefact.Id, artefact.Name, ownerId)
 {
 }
Esempio n. 6
0
 public Artefact ProduceArtefact(Artefact artefact)
 => _knownArtefacts.TryGetValue(artefact.Id, out var knownArtefact)
     ? knownArtefact
     : new Artefact(artefact, default);
Esempio n. 7
0
 public void MoveArtefact(Artefact artefact, AgentId ownerId)
 {
     ForgetArtefact(artefact.Id);
     AddArtefact(artefact, ownerId);
 }
Esempio n. 8
0
 public void RememberArtefact(Artefact artefact)
 {
     _knownArtefacts.Add(artefact.Id, artefact);
 }
Esempio n. 9
0
 private bool VerifyArtefact(AgentId giver, Artefact transferedArtefact)
 => giver == transferedArtefact.OwnerId &&
 (!Account.KnowsArtefact(transferedArtefact.Id) ||
  Account.GetArtefact(transferedArtefact.Id).OwnerId == transferedArtefact.OwnerId);