Commit 8feb8c99 authored by Pavel Pavlov's avatar Pavel Pavlov

Code research and analysis (Stratis)

- work of wallet
parent 8152e6c4
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<ProjectReference Include="..\Stratis.Bitcoin.Features.RPC\Stratis.Bitcoin.Features.RPC.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.Features.Wallet\Stratis.Bitcoin.Features.Wallet.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.IntegrationTests.Common\Stratis.Bitcoin.IntegrationTests.Common.csproj" /> <ProjectReference Include="..\Stratis.Bitcoin.IntegrationTests.Common\Stratis.Bitcoin.IntegrationTests.Common.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Tests.Wallet.Common\Stratis.Bitcoin.Tests.Wallet.Common.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin\Stratis.Bitcoin.csproj" /> <ProjectReference Include="..\Stratis.Bitcoin\Stratis.Bitcoin.csproj" />
</ItemGroup> </ItemGroup>
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using DeStream.Stratis.Bitcoin.Configuration; using DeStream.Stratis.Bitcoin.Configuration;
using Moq;
using NBitcoin; using NBitcoin;
using NBitcoin.Protocol; using NBitcoin.Protocol;
using Stratis.Bitcoin; using Stratis.Bitcoin;
using Stratis.Bitcoin.Builder; using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Configuration;
using Stratis.Bitcoin.Features.Api; using Stratis.Bitcoin.Features.Api;
using Stratis.Bitcoin.Features.BlockStore; using Stratis.Bitcoin.Features.BlockStore;
using Stratis.Bitcoin.Features.Consensus; using Stratis.Bitcoin.Features.Consensus;
...@@ -19,6 +22,7 @@ using Stratis.Bitcoin.Features.Wallet.Interfaces; ...@@ -19,6 +22,7 @@ using Stratis.Bitcoin.Features.Wallet.Interfaces;
using Stratis.Bitcoin.IntegrationTests.Common; using Stratis.Bitcoin.IntegrationTests.Common;
using Stratis.Bitcoin.IntegrationTests.Common.EnvironmentMockUpHelpers; using Stratis.Bitcoin.IntegrationTests.Common.EnvironmentMockUpHelpers;
using Stratis.Bitcoin.Interfaces; using Stratis.Bitcoin.Interfaces;
using Stratis.Bitcoin.Tests.Wallet.Common;
using Stratis.Bitcoin.Utilities; using Stratis.Bitcoin.Utilities;
using static Stratis.Bitcoin.BlockPulling.BlockPuller; using static Stratis.Bitcoin.BlockPulling.BlockPuller;
...@@ -121,6 +125,52 @@ namespace DeStream.DeStreamD.ForTest ...@@ -121,6 +125,52 @@ namespace DeStream.DeStreamD.ForTest
return blocks.ToArray(); return blocks.ToArray();
} }
#region Test
public static List<Block> AddBlocksWithCoinbaseToChain(Network network, ConcurrentChain chain, HdAddress address, int blocks = 1)
{
//var chain = new ConcurrentChain(network.GetGenesis().Header);
var blockList = new List<Block>();
for (int i = 0; i < blocks; i++)
{
var block = new Block();
block.Header.HashPrevBlock = chain.Tip.HashBlock;
block.Header.Bits = block.Header.GetWorkRequired(network, chain.Tip);
block.Header.UpdateTime(DateTimeOffset.UtcNow, network, chain.Tip);
var coinbase = new Transaction();
coinbase.AddInput(TxIn.CreateCoinbase(chain.Height + 1));
coinbase.AddOutput(new TxOut(network.GetReward(chain.Height + 1), address.ScriptPubKey));
block.AddTransaction(coinbase);
block.Header.Nonce = 0;
block.UpdateMerkleRoot();
block.Header.PrecomputeHash();
chain.SetTip(block.Header);
var addressTransaction = new TransactionData
{
Amount = coinbase.TotalOut,
BlockHash = block.GetHash(),
BlockHeight = chain.GetBlock(block.GetHash()).Height,
CreationTime = DateTimeOffset.FromUnixTimeSeconds(block.Header.Time),
Id = coinbase.GetHash(),
Index = 0,
ScriptPubKey = coinbase.Outputs[0].ScriptPubKey,
};
address.Transactions.Add(addressTransaction);
blockList.Add(block);
}
return blockList;
}
#endregion
public static async Task MainAsync(string[] args) public static async Task MainAsync(string[] args)
{ {
try try
...@@ -146,52 +196,25 @@ namespace DeStream.DeStreamD.ForTest ...@@ -146,52 +196,25 @@ namespace DeStream.DeStreamD.ForTest
.UseApi() .UseApi()
.AddRPC() .AddRPC()
.Build(); .Build();
Mnemonic _mnemonic1 = node.NodeService<IWalletManager>().CreateWallet("123456", "mywallet");
Wallet _wallet = node.NodeService<IWalletManager>().GetWalletByName("mywallet");
HdAddress _addr = node.NodeService<IWalletManager>().GetUnusedAddress(new WalletAccountReference("mywallet", "account 0"));
Key _key = _wallet.GetExtendedPrivateKeyForAddress("123456", _addr).PrivateKey;
var _walletTransactionHandler = ((FullNode)node).NodeService<IWalletTransactionHandler>() as WalletTransactionHandler;
TransactionBuildContext context = CreateContext(new WalletAccountReference("mywallet", "account 0"), "password", _key.PubKey.ScriptPubKey, new Money(777), FeeType.Low, 0);
Transaction transactionResult = _walletTransactionHandler.BuildTransaction(context);
int qwe = 1;
if (node != null)
await node.RunAsync();
//Mnemonic _mnemonic2 = node.NodeService<IWalletManager>().CreateWallet("123456", "mywallet"); //Mnemonic _mnemonic1 = node.NodeService<IWalletManager>().CreateWallet("123456", "mywallet");
//Wallet _wallet = node.NodeService<IWalletManager>().GetWalletByName("mywallet"); //Wallet _wallet = node.NodeService<IWalletManager>().GetWalletByName("mywallet");
//HdAddress _addr = node.NodeService<IWalletManager>().GetUnusedAddress(new WalletAccountReference("mywallet", "account 0"));
//Key _key = _wallet.GetExtendedPrivateKeyForAddress("123456", _addr).PrivateKey;
//var _walletTransactionHandler = ((FullNode)node).NodeService<IWalletTransactionHandler>() as WalletTransactionHandler;
//var chain = new ConcurrentChain(_wallet.Network);
//WalletTestsHelpers.AddBlocksWithCoinbaseToChain(_wallet.Network, chain, _addr);
////var walletAccountReference = new WalletAccountReference()
//var account = _wallet.AccountsRoot.FirstOrDefault();
//TransactionBuildContext context = CreateContext(new WalletAccountReference("mywallet", "account 0"), "123456", _key.PubKey.ScriptPubKey, new Money(777), FeeType.Low, 0);
//Transaction transactionResult = _walletTransactionHandler.BuildTransaction(context);
//int qwe = 1;
//if (node != null)
// await node.RunAsync();
//BitcoinSecret bitcoinSecret = new BitcoinSecret(_key, node.Network);
//int _maturity = (int)node.Network.Consensus.CoinbaseMaturity;
//GenerateStratis(node, bitcoinSecret, 10);
//TestHelper.WaitLoop(() => TestHelper.IsNodeSynced((FullNode)node));
//// 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);
...@@ -221,9 +244,9 @@ namespace DeStream.DeStreamD.ForTest ...@@ -221,9 +244,9 @@ namespace DeStream.DeStreamD.ForTest
var walletManager = stratisSender.FullNode.NodeService<IWalletManager>() as WalletManager; var walletManager = stratisSender.FullNode.NodeService<IWalletManager>() as WalletManager;
//var walletManager1 = ((FullNode)node).NodeService<IWalletManager>() as WalletManager; var walletManager1 = ((FullNode)node).NodeService<IWalletManager>() as WalletManager;
//HdAddress addr = ((FullNode)node).WalletManager().GetUnusedAddress(new WalletAccountReference("mywallet", "account 0")); HdAddress addr1= ((FullNode)node).WalletManager().GetUnusedAddress(new WalletAccountReference("mywallet", "account 0"));
walletManager.CreateWallet("123456", "mywallet"); walletManager.CreateWallet("123456", "mywallet");
HdAddress sendto = walletManager.GetUnusedAddress(new WalletAccountReference("mywallet", "account 0")); HdAddress sendto = walletManager.GetUnusedAddress(new WalletAccountReference("mywallet", "account 0"));
var walletTransactionHandler = ((FullNode)node).NodeService<IWalletTransactionHandler>() as WalletTransactionHandler; var walletTransactionHandler = ((FullNode)node).NodeService<IWalletTransactionHandler>() as WalletTransactionHandler;
...@@ -233,8 +256,8 @@ namespace DeStream.DeStreamD.ForTest ...@@ -233,8 +256,8 @@ namespace DeStream.DeStreamD.ForTest
Transaction trx = walletTransactionHandler.BuildTransaction(transactionBuildContext); Transaction trx = walletTransactionHandler.BuildTransaction(transactionBuildContext);
if (node != null) //if (node != null)
await node.RunAsync(); // await node.RunAsync();
} }
catch (Exception ex) catch (Exception ex)
{ {
......
...@@ -2,11 +2,11 @@ regtest=1 ...@@ -2,11 +2,11 @@ regtest=1
rest=1 rest=1
server=1 server=1
txindex=1 txindex=1
rpcuser=fc838d2724c71aac7fcbd4defb0b626a7b070c30 rpcuser=0d723c05d8207d152a545f1d3106060617b9134e
rpcpassword=fc838d2724c71aac7fcbd4defb0b626a7b070c30 rpcpassword=0d723c05d8207d152a545f1d3106060617b9134e
port=12655 port=10346
rpcport=11967 rpcport=13972
apiport=12829 apiport=10949
printtoconsole=1 printtoconsole=1
keypool=10 keypool=10
agentprefix=node12655 agentprefix=node10346
__cookie__:075d8aa788d270f13fdcd44d625f7229338cf7d6ac55475fbd15fb0ed8d1cee7 __cookie__:7a1bd544829d4b891ae182fa73dab69b5bd13668c9987e83a595f7a4e315249f
\ No newline at end of file \ No newline at end of file
...@@ -2,11 +2,11 @@ regtest=1 ...@@ -2,11 +2,11 @@ regtest=1
rest=1 rest=1
server=1 server=1
txindex=1 txindex=1
rpcuser=de893caee72f1c34ac73ee6953cb0f40587492ec rpcuser=42852640b1aa0c94ddb6e22581fa4a672746df12
rpcpassword=de893caee72f1c34ac73ee6953cb0f40587492ec rpcpassword=42852640b1aa0c94ddb6e22581fa4a672746df12
port=13329 port=12731
rpcport=12223 rpcport=12906
apiport=13286 apiport=11375
printtoconsole=1 printtoconsole=1
keypool=10 keypool=10
agentprefix=node13329 agentprefix=node12731
__cookie__:ef2a355088fa991c75f6a28b336a40db14fd157bad716e64bae2494e0b236f13 __cookie__:f180e01485a65770cdd27b6a294693437ca63ea018034403cd3673ebd1b4d110
\ No newline at end of file \ 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