Пример #1
0
        public void WalletStore_GetData()
        {
            DataFolder dataFolder = CreateDataFolder(this);

            WalletStore store1 = new WalletStore(this.Network, dataFolder, new Types.Wallet {
                Name = "wallet1", EncryptedSeed = "EncryptedSeed1"
            });

            store1.GetData().Should().NotBeNull();
            store1.GetData().WalletTip.Height.Should().Be(0);
            store1.GetData().WalletTip.Hash.Should().Be(this.Network.GenesisHash);
            store1.GetData().WalletName.Should().Be("wallet1");
            store1.GetData().EncryptedSeed.Should().Be("EncryptedSeed1");

            var data = store1.GetData();

            data.BlockLocator = new List <uint256>()
            {
                new uint256(1), new uint256(2)
            };
            data.WalletTip = new Utilities.HashHeightPair(new uint256(2), 2);
            store1.SetData(data);

            store1.Dispose();

            WalletStore store2 = new WalletStore(this.Network, dataFolder, new Types.Wallet {
                Name = "wallet1", EncryptedSeed = "EncryptedSeed1"
            });

            store2.GetData().WalletTip.Height.Should().Be(2);
            store2.GetData().WalletTip.Hash.Should().Be(new uint256(2));
            store2.GetData().BlockLocator.Should().HaveCount(2);

            store2.Dispose();
        }
Пример #2
0
        public void CreateWalletData()
        {
            string walltName = "wallet-with-funds";
            string path      = Path.Combine(WalletOutputDataPath + @"\txdb", walltName + ".db");

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            var network = new BitcoinRegTest();
            var folder  = new DataFolder(WalletOutputDataPath);
            var wallet  = new Features.Wallet.Types.Wallet()
            {
                Name = walltName
            };

            var walletStore = new WalletStore(network, folder, wallet);

            string dataPath = Path.Combine(DataPath, "wallet-data-table.json");

            var dataTable = JsonConvert.DeserializeObject <WalletDataItem[]>(File.ReadAllText(dataPath))[0];

            WalletData walletData = new WalletData
            {
                Key           = dataTable.Id,
                WalletName    = dataTable.WalletName,
                EncryptedSeed = dataTable.EncryptedSeed,
                WalletTip     = new HashHeightPair(uint256.Parse(dataTable.WalletTip.Split("-")[1]),
                                                   int.Parse(dataTable.WalletTip.Split("-")[0])),
                BlockLocator = dataTable.BlockLocator.Select(uint256.Parse).ToList()
            };

            walletStore.SetData(walletData);

            dataPath = Path.Combine(DataPath, "wallet-transactions-table.json");

            var transactionsTable = JsonConvert.DeserializeObject <TransactionDataItem[]>(File.ReadAllText(dataPath));

            foreach (var item in transactionsTable)
            {
                var trx = new TransactionOutputData
                {
                    OutPoint = new OutPoint(uint256.Parse(item.OutPoint.Split("-")[0]),
                                            int.Parse(item.OutPoint.Split("-")[1])),
                    Address     = item.Address,
                    Id          = uint256.Parse(item.Id),
                    Amount      = new Money(item.Amount),
                    Index       = item.Index,
                    BlockHeight = item.BlockHeight,
                    BlockHash   = item.BlockHash != null?uint256.Parse(item.BlockHash) : null,
                                      CreationTime    = DateTimeOffset.FromUnixTimeSeconds(long.Parse(item.CreationTime)),
                                      ScriptPubKey    = new Script(Encoders.Hex.DecodeData(item.ScriptPubKey)),
                                      IsPropagated    = item.IsPropagated,
                                      AccountIndex    = item.AccountIndex,
                                      IsCoinStake     = item.IsCoinStake,
                                      IsCoinBase      = item.IsCoinBase,
                                      IsColdCoinStake = item.IsColdCoinStake,
                };

                if (item.SpendingDetails != null)
                {
                    trx.SpendingDetails = new Features.Wallet.Database.SpendingDetails
                    {
                        BlockHeight   = item.SpendingDetails.BlockHeight,
                        IsCoinStake   = item.SpendingDetails.IsCoinStake,
                        CreationTime  = DateTimeOffset.FromUnixTimeSeconds(long.Parse(item.SpendingDetails.CreationTime)),
                        TransactionId = uint256.Parse(item.SpendingDetails.TransactionId)
                    };

                    if (item.SpendingDetails.Payments != null)
                    {
                        foreach (PaymentDetails spendingDetailsPayment in item.SpendingDetails.Payments)
                        {
                            trx.SpendingDetails.Payments.Add(new Features.Wallet.Database.PaymentDetails
                            {
                                Amount                  = new Money(spendingDetailsPayment.Amount),
                                DestinationAddress      = spendingDetailsPayment.DestinationAddress,
                                DestinationScriptPubKey = new Script(Encoders.Hex.DecodeData(spendingDetailsPayment.DestinationScriptPubKey)),
                                OutputIndex             = spendingDetailsPayment.OutputIndex,
                                PayToSelf               = spendingDetailsPayment.PayToSelf
                            });
                        }
                    }
                }

                walletStore.InsertOrUpdate(trx);
            }
        }