Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ValidateContractSigned.cs
1using System.Threading.Tasks;
6
8{
13 {
14 private readonly LegalComponent legal;
15 private readonly ValidateSenderContractSignature senderValidation;
16
23 : this(Uri, Legal, null)
24 {
25 }
26
34 : base(Uri)
35 {
36 this.legal = Legal;
37 this.senderValidation = SenderValidation;
38 }
39
44 protected override async Task<bool> DoPrepare()
45 {
46 if (CaseInsensitiveString.IsNullOrEmpty(this.Uri.ContractCondition))
47 return true;
48
50
51 if (!(this.senderValidation is null) &&
52 this.Uri is IEDalerContractualPaymentUri ContractualPaymentUri &&
53 ContractualPaymentUri.ContractWithSignatures == this.Uri.ContractCondition)
54 {
55 Contract = await this.senderValidation.GetContractAsync(); // Avoid getting same contract twice.
56 }
57 else
58 Contract = await this.legal.GetContract(this.Uri.ContractCondition);
59
60 return await CheckContractValid(Contract, this.Uri, this.Uri.ContractCondition, XmppServerModule.Legal);
61 }
62
63 internal static async Task<bool> CheckContractValid(Contract Contract, EDalerUri Uri, string ContractId, LegalComponent Legal)
64 {
65 if (Contract is null)
66 {
67 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Conditional contract not found: " + ContractId, false);
68 return false;
69 }
70
71 // TODO: Double check contract signature & state
72
73 switch (Contract.State)
74 {
75 case ContractState.Approved:
76 Uri.State.Error(Uris.States.EDalerUriErrorType.Conflict, "Conditional contract is approved, but not signed.", true);
77 return false;
78
79 case ContractState.BeingSigned:
80 Uri.State.Error(Uris.States.EDalerUriErrorType.Conflict, "Conditional contract is being signed, but not all parties have signed yet.", true);
81 return false;
82
83 case ContractState.Deleted:
84 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Conditional contract has been deleted.", false);
85 return false;
86
87 case ContractState.Obsoleted:
88 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Conditional contract has been obsoleted.", false);
89 return false;
90
91 case ContractState.Proposed:
92 Uri.State.Error(Uris.States.EDalerUriErrorType.Conflict, "Conditional contract has been proposed, but has not been approved and signed yet.", true);
93 return false;
94
95 case ContractState.Rejected:
96 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Conditional contract has been rejected.", false);
97 return false;
98
99 case ContractState.Failed:
100 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Conditional contract has failed.", false);
101 return false;
102
103 case ContractState.Signed:
104 if (!await Contract.IsLegallyBinding(true, false, Legal))
105 {
106 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Contract not legally binding at the current time.", false);
107 return false;
108 }
109 else
110 return true;
111
112 default:
113 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Conditional contract is in an invalid state.", false);
114 return false;
115 }
116 }
117
122 protected override Task<bool> DoExecute()
123 {
124 return Task.FromResult(true); // No need to do nothing.
125 }
126
131 protected override Task<bool> DoCommit()
132 {
133 return Task.FromResult(true); // No need to do nothing.
134 }
135
140 protected override Task<bool> DoRollback()
141 {
142 return Task.FromResult(true); // No need to do nothing.
143 }
144 }
145}
Represents a case-insensitive string.
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
Abstract base class for eDaler transactions.
Validates a contract has been signed before a transaction can be realized.
override Task< bool > DoRollback()
Performs actual rollback.
override Task< bool > DoExecute()
Performs actual execution.
ValidateContractSigned(EDalerUri Uri, LegalComponent Legal)
Validates a contract has been signed before a transaction can be realized.
override async Task< bool > DoPrepare()
Performs actual preparation.
ValidateContractSigned(EDalerUri Uri, LegalComponent Legal, ValidateSenderContractSignature SenderValidation)
Validates a contract has been signed before a transaction can be realized.
Validates that the sender has signed the contract and that the contract is valid.
Abstract base class for eDaler URIs
Definition: EDalerUri.cs:20
CaseInsensitiveString ContractCondition
Optional Contract defining conditions that must be met before payment can be realized....
Definition: EDalerUri.cs:210
EDalerUriState State
URI State object.
Definition: EDalerUri.cs:173
Service Module hosting the XMPP broker and its components.
CaseInsensitiveString ContractWithSignatures
ID of contract containing signatures authorizing payment.