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

            OnCreatedArtefact(counterfeit);
        }
Exemplo 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);
        }
Exemplo 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);
 }
Exemplo 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);
        }
Exemplo n.º 5
0
 public Artefact(Artefact artefact, AgentId ownerId)
     : this(artefact.Id, artefact.Name, ownerId)
 {
 }
Exemplo n.º 6
0
 public Artefact ProduceArtefact(Artefact artefact)
 => _knownArtefacts.TryGetValue(artefact.Id, out var knownArtefact)
     ? knownArtefact
     : new Artefact(artefact, default);
Exemplo n.º 7
0
 public void MoveArtefact(Artefact artefact, AgentId ownerId)
 {
     ForgetArtefact(artefact.Id);
     AddArtefact(artefact, ownerId);
 }
Exemplo n.º 8
0
 public void RememberArtefact(Artefact artefact)
 {
     _knownArtefacts.Add(artefact.Id, artefact);
 }
Exemplo n.º 9
0
 private bool VerifyArtefact(AgentId giver, Artefact transferedArtefact)
 => giver == transferedArtefact.OwnerId &&
 (!Account.KnowsArtefact(transferedArtefact.Id) ||
  Account.GetArtefact(transferedArtefact.Id).OwnerId == transferedArtefact.OwnerId);