Beispiel #1
0
        internal Block(Stream s) : base(s)
        {
            if (BlockSignature == 1 || BlockSignature == 3)
            {
                return;
            }
            using (var br = new BinaryReader(s, Encoding.Default, true))
            {
                TransactionCount = br.ReadUInt32();
                if (TransactionCount <= 0)
                {
                    return;
                }
                Transactions = new List <ITransaction>();
                for (var i = 0; i < TransactionCount; i++)
                {
                    TransactionsType = (TransactionType)br.ReadUInt32();
                    Transaction t;
                    switch (TransactionsType)
                    {
                    case TransactionType.Transaction:
                    case TransactionType.BuyAccount:
                        t = new TransferTransaction(s);
                        break;

                    case TransactionType.ChangeKey:
                    case TransactionType.ChangeKeySigned:
                        t = new ChangeKeyTransaction(s, TransactionsType);
                        break;

                    case TransactionType.ListAccountForSale:
                    case TransactionType.DeListAccountForSale:
                        t = new ListAccountTransaction(s);
                        break;

                    case TransactionType.ChangeAccountInfo:
                        t = new ChangeAccountInfoTransaction(s);
                        break;

                    default:
                        s.Position = s.Length;
                        return;
                    }
                    t.TransactionType = TransactionsType;
                    Transactions.Add(t);
                }
            }
        }
        internal NewTransactionMessage(Stream stream, MessageHeader rp) : base(rp)
        {
            using (BinaryReader br = new BinaryReader(stream))
            {
                TransactionCount = br.ReadUInt32();
                Transactions     = new ITransaction[TransactionCount];
                TransactionTypes = new TransactionType[TransactionCount];
                for (int i = 0; i < TransactionCount; i++)
                {
                    TransactionTypes[i] = (TransactionType)br.ReadByte();
                    switch (TransactionTypes[i])
                    {
                    case TransactionType.Transaction:
                    case TransactionType.BuyAccount:
                        TransferTransaction t = new TransferTransaction(stream);
                        Transactions[i] = t;
                        break;

                    case TransactionType.ChangeKey:
                    case TransactionType.ChangeKeySigned:
                        Transactions[i] = new ChangeKeyTransaction(stream, TransactionTypes[i]);
                        break;

                    case TransactionType.ListAccountForSale:
                    case TransactionType.DeListAccountForSale:
                        Transactions[i] = new ListAccountTransaction(stream);
                        break;

                    case TransactionType.ChangeAccountInfo:
                        Transactions[i] = new ChangeAccountInfoTransaction(stream);
                        break;

                    default:
                        stream.Position = stream.Length;
                        return;
                    }
                }
            }
        }
Beispiel #3
0
        public static void ApplyTransaction(ITransaction t, Block b = null)
        {
            Account targetAccount = null;
            Account signerAccount = null;

            try
            {
                signerAccount = Accounts[t.SignerAccount];
                targetAccount = Accounts[t.TargetAccount];
            }
            catch
            {
                SaveNext();
                signerAccount = Accounts[t.SignerAccount];
                targetAccount = Accounts[t.TargetAccount];
            }
            targetAccount.Saved = false;
            signerAccount.Saved = false;
            var signerBlock = Get(signerAccount.BlockNumber);
            var targetBlock = Get(targetAccount.BlockNumber);

            if (t.Fee != 0)
            {
                signerAccount.NumberOfOperations++;
            }
            if (b != null)
            {
                signerAccount.UpdatedBlock = b.BlockNumber;
                targetAccount.UpdatedBlock = b.BlockNumber;
                targetAccount.Saved        = true;
                signerAccount.Saved        = true;
            }
            if (TransactionType.BuyAccount == t.TransactionType)
            {
                TransferTransaction transferTransaction = (TransferTransaction)t;
                Account             sellerAccount       = Accounts[transferTransaction.SellerAccount];
                sellerAccount.Saved = false;
                if (b != null)
                {
                    sellerAccount.UpdatedBlock = b.BlockNumber;
                    sellerAccount.Saved        = true;
                }
            }
            if (AppliedTransactions.Count(p => p.GetHash().SequenceEqual(t.GetHash())) > 0)
            {
                return; // FDon't apply twice
            }
            switch (t.TransactionType)
            {
            case TransactionType.Transaction:
                TransferTransaction transfer = (TransferTransaction)t;
                if (signerBlock != null && targetBlock != null)
                {
                    if (t.Fee == 0)
                    {
                        signerAccount.NumberOfOperations++;
                    }
                    signerAccount.Balance -= (transfer.Fee + transfer.Amount);
                    targetAccount.Balance += transfer.Amount;
                }

                break;

            case TransactionType.BuyAccount:
                TransferTransaction transferTransaction = (TransferTransaction)t;
                if (t.Fee == 0)
                {
                    signerBlock.Accounts.First(p => p.AccountNumber == t.SignerAccount).NumberOfOperations++;
                }
                signerBlock.Accounts.First(p => p.AccountNumber == t.SignerAccount).Balance -=
                    (transferTransaction.Fee + transferTransaction.Amount);
                Account sellerAccount = Accounts[transferTransaction.SellerAccount];
                Get(sellerAccount.BlockNumber);
                sellerAccount.Balance += transferTransaction.Amount;
                targetAccount.AccountInfo.AccountKey        = transferTransaction.NewAccountKey;
                targetAccount.AccountInfo.Price             = 0;
                targetAccount.AccountInfo.LockedUntilBlock  = 0;
                targetAccount.AccountInfo.State             = AccountState.Normal;
                targetAccount.AccountInfo.AccountToPayPrice = 0;
                targetAccount.AccountInfo.NewPublicKey      = null;
                break;

            case TransactionType.DeListAccountForSale:
            case TransactionType.ListAccountForSale:
                ListAccountTransaction listAccountTransaction = (ListAccountTransaction)t;
                signerAccount.Balance -= listAccountTransaction.Fee;
                if (t.Fee == 0)
                {
                    signerAccount.NumberOfOperations++;
                }
                if (signerBlock != null && targetBlock != null)
                {
                    if (listAccountTransaction.TransactionType == TransactionType.ListAccountForSale)
                    {
                        targetAccount.AccountInfo.Price             = listAccountTransaction.AccountPrice;
                        targetAccount.AccountInfo.LockedUntilBlock  = listAccountTransaction.LockedUntilBlock;
                        targetAccount.AccountInfo.State             = AccountState.Sale;
                        targetAccount.AccountInfo.Price             = listAccountTransaction.AccountPrice;
                        targetAccount.AccountInfo.NewPublicKey      = listAccountTransaction.NewPublicKey;
                        targetAccount.AccountInfo.AccountToPayPrice = listAccountTransaction.AccountToPay;
                    }
                    else
                    {
                        targetAccount.AccountInfo.State             = AccountState.Normal;
                        targetAccount.AccountInfo.Price             = 0;
                        targetAccount.AccountInfo.NewPublicKey      = null;
                        targetAccount.AccountInfo.LockedUntilBlock  = 0;
                        targetAccount.AccountInfo.AccountToPayPrice = 0;
                    }
                }

                break;

            case TransactionType.ChangeAccountInfo:
                ChangeAccountInfoTransaction changeAccountInfoTransaction = (ChangeAccountInfoTransaction)t;
                if ((changeAccountInfoTransaction.ChangeType & 1) == 1)
                {
                    targetAccount.AccountInfo.AccountKey = changeAccountInfoTransaction.NewAccountKey;
                }

                if ((changeAccountInfoTransaction.ChangeType & 4) == 4)
                {
                    targetAccount.AccountType = changeAccountInfoTransaction.NewType;
                }

                if ((changeAccountInfoTransaction.ChangeType & 2) == 2)
                {
                    targetAccount.Name = changeAccountInfoTransaction.NewName;
                }

                signerAccount.Balance -= changeAccountInfoTransaction.Fee;
                if (t.Fee == 0)
                {
                    signerAccount.NumberOfOperations++;
                }
                break;

            case TransactionType.ChangeKey:
            case TransactionType.ChangeKeySigned:
                ChangeKeyTransaction changeKeyTransaction = (ChangeKeyTransaction)t;
                signerAccount.Balance -= changeKeyTransaction.Fee;
                targetAccount.AccountInfo.AccountKey = changeKeyTransaction.NewAccountKey;
                if (t.Fee == 0)
                {
                    signerAccount.NumberOfOperations++;
                }
                break;
            }
            AppliedTransactions.Add(t);
        }
Beispiel #4
0
        internal static List <CheckPointBlock> BuildFromBlockChain(BlockChain blockChain)
        {
            List <CheckPointBlock> checkPoint = new List <CheckPointBlock>(blockChain.BlockHeight() + 1);
            uint  accNumber = 0;
            ulong accWork   = 0;

            for (int block = 0; block < 100 * ((blockChain.GetLastBlock().BlockNumber + 1) / 100); block++)
            {
                Block currentBlock = blockChain.Get(block);
                if (currentBlock == null)
                {
                    var   h             = blockChain.GetLastBlock().BlockNumber;
                    Block currentBlock1 = blockChain.Get((int)block);
                    continue;
                }
                CheckPointBlock checkPointBlock = new CheckPointBlock {
                    AccountKey = currentBlock.AccountKey
                };
                for (int i = 0; i < 5; i++)
                {
                    checkPointBlock.Accounts.Add(new Account
                    {
                        AccountNumber      = accNumber,
                        Balance            = (i == 0 ? 1000000ul + (ulong)currentBlock.Fee : 0ul),
                        BlockNumber        = currentBlock.BlockNumber,
                        UpdatedBlock       = currentBlock.BlockNumber,
                        NumberOfOperations = 0,
                        AccountType        = 0,
                        Name           = "",
                        UpdatedByBlock = currentBlock.BlockNumber,
                        AccountInfo    = new AccountInfo
                        {
                            AccountKey = currentBlock.AccountKey,
                            State      = AccountState.Normal
                        }
                    });
                    accNumber++;
                }

                accWork += currentBlock.CompactTarget;
                checkPointBlock.AccumulatedWork   = accWork;
                checkPointBlock.AvailableProtocol = currentBlock.AvailableProtocol;
                checkPointBlock.BlockNumber       = currentBlock.BlockNumber;
                checkPointBlock.BlockSignature    = 2; //b.BlockSignature;
                checkPointBlock.CheckPointHash    = currentBlock.CheckPointHash;
                checkPointBlock.CompactTarget     = currentBlock.CompactTarget;
                checkPointBlock.Fee             = currentBlock.Fee;
                checkPointBlock.Nonce           = currentBlock.Nonce;
                checkPointBlock.Payload         = currentBlock.Payload;
                checkPointBlock.ProofOfWork     = currentBlock.ProofOfWork;
                checkPointBlock.ProtocolVersion = currentBlock.ProtocolVersion;
                checkPointBlock.Reward          = currentBlock.Reward;
                checkPointBlock.Timestamp       = currentBlock.Timestamp;
                checkPointBlock.TransactionHash = currentBlock.TransactionHash;
                WorkSum += currentBlock.CompactTarget;
                foreach (var t in currentBlock.Transactions)
                {
                    Account account;
                    var     signer = checkPoint.FirstOrDefault(p =>
                                                               p.Accounts.Count(a => a.AccountNumber == t.SignerAccount) > 0);
                    var target = checkPoint.FirstOrDefault(p =>
                                                           p.Accounts.Count(a => a.AccountNumber == t.TargetAccount) > 0);
                    if (t.Fee != 0)
                    {
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).NumberOfOperations++;
                    }
                    switch (t.TransactionType)
                    {
                    case TransactionType.Transaction:
                        TransferTransaction transfer = (TransferTransaction)t;
                        if (signer != null && target != null)
                        {
                            if (t.Fee == 0)
                            {
                                signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).NumberOfOperations++;
                            }
                            signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).Balance -=
                                (transfer.Fee + transfer.Amount);
                            target.Accounts.First(p => p.AccountNumber == t.TargetAccount).Balance +=
                                transfer.Amount;
                            signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).UpdatedBlock =
                                currentBlock.BlockNumber;
                            target.Accounts.First(p => p.AccountNumber == t.TargetAccount).UpdatedBlock =
                                currentBlock.BlockNumber;
                        }

                        break;

                    case TransactionType.BuyAccount:
                        TransferTransaction transferTransaction = (TransferTransaction)t;      // TODO: be kell fejezni
                        if (t.Fee == 0)
                        {
                            signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).NumberOfOperations++;
                        }
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).Balance -=
                            (transferTransaction.Fee + transferTransaction.Amount);
                        CheckPointBlock seller = checkPoint.FirstOrDefault(p =>
                                                                           p.Accounts.Count(a => a.AccountNumber == transferTransaction.SellerAccount) > 0);
                        seller.Accounts.First(p => p.AccountNumber == transferTransaction.SellerAccount).Balance +=
                            transferTransaction.Amount;
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).UpdatedBlock = currentBlock.BlockNumber;
                        target.Accounts.First(p => p.AccountNumber == t.TargetAccount).UpdatedBlock = currentBlock.BlockNumber;
                        seller.Accounts.First(p => p.AccountNumber == transferTransaction.SellerAccount)
                        .UpdatedBlock = currentBlock.BlockNumber;
                        account       = target.Accounts.First(p => p.AccountNumber == t.TargetAccount);
                        account.AccountInfo.AccountKey        = transferTransaction.NewAccountKey;
                        account.AccountInfo.Price             = 0;
                        account.AccountInfo.LockedUntilBlock  = 0;
                        account.AccountInfo.State             = AccountState.Normal;
                        account.AccountInfo.AccountToPayPrice = 0;
                        account.AccountInfo.NewPublicKey      = null;
                        break;

                    case TransactionType.DeListAccountForSale:
                    case TransactionType.ListAccountForSale:
                        ListAccountTransaction listAccountTransaction = (ListAccountTransaction)t;
                        account = target.Accounts.First(p => p.AccountNumber == t.TargetAccount);
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).Balance -=
                            listAccountTransaction.Fee;
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).UpdatedBlock = currentBlock.BlockNumber;
                        target.Accounts.First(p => p.AccountNumber == t.TargetAccount).UpdatedBlock = currentBlock.BlockNumber;
                        if (t.Fee == 0)
                        {
                            signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).NumberOfOperations++;
                        }
                        if (listAccountTransaction.TransactionType == TransactionType.ListAccountForSale)
                        {
                            account.AccountInfo.Price             = listAccountTransaction.AccountPrice;
                            account.AccountInfo.LockedUntilBlock  = listAccountTransaction.LockedUntilBlock;
                            account.AccountInfo.State             = AccountState.Sale;
                            account.AccountInfo.Price             = listAccountTransaction.AccountPrice;
                            account.AccountInfo.NewPublicKey      = listAccountTransaction.NewPublicKey;
                            account.AccountInfo.AccountToPayPrice = listAccountTransaction.AccountToPay;
                        }
                        else
                        {
                            account.AccountInfo.State             = AccountState.Normal;
                            account.AccountInfo.Price             = 0;
                            account.AccountInfo.NewPublicKey      = null;
                            account.AccountInfo.LockedUntilBlock  = 0;
                            account.AccountInfo.AccountToPayPrice = 0;
                        }

                        break;

                    case TransactionType.ChangeAccountInfo:
                        ChangeAccountInfoTransaction changeAccountInfoTransaction =
                            (ChangeAccountInfoTransaction)t;
                        account = target.Accounts.First(p => p.AccountNumber == t.TargetAccount);
                        if ((changeAccountInfoTransaction.ChangeType & 1) == 1)
                        {
                            account.AccountInfo.AccountKey = changeAccountInfoTransaction.NewAccountKey;
                        }

                        if ((changeAccountInfoTransaction.ChangeType & 4) == 4)
                        {
                            account.AccountType = changeAccountInfoTransaction.NewType;
                        }

                        if ((changeAccountInfoTransaction.ChangeType & 2) == 2)
                        {
                            account.Name = changeAccountInfoTransaction.NewName;
                        }

                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).Balance -=
                            changeAccountInfoTransaction.Fee;
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).UpdatedBlock = currentBlock.BlockNumber;
                        account.UpdatedBlock = currentBlock.BlockNumber;
                        if (t.Fee == 0)
                        {
                            signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).NumberOfOperations++;
                        }
                        break;

                    case TransactionType.ChangeKey:
                    case TransactionType.ChangeKeySigned:
                        ChangeKeyTransaction changeKeyTransaction = (ChangeKeyTransaction)t;
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).Balance -=
                            changeKeyTransaction.Fee;
                        account = target.Accounts.First(p => p.AccountNumber == t.TargetAccount);
                        account.AccountInfo.AccountKey = changeKeyTransaction.NewAccountKey;
                        account.UpdatedBlock           = currentBlock.BlockNumber;
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).UpdatedBlock = currentBlock.BlockNumber;
                        if (t.Fee == 0)
                        {
                            signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).NumberOfOperations++;
                        }
                        break;
                    }
                }

                checkPoint.Add(checkPointBlock);
                if (block % 100 == 0)
                {
                    CheckPointBuilding?.Invoke(new object(), new CheckPointBuildingEventArgs
                    {
                        BlocksDone   = block,
                        BlocksNeeded = (int)(100 * ((blockChain.GetLastBlock().BlockNumber + 1) / 100)) * 2
                    });
                }
            }

            foreach (var p in checkPoint)
            {
                p.BlockHash = p.CalculateBlockHash();

                if (p.BlockNumber % 100 == 0)
                {
                    CheckPointBuilding?.Invoke(new object(), new CheckPointBuildingEventArgs
                    {
                        BlocksDone   = (int)(p.BlockNumber + checkPoint.Count),
                        BlocksNeeded = (int)(checkPoint.Count * 2)
                    });
                }
            }
            return(checkPoint);
        }
Beispiel #5
0
        public static List <CheckPointBlock> BuildFromBlockChain(BlockChain blockChain)
        {
            var   checkPoint = new List <CheckPointBlock>(blockChain.BlockHeight() + 1);
            uint  accNumber  = 0;
            ulong accWork    = 0;

            for (int block = 0; block < 100 * ((blockChain.GetLastBlock().BlockNumber + 1) / 100); block++)
            {
#if !NETCOREAPP
                if (block % 1000 == 0)
                {
                    Log.Info($"Building checkpont: {block} block");
                }
#endif
                Block b = blockChain.Get(block);
                var   checkPointBlock = new CheckPointBlock {
                    AccountKey = b.AccountKey
                };
                for (var i = 0; i < 5; i++)
                {
                    checkPointBlock.Accounts.Add(new Account
                    {
                        AccountNumber      = accNumber,
                        Balance            = (i == 0)?1000000ul + (ulong)b.Fee:0ul,
                        BlockNumber        = b.BlockNumber,
                        UpdatedBlock       = b.BlockNumber,
                        NumberOfOperations = 0,
                        AccountType        = 0,
                        Name           = "",
                        UpdatedByBlock = b.BlockNumber,
                        AccountInfo    = new AccountInfo
                        {
                            AccountKey = b.AccountKey,
                            State      = AccountState.Normal
                        }
                    });
                    accNumber++;
                }
                accWork += b.CompactTarget;
                checkPointBlock.AccumulatedWork   = accWork;
                checkPointBlock.AvailableProtocol = b.AvailableProtocol;
                checkPointBlock.BlockNumber       = b.BlockNumber;
                checkPointBlock.BlockSignature    = 2;//b.BlockSignature;
                checkPointBlock.CheckPointHash    = b.CheckPointHash;
                checkPointBlock.CompactTarget     = b.CompactTarget;
                checkPointBlock.Fee             = b.Fee;
                checkPointBlock.Nonce           = b.Nonce;
                checkPointBlock.Payload         = b.Payload;
                checkPointBlock.ProofOfWork     = b.ProofOfWork;
                checkPointBlock.ProtocolVersion = b.ProtocolVersion;
                checkPointBlock.Reward          = b.Reward;
                checkPointBlock.Timestamp       = b.Timestamp;
                checkPointBlock.TransactionHash = b.TransactionHash;
                foreach (var t in b.Transactions)
                {
                    Account account;
                    var     signer = checkPoint.FirstOrDefault(p => p.Accounts.Count(a => a.AccountNumber == t.SignerAccount) > 0);
                    var     target = checkPoint.FirstOrDefault(p => p.Accounts.Count(a => a.AccountNumber == t.TargetAccount) > 0);
                    if (signer == null)
                    {
                        throw new NullReferenceException("Signer account is null");
                    }
                    if (t.Fee != 0)
                    {
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).NumberOfOperations++;
                    }
                    switch (t.TransactionType)
                    {
                    case TransactionType.Transaction:
                        var transfer = (TransferTransaction)t;
                        if (target != null)
                        {
                            if (t.Fee == 0)
                            {
                                signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).NumberOfOperations++;
                            }
                            signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).Balance     -= transfer.Fee + transfer.Amount;
                            target.Accounts.First(p => p.AccountNumber == t.TargetAccount).Balance     += transfer.Amount;
                            signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).UpdatedBlock = b.BlockNumber;
                            target.Accounts.First(p => p.AccountNumber == t.TargetAccount).UpdatedBlock = b.BlockNumber;
                        }
                        break;

                    case TransactionType.BuyAccount:
                        TransferTransaction transferTransaction = (TransferTransaction)t;     // TODO: be kell fejezni
                        if (t.Fee == 0)
                        {
                            signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).NumberOfOperations++;
                        }
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).Balance -= transferTransaction.Fee + transferTransaction.Amount;
                        CheckPointBlock seller = checkPoint.FirstOrDefault(p => p.Accounts.Count(a => a.AccountNumber == transferTransaction.SellerAccount) > 0);
                        seller.Accounts.First(p => p.AccountNumber == transferTransaction.SellerAccount).Balance += transferTransaction.Amount;
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).UpdatedBlock = b.BlockNumber;
                        target.Accounts.First(p => p.AccountNumber == t.TargetAccount).UpdatedBlock = b.BlockNumber;
                        seller.Accounts.First(p => p.AccountNumber == transferTransaction.SellerAccount).UpdatedBlock = b.BlockNumber;
                        account = target.Accounts.First(p => p.AccountNumber == t.TargetAccount);
                        account.AccountInfo.AccountKey        = transferTransaction.NewAccountKey;
                        account.AccountInfo.Price             = 0;
                        account.AccountInfo.LockedUntilBlock  = 0;
                        account.AccountInfo.State             = AccountState.Normal;
                        account.AccountInfo.AccountToPayPrice = 0;
                        account.AccountInfo.NewPublicKey      = null;
                        break;

                    case TransactionType.DeListAccountForSale:
                    case TransactionType.ListAccountForSale:
                        ListAccountTransaction listAccountTransaction = (ListAccountTransaction)t;
                        account = target.Accounts.First(p => p.AccountNumber == t.TargetAccount);
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).Balance     -= listAccountTransaction.Fee;
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).UpdatedBlock = b.BlockNumber;
                        target.Accounts.First(p => p.AccountNumber == t.TargetAccount).UpdatedBlock = b.BlockNumber;
                        if (t.Fee == 0)
                        {
                            signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).NumberOfOperations++;
                        }
                        if (listAccountTransaction.TransactionType == TransactionType.ListAccountForSale)
                        {
                            account.AccountInfo.Price             = listAccountTransaction.AccountPrice;
                            account.AccountInfo.LockedUntilBlock  = listAccountTransaction.LockedUntilBlock;
                            account.AccountInfo.State             = AccountState.Sale;
                            account.AccountInfo.Price             = listAccountTransaction.AccountPrice;
                            account.AccountInfo.NewPublicKey      = listAccountTransaction.NewPublicKey;
                            account.AccountInfo.AccountToPayPrice = listAccountTransaction.AccountToPay;
                        }
                        else
                        {
                            account.AccountInfo.State             = AccountState.Normal;
                            account.AccountInfo.Price             = 0;
                            account.AccountInfo.NewPublicKey      = null;
                            account.AccountInfo.LockedUntilBlock  = 0;
                            account.AccountInfo.AccountToPayPrice = 0;
                        }
                        break;

                    case TransactionType.ChangeAccountInfo:
                        ChangeAccountInfoTransaction changeAccountInfoTransaction = (ChangeAccountInfoTransaction)t;
                        account = target.Accounts.First(p => p.AccountNumber == t.TargetAccount);
                        if ((changeAccountInfoTransaction.ChangeType & 1) == 1)
                        {
                            account.AccountInfo.AccountKey = changeAccountInfoTransaction.NewAccountKey;
                        }
                        if ((changeAccountInfoTransaction.ChangeType & 4) == 4)
                        {
                            account.AccountType = changeAccountInfoTransaction.NewType;
                        }
                        if ((changeAccountInfoTransaction.ChangeType & 2) == 2)
                        {
                            account.Name = changeAccountInfoTransaction.NewName;
                        }
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).Balance     -= changeAccountInfoTransaction.Fee;
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).UpdatedBlock = b.BlockNumber;
                        account.UpdatedBlock = b.BlockNumber;
                        if (t.Fee == 0)
                        {
                            signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).NumberOfOperations++;
                        }
                        break;

                    case TransactionType.ChangeKey:
                    case TransactionType.ChangeKeySigned:
                        ChangeKeyTransaction changeKeyTransaction = (ChangeKeyTransaction)t;
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).Balance -= changeKeyTransaction.Fee;
                        account = target.Accounts.First(p => p.AccountNumber == t.TargetAccount);
                        account.AccountInfo.AccountKey = changeKeyTransaction.NewAccountKey;
                        account.UpdatedBlock           = b.BlockNumber;
                        signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).UpdatedBlock = b.BlockNumber;
                        if (t.Fee == 0)
                        {
                            signer.Accounts.First(p => p.AccountNumber == t.SignerAccount).NumberOfOperations++;
                        }
                        break;
                    }
                }
                checkPoint.Add(checkPointBlock);
            }
            foreach (var p in checkPoint)
            {
                p.BlockHash = p.CalculateBlockHash();
            }
            return(checkPoint);
        }