Commit 9d4a231a authored by Pavel Pavlov's avatar Pavel Pavlov

code analysis and implementation of the traverse in DeStream network

parent 2a918bb7
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
</Project>
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion>
<Company />
<Product>Stratis.StratisD</Product>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DeStream.Stratis.Bitcoin\DeStream.Stratis.Bitcoin.csproj" />
<ProjectReference Include="..\NBitcoin\NBitcoin.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.Api\Stratis.Bitcoin.Features.Api.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.BlockStore\Stratis.Bitcoin.Features.BlockStore.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.Consensus\Stratis.Bitcoin.Features.Consensus.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.MemoryPool\Stratis.Bitcoin.Features.MemoryPool.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.Miner\Stratis.Bitcoin.Features.Miner.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.RPC\Stratis.Bitcoin.Features.RPC.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.Wallet\Stratis.Bitcoin.Features.Wallet.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.IntegrationTests.Common\Stratis.Bitcoin.IntegrationTests.Common.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin\Stratis.Bitcoin.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.1.1" />
</ItemGroup>
</Project>
using System;
using System.Linq;
using System.Threading.Tasks;
using DeStream.Stratis.Bitcoin.Configuration;
using NBitcoin;
using NBitcoin.Protocol;
using Stratis.Bitcoin;
using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Features.Api;
using Stratis.Bitcoin.Features.BlockStore;
using Stratis.Bitcoin.Features.Consensus;
using Stratis.Bitcoin.Features.MemoryPool;
using Stratis.Bitcoin.Features.Miner;
using Stratis.Bitcoin.Features.RPC;
using Stratis.Bitcoin.Features.Wallet;
using Stratis.Bitcoin.Features.Wallet.Interfaces;
using Stratis.Bitcoin.IntegrationTests.Common;
using Stratis.Bitcoin.IntegrationTests.Common.EnvironmentMockUpHelpers;
using Stratis.Bitcoin.Utilities;
namespace DeStream.DeStreamD.ForTest
{
public class Program
{
public static void Main(string[] args)
{
MainAsync(args).Wait();
}
public static async Task MainAsync(string[] args)
{
try
{
Network network = null;
if (args.Contains("-testnet"))
network = Network.DeStreamTest;
else
network = Network.DeStreamMain;
DeStreamNodeSettings nodeSettings = new DeStreamNodeSettings(network, ProtocolVersion.ALT_PROTOCOL_VERSION, args: args, loadConfiguration: false);
Console.WriteLine($"current network: {network.Name}");
// NOTES: running BTC and STRAT side by side is not possible yet as the flags for serialization are static
var node = new FullNodeBuilder()
.UseNodeSettings(nodeSettings)
.UseBlockStore()
.UsePosConsensus()
.UseMempool()
.UseWallet()
.AddPowPosMining()
.UseApi()
.AddRPC()
.Build();
NodeBuilder builder = NodeBuilder.Create(node);
CoreNode stratisSender = builder.CreateStratisPowNode();
CoreNode stratisReceiver = builder.CreateStratisPowNode();
builder.StartAll();
stratisSender.NotInIBD();
stratisReceiver.NotInIBD();
// get a key from the wallet
Mnemonic mnemonic1 = stratisSender.FullNode.WalletManager().CreateWallet("123456", "mywallet");
Mnemonic mnemonic2 = stratisReceiver.FullNode.WalletManager().CreateWallet("123456", "mywallet");
HdAddress addr = stratisSender.FullNode.WalletManager().GetUnusedAddress(new WalletAccountReference("mywallet", "account 0"));
Wallet wallet = stratisSender.FullNode.WalletManager().GetWalletByName("mywallet");
Key key = wallet.GetExtendedPrivateKeyForAddress("123456", addr).PrivateKey;
stratisSender.SetDummyMinerSecret(new BitcoinSecret(key, stratisSender.FullNode.Network));
int maturity = (int)stratisSender.FullNode.Network.Consensus.CoinbaseMaturity;
stratisSender.GenerateStratis(maturity + 5);
// wait for block repo for block sync to work
TestHelper.WaitLoop(() => TestHelper.IsNodeSynced(stratisSender));
// the mining should add coins to the wallet
long total = stratisSender.FullNode.WalletManager().GetSpendableTransactionsInWallet("mywallet").Sum(s => s.Transaction.Amount);
var walletManager = ((FullNode)node).NodeService<IWalletManager>() as WalletManager;
//HdAddress addr = ((FullNode)node).WalletManager().GetUnusedAddress(new WalletAccountReference("mywallet", "account 0"));
walletManager.CreateWallet("123456", "mywallet");
HdAddress sendto = walletManager.GetUnusedAddress(new WalletAccountReference("mywallet", "account 0"));
var walletTransactionHandler = ((FullNode)node).NodeService<IWalletTransactionHandler>() as WalletTransactionHandler;
var transactionBuildContext = CreateContext(
new WalletAccountReference("mywallet", "account 0"), "123456", sendto.ScriptPubKey, Money.COIN * 100, FeeType.Medium, 101);
Transaction trx = walletTransactionHandler.BuildTransaction(transactionBuildContext);
if (node != null)
await node.RunAsync();
}
catch (Exception ex)
{
Console.WriteLine("There was a problem initializing the node. Details: '{0}'", ex.Message);
}
}
public static TransactionBuildContext CreateContext(WalletAccountReference accountReference, string password,
Script destinationScript, Money amount, FeeType feeType, int minConfirmations)
{
return new TransactionBuildContext(accountReference,
new[] { new Recipient { Amount = amount, ScriptPubKey = destinationScript } }.ToList(), password)
{
MinConfirmations = minConfirmations,
FeeType = feeType
};
}
}
}
{
"profiles": {
"DeStream.DeStreamD.ForTest": {
"commandName": "Project",
"commandLineArgs": "-testnet -debug -loglevel=trace"
}
}
}
\ No newline at end of file
regtest=1
rest=1
server=1
txindex=1
rpcuser=393d81b8e43ff157920b046ab96b19d823275a98
rpcpassword=393d81b8e43ff157920b046ab96b19d823275a98
port=10150
rpcport=11253
apiport=10345
printtoconsole=1
keypool=10
agentprefix=node10150
__cookie__:704d1ae658fa55e1d203064e6e4c69896dd8fb8519aee6fccefbe194981a8695
\ No newline at end of file
regtest=1
rest=1
server=1
txindex=1
rpcuser=c3d3d8db189fa9f02034c87a0e4120e8bf94b7cb
rpcpassword=c3d3d8db189fa9f02034c87a0e4120e8bf94b7cb
port=12728
rpcport=10087
apiport=11140
printtoconsole=1
keypool=10
agentprefix=node12728
__cookie__:e36ddf2fc6f8bc954b56ec79d81a68f144921a4e752423493f8b9d932c60234a
\ No newline at end of file
regtest=1
rest=1
server=1
txindex=1
rpcuser=83afd44227ef145a8b8a8f34c7d468edfeb50d2b
rpcpassword=83afd44227ef145a8b8a8f34c7d468edfeb50d2b
port=10234
rpcport=13432
apiport=13205
printtoconsole=1
keypool=10
agentprefix=node10234
__cookie__:b3b7ea32193d16852da7bcbf15a5117c12ed24b8dd8e97579609dbd4480aeea2
\ No newline at end of file
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