-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added EthereumAddress payload.
- Loading branch information
Showing
10 changed files
with
116 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,14 @@ | ||
namespace QrCodes.Payloads; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class BitcoinAddress : BitcoinLikeCryptoCurrencyAddress | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="address"></param> | ||
/// <param name="amount"></param> | ||
/// <param name="label"></param> | ||
/// <param name="message"></param> | ||
public BitcoinAddress( | ||
string address, | ||
double? amount, | ||
string? label = null, | ||
string? message = null) | ||
: base( | ||
BitcoinLikeCryptoCurrencyType.Bitcoin, | ||
address, | ||
amount, | ||
label, | ||
message) { } | ||
} | ||
/// <inheritdoc /> | ||
public class BitcoinAddress( | ||
string address, | ||
double? amount = null, | ||
string? label = null, | ||
string? message = null) | ||
: BitcoinLikeCryptoCurrencyAddress( | ||
currencyType: BitcoinLikeCryptoCurrencyType.Bitcoin, | ||
address: address, | ||
amount: amount, | ||
label: label, | ||
message: message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,14 @@ | ||
namespace QrCodes.Payloads; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class BitcoinCashAddress : BitcoinLikeCryptoCurrencyAddress | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="address"></param> | ||
/// <param name="amount"></param> | ||
/// <param name="label"></param> | ||
/// <param name="message"></param> | ||
public BitcoinCashAddress( | ||
string address, | ||
double? amount, | ||
string? label = null, | ||
string? message = null) | ||
: base( | ||
BitcoinLikeCryptoCurrencyType.BitcoinCash, | ||
address, | ||
amount, | ||
label, | ||
message) { } | ||
} | ||
/// <inheritdoc /> | ||
public class BitcoinCashAddress( | ||
string address, | ||
double? amount = null, | ||
string? label = null, | ||
string? message = null) | ||
: BitcoinLikeCryptoCurrencyAddress( | ||
currencyType: BitcoinLikeCryptoCurrencyType.BitcoinCash, | ||
address: address, | ||
amount: amount, | ||
label: label, | ||
message: message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Globalization; | ||
|
||
namespace QrCodes.Payloads; | ||
|
||
/// <summary> | ||
/// Generates a Ethereum like cryptocurrency payment payload. <br/> | ||
/// A standard way of representing various transactions, especially payment requests in ether and ERC-20 tokens as URLs. <br/> | ||
/// QR Codes with this payload can open a payment app. <br/> | ||
/// According: https://github.com/ethereum/ercs/blob/master/ERCS/erc-681.md <br/> | ||
/// Example: "ethereum:0xfb6916095ca1df60bb79Ce92ce3ea74c37c5d359?value=2.014e18" <br/> | ||
/// </summary> | ||
/// <param name="address">Bitcoin like cryptocurrency address of the payment receiver</param> | ||
/// <param name="value">Amount of coins to transfer</param> | ||
public class EthereumAddress( | ||
string address, | ||
double? value = null) | ||
{ | ||
/// <inheritdoc /> | ||
public override string ToString() | ||
{ | ||
var query = string.Empty; | ||
|
||
var queryValues = new[]{ | ||
new KeyValuePair<string, string?>("value", value?.ToString("#.000e0", CultureInfo.InvariantCulture)) | ||
}; | ||
|
||
if (queryValues.Any(keyPair => !string.IsNullOrEmpty(keyPair.Value))) | ||
{ | ||
query = "?" + string.Join("&", queryValues | ||
.Where(keyPair => !string.IsNullOrEmpty(keyPair.Value)) | ||
.Select(keyPair => $"{keyPair.Key}={keyPair.Value}") | ||
.ToArray()); | ||
} | ||
|
||
return $"ethereum:{address}{query}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,14 @@ | ||
namespace QrCodes.Payloads; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class LitecoinAddress : BitcoinLikeCryptoCurrencyAddress | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="address"></param> | ||
/// <param name="amount"></param> | ||
/// <param name="label"></param> | ||
/// <param name="message"></param> | ||
public LitecoinAddress( | ||
string address, | ||
double? amount, | ||
string? label = null, | ||
string? message = null) | ||
: base( | ||
currencyType: BitcoinLikeCryptoCurrencyType.Litecoin, | ||
address: address, | ||
amount: amount, | ||
label: label, | ||
message: message) { } | ||
} | ||
/// <inheritdoc /> | ||
public class LitecoinAddress( | ||
string address, | ||
double? amount = null, | ||
string? label = null, | ||
string? message = null) | ||
: BitcoinLikeCryptoCurrencyAddress( | ||
currencyType: BitcoinLikeCryptoCurrencyType.Litecoin, | ||
address: address, | ||
amount: amount, | ||
label: label, | ||
message: message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using FluentAssertions; | ||
using QrCodes.Payloads; | ||
using Xunit; | ||
|
||
namespace QrCodes.Tests; | ||
|
||
public partial class PayloadTests | ||
{ | ||
[Fact] | ||
public void ethereum_address_generator_can_generate_address() | ||
{ | ||
new EthereumAddress( | ||
address: "0xfb6916095ca1df60bb79Ce92ce3ea74c37c5d359", | ||
value: 2014000000000000000D) | ||
.ToString() | ||
.Should().Be( | ||
"ethereum:0xfb6916095ca1df60bb79Ce92ce3ea74c37c5d359?value=2.014e18"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ public void mail_should_build_type_mailto_receiver_only() | |
var receiver = "[email protected]"; | ||
var encoding = Mail.MailEncoding.MailTo; | ||
|
||
var generator = new Mail(mailReceiver: receiver, encoding: encoding); | ||
var generator = new Mail(email: receiver, encoding: encoding); | ||
|
||
generator.ToString().Should().Be("mailto:[email protected]"); | ||
} | ||
|