Esempio n. 1
0
 public Task Init(Block block, RawBlock rawBlock)
 {
     Block        = block;
     NextProtocol = rawBlock.Metadata.NextProtocol;
     AppState     = Cache.AppState.Get();
     return(Task.CompletedTask);
 }
Esempio n. 2
0
        public static async Task <VotingCommit> Apply(ProtocolHandler proto, RawBlock rawBlock)
        {
            var commit = new VotingCommit(proto);
            await commit.Init(rawBlock);

            await commit.Apply();

            return(commit);
        }
Esempio n. 3
0
        public async Task Init(RawBlock rawBlock)
        {
            var protocol = await Cache.Protocols.GetAsync(rawBlock.Protocol);

            VotingPeriod = new ProposalPeriod
            {
                Code  = 0,
                Epoch = new VotingEpoch {
                    Level = rawBlock.Level
                },
                Kind       = VotingPeriods.Proposal,
                StartLevel = rawBlock.Level,
                EndLevel   = protocol.BlocksPerVoting
            };
        }
Esempio n. 4
0
 public async Task Init(RawBlock rawBlock)
 {
     Block = new Block
     {
         Id        = Cache.AppState.NextOperationId(),
         Hash      = rawBlock.Hash,
         Level     = rawBlock.Level,
         Protocol  = await Cache.Protocols.GetAsync(rawBlock.Protocol),
         Timestamp = rawBlock.Header.Timestamp,
         Events    = BlockEvents.CycleBegin
                     | BlockEvents.ProtocolBegin
                     | BlockEvents.ProtocolEnd
                     | BlockEvents.VotingPeriodBegin
                     | BlockEvents.Snapshot
     };
 }
Esempio n. 5
0
        public async Task Init(Block block, RawBlock rawBlock)
        {
            var protocol = await Cache.Protocols.GetAsync(rawBlock.Protocol);

            BootstrapedAccounts = new List <Account>(65);
            Timestamp           = rawBlock.Header.Timestamp;
            Level = rawBlock.Level;
            Block = block;

            var stream = await Proto.Node.GetContractsAsync(level : 1);

            var contracts = await(Proto.Serializer as Serializer).DeserializeContracts(stream);
            var delegates = new List <Data.Models.Delegate>(8);

            #region bootstrap delegates
            foreach (var data in contracts.Where(x => x.Delegate == x.Address))
            {
                var baker = new Data.Models.Delegate
                {
                    Id                = Cache.AppState.NextAccountId(),
                    Address           = data.Address,
                    FirstLevel        = rawBlock.Level,
                    LastLevel         = rawBlock.Level,
                    ActivationLevel   = 1,
                    DeactivationLevel = GracePeriod.Init(1, protocol.BlocksPerCycle, protocol.PreservedCycles),
                    Balance           = data.Balance,
                    Counter           = data.Counter,
                    PublicKey         = data.Manager,
                    Staked            = true,
                    Revealed          = true,
                    Type              = AccountType.Delegate
                };
                Cache.Accounts.Add(baker);
                BootstrapedAccounts.Add(baker);
                delegates.Add(baker);
            }
            #endregion

            #region bootstrap users
            foreach (var data in contracts.Where(x => x.Address[0] == 't' && String.IsNullOrEmpty(x.Delegate)))
            {
                var user = new User
                {
                    Id         = Cache.AppState.NextAccountId(),
                    Address    = data.Address,
                    FirstLevel = rawBlock.Level,
                    LastLevel  = rawBlock.Level,
                    Balance    = data.Balance,
                    Counter    = data.Counter,
                    Type       = AccountType.User
                };
                Cache.Accounts.Add(user);
                BootstrapedAccounts.Add(user);
            }
            #endregion

            #region bootstrap contracts
            foreach (var data in contracts.Where(x => x.Address[0] == 'K'))
            {
                var manager = (User)await Cache.Accounts.GetAsync(data.Manager);

                manager.ContractsCount++;

                var contract = new Contract
                {
                    Id              = Cache.AppState.NextAccountId(),
                    Address         = data.Address,
                    FirstLevel      = rawBlock.Level,
                    LastLevel       = rawBlock.Level,
                    Balance         = data.Balance,
                    Counter         = data.Counter,
                    Spendable       = false,
                    DelegationLevel = 1,
                    Delegate        = Cache.Accounts.GetDelegate(data.Delegate),
                    Manager         = manager,
                    Staked          = !String.IsNullOrEmpty(data.Delegate),
                    Type            = AccountType.Contract,
                    Kind            = ContractKind.SmartContract,
                };

                Cache.Accounts.Add(contract);
                BootstrapedAccounts.Add(contract);
            }
            #endregion

            #region stats
            foreach (var baker in delegates)
            {
                var delegators = BootstrapedAccounts.Where(x => x.Delegate == baker);

                baker.DelegatorsCount = delegators.Count();
                baker.StakingBalance  = baker.Balance
                                        + (baker.DelegatorsCount > 0 ? delegators.Sum(x => x.Balance) : 0);
            }
            #endregion
        }
Esempio n. 6
0
        public static async Task <BootstrapCommit> Apply(ProtocolHandler proto, Block block, RawBlock rawBlock)
        {
            var commit = new BootstrapCommit(proto);
            await commit.Init(block, rawBlock);

            await commit.Apply();

            return(commit);
        }