public void CanParsePaymentUrl() { Assert.Equal("bitcoin:", new BitcoinUrlBuilder().Uri.ToString()); var url = CreateBuilder("bitcoin:129mVqKUmJ9uwPxKJBnNdABbuaaNfho4Ha"); Assert.Equal("129mVqKUmJ9uwPxKJBnNdABbuaaNfho4Ha", url.Address.ToString()); url = CreateBuilder("bitcoin:129mVqKUmJ9uwPxKJBnNdABbuaaNfho4Ha?amount=0.06"); Assert.Equal("129mVqKUmJ9uwPxKJBnNdABbuaaNfho4Ha", url.Address.ToString()); Assert.Equal(Money.Parse("0.06"), url.Amount); url = new BitcoinUrlBuilder("bitcoin:129mVqKUmJ9uwPxKJBnNdABbuaaNfho4Ha?amount=0.06&label=Tom%20%26%20Jerry"); Assert.Equal("129mVqKUmJ9uwPxKJBnNdABbuaaNfho4Ha", url.Address.ToString()); Assert.Equal(Money.Parse("0.06"), url.Amount); Assert.Equal("Tom & Jerry", url.Label); Assert.Equal(url.ToString(), new BitcoinUrlBuilder(url.ToString()).ToString()); //Request 50 BTC with message: url = new BitcoinUrlBuilder("bitcoin:129mVqKUmJ9uwPxKJBnNdABbuaaNfho4Ha?amount=50&label=Luke-Jr&message=Donation%20for%20project%20xyz"); Assert.Equal(Money.Parse("50"), url.Amount); Assert.Equal("Luke-Jr", url.Label); Assert.Equal("Donation for project xyz", url.Message); Assert.Equal(url.ToString(), new BitcoinUrlBuilder(url.ToString()).ToString()); //Some future version that has variables which are (currently) not understood and required and thus invalid: url = new BitcoinUrlBuilder("bitcoin:129mVqKUmJ9uwPxKJBnNdABbuaaNfho4Ha?amount=50&label=Luke-Jr&message=Donation%20for%20project%20xyz&unknownparam=lol"); //Some future version that has variables which are (currently) not understood but not required and thus valid: Assert.Throws <FormatException>(() => new BitcoinUrlBuilder("bitcoin:129mVqKUmJ9uwPxKJBnNdABbuaaNfho4Ha?amount=50&label=Luke-Jr&message=Donation%20for%20project%20xyz&req-unknownparam=lol")); Assert.Throws <FormatException>(() => new BitcoinUrlBuilder("bitcoin:129mVqKUmJ9uwPxKJBnNdABbuaaNfho4Ha?amount=50&amount=50")); url = new BitcoinUrlBuilder("bitcoin:mq7se9wy2egettFxPbmn99cK8v5AFq55Lx?amount=0.11&r=https://merchant.com/pay.php?h%3D2a8628fc2fbe"); Assert.Equal("bitcoin:mq7se9wy2egettFxPbmn99cK8v5AFq55Lx?amount=0.11&r=https://merchant.com/pay.php?h%3d2a8628fc2fbe", url.ToString()); #pragma warning disable CS0618 // Type or member is obsolete Assert.Equal("https://merchant.com/pay.php?h=2a8628fc2fbe", url.PaymentRequestUrl.ToString()); #pragma warning restore CS0618 // Type or member is obsolete Assert.Equal(url.ToString(), new BitcoinUrlBuilder(url.ToString()).ToString()); //Support no address url = new BitcoinUrlBuilder("bitcoin:?r=https://merchant.com/pay.php?h%3D2a8628fc2fbe"); #pragma warning disable CS0618 // Type or member is obsolete Assert.Equal("https://merchant.com/pay.php?h=2a8628fc2fbe", url.PaymentRequestUrl.ToString()); #pragma warning restore CS0618 // Type or member is obsolete Assert.Equal(url.ToString(), new BitcoinUrlBuilder(url.ToString()).ToString()); }
private BitcoinUrlBuilder CreateBuilder(string uri) { var builder = new BitcoinUrlBuilder(uri); Assert.Equal(builder.Uri.ToString(), uri); builder = new BitcoinUrlBuilder(new Uri(uri, UriKind.Absolute)); Assert.Equal(builder.ToString(), uri); return(builder); }
internal bool HandleScan(string scannedIn) { BitcoinAddress address = null; try { address = BitcoinAddress.Create(scannedIn, Global.Network); } catch (Exception) { try { address = new BitcoinUrlBuilder(scannedIn, Global.Network).Address; } catch (Exception) { } } if (address != null) { Address = address.ToString(); return(true); } return(false); }
public override string ToString() { return(_bitcoinUrl.ToString()); }