Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
LocalDestruction.cs
1using System.Collections.Generic;
2using System.Threading.Tasks;
3using Waher.Events;
6
8{
13 {
14 private readonly bool validateServerSignature;
15
21 public LocalDestruction(EDalerUri Uri, bool ValidateServerSignature)
22 : base(Uri)
23 {
24 this.validateServerSignature = ValidateServerSignature;
25 }
26
31 protected override Task<bool> DoPrepare()
32 {
33 if (this.validateServerSignature)
34 {
35 if (!this.Uri.EDaler.Legal.Verify(this.Uri.PreSign, this.Uri.Signature) &&
36 (!string.IsNullOrEmpty(IoTGateway.Gateway.Domain) ||
37 ((this.Uri.EDaler.Server.Domain != "example.com") &&
38 (this.Uri.EDaler.Server.Domain != "example2.com") &&
39 (this.Uri.EDaler.Server.Domain != "example3.com"))))
40 {
41 this.Uri.State.Error(EDalerUriErrorType.BadRequest, "Invalid signature.", false);
42 return Task.FromResult(false);
43 }
44 }
45
46 // TODO: Check authorized to destroy eDaler.
47
48 return Task.FromResult(true);
49 }
50
55 protected override Task<bool> DoExecute()
56 {
57 return Task.FromResult(true);
58 }
59
64 protected override Task<bool> DoCommit()
65 {
66 Log.Notice(this.Uri.TotalAmount.ToString() + " " + this.Uri.Currency +
67 " eDaler destroyed.", this.Uri.To.Address, this.Uri.From.Address,
68 "eDalerDestroyed", EventLevel.Major,
69 new KeyValuePair<string, object>("Amount", this.Uri.TotalAmount),
70 new KeyValuePair<string, object>("Currency", this.Uri.Currency),
71 new KeyValuePair<string, object>("RefId", this.Uri.Id.ToString()),
72 new KeyValuePair<string, object>("Sender", this.Uri.State.Sender.Value),
73 new KeyValuePair<string, object>("From", this.Uri.From.Address.Value),
74 new KeyValuePair<string, object>("To", this.Uri.To.Address.Value),
75 new KeyValuePair<string, object>("Uri", this.Uri.UriString));
76
77 return Task.FromResult(true);
78 }
79
84 protected override Task<bool> DoRollback()
85 {
86 return Task.FromResult(true);
87 }
88
89 }
90}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static void Notice(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs a notice event.
Definition: Log.cs:450
Abstract base class for eDaler transactions.
override Task< bool > DoRollback()
Performs actual rollback.
LocalDestruction(EDalerUri Uri, bool ValidateServerSignature)
Handles the local destruction of eDaler.
override Task< bool > DoPrepare()
Performs actual preparation.
override Task< bool > DoExecute()
Performs actual execution.
override Task< bool > DoCommit()
Performs actual commit.
Abstract base class for eDaler URIs
Definition: EDalerUri.cs:20
EDalerUriState State
URI State object.
Definition: EDalerUri.cs:173
EDalerComponent EDaler
eDaler component reference
Definition: EDalerUri.cs:167
decimal TotalAmount
Total amount: Amount+AmountExtra
Definition: EDalerUri.cs:121
virtual void Error(EDalerUriErrorType ErrorType, string ErrorMessage, bool LogAsNotice)
Reports an error with the URI
EventLevel
Event level.
Definition: EventLevel.cs:7