Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ValidateContractSigned.cs
2using System.Threading.Tasks;
8
10{
15 {
16 private readonly LegalComponent legal;
17 private readonly ValidateSenderContractSignature senderValidation;
18
25 : this(Uri, Legal, null)
26 {
27 }
28
36 : base(Uri)
37 {
38 this.legal = Legal;
39 this.senderValidation = SenderValidation;
40 }
41
46 protected override async Task<bool> DoPrepare()
47 {
48 if (CaseInsensitiveString.IsNullOrEmpty(this.Uri.ContractCondition))
49 return true;
50
52
53 if (!(this.senderValidation is null) &&
54 this.Uri is IEDalerContractualPaymentUri ContractualPaymentUri &&
55 ContractualPaymentUri.ContractWithSignatures == this.Uri.ContractCondition)
56 {
57 Contract = await this.senderValidation.GetContractAsync(); // Avoid getting same contract twice.
58 }
59 else
60 {
61 KeyValuePair<Contract,IqResultEventArgs> P = await this.legal.GetContract(this.Uri.ContractCondition);
62 Contract = P.Key;
63 }
64
65 return await CheckContractValid(Contract, this.Uri, this.Uri.ContractCondition, XmppServerModule.Legal);
66 }
67
68 internal static async Task<bool> CheckContractValid(Contract Contract, EDalerUri Uri, string ContractId, LegalComponent Legal)
69 {
70 if (Contract is null)
71 {
72 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Conditional contract not found: " + ContractId, false);
73 return false;
74 }
75
76 // TODO: Double check contract signature & state
77
78 switch (Contract.State)
79 {
80 case ContractState.Approved:
81 Uri.State.Error(Uris.States.EDalerUriErrorType.Conflict, "Conditional contract is approved, but not signed.", true);
82 return false;
83
84 case ContractState.BeingSigned:
85 Uri.State.Error(Uris.States.EDalerUriErrorType.Conflict, "Conditional contract is being signed, but not all parties have signed yet.", true);
86 return false;
87
88 case ContractState.Deleted:
89 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Conditional contract has been deleted.", false);
90 return false;
91
92 case ContractState.Obsoleted:
93 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Conditional contract has been obsoleted.", false);
94 return false;
95
96 case ContractState.Proposed:
97 Uri.State.Error(Uris.States.EDalerUriErrorType.Conflict, "Conditional contract has been proposed, but has not been approved and signed yet.", true);
98 return false;
99
100 case ContractState.Rejected:
101 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Conditional contract has been rejected.", false);
102 return false;
103
104 case ContractState.Failed:
105 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Conditional contract has failed.", false);
106 return false;
107
108 case ContractState.Signed:
109 if (!await Contract.IsLegallyBinding(true, false, Legal))
110 {
111 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Contract not legally binding at the current time.", false);
112 return false;
113 }
114 else
115 return true;
116
117 default:
118 Uri.State.Error(Uris.States.EDalerUriErrorType.BadRequest, "Conditional contract is in an invalid state.", false);
119 return false;
120 }
121 }
122
127 protected override Task<bool> DoExecute()
128 {
129 return Task.FromResult(true); // No need to do nothing.
130 }
131
136 protected override Task<bool> DoCommit()
137 {
138 return Task.FromResult(true); // No need to do nothing.
139 }
140
145 protected override Task<bool> DoRollback()
146 {
147 return Task.FromResult(true); // No need to do nothing.
148 }
149 }
150}
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.