[smuxi: 147/179] Engine(-Tests): support Bitcoin message patterns



commit 9469328cee27d79c00b6e89c7a4e724aa29e1816
Author: Mirco Bauer <meebey meebey net>
Date:   Sun May 21 15:46:48 2017 +0800

    Engine(-Tests): support Bitcoin message patterns

 src/Engine-Tests/MessageBuilderTests.cs     |   30 +++++++++++++++++++++++++++
 src/Engine/Config/MessageBuilderSettings.cs |   22 +++++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/src/Engine-Tests/MessageBuilderTests.cs b/src/Engine-Tests/MessageBuilderTests.cs
index 1f04985..63c591a 100644
--- a/src/Engine-Tests/MessageBuilderTests.cs
+++ b/src/Engine-Tests/MessageBuilderTests.cs
@@ -719,5 +719,35 @@ namespace Smuxi.Engine
             builder.Append(new UrlMessagePartModel("http://[2a01:4f8:a0:7041::2]/";));
             TestMessage("http://[2a01:4f8:a0:7041::2]/";, builder.ToMessage());
         }
+
+        [Test]
+        public void AppendMessageWithBitcoinTxHash()
+        {
+            var msg = "foo bc4c50f4bcacf990804e2dbc0049ff04eb1500acd535a20f8adf24212f333ed8 bar";
+            var builder = new MessageBuilder();
+            builder.TimeStamp = DateTime.MinValue;
+            builder.Append(new TextMessagePartModel("foo "));
+            builder.Append(
+                new UrlMessagePartModel(
+                    
"https://blockchain.info/tx/bc4c50f4bcacf990804e2dbc0049ff04eb1500acd535a20f8adf24212f333ed8";,
+                    "bc4c50f4bcacf990804e2dbc0049ff04eb1500acd535a20f8adf24212f333ed8"
+                )
+            );
+            builder.Append(new TextMessagePartModel(" bar"));
+            TestMessage(msg, builder.ToMessage());
+
+            msg = "foo (bc4c50f4bcacf990804e2dbc0049ff04eb1500acd535a20f8adf24212f333ed8) bar";
+            builder = new MessageBuilder();
+            builder.TimeStamp = DateTime.MinValue;
+            builder.Append(new TextMessagePartModel("foo ("));
+            builder.Append(
+                new UrlMessagePartModel(
+                    
"https://blockchain.info/tx/bc4c50f4bcacf990804e2dbc0049ff04eb1500acd535a20f8adf24212f333ed8";,
+                    "bc4c50f4bcacf990804e2dbc0049ff04eb1500acd535a20f8adf24212f333ed8"
+                )
+            );
+            builder.Append(new TextMessagePartModel(") bar"));
+            TestMessage(msg, builder.ToMessage());
+        }
     }
 }
diff --git a/src/Engine/Config/MessageBuilderSettings.cs b/src/Engine/Config/MessageBuilderSettings.cs
index 7177d99..05590d4 100644
--- a/src/Engine/Config/MessageBuilderSettings.cs
+++ b/src/Engine/Config/MessageBuilderSettings.cs
@@ -124,6 +124,28 @@ namespace Smuxi.Engine
                 LinkFormat = "mailto:{1}";
             });
 
+            // bitcoin address
+            var bitcoin_address = @"[13][a-km-zA-HJ-NP-Z1-9]{25,34}";
+            var query = @"(\?[" + path_chars + @"]+)?";
+            var bitcoin_address_query = bitcoin_address + query;
+            regex = new Regex(
+                @"(?:bitcoin:)?(" + bitcoin_address_query + @")",
+                RegexOptions.IgnoreCase | RegexOptions.Compiled
+            );
+            BuiltinPatterns.Add(new MessagePatternModel(regex) {
+                LinkFormat = "bitcoin:{1}"
+            });
+
+            // bitcoin tx hash
+            var bitcoin_tx_hash = @"[a-fA-F0-9]{64}";
+            regex = new Regex(
+                start_delimiter + @"(" + bitcoin_tx_hash + @")" + end_delimiter,
+                RegexOptions.IgnoreCase | RegexOptions.Compiled
+            );
+            BuiltinPatterns.Add(new MessagePatternModel(regex) {
+                LinkFormat = "https://blockchain.info/tx/{1}";
+            });
+
             // addresses without protocol (heuristical)
             // include well known TLDs to prevent autogen.sh, configure.ac or
             // Gst.Buffer.Unref() from matching


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]