Exemplo n.º 1
0
        private void SetCrossChainIndexingProposalStatus(ChainIndexingProposal crossChainIndexingProposal,
                                                         CrossChainIndexingProposalStatus status)
        {
            crossChainIndexingProposal.Status = status;
            var proposedIndexingProposal = State.IndexingPendingProposal.Value;

            proposedIndexingProposal.ChainIndexingProposalCollections[crossChainIndexingProposal.ChainId] =
                crossChainIndexingProposal;
            State.IndexingPendingProposal.Value = proposedIndexingProposal;
        }
Exemplo n.º 2
0
        private bool TryGetIndexingProposalWithStatus(int chainId, CrossChainIndexingProposalStatus status,
                                                      out ChainIndexingProposal proposal)
        {
            var proposedIndexingProposal = State.IndexingPendingProposal.Value;

            if (!proposedIndexingProposal.ChainIndexingProposalCollections.TryGetValue(chainId, out proposal))
            {
                return(false);
            }
            return(proposal.Status == status);
        }
Exemplo n.º 3
0
        private bool TryGetIndexingProposal(int chainId, out ChainIndexingProposal proposal)
        {
            var proposedIndexingProposal = State.IndexingPendingProposal.Value;

            return(proposedIndexingProposal.ChainIndexingProposalCollections.TryGetValue(chainId, out proposal));
        }
Exemplo n.º 4
0
        private void ProposeCrossChainBlockData(CrossChainDataDto crossChainDataDto, Address proposer)
        {
            var crossChainIndexingController = GetCrossChainIndexingController();

            foreach (var chainId in crossChainDataDto.GetChainIdList())
            {
                Assert(!TryGetIndexingProposal(chainId, out _), "Chain indexing already proposed.");
                var proposalToken =
                    HashHelper.ConcatAndCompute(Context.PreviousBlockHash, ConvertChainIdToHash(chainId));
                var proposalCreationInput = new CreateProposalBySystemContractInput
                {
                    ProposalInput = new CreateProposalInput
                    {
                        Params = new AcceptCrossChainIndexingProposalInput
                        {
                            ChainId = chainId
                        }.ToByteString(),
                    ContractMethodName = nameof(AcceptCrossChainIndexingProposal),
                    ExpiredTime        =
                            Context.CurrentBlockTime.AddSeconds(CrossChainIndexingProposalExpirationTimePeriod),
                    OrganizationAddress = crossChainIndexingController.OwnerAddress,
                    ToAddress           = Context.Self,
                    Token = proposalToken
                    },
                    OriginProposer = Context.Sender
                };

                Context.SendInline(crossChainIndexingController.ContractAddress,
                                   nameof(AuthorizationContractContainer.AuthorizationContractReferenceState
                                          .CreateProposalBySystemContract), proposalCreationInput);

                var proposedCrossChainBlockData = new CrossChainBlockData();
                if (crossChainDataDto.ParentChainToBeIndexedData.TryGetValue(chainId,
                                                                             out var parentChainToBeIndexedData))
                {
                    proposedCrossChainBlockData.ParentChainBlockDataList.Add(parentChainToBeIndexedData);
                }
                else if (crossChainDataDto.SideChainToBeIndexedData.TryGetValue(chainId,
                                                                                out var sideChainToBeIndexedData))
                {
                    proposedCrossChainBlockData.SideChainBlockDataList.Add(sideChainToBeIndexedData);
                }

                var crossChainIndexingProposal = new ChainIndexingProposal
                {
                    ChainId  = chainId,
                    Proposer = proposer,
                    ProposedCrossChainBlockData = proposedCrossChainBlockData
                };
                var proposalId = Context.GenerateId(crossChainIndexingController.ContractAddress, proposalToken);
                crossChainIndexingProposal.ProposalId = proposalId;
                SetCrossChainIndexingProposalStatus(crossChainIndexingProposal,
                                                    CrossChainIndexingProposalStatus.Pending);
                Context.Fire(new CrossChainIndexingDataProposedEvent
                {
                    ProposedCrossChainData = proposedCrossChainBlockData,
                    ProposalId             = proposalId
                });

                Context.LogDebug(() =>
                                 $"Proposed cross chain data for chain {ChainHelper.ConvertChainIdToBase58(chainId)}");
            }
        }