Commit 0191a5d6 authored by Pavel Pavlov's avatar Pavel Pavlov

The research of the problem of the lack of connection with the wallet "Electrum"

parent ecf81b95
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
...@@ -68,19 +69,22 @@ namespace DeStream.DeStreamD.ForTest ...@@ -68,19 +69,22 @@ namespace DeStream.DeStreamD.ForTest
.AddRPC() .AddRPC()
.Build(); .Build();
(Wallet wallet, Block block, ChainedHeader chainedHeader) result = TestClassHelper.CreateFirstTransaction(nodeSettings, node.WalletManager(), node.NodeService<WalletSettings>(), //(Wallet wallet, Block block, ChainedHeader chainedHeader) result = TestClassHelper.CreateFirstTransaction(nodeSettings, node.WalletManager(), node.NodeService<WalletSettings>(),
node.NodeService<IWalletFeePolicy>()); // node.NodeService<IWalletFeePolicy>());
var walletManager = node.WalletManager(); //var walletManager = node.WalletManager();
walletManager.Wallets.Add(result.wallet); //walletManager.Wallets.Add(result.wallet);
HdAddress addr = result.wallet.AccountsRoot.ElementAt(0).Accounts.ElementAt(0).ExternalAddresses.ElementAt(0); //HdAddress addr = result.wallet.AccountsRoot.ElementAt(0).Accounts.ElementAt(0).ExternalAddresses.ElementAt(0);
Key key = result.wallet.GetExtendedPrivateKeyForAddress("password", addr).PrivateKey; //Key key = result.wallet.GetExtendedPrivateKeyForAddress("password", addr).PrivateKey;
TestClassHelper.CreateTestBlock(node, key); //TestClassHelper.CreateTestBlock(node, key);
//walletManager.SaveWallets(); //walletManager.SaveWallets();
var test = node.WalletManager().GetSpendableTransactionsInWallet("myWallet1").Sum(s => s.Transaction.Amount); //var test = node.WalletManager().GetSpendableTransactionsInWallet("myWallet1").Sum(s => s.Transaction.Amount);
Process currentProcess = Process.GetCurrentProcess();
Console.WriteLine("##############################: " + currentProcess.Id.ToString());
int qwe0 = 1; int qwe0 = 1;
if (node != null) if (node != null)
await node.RunAsync(); await node.RunAsync();
......
...@@ -49,7 +49,7 @@ namespace DeStream.DeStreamD.ForTest ...@@ -49,7 +49,7 @@ namespace DeStream.DeStreamD.ForTest
var coinbase = new Transaction(); var coinbase = new Transaction();
coinbase.AddInput(TxIn.CreateCoinbase(chain.Height + 1)); coinbase.AddInput(TxIn.CreateCoinbase(chain.Height + 1));
coinbase.AddOutput(new TxOut(Get9Billion(), address.ScriptPubKey)); coinbase.AddOutput(new TxOut(Get6Billion(), address.ScriptPubKey));
block.AddTransaction(coinbase); block.AddTransaction(coinbase);
block.Header.Nonce = 0; block.Header.Nonce = 0;
...@@ -231,7 +231,7 @@ namespace DeStream.DeStreamD.ForTest ...@@ -231,7 +231,7 @@ namespace DeStream.DeStreamD.ForTest
public static Block CreateTestBlock(FullNode fullNode, Key key) public static Block CreateTestBlock(FullNode fullNode, Key key)
{ {
//FullNode fullNode = (this.runner as StratisBitcoinPowRunner).FullNode; //FullNode fullNode = (this.runner as StratisBitcoinPowRunner).FullNode;
BitcoinSecret dest = new BitcoinSecret(key, fullNode.Network); BitcoinSecret dest = new BitcoinSecret(key, fullNode.Network);
var blocks = new List<Block>(); var blocks = new List<Block>();
...@@ -244,7 +244,7 @@ namespace DeStream.DeStreamD.ForTest ...@@ -244,7 +244,7 @@ namespace DeStream.DeStreamD.ForTest
block.Header.UpdateTime(DateTimeOffset.UtcNow, fullNode.Network, fullNode.Chain.Tip); block.Header.UpdateTime(DateTimeOffset.UtcNow, fullNode.Network, fullNode.Chain.Tip);
var coinbase = new Transaction(); var coinbase = new Transaction();
//coinbase.AddInput(TxIn.CreateCoinbase(fullNode.Chain.Height + 1)); //coinbase.AddInput(TxIn.CreateCoinbase(fullNode.Chain.Height + 1));
coinbase.AddOutput(new TxOut(Get9Billion(), dest.GetAddress())); coinbase.AddOutput(new TxOut(Get6Billion(), dest.GetAddress()));
block.AddTransaction(coinbase); block.AddTransaction(coinbase);
if (passedTransactions?.Any() ?? false) if (passedTransactions?.Any() ?? false)
{ {
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using NBitcoin; using NBitcoin;
using Stratis.Bitcoin.Configuration.Settings;
using Stratis.Bitcoin.Consensus;
using Xunit; using Xunit;
namespace Stratis.Bitcoin.Features.Consensus.Tests namespace Stratis.Bitcoin.Features.Consensus.Tests
......
...@@ -150,7 +150,7 @@ namespace Stratis.Bitcoin.P2P.Peer ...@@ -150,7 +150,7 @@ namespace Stratis.Bitcoin.P2P.Peer
this.MessageProducer.PushMessage(incomingMessage); this.MessageProducer.PushMessage(incomingMessage);
} }
} }
catch (OperationCanceledException) catch (OperationCanceledException ex)
{ {
this.logger.LogTrace("Receiving cancelled."); this.logger.LogTrace("Receiving cancelled.");
this.peer.Disconnect("Receiving cancelled."); this.peer.Disconnect("Receiving cancelled.");
...@@ -340,7 +340,7 @@ namespace Stratis.Bitcoin.P2P.Peer ...@@ -340,7 +340,7 @@ namespace Stratis.Bitcoin.P2P.Peer
/// <exception cref="ProtocolViolationException">Thrown if the incoming message is too big.</exception> /// <exception cref="ProtocolViolationException">Thrown if the incoming message is too big.</exception>
private async Task<byte[]> ReadMessageAsync(ProtocolVersion protocolVersion, CancellationToken cancellation = default(CancellationToken)) private async Task<byte[]> ReadMessageAsync(ProtocolVersion protocolVersion, CancellationToken cancellation = default(CancellationToken))
{ {
this.logger.LogTrace("({0}:{1})", nameof(protocolVersion), protocolVersion); //this.logger.LogTrace("({0}:{1})", nameof(protocolVersion), protocolVersion);
// First find and read the magic. // First find and read the magic.
await this.ReadMagicAsync(this.network.MagicBytes, cancellation).ConfigureAwait(false); await this.ReadMagicAsync(this.network.MagicBytes, cancellation).ConfigureAwait(false);
...@@ -411,7 +411,7 @@ namespace Stratis.Bitcoin.P2P.Peer ...@@ -411,7 +411,7 @@ namespace Stratis.Bitcoin.P2P.Peer
this.logger.LogTrace("(-)"); this.logger.LogTrace("(-)");
} }
static int _offset=0;
/// <summary> /// <summary>
/// Reads a specific number of bytes from the connection stream into a buffer. /// Reads a specific number of bytes from the connection stream into a buffer.
/// </summary> /// </summary>
...@@ -423,11 +423,20 @@ namespace Stratis.Bitcoin.P2P.Peer ...@@ -423,11 +423,20 @@ namespace Stratis.Bitcoin.P2P.Peer
/// <exception cref="OperationCanceledException">Thrown if the operation was cancelled or the end of the stream was reached.</exception> /// <exception cref="OperationCanceledException">Thrown if the operation was cancelled or the end of the stream was reached.</exception>
private async Task ReadBytesAsync(byte[] buffer, int offset, int bytesToRead, CancellationToken cancellation = default(CancellationToken)) private async Task ReadBytesAsync(byte[] buffer, int offset, int bytesToRead, CancellationToken cancellation = default(CancellationToken))
{ {
this.logger.LogTrace("({0}:{1},{2}:{3})", nameof(offset), offset, nameof(bytesToRead), bytesToRead); //this.logger.LogTrace("({0}:{1},{2}:{3})", nameof(offset), offset, nameof(bytesToRead), bytesToRead);
while (bytesToRead > 0) while (bytesToRead > 0)
{ {
int chunkSize = await this.stream.ReadAsync(buffer, offset, bytesToRead, cancellation).ConfigureAwait(false); int chunkSize = 0;
try
{
chunkSize = this.stream.Read(buffer, offset, bytesToRead);
//chunkSize = await this.stream.ReadAsync(buffer, offset, bytesToRead, cancellation).ConfigureAwait(false);
}catch(Exception ex)
{
int qwe = 1;
_offset = 0;
}
if (chunkSize == 0) if (chunkSize == 0)
{ {
this.logger.LogTrace("(-)[STREAM_END]"); this.logger.LogTrace("(-)[STREAM_END]");
...@@ -435,10 +444,11 @@ namespace Stratis.Bitcoin.P2P.Peer ...@@ -435,10 +444,11 @@ namespace Stratis.Bitcoin.P2P.Peer
} }
offset += chunkSize; offset += chunkSize;
_offset += offset;
bytesToRead -= chunkSize; bytesToRead -= chunkSize;
} }
this.logger.LogTrace("(-)"); //this.logger.LogTrace("(-)");
} }
/// <summary> /// <summary>
...@@ -456,7 +466,7 @@ namespace Stratis.Bitcoin.P2P.Peer ...@@ -456,7 +466,7 @@ namespace Stratis.Bitcoin.P2P.Peer
/// </remarks> /// </remarks>
private async Task<Message> ReadAndParseMessageAsync(ProtocolVersion protocolVersion, CancellationToken cancellation) private async Task<Message> ReadAndParseMessageAsync(ProtocolVersion protocolVersion, CancellationToken cancellation)
{ {
this.logger.LogTrace("({0}:{1})", nameof(protocolVersion), protocolVersion); //this.logger.LogTrace("({0}:{1})", nameof(protocolVersion), protocolVersion);
Message message = null; Message message = null;
......
{ {
"profiles": { "profiles": {
"Stratis.StratisD": { "Stratis.StratisD": {
"commandName": "Project" "commandName": "Project",
"commandLineArgs": "-testnode"
}, },
"Stratis.StratisD Test": { "Stratis.StratisD Test": {
"commandName": "Project", "commandName": "Project",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment