Exemple #1
0
        private CrossChainDataDto ValidateCrossChainDataBeforeIndexing(CrossChainBlockData crossChainBlockData)
        {
            Assert(
                crossChainBlockData.ParentChainBlockDataList.Count > 0 ||
                crossChainBlockData.SideChainBlockDataList.Count > 0,
                "Empty cross chain data proposed.");
            var validatedParentChainBlockData = new Dictionary <int, List <ParentChainBlockData> >();
            var validationResult = ValidateSideChainBlockData(crossChainBlockData.SideChainBlockDataList,
                                                              out var validatedSideChainBlockData) &&
                                   ValidateParentChainBlockData(crossChainBlockData.ParentChainBlockDataList,
                                                                out validatedParentChainBlockData);

            Assert(validationResult, "Invalid cross chain data to be indexed.");
            var crossChainDataDto = new CrossChainDataDto(validatedSideChainBlockData, validatedParentChainBlockData);

            Assert(crossChainDataDto.GetChainIdList().Count > 0, "Empty cross chain data not allowed.");
            return(crossChainDataDto);
        }
Exemple #2
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)}");
            }
        }