NetworkList;
38 | Network network;
39 | string selectedNetwork;
40 |
41 | protected override async Task OnInitializedAsync()
42 | {
43 | NetworkList = Networks.NetworkItems.Keys.ToList();
44 | }
45 |
46 |
47 |
48 | private void ParseTransaction()
49 | {
50 | if (string.IsNullOrEmpty(TransactionHex))
51 | {
52 | error = "set trx hex";
53 | return;
54 | }
55 |
56 | network = Networks.NetworkItems[selectedNetwork];
57 |
58 | var trx = network.Consensus.ConsensusFactory.CreateTransaction(TransactionHex);
59 |
60 | var parsed = new TransactionVerboseModel(trx, network);
61 | Result = JsonSerializer.Serialize(parsed, new JsonSerializerOptions { WriteIndented = true, });
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/Blockcore.AtomicSwaps.BlockcoreWallet/BlockcoreWallet.razor:
--------------------------------------------------------------------------------
1 | @page "/blockcorewallet"
2 | @using Microsoft.JSInterop
3 | @inject IJSRuntime JSRuntime;
4 |
5 | Blockcore Wallet
6 |
7 | Blockcore Wallet!
8 | @if (!HasBlockcoreWallet)
9 | {
10 | No Blockcore Wallet detected. Please install Blockcore Wallet .
11 | }
12 | else
13 | {
14 | SignMessage("message"))">Ask for Signing (Message)
15 |
16 |
19 |
20 |
21 |
22 | SignMessageAnyAccount("message"))">Signing (text)
23 |
24 |
27 |
28 |
29 |
30 | SignMessageAnyAccountJson("{ \"id\": 5, \"text\": \"Hello World\" }"))">Signing (Json)
31 |
32 |
35 |
36 |
37 |
38 | PaymentRequest("BTC","2"))">Payment Request
39 |
40 |
43 |
44 |
45 |
46 | DIDSupportedMethods())">Supported DID Methods
47 |
48 |
51 |
52 |
53 |
54 | DIDRequest(@arr))">Select DID Request
55 |
56 |
59 |
60 |
61 |
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/dapp-wasm/Pages/SignMessage.razor:
--------------------------------------------------------------------------------
1 | @page "/signmessage"
2 | @using Blockcore.Networks
3 |
4 | Message Signing
5 |
6 | Message Signing
7 |
8 | Private key
9 |
10 |
11 |
12 | public key : @pubkey
13 | Address : @Address
14 |
15 | Data to sign
16 |
17 |
18 |
19 | Sign Message
20 |
21 | Payload
22 |
23 |
24 |
25 | VerifyMessage
26 |
27 | Result : @Result
28 |
29 |
30 | @code {
31 | public string WalletWords { get; set; } = string.Empty;
32 |
33 | public string SignData { get; set; } = string.Empty;
34 |
35 | public string Payload { get; set; } = string.Empty;
36 | public string Address { get; set; } = string.Empty;
37 | public string pubkey { get; set; } = string.Empty;
38 |
39 | public string Result { get; set; } = string.Empty;
40 |
41 | private int currentCount = 0;
42 |
43 | NBitcoin.Key key;
44 | Network network;
45 |
46 | protected override async Task OnInitializedAsync()
47 | {
48 | key = new NBitcoin.Key();
49 | network = Blockcore.Networks.Networks.Bitcoin.Mainnet();
50 |
51 | WalletWords = key.ToString(network);
52 | Address = key.PubKey.GetAddress(network).ToString();
53 | pubkey = key.PubKey.ToHex();
54 | }
55 |
56 | private void Sign()
57 | {
58 | Payload = key.SignMessage(SignData);
59 | }
60 |
61 | private void Verify()
62 | {
63 | var success = key.PubKey.VerifyMessage(SignData, Payload);
64 |
65 | Result = success.ToString();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/dapp-wasm/Data/BtcDecimalJsonConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using Newtonsoft.Json;
4 |
5 | namespace Blockcore.Controllers.Converters
6 | {
7 | ///
8 | /// Converts a decimal value to a string with the minimum number of decimals used by bitcoin (8).
9 | ///
10 | public class BtcDecimalJsonConverter : JsonConverter
11 | {
12 | private const int MinDecimals = 8;
13 |
14 | ///
15 | /// Method for writing a string formatted decimal to Json that truncates at decimal points.
16 | /// A instance.
17 | /// The value to be written.
18 | /// A instance.
19 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
20 | {
21 | decimal btcDecimal = (decimal)value;
22 | string result = btcDecimal.ToString(CultureInfo.InvariantCulture);
23 | if (!result.Contains('.') || result.Split('.')[1].Length < MinDecimals)
24 | {
25 | result = btcDecimal.ToString("0." + new string('0', MinDecimals), CultureInfo.InvariantCulture);
26 | }
27 |
28 | writer.WriteRawValue(result);
29 | }
30 |
31 | ///
32 | /// A method for reading a string formatted decimal in Json that was truncated at decimals.
33 | ///
34 | /// Not implemented.
35 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
36 | JsonSerializer serializer)
37 | {
38 | throw new NotImplementedException();
39 | }
40 |
41 | public override bool CanRead => false;
42 |
43 | public override bool CanConvert(Type objectType) => objectType == typeof(decimal);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/dapp-wasm/Pages/FetchData.razor:
--------------------------------------------------------------------------------
1 | @page "/fetchdata"
2 | @using Blockcore.Consensus.BlockInfo
3 | @using Blockcore.Networks
4 | @using Data
5 | @inject HttpClient Http
6 |
7 | Fetch block
8 |
9 | Fetch block
10 |
11 |
12 |
13 | This component demonstrates fetching data from the server.
14 |
15 | Link to an indexer.
16 |
17 |
18 |
19 | block height.
20 |
25 |
26 |
27 | Fetch block
28 |
29 |
30 | @if (block != null)
31 | {
32 |
33 | block hash: @blockData.blockHash
34 | block HashMerkleRoot: @block.Header.HashMerkleRoot.ToString()
35 | block Bits: @block.Header.Bits.ToString()
36 | block Version: @block.Header.Version.ToString()
37 |
38 | foreach (var trx in block.Transactions)
39 | {
40 | trx hash: @trx.GetHash().ToString()
41 | }
42 | }
43 |
44 | @code {
45 | private bool busy = false;
46 | private BlockData? blockData;
47 | public string link { get; set; } = string.Empty;
48 | public int blockheight;
49 | public Block block;
50 | Network network;
51 |
52 | private async Task Fetch()
53 | {
54 | if (busy) return;
55 | busy = true;
56 | try
57 | {
58 | blockData = await Http.GetFromJsonAsync(link + "api/query/block/index/" + blockheight);
59 |
60 | var blockhex = await Http.GetStringAsync(link + "api/query/block/" + blockData.blockHash + "/hex");
61 |
62 | block = Block.Parse(blockhex, network.Consensus.ConsensusFactory);
63 | }
64 | finally
65 | {
66 | busy = false;
67 | }
68 | }
69 |
70 | protected override async Task OnInitializedAsync()
71 | {
72 | network = Blockcore.Networks.Networks.Bitcoin.Mainnet();
73 |
74 | link = "https://btc.indexer.coinvault.io/";
75 |
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/dapp-wasm/Shared/NavMenu.razor:
--------------------------------------------------------------------------------
1 |
9 |
10 |
44 |
45 | @code {
46 | private bool collapseNavMenu = true;
47 |
48 | private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;
49 |
50 | private void ToggleNavMenu()
51 | {
52 | collapseNavMenu = !collapseNavMenu;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/Blockcore.MetaMask/IMetaMaskService.cs:
--------------------------------------------------------------------------------
1 | using Blockcore.AtomicSwaps.MetaMask.Enums;
2 | using Blockcore.AtomicSwaps.MetaMask.Extensions;
3 | using Microsoft.JSInterop;
4 | using System;
5 | using System.Numerics;
6 | using System.Threading.Tasks;
7 |
8 | namespace Blockcore.AtomicSwaps.MetaMask
9 | {
10 | public interface IMetaMaskService
11 | {
12 | public static event Func? AccountChangedEvent;
13 | public static event Func<(long, Chain), Task>? ChainChangedEvent;
14 |
15 | ValueTask ConnectMetaMask();
16 | ValueTask DisposeAsync();
17 | ValueTask GenericRpc(string method, params dynamic[]? args);
18 | Task GetBalance(string address, string block = "latest");
19 | ValueTask GetSelectedAddress();
20 | ValueTask<(long chainId, Chain chain)> GetSelectedChain();
21 | ValueTask GetTransactionCount();
22 | ValueTask HasMetaMask();
23 | ValueTask IsSiteConnected();
24 | ValueTask ListenToEvents();
25 | ValueTask LoadScripts(IJSRuntime jsRuntime);
26 | Task RequestAccounts();
27 | ValueTask SendTransaction(string to, BigInteger weiValue, string? data = null);
28 | ValueTask SignTypedData(string label, string value);
29 | ValueTask SignTypedDataV4(string typedData);
30 |
31 | [JSInvokable()]
32 | static async Task OnAccountsChanged(string selectedAccount)
33 | {
34 | if (AccountChangedEvent != null)
35 | {
36 | await AccountChangedEvent.Invoke(selectedAccount);
37 | }
38 | }
39 |
40 | [JSInvokable()]
41 | static async Task OnChainChanged(string chainhex)
42 | {
43 | if (ChainChangedEvent != null)
44 | {
45 | await ChainChangedEvent.Invoke(ChainHexToChainResponse(chainhex));
46 | }
47 | }
48 |
49 | protected static (long chainId, Chain chain) ChainHexToChainResponse(string chainHex)
50 | {
51 | long chainId = chainHex.HexToInt();
52 | return (chainId, (Chain)chainId);
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/Blockcore.AtomicSwaps.BlockcoreDns/BlockcoreDns.razor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 | using Blockcore.AtomicSwaps.BlockcoreDns.Models;
5 | using Microsoft.AspNetCore.Components;
6 |
7 | namespace Blockcore.AtomicSwaps.BlockcoreDns
8 | {
9 | public partial class BlockcoreDns : IDisposable
10 | {
11 | private bool disposedValue;
12 | [Inject]
13 | public IBlockcoreDnsService blockcoreDnsService { get; set; } = default!;
14 | public string? blockcoreDnsUrl { get; set; }
15 | public string? network { get; set; }
16 | public string? type { get; set; }
17 | public string textColor { get; set; } = "text-success";
18 |
19 | public IList services { get; set; }
20 |
21 | protected override Task OnInitializedAsync()
22 | {
23 | blockcoreDnsUrl = blockcoreDnsService.GetDnsServiceUrl();
24 | return Task.CompletedTask;
25 | }
26 |
27 | public async Task GetServicesByNetwork()
28 | {
29 | services = await blockcoreDnsService.GetServicesByNetwork(network);
30 | }
31 |
32 | public async Task GetServicesByType()
33 | {
34 | services = await blockcoreDnsService.GetServicesByType(type);
35 | }
36 |
37 | public async Task GetServicesByTypeAndNetwork()
38 | {
39 | services = await blockcoreDnsService.GetServicesByTypeAndNetwork(type,network);
40 | }
41 |
42 | protected virtual void Dispose(bool disposing)
43 | {
44 | if (!disposedValue)
45 | {
46 | if (disposing)
47 | {
48 | // TODO: dispose managed state (managed objects)
49 | }
50 |
51 | // TODO: free unmanaged resources (unmanaged objects) and override finalizer
52 | // TODO: set large fields to null
53 | disposedValue = true;
54 | }
55 | }
56 |
57 | public void Dispose()
58 | {
59 | // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
60 | Dispose(disposing: true);
61 | GC.SuppressFinalize(this);
62 | }
63 | }
64 |
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/Blockcore.MetaMask/Metamask.razor:
--------------------------------------------------------------------------------
1 | @page "/metamask"
2 | @using Nethereum.Signer
3 |
4 | MetaMask
5 |
6 | MetaMask
7 |
8 | @if (!HasMetaMask)
9 | {
10 | No MetaMask detected. Please install MetaMask .
11 | }
12 | else if (string.IsNullOrEmpty(SelectedAddress))
13 | {
14 | Initialize connection with MetaMask
15 |
16 |
17 | }
18 | else
19 | {
20 | Get Selected Address
21 |
22 | @SelectedAddress
23 |
24 |
25 | Get Selected Chain
26 |
27 | @SelectedChain
28 |
29 |
30 | Get Transaction Count
31 |
32 | @TransactionCount
33 |
34 |
35 | SignData("label", "value"))">Sign Data
36 |
37 | @SignedData
38 |
39 |
40 | SignDataV4())">Sign Data V4
41 |
42 | @SignedDataV4
43 |
44 |
45 |
46 |
47 | Generic RPC call examle
48 | Get Balance examle
49 |
50 |
51 | @RpcResult
52 |
53 |
54 | Kovan testnet only:
55 | Interact with a smart contract. These two example smart contracts are only deployed to the Kovan testnet. Make sure to select Kovan in MetaMask
56 |
57 | @if (Chain == Blockcore.AtomicSwaps.MetaMask.Enums.Chain.Kovan)
58 | {
59 | CallSmartContractFunctionExample1())">Call a Smart Contract function
60 |
61 | CallSmartContractFunctionExample2())">Call a Smart Contract example 2
62 |
63 |
64 | @FunctionResult
65 |
66 | }
67 | else
68 | {
69 | Please switch to Kovan testnet!
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes recent versions of Safari, Chrome (including
12 | * Opera), Edge on the desktop, and iOS and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/guide/browser-support
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /**
22 | * By default, zone.js will patch all possible macroTask and DomEvents
23 | * user can disable parts of macroTask/DomEvents patch by setting following flags
24 | * because those flags need to be set before `zone.js` being loaded, and webpack
25 | * will put import in the top of bundle, so user need to create a separate file
26 | * in this directory (for example: zone-flags.ts), and put the following flags
27 | * into that file, and then add the following code before importing zone.js.
28 | * import './zone-flags';
29 | *
30 | * The flags allowed in zone-flags.ts are listed here.
31 | *
32 | * The following flags will work for all browsers.
33 | *
34 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
35 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
36 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
37 | *
38 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
39 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
40 | *
41 | * (window as any).__Zone_enable_cross_context_check = true;
42 | *
43 | */
44 |
45 | /***************************************************************************************************
46 | * Zone JS is required by default for Angular itself.
47 | */
48 | import 'zone.js'; // Included with Angular CLI.
49 |
50 |
51 | /***************************************************************************************************
52 | * APPLICATION IMPORTS
53 | */
54 |
55 |
56 | // Needed for BIP39 and likely more.
57 | (window as any)['global'] = window;
58 |
59 | import * as buffer from 'buffer';
60 | (window as any).Buffer = buffer.Buffer;
61 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/dapp-wasm.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.4.33110.190
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dapp-wasm", "dapp-wasm\dapp-wasm.csproj", "{791D7A5E-0A39-49E0-BABA-E11A6581FCFF}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.MetaMask", "Blockcore.MetaMask\Blockcore.MetaMask.csproj", "{E959D45D-6931-4977-89A7-60BF2FDDE18D}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.AtomicSwaps.BlockcoreDns", "Blockcore.AtomicSwaps.BlockcoreDns\Blockcore.AtomicSwaps.BlockcoreDns.csproj", "{6E5116F7-7A42-45C8-A389-6BD7DBBEF052}"
11 | EndProject
12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.AtomicSwaps.BlockcoreWallet", "Blockcore.AtomicSwaps.BlockcoreWallet\Blockcore.AtomicSwaps.BlockcoreWallet.csproj", "{602033E1-57C3-458F-BC2C-B0B1E88A91E7}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {791D7A5E-0A39-49E0-BABA-E11A6581FCFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {791D7A5E-0A39-49E0-BABA-E11A6581FCFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {791D7A5E-0A39-49E0-BABA-E11A6581FCFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {791D7A5E-0A39-49E0-BABA-E11A6581FCFF}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {E959D45D-6931-4977-89A7-60BF2FDDE18D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {E959D45D-6931-4977-89A7-60BF2FDDE18D}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {E959D45D-6931-4977-89A7-60BF2FDDE18D}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {E959D45D-6931-4977-89A7-60BF2FDDE18D}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {6E5116F7-7A42-45C8-A389-6BD7DBBEF052}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {6E5116F7-7A42-45C8-A389-6BD7DBBEF052}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {6E5116F7-7A42-45C8-A389-6BD7DBBEF052}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {6E5116F7-7A42-45C8-A389-6BD7DBBEF052}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {602033E1-57C3-458F-BC2C-B0B1E88A91E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {602033E1-57C3-458F-BC2C-B0B1E88A91E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {602033E1-57C3-458F-BC2C-B0B1E88A91E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {602033E1-57C3-458F-BC2C-B0B1E88A91E7}.Release|Any CPU.Build.0 = Release|Any CPU
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | GlobalSection(ExtensibilityGlobals) = postSolution
41 | SolutionGuid = {A87AE351-CD8C-43F7-A8F8-F88181F0352E}
42 | EndGlobalSection
43 | EndGlobal
44 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/Blockcore.AtomicSwaps.BlockcoreWallet/BlockcoreWallet.razor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Blockcore.AtomicSwaps.BlockcoreWallet;
4 | using Blockcore.AtomicSwaps.BlockcoreWallet.Exceptions;
5 | using Microsoft.AspNetCore.Components;
6 |
7 |
8 | namespace Blockcore.AtomicSwaps.BlockcoreWallet
9 | {
10 |
11 | public partial class BlockcoreWallet : IDisposable
12 | {
13 | private bool disposedValue;
14 |
15 | [Inject]
16 | public IBlockcoreWalletConnector BlockcoreWalletConnector { get; set; } = default!;
17 | public bool HasBlockcoreWallet { get; set; }
18 | string[] arr = new string[] { };
19 |
20 | public string? SignedMessage { get; set; }
21 | public string? SignedMessageAnyAccount { get; set; }
22 | public string? SignedMessageAnyAccountJson { get; set; }
23 | public string? PaymentRequestResult { get; set; }
24 | public string? DIDSupportedMethodsResult { get; set; }
25 | public string? DIDRequestResult { get; set; }
26 |
27 | protected override async Task OnInitializedAsync()
28 | {
29 | HasBlockcoreWallet = await BlockcoreWalletConnector.HasBlockcoreWallet();
30 | }
31 |
32 | public async Task SignMessageAnyAccount(string value)
33 | {
34 | var result = await BlockcoreWalletConnector.SignMessageAnyAccount(value);
35 | SignedMessageAnyAccount = $"Signed: {result}";
36 | }
37 |
38 | public async Task SignMessageAnyAccountJson(string value)
39 | {
40 | var result = await BlockcoreWalletConnector.SignMessageAnyAccountJson(value);
41 | SignedMessageAnyAccountJson = $"Signed: {result}";
42 | }
43 |
44 | public async Task PaymentRequest(string network, string amount)
45 | {
46 | var result = await BlockcoreWalletConnector.PaymentRequest(network, amount);
47 | PaymentRequestResult = $"{result}";
48 | }
49 |
50 | public async Task DIDSupportedMethods()
51 | {
52 | var result = await BlockcoreWalletConnector.DIDSupportedMethods();
53 | DIDSupportedMethodsResult = $"{result}";
54 | }
55 |
56 | public async Task DIDRequest(string[] methods)
57 | {
58 | var result = await BlockcoreWalletConnector.DIDRequest(methods);
59 | DIDRequestResult = $"{result}";
60 | }
61 |
62 | public async Task SignMessage(string message)
63 | {
64 | try
65 | {
66 | var result = await BlockcoreWalletConnector.SignMessage(message);
67 | SignedMessage = $"Signed: {result}";
68 | }
69 | catch (UserDeniedException)
70 | {
71 | SignedMessage = "User Denied";
72 | }
73 | catch (Exception ex)
74 | {
75 | SignedMessage = $"Exception: {ex}";
76 | }
77 | }
78 |
79 |
80 |
81 |
82 | protected virtual void Dispose(bool disposing)
83 | {
84 | if (!disposedValue)
85 | {
86 | if (disposing)
87 | {
88 | // TODO: dispose managed state (managed objects)
89 | }
90 |
91 | // TODO: free unmanaged resources (unmanaged objects) and override finalizer
92 | // TODO: set large fields to null
93 | disposedValue = true;
94 | }
95 | }
96 |
97 |
98 |
99 | public void Dispose()
100 | {
101 | // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
102 | Dispose(disposing: true);
103 | GC.SuppressFinalize(this);
104 | }
105 | }
106 |
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/dapp-wasm/wwwroot/css/open-iconic/README.md:
--------------------------------------------------------------------------------
1 | [Open Iconic v1.1.1](https://github.com/iconic/open-iconic)
2 | ===========
3 |
4 | ### Open Iconic is the open source sibling of [Iconic](https://github.com/iconic/open-iconic). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](https://github.com/iconic/open-iconic)
5 |
6 |
7 |
8 | ## What's in Open Iconic?
9 |
10 | * 223 icons designed to be legible down to 8 pixels
11 | * Super-light SVG files - 61.8 for the entire set
12 | * SVG sprite—the modern replacement for icon fonts
13 | * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats
14 | * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats
15 | * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px.
16 |
17 |
18 | ## Getting Started
19 |
20 | #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](https://github.com/iconic/open-iconic) and [Reference](https://github.com/iconic/open-iconic) sections.
21 |
22 | ### General Usage
23 |
24 | #### Using Open Iconic's SVGs
25 |
26 | We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute).
27 |
28 | ```
29 |
30 | ```
31 |
32 | #### Using Open Iconic's SVG Sprite
33 |
34 | Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack.
35 |
36 | Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `` *tag and a unique class name for each different icon in the* `` *tag.*
37 |
38 | ```
39 |
40 |
41 |
42 | ```
43 |
44 | Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `` tag with equal width and height dimensions.
45 |
46 | ```
47 | .icon {
48 | width: 16px;
49 | height: 16px;
50 | }
51 | ```
52 |
53 | Coloring icons is even easier. All you need to do is set the `fill` rule on the `` tag.
54 |
55 | ```
56 | .icon-account-login {
57 | fill: #f00;
58 | }
59 | ```
60 |
61 | To learn more about SVG Sprites, read [Chris Coyier's guide](http://css-tricks.com/svg-sprites-use-better-icon-fonts/).
62 |
63 | #### Using Open Iconic's Icon Font...
64 |
65 |
66 | ##### …with Bootstrap
67 |
68 | You can find our Bootstrap stylesheets in `font/css/open-iconic-bootstrap.{css, less, scss, styl}`
69 |
70 |
71 | ```
72 |
73 | ```
74 |
75 |
76 | ```
77 |
78 | ```
79 |
80 | ##### …with Foundation
81 |
82 | You can find our Foundation stylesheets in `font/css/open-iconic-foundation.{css, less, scss, styl}`
83 |
84 | ```
85 |
86 | ```
87 |
88 |
89 | ```
90 |
91 | ```
92 |
93 | ##### …on its own
94 |
95 | You can find our default stylesheets in `font/css/open-iconic.{css, less, scss, styl}`
96 |
97 | ```
98 |
99 | ```
100 |
101 | ```
102 |
103 | ```
104 |
105 |
106 | ## License
107 |
108 | ### Icons
109 |
110 | All code (including SVG markup) is under the [MIT License](http://opensource.org/licenses/MIT).
111 |
112 | ### Fonts
113 |
114 | All fonts are under the [SIL Licensed](http://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web).
115 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/dapp-wasm/wwwroot/css/app.css:
--------------------------------------------------------------------------------
1 | @import url('open-iconic/font/css/open-iconic-bootstrap.min.css');
2 |
3 | html, body {
4 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
5 | }
6 |
7 | h1:focus {
8 | outline: none;
9 | }
10 |
11 | a, .btn-link {
12 | color: #0071c1;
13 | }
14 |
15 | .btn-primary {
16 | color: #fff;
17 | background-color: #1b6ec2;
18 | border-color: #1861ac;
19 | }
20 |
21 | .btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
22 | box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
23 | }
24 |
25 | .content {
26 | padding-top: 1.1rem;
27 | }
28 |
29 | .valid.modified:not([type=checkbox]) {
30 | outline: 1px solid #26b050;
31 | }
32 |
33 | .invalid {
34 | outline: 1px solid red;
35 | }
36 |
37 | .validation-message {
38 | color: red;
39 | }
40 |
41 | #blazor-error-ui {
42 | background: lightyellow;
43 | bottom: 0;
44 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
45 | display: none;
46 | left: 0;
47 | padding: 0.6rem 1.25rem 0.7rem 1.25rem;
48 | position: fixed;
49 | width: 100%;
50 | z-index: 1000;
51 | }
52 |
53 | #blazor-error-ui .dismiss {
54 | cursor: pointer;
55 | position: absolute;
56 | right: 0.75rem;
57 | top: 0.5rem;
58 | }
59 |
60 | .blazor-error-boundary {
61 | background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
62 | padding: 1rem 1rem 1rem 3.7rem;
63 | color: white;
64 | }
65 |
66 | .blazor-error-boundary::after {
67 | content: "An error has occurred."
68 | }
69 |
70 | .loading-progress {
71 | position: relative;
72 | display: block;
73 | width: 8rem;
74 | height: 8rem;
75 | margin: 20vh auto 1rem auto;
76 | }
77 |
78 | .loading-progress circle {
79 | fill: none;
80 | stroke: #e0e0e0;
81 | stroke-width: 0.6rem;
82 | transform-origin: 50% 50%;
83 | transform: rotate(-90deg);
84 | }
85 |
86 | .loading-progress circle:last-child {
87 | stroke: #1b6ec2;
88 | stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
89 | transition: stroke-dasharray 0.05s ease-in-out;
90 | }
91 |
92 | .loading-progress-text {
93 | position: absolute;
94 | text-align: center;
95 | font-weight: bold;
96 | inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
97 | }
98 |
99 | .loading-progress-text:after {
100 | content: var(--blazor-load-percentage-text, "Loading");
101 | }
102 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/Blockcore.MetaMask/Extensions/SendTransactionExtensions.cs:
--------------------------------------------------------------------------------
1 | using Nethereum.ABI.FunctionEncoding;
2 | using Nethereum.ABI.Model;
3 | using Nethereum.JsonRpc.Client;
4 | using Nethereum.RPC.Eth.DTOs;
5 | using Nethereum.RPC.Eth.Transactions;
6 | using System.Numerics;
7 | using System.Threading.Tasks;
8 |
9 | namespace Blockcore.AtomicSwaps.MetaMask
10 | {
11 | public static class SendTransactionExtensions
12 | {
13 | private static async Task CallFunction(IMetaMaskService metaMask, string funcName, string contractAddress, BigInteger valueInWei, Parameter[] paramaters, params object[] values)
14 | {
15 | FunctionABI function = new FunctionABI(funcName, false);
16 |
17 | function.InputParameters = paramaters;
18 | var functionCallEncoder = new FunctionCallEncoder();
19 |
20 | var data = functionCallEncoder.EncodeRequest(function.Sha3Signature, paramaters,
21 | values);
22 |
23 | data = data[2..];
24 | var result = await metaMask.SendTransaction(contractAddress, valueInWei, data);
25 |
26 | return result;
27 | }
28 |
29 | private static async Task GetTransactionReceipt(string txHash, IClient client, int interval = 1000)
30 | {
31 | EthGetTransactionReceipt getTransactionReceipt = new EthGetTransactionReceipt(client);
32 | TransactionReceipt? receipt = null;
33 | while (receipt == null)
34 | {
35 | receipt = await getTransactionReceipt.SendRequestAsync(txHash);
36 | await Task.Delay(interval);
37 | }
38 | return receipt;
39 | }
40 |
41 | ///
42 | /// Send transaction to smart contract and wait for receipt
43 | ///
44 | /// Web3 Client
45 | /// Function To Call
46 | /// Smart Contract Address
47 | /// Value In Wei
48 | /// Function Parameters
49 | /// Function Values
50 | /// Receipt Of Transaction
51 | public static async Task SendTransactionAndWaitForReceipt
52 | (
53 | this IMetaMaskService metaMask,
54 | IClient client,
55 | string funcName,
56 | string contractAddress,
57 | BigInteger value,
58 | Parameter[] inputParams,
59 | params object[] values
60 | )
61 | {
62 | var txHash = await CallFunction(metaMask, funcName, contractAddress, value, inputParams, values);
63 | var receipt = await GetTransactionReceipt(txHash, client);
64 | return receipt;
65 | }
66 |
67 | ///
68 | /// Send transaction to smart contract and wait for receipt
69 | ///
70 | /// Web3 Client
71 | /// Function To Call
72 | /// Smart Contract Address
73 | /// Value In Wei
74 | /// Function Parameters
75 | /// Function Values
76 | /// The interval at which we check for a transaction receipt
77 | /// Receipt Of Transaction
78 | public static async Task SendTransactionAndWaitForReceipt
79 | (
80 | this IMetaMaskService metaMask,
81 | IClient client,
82 | string funcName,
83 | string contractAddress,
84 | BigInteger value,
85 | Parameter[] inputParams,
86 | int interval = 1000,
87 | params object[] values
88 | )
89 | {
90 | var txHash = await CallFunction(metaMask, funcName, contractAddress, value, inputParams, values);
91 | return await GetTransactionReceipt(txHash, client, interval);
92 | }
93 | }
94 | }
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "dapp-sample": {
7 | "projectType": "application",
8 | "schematics": {
9 | "@schematics/angular:component": {
10 | "style": "scss"
11 | }
12 | },
13 | "root": "",
14 | "sourceRoot": "src",
15 | "prefix": "app",
16 | "architect": {
17 | "build": {
18 | "builder": "@angular-builders/custom-webpack:browser",
19 | "options": {
20 | "customWebpackConfig": {
21 | "path": "./src/webpack.config.js",
22 | "mergeRules": {
23 | "externals": "replace"
24 | }
25 | },
26 | "outputPath": "dist/dapp-sample",
27 | "index": "src/index.html",
28 | "main": "src/main.ts",
29 | "polyfills": "src/polyfills.ts",
30 | "tsConfig": "tsconfig.app.json",
31 | "inlineStyleLanguage": "scss",
32 | "assets": [
33 | "src/favicon.ico",
34 | "src/assets"
35 | ],
36 | "styles": [
37 | "./node_modules/@angular/material/prebuilt-themes/pink-bluegrey.css",
38 | "src/styles.scss"
39 | ],
40 | "scripts": []
41 | },
42 | "configurations": {
43 | "production": {
44 | "budgets": [
45 | {
46 | "type": "initial",
47 | "maximumWarning": "500kb",
48 | "maximumError": "1mb"
49 | },
50 | {
51 | "type": "anyComponentStyle",
52 | "maximumWarning": "2kb",
53 | "maximumError": "4kb"
54 | }
55 | ],
56 | "fileReplacements": [
57 | {
58 | "replace": "src/environments/environment.ts",
59 | "with": "src/environments/environment.prod.ts"
60 | }
61 | ],
62 | "outputHashing": "all"
63 | },
64 | "development": {
65 | "buildOptimizer": false,
66 | "optimization": false,
67 | "vendorChunk": true,
68 | "extractLicenses": false,
69 | "sourceMap": true,
70 | "namedChunks": true
71 | }
72 | },
73 | "defaultConfiguration": "production"
74 | },
75 | "serve": {
76 | "builder": "@angular-builders/custom-webpack:dev-server",
77 | "configurations": {
78 | "production": {
79 | "browserTarget": "dapp-sample:build:production"
80 | },
81 | "development": {
82 | "browserTarget": "dapp-sample:build:development"
83 | }
84 | },
85 | "defaultConfiguration": "development"
86 | },
87 | "extract-i18n": {
88 | "builder": "@angular-builders/custom-webpack:extract-i18n",
89 | "options": {
90 | "browserTarget": "dapp-sample:build"
91 | }
92 | },
93 | "test": {
94 | "builder": "@angular-builders/custom-webpack:karma",
95 | "options": {
96 | "customWebpackConfig": {
97 | "path": "./src/webpack.config.js",
98 | "mergeRules": {
99 | "externals": "replace"
100 | }
101 | },
102 | "main": "src/test.ts",
103 | "polyfills": "src/polyfills.ts",
104 | "tsConfig": "tsconfig.spec.json",
105 | "karmaConfig": "karma.conf.js",
106 | "inlineStyleLanguage": "scss",
107 | "assets": [
108 | "src/favicon.ico",
109 | "src/assets"
110 | ],
111 | "styles": [
112 | "./node_modules/@angular/material/prebuilt-themes/pink-bluegrey.css",
113 | "src/styles.scss"
114 | ],
115 | "scripts": []
116 | }
117 | }
118 | }
119 | }
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/dapp-wasm/wwwroot/css/open-iconic/FONT-LICENSE:
--------------------------------------------------------------------------------
1 | SIL OPEN FONT LICENSE Version 1.1
2 |
3 | Copyright (c) 2014 Waybury
4 |
5 | PREAMBLE
6 | The goals of the Open Font License (OFL) are to stimulate worldwide
7 | development of collaborative font projects, to support the font creation
8 | efforts of academic and linguistic communities, and to provide a free and
9 | open framework in which fonts may be shared and improved in partnership
10 | with others.
11 |
12 | The OFL allows the licensed fonts to be used, studied, modified and
13 | redistributed freely as long as they are not sold by themselves. The
14 | fonts, including any derivative works, can be bundled, embedded,
15 | redistributed and/or sold with any software provided that any reserved
16 | names are not used by derivative works. The fonts and derivatives,
17 | however, cannot be released under any other type of license. The
18 | requirement for fonts to remain under this license does not apply
19 | to any document created using the fonts or their derivatives.
20 |
21 | DEFINITIONS
22 | "Font Software" refers to the set of files released by the Copyright
23 | Holder(s) under this license and clearly marked as such. This may
24 | include source files, build scripts and documentation.
25 |
26 | "Reserved Font Name" refers to any names specified as such after the
27 | copyright statement(s).
28 |
29 | "Original Version" refers to the collection of Font Software components as
30 | distributed by the Copyright Holder(s).
31 |
32 | "Modified Version" refers to any derivative made by adding to, deleting,
33 | or substituting -- in part or in whole -- any of the components of the
34 | Original Version, by changing formats or by porting the Font Software to a
35 | new environment.
36 |
37 | "Author" refers to any designer, engineer, programmer, technical
38 | writer or other person who contributed to the Font Software.
39 |
40 | PERMISSION & CONDITIONS
41 | Permission is hereby granted, free of charge, to any person obtaining
42 | a copy of the Font Software, to use, study, copy, merge, embed, modify,
43 | redistribute, and sell modified and unmodified copies of the Font
44 | Software, subject to the following conditions:
45 |
46 | 1) Neither the Font Software nor any of its individual components,
47 | in Original or Modified Versions, may be sold by itself.
48 |
49 | 2) Original or Modified Versions of the Font Software may be bundled,
50 | redistributed and/or sold with any software, provided that each copy
51 | contains the above copyright notice and this license. These can be
52 | included either as stand-alone text files, human-readable headers or
53 | in the appropriate machine-readable metadata fields within text or
54 | binary files as long as those fields can be easily viewed by the user.
55 |
56 | 3) No Modified Version of the Font Software may use the Reserved Font
57 | Name(s) unless explicit written permission is granted by the corresponding
58 | Copyright Holder. This restriction only applies to the primary font name as
59 | presented to the users.
60 |
61 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
62 | Software shall not be used to promote, endorse or advertise any
63 | Modified Version, except to acknowledge the contribution(s) of the
64 | Copyright Holder(s) and the Author(s) or with their explicit written
65 | permission.
66 |
67 | 5) The Font Software, modified or unmodified, in part or in whole,
68 | must be distributed entirely under this license, and must not be
69 | distributed under any other license. The requirement for fonts to
70 | remain under this license does not apply to any document created
71 | using the Font Software.
72 |
73 | TERMINATION
74 | This license becomes null and void if any of the above conditions are
75 | not met.
76 |
77 | DISCLAIMER
78 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
81 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
82 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
83 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
84 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
85 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
86 | OTHER DEALINGS IN THE FONT SOFTWARE.
87 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/Blockcore.AtomicSwaps.BlockcoreDns/BlockcoreDnsService.cs:
--------------------------------------------------------------------------------
1 | using Blockcore.AtomicSwaps.BlockcoreDns.Models;
2 | using Blockcore.AtomicSwaps.BlockcoreDns.Toolkit;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 |
8 | namespace Blockcore.AtomicSwaps.BlockcoreDns
9 | {
10 | public class BlockcoreDnsService : IBlockcoreDnsService
11 | {
12 | private readonly string dnsServiceUrl = "https://chains.blockcore.net/services/DNS.json";
13 |
14 | public async ValueTask> GetNsServices(string url)
15 | {
16 | var services = await new JsonToolKit>().DownloadAndConverJsonToObjectAsync(url);
17 | return services;
18 | }
19 |
20 | public async ValueTask> GetServicesByNetwork(string network)
21 | {
22 | if (string.IsNullOrEmpty(network))
23 | {
24 | return null;
25 | }
26 | var nsServices = await GetNsServices(dnsServiceUrl);
27 | if (nsServices.Any())
28 | {
29 | List dnsservices = new List();
30 | foreach (var ns in nsServices)
31 | {
32 | List dnsResult = new List();
33 | var result = await new JsonToolKit>().DownloadAndConverJsonToObjectAsync(ns.Url + "/api/dns/services/symbol/"+ network);
34 | if (result.Any())
35 | {
36 | dnsResult.AddRange(result);
37 | dnsservices.Add(new DnsServices { Url = ns.Url, DnsResults = dnsResult });
38 | }
39 | }
40 | return dnsservices;
41 | }
42 | return null;
43 | }
44 |
45 | public async ValueTask> GetServicesByType(string type)
46 | {
47 | if (string.IsNullOrEmpty(type))
48 | {
49 | return null;
50 | }
51 | var nsServices = await GetNsServices(dnsServiceUrl);
52 | if (nsServices.Any())
53 | {
54 | List dnsservices = new List();
55 | foreach (var ns in nsServices)
56 | {
57 | List dnsResult = new List();
58 | var result = await new JsonToolKit>().DownloadAndConverJsonToObjectAsync(ns.Url + "/api/dns/services/service/" + type);
59 | if (result.Any())
60 | {
61 | dnsResult.AddRange(result);
62 | dnsservices.Add(new DnsServices { Url = ns.Url, DnsResults = dnsResult });
63 | }
64 | }
65 | return dnsservices;
66 | }
67 | return null;
68 | }
69 |
70 | public async ValueTask> GetServicesByTypeAndNetwork(string type, string network)
71 | {
72 | if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(network))
73 | {
74 | return null;
75 | }
76 |
77 | var nsServices = await GetNsServices(dnsServiceUrl);
78 | if (nsServices.Any())
79 | {
80 | List dnsservices = new List();
81 | foreach (var ns in nsServices)
82 | {
83 | List dnsResult = new List();
84 | var result = await new JsonToolKit>().DownloadAndConverJsonToObjectAsync(ns.Url + "/api/dns/services/symbol/"+ network + "/service/" + type);
85 | if (result.Any())
86 | {
87 | dnsResult.AddRange(result);
88 | dnsservices.Add(new DnsServices { Url = ns.Url, DnsResults = dnsResult });
89 | }
90 | }
91 | return dnsservices;
92 | }
93 | return null;
94 | }
95 |
96 | public string GetDnsServiceUrl()
97 | {
98 | return dnsServiceUrl;
99 | }
100 |
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/Blockcore.MetaMask/wwwroot/metaMask.js:
--------------------------------------------------------------------------------
1 | // This is a JavaScript module that is loaded on demand. It can export any number of
2 | // functions, and may import other JavaScript modules if required.
3 |
4 | export async function checkMetaMask() {
5 | // Modern dapp browsers...
6 | if (window.ethereum) {
7 | if (ethereum.selectedAddress === null || ethereum.selectedAddress === undefined) {
8 | try {
9 | // Request account access if needed
10 | await requestAccounts();
11 | } catch (error) {
12 | // User denied account access...
13 | throw "UserDenied"
14 | }
15 | }
16 | else {
17 | console.log("Selected:" + ethereum.selectedAddress);
18 | }
19 | }
20 | // Non-dapp browsers...
21 | else {
22 | throw "NoMetaMask"
23 | }
24 | }
25 |
26 | export async function requestAccounts() {
27 | console.log('reqAccount');
28 | var result = await ethereum.request({
29 | method: 'eth_requestAccounts',
30 | });
31 | return result;
32 | }
33 |
34 | export function hasMetaMask() {
35 | return (window.ethereum != undefined);
36 | }
37 |
38 | export function isSiteConnected() {
39 | return (window.ethereum != undefined && (ethereum.selectedAddress != undefined || ethereum.selectedAddress != null));
40 | }
41 |
42 | export async function getSelectedAddress() {
43 | await checkMetaMask();
44 |
45 | return ethereum.selectedAddress;
46 | }
47 |
48 | export async function listenToChangeEvents() {
49 | if (hasMetaMask()) {
50 | //ethereum.on("connect", function () {
51 | // DotNet.invokeMethodAsync('Blockcore.AtomicSwaps.MetaMask', 'OnConnect');
52 | //});
53 |
54 | //ethereum.on("disconnect", function () {
55 | // DotNet.invokeMethodAsync('Blockcore.AtomicSwaps.MetaMask', 'OnDisconnect');
56 | //});
57 |
58 | ethereum.on("accountsChanged", function (accounts) {
59 | DotNet.invokeMethodAsync('Blockcore.AtomicSwaps.MetaMask', 'OnAccountsChanged', accounts[0]);
60 | });
61 |
62 | ethereum.on("chainChanged", function (chainId) {
63 | DotNet.invokeMethodAsync('Blockcore.AtomicSwaps.MetaMask', 'OnChainChanged', chainId);
64 | });
65 | }
66 | }
67 |
68 | export async function getSelectedChain() {
69 | await checkMetaMask();
70 |
71 | var result = await ethereum.request({
72 | method: 'eth_chainId'
73 | });
74 | return result;
75 | }
76 |
77 | export async function getTransactionCount() {
78 | await checkMetaMask();
79 |
80 | var result = await ethereum.request({
81 | method: 'eth_getTransactionCount',
82 | params:
83 | [
84 | ethereum.selectedAddress,
85 | 'latest'
86 | ]
87 |
88 | });
89 | return result;
90 | }
91 |
92 | export async function signTypedData(label, value) {
93 | await checkMetaMask();
94 |
95 | const msgParams = [
96 | {
97 | type: 'string', // Valid solidity type
98 | name: label,
99 | value: value
100 | }
101 | ]
102 |
103 | try {
104 | var result = await ethereum.request({
105 | method: 'eth_signTypedData',
106 | params:
107 | [
108 | msgParams,
109 | ethereum.selectedAddress
110 | ]
111 | });
112 |
113 | return result;
114 | } catch (error) {
115 | // User denied account access...
116 | throw "UserDenied"
117 | }
118 | }
119 |
120 | export async function signTypedDataV4(typedData) {
121 | await checkMetaMask();
122 |
123 | try {
124 | var result = await ethereum.request({
125 | method: 'eth_signTypedData_v4',
126 | params:
127 | [
128 | ethereum.selectedAddress,
129 | typedData
130 | ],
131 | from: ethereum.selectedAddress
132 | });
133 |
134 | return result;
135 | } catch (error) {
136 | // User denied account access...
137 | throw "UserDenied"
138 | }
139 | }
140 |
141 | export async function sendTransaction(to, value, data) {
142 | await checkMetaMask();
143 |
144 | const transactionParameters = {
145 | to: to,
146 | from: ethereum.selectedAddress, // must match user's active address.
147 | value: value,
148 | data: data
149 | };
150 |
151 | try {
152 | var result = await ethereum.request({
153 | method: 'eth_sendTransaction',
154 | params: [transactionParameters]
155 | });
156 |
157 | return result;
158 | } catch (error) {
159 | if (error.code == 4001) {
160 | throw "UserDenied"
161 | }
162 | throw error;
163 | }
164 | }
165 |
166 | export async function genericRpc(method, params) {
167 | await checkMetaMask();
168 |
169 | var result = await ethereum.request({
170 | method: method,
171 | params: params
172 | });
173 |
174 | return result;
175 | }
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/Blockcore.AtomicSwaps.BlockcoreWallet/wwwroot/blockcoreWallet.js:
--------------------------------------------------------------------------------
1 | export async function hasBlockcoreWallet() {
2 | return (globalThis.blockcore != undefined);
3 | }
4 |
5 | export async function signMessageAnyAccount(value) {
6 | const provider = globalThis.blockcore;
7 |
8 | const result = await provider.request({
9 | method: 'signMessage',
10 | params: [{ message: value }],
11 | });
12 | console.log('Result:', result);
13 | return JSON.stringify(result);
14 |
15 | //var key = result.key;
16 | //var signature = result.signature;
17 | //var network = result.network;
18 | //var verify = bitcoinMessage.verify(value, result.key, result.signature);
19 | }
20 |
21 | export async function sendCoins(input) {
22 | const provider = globalThis.blockcore;
23 |
24 | var data = JSON.parse(input)
25 | const result = await provider.request({
26 | method: 'transaction.send',
27 | params: [data],
28 | });
29 | console.log('Result:', result);
30 | return JSON.stringify(result);
31 | }
32 |
33 | export async function swapCoins(input) {
34 | const provider = globalThis.blockcore;
35 |
36 | var data = JSON.parse(input)
37 | const result = await provider.request({
38 | method: 'atomicswaps.send',
39 | params: [data],
40 | });
41 | console.log('Result:', result);
42 | return JSON.stringify(result.response);
43 | }
44 |
45 | export async function getWallet(key) {
46 | const provider = globalThis.blockcore;
47 |
48 | const result = await provider.request({
49 | method: 'wallets',
50 | params: [{ key: key }],
51 | });
52 | console.log('Result:', result);
53 | return JSON.stringify(result);
54 | }
55 |
56 | export async function getSwapKey(key, walletId, accountId, includePrivateKey) {
57 | const provider = globalThis.blockcore;
58 |
59 | const result = await provider.request({
60 | method: 'atomicswaps.key',
61 | params: [{ key: key, walletId: walletId, accountId: accountId, includePrivateKey: includePrivateKey }],
62 | });
63 | console.log('Result:', result);
64 | return JSON.stringify(result);
65 | }
66 |
67 | export async function getSwapSecret(key, walletId, accountId, message) {
68 | const provider = globalThis.blockcore;
69 |
70 | const result = await provider.request({
71 | method: 'atomicswaps.secret',
72 | params: [{ key: key, walletId: walletId, accountId: accountId, message: message }],
73 | });
74 | console.log('Result:', result);
75 | return JSON.stringify(result);
76 | }
77 |
78 | export async function signMessageAnyAccountJson(value) {
79 | const message = JSON.parse(value);
80 |
81 | const provider = globalThis.blockcore;
82 |
83 | const result = await provider.request({
84 | method: 'signMessage',
85 | params: [{ message: message }],
86 | });
87 |
88 | console.log('Result:', result);
89 | return JSON.stringify(result);
90 |
91 | //this.signedJsonKey = result.key;
92 | //this.signedJsonSignature = result.signature;
93 | //this.signedJsonNetwork = result.network;
94 | //const preparedMessage = JSON.stringify(message);
95 | //this.signedJsonValidSignature = bitcoinMessage.verify(preparedMessage, result.key, result.signature);
96 | }
97 |
98 | export async function paymentRequest(network, amount) {
99 | try {
100 | const provider = globalThis.blockcore;
101 |
102 | var result = await provider.request({
103 | method: 'payment',
104 | params: [
105 | {
106 | network: network.toLowerCase(),
107 | amount: amount,
108 | address: 'Ccoquhaae7u6ASqQ5BiYueASz8EavUXrKn',
109 | label: 'Your Local Info',
110 | message: 'Invoice Number 5',
111 | data: 'MzExMzUzNDIzNDY',
112 | id: '4324',
113 | },
114 | ],
115 | });
116 |
117 | console.log('Result:', result);
118 | return JSON.stringify(result);
119 | } catch (err) {
120 | console.error(err);
121 | }
122 | }
123 |
124 | async function request(method, params) {
125 | if (!params) {
126 | params = [];
127 | }
128 | const provider = globalThis.blockcore;
129 | const result = await provider.request({
130 | method: method,
131 | params: params,
132 | });
133 | console.log('Result:', result);
134 |
135 | return result;
136 | }
137 |
138 | export async function didSupportedMethods() {
139 | const result = await request('did.supportedMethods');
140 | return JSON.stringify(result.response);
141 | }
142 |
143 | export async function didRequest(methods) {
144 | const result = await request('did.request', [
145 | {
146 | challenge: 'fc0949c4-fd9c-4825-b18d-79348e358156',
147 | methods: methods,
148 | reason: 'Sample app need access to any of your DIDs.',
149 | },
150 | ]);
151 |
152 | return JSON.stringify(result.response);
153 | }
154 |
155 | export async function signMessage(msg) {
156 | const provider = globalThis.blockcore;
157 | let signature;
158 | try {
159 | signature = await provider.request({ method: "signMessage", params: [{ scheme: "schnorr", message: msg }] });
160 | return JSON.stringify(signature);
161 | }
162 | catch (error) {
163 | console.error("Error: " + error.message);
164 | // User denied account access...
165 | throw "UserDenied";
166 | }
167 | }
168 |
169 |
170 |
171 |
172 |
173 |
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/Blockcore.AtomicSwaps.BlockcoreWallet/BlockcoreWalletModels.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.JSInterop;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Numerics;
5 | using System.Threading.Tasks;
6 | #pragma warning disable CS8618
7 |
8 | namespace Blockcore.AtomicSwaps.BlockcoreWallet
9 | {
10 | public class BlockcoreWalletSendFundsRecipients
11 | {
12 | public string address { get; set; } = null!;
13 | public long amount { get; set; }
14 | public string hint { get; set; } = string.Empty;
15 | }
16 | public class BlockcoreWalletSendFunds
17 | {
18 | public List recipients { get; set; } = new();
19 |
20 | public string data { get; set; }
21 | public string feeRate { get; set; }
22 | public string network { get; set; }
23 | }
24 |
25 | public class BlockcoreWalletSendFundsOut
26 | {
27 | public string transactionId { get; set; }
28 | public string transactionHex { get; set; }
29 | }
30 |
31 | public class BlockcoreWalletSwapCoins
32 | {
33 | public string walletId { get; set; }
34 | public string accountId { get; set; }
35 | public string swapTrxHex { get; set; }
36 | public string trxToSignHex { get; set; }
37 | public string redeemScriptHex { get; set; }
38 | public string secretHashHex { get; set; }
39 | public string network { get; set; }
40 | public string message { get; set; }
41 | }
42 |
43 | public class BlockcoreWalletSwapCoinsOut
44 | {
45 | public string privateKey { get; set; }
46 | public string transactionId { get; set; }
47 | public string transactionHex { get; set; }
48 |
49 | }
50 |
51 | public class BlockcoreWalletMessageOut
52 | {
53 | public string key { get; set; }
54 | public ContentData response { get; set; }
55 |
56 | public class Account
57 | {
58 | public string icon { get; set; }
59 | public string name { get; set; }
60 | public string id { get; set; }
61 | public int network { get; set; }
62 | public string networkType { get; set; }
63 | public int purpose { get; set; }
64 | public int purposeAddress { get; set; }
65 | public string type { get; set; }
66 | public History history { get; set; }
67 | public State state { get; set; }
68 | public NetworkDefinition networkDefinition { get; set; }
69 | }
70 |
71 | public class Bip32
72 | {
73 | public int @public { get; set; }
74 | public int @private { get; set; }
75 | }
76 |
77 | public class Change
78 | {
79 | public string address { get; set; }
80 | public int index { get; set; }
81 | }
82 |
83 | public class Confirmation
84 | {
85 | public int low { get; set; }
86 | public int high { get; set; }
87 | public int count { get; set; }
88 | }
89 |
90 | public class History
91 | {
92 | public long balance { get; set; }
93 | public List history { get; set; }
94 | public int unconfirmed { get; set; }
95 | public List unspent { get; set; }
96 | }
97 |
98 | public class HistoryItem
99 | {
100 | public int blockIndex { get; set; }
101 | public string calculatedAddress { get; set; }
102 | public long calculatedValue { get; set; }
103 | public string entryType { get; set; }
104 | public int fee { get; set; }
105 | public bool finalized { get; set; }
106 | public bool isCoinbase { get; set; }
107 | public bool isCoinstake { get; set; }
108 | public int timestamp { get; set; }
109 | public string transactionHash { get; set; }
110 | }
111 |
112 | public class NetworkDefinition
113 | {
114 | public string id { get; set; }
115 | public string name { get; set; }
116 | public string symbol { get; set; }
117 | public int network { get; set; }
118 | public int purpose { get; set; }
119 | public string messagePrefix { get; set; }
120 | public string bech32 { get; set; }
121 | public Bip32 bip32 { get; set; }
122 | public int pubKeyHash { get; set; }
123 | public int scriptHash { get; set; }
124 | public int wif { get; set; }
125 | public int minimumFeeRate { get; set; }
126 | public int maximumFeeRate { get; set; }
127 | public bool testnet { get; set; }
128 | public bool isProofOfStake { get; set; }
129 | public bool smartContractSupport { get; set; }
130 | public string type { get; set; }
131 | public int? purposeAddress { get; set; }
132 | }
133 |
134 | public class Param
135 | {
136 | public object key { get; set; }
137 | }
138 |
139 | public class Peg
140 | {
141 | public string type { get; set; }
142 | public string address { get; set; }
143 | }
144 |
145 | public class Receive
146 | {
147 | public string address { get; set; }
148 | public int index { get; set; }
149 | }
150 |
151 |
152 | public class ContentData
153 | {
154 | public Wallet wallet { get; set; }
155 | public List accounts { get; set; }
156 | }
157 |
158 | public class State
159 | {
160 | public int balance { get; set; }
161 | public List change { get; set; }
162 | public bool completedScan { get; set; }
163 | public string id { get; set; }
164 | public DateTime lastScan { get; set; }
165 | public List receive { get; set; }
166 | }
167 |
168 | public class Unspent
169 | {
170 | public string address { get; set; }
171 | public long balance { get; set; }
172 | public int index { get; set; }
173 | public string transactionHash { get; set; }
174 | public bool unconfirmed { get; set; }
175 | }
176 |
177 | public class Wallet
178 | {
179 | public string id { get; set; }
180 | public string name { get; set; }
181 | public string key { get; set; }
182 | }
183 |
184 | }
185 | }
--------------------------------------------------------------------------------
/src/blazor/dapp-wasm/dapp-wasm/Networks/BitcoinMain.cs:
--------------------------------------------------------------------------------
1 | using Blockcore.Consensus;
2 | using Blockcore.Consensus.ScriptInfo;
3 | using Blockcore.Consensus.TransactionInfo;
4 | using NBitcoin;
5 | using NBitcoin.BitcoinCore;
6 | using NBitcoin.DataEncoders;
7 | using NBitcoin.Protocol;
8 |
9 | namespace Blockcore.Networks.Bitcoin
10 | {
11 | public class BitcoinMain : Network
12 | {
13 | public BitcoinMain()
14 | {
15 | this.Name = "Main";
16 | this.AdditionalNames = new List { "Mainnet" };
17 | this.NetworkType = NetworkType.Mainnet;
18 |
19 | // The message start string is designed to be unlikely to occur in normal data.
20 | // The characters are rarely used upper ASCII, not valid as UTF-8, and produce
21 | // a large 4-byte int at any alignment.
22 | this.Magic = 0xD9B4BEF9;
23 | this.DefaultPort = 8333;
24 | this.DefaultMaxOutboundConnections = 8;
25 | this.DefaultMaxInboundConnections = 117;
26 | this.DefaultRPCPort = 8332;
27 | this.DefaultAPIPort = 37220;
28 | this.MinTxFee = 1000;
29 | this.MaxTxFee = Money.Coins(0.1m).Satoshi;
30 | this.FallbackFee = 20000;
31 | this.MinRelayTxFee = 1000;
32 | this.CoinTicker = "BTC";
33 | this.DefaultBanTimeSeconds = 60 * 60 * 24; // 24 Hours
34 |
35 | var consensusFactory = new ConsensusFactory();
36 |
37 |
38 |
39 | consensusFactory.Protocol = new ConsensusProtocol()
40 | {
41 | ProtocolVersion = ProtocolVersion.FEEFILTER_VERSION,
42 | MinProtocolVersion = ProtocolVersion.SENDHEADERS_VERSION,
43 | };
44 |
45 | this.Consensus = new Consensus.Consensus(
46 | consensusFactory: consensusFactory,
47 | consensusOptions: new ConsensusOptions(), // Default - set to Bitcoin params.
48 | coinType: 0,
49 | hashGenesisBlock: null,
50 | subsidyHalvingInterval: 210000,
51 | majorityEnforceBlockUpgrade: 750,
52 | majorityRejectBlockOutdated: 950,
53 | majorityWindow: 1000,
54 | buriedDeployments: null,
55 | bip9Deployments: null,
56 | bip34Hash: null,
57 | minerConfirmationWindow: 2016, // nPowTargetTimespan / nPowTargetSpacing
58 | maxReorgLength: 0,
59 | defaultAssumeValid: null, // 629000
60 | maxMoney: 21000000 * Money.COIN,
61 | coinbaseMaturity: 100,
62 | premineHeight: 0,
63 | premineReward: Money.Zero,
64 | proofOfWorkReward: Money.Coins(50),
65 | targetTimespan: TimeSpan.FromSeconds(14 * 24 * 60 * 60), // two weeks
66 | targetSpacing: TimeSpan.FromSeconds(10 * 60),
67 | powAllowMinDifficultyBlocks: false,
68 | posNoRetargeting: false,
69 | powNoRetargeting: false,
70 | powLimit: null,
71 | minimumChainWork: null,
72 | isProofOfStake: false,
73 | lastPowBlock: default(int),
74 | proofOfStakeLimit: null,
75 | proofOfStakeLimitV2: null,
76 | proofOfStakeReward: Money.Zero,
77 | proofOfStakeTimestampMask: 0
78 | );
79 |
80 | this.Base58Prefixes = new byte[12][];
81 | this.Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (0) };
82 | this.Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (5) };
83 | this.Base58Prefixes[(int)Base58Type.SECRET_KEY] = new byte[] { (128) };
84 | this.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_NO_EC] = new byte[] { 0x01, 0x42 };
85 | this.Base58Prefixes[(int)Base58Type.ENCRYPTED_SECRET_KEY_EC] = new byte[] { 0x01, 0x43 };
86 | this.Base58Prefixes[(int)Base58Type.EXT_PUBLIC_KEY] = new byte[] { (0x04), (0x88), (0xB2), (0x1E) };
87 | this.Base58Prefixes[(int)Base58Type.EXT_SECRET_KEY] = new byte[] { (0x04), (0x88), (0xAD), (0xE4) };
88 | this.Base58Prefixes[(int)Base58Type.PASSPHRASE_CODE] = new byte[] { 0x2C, 0xE9, 0xB3, 0xE1, 0xFF, 0x39, 0xE2 };
89 | this.Base58Prefixes[(int)Base58Type.CONFIRMATION_CODE] = new byte[] { 0x64, 0x3B, 0xF6, 0xA8, 0x9A };
90 | this.Base58Prefixes[(int)Base58Type.ASSET_ID] = new byte[] { 23 };
91 |
92 | var encoder = new Bech32Encoder("bc");
93 | this.Bech32Encoders = new Bech32Encoder[2];
94 | this.Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
95 | this.Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;
96 |
97 | this.StandardScriptsRegistry = new BitcoinStandardScriptsRegistry();
98 |
99 | }
100 | }
101 |
102 | public class BitcoinStandardScriptsRegistry : StandardScriptsRegistry
103 | {
104 | // See MAX_OP_RETURN_RELAY in Bitcoin Core,