Пример #1
0
        public override Empty UpdateRental(UpdateRentalInput input)
        {
            AssertControllerForSideChainRental();
            foreach (var pair in input.Rental)
            {
                Assert(Context.Variables.GetStringArray(TokenContractConstants.PayRentalSymbolListName).Contains(pair.Key), "Invalid symbol.");
                Assert(pair.Value >= 0, "Invalid amount.");
                State.Rental[pair.Key] = pair.Value;
            }

            return(new Empty());
        }
        private async Task InitialTokenContractAsync(bool issueToken = true)
        {
            await CreateTokenAsync("CPU", ResourceSupply, issueToken);
            await CreateTokenAsync("RAM", ResourceSupply, issueToken);
            await CreateTokenAsync("DISK", ResourceSupply, issueToken);
            await CreateTokenAsync("NET", ResourceSupply, issueToken);

            var defaultParliamentOrganization = await ParliamentContractStub.GetDefaultOrganizationAddress.CallAsync(new Empty());

            var setSideChainCreatorProposalInput = new InitializeFromParentChainInput
            {
                ResourceAmount =
                {
                    { "CPU",  CpuAmount  },
                    { "RAM",  RamAmount  },
                    { "DISK", DiskAmount },
                    { "NET",  NetAmount  }
                },
                Creator = Creator
            };

            await ParliamentReachAnAgreementAsync(TokenContractAddress, defaultParliamentOrganization,
                                                  nameof(TokenContractImplContainer.TokenContractImplStub.InitializeFromParentChain),
                                                  setSideChainCreatorProposalInput);

            var updateRentalInput = new UpdateRentalInput
            {
                Rental =
                {
                    { "CPU",  Rental },
                    { "RAM",  Rental },
                    { "DISK", Rental },
                    { "NET",  Rental },
                }
            };
            await TokenContractStub.SetPrimaryTokenSymbol.SendAsync(new SetPrimaryTokenSymbolInput { Symbol = NativeTokenSymbol });

            await TokenContractStub.InitializeAuthorizedController.SendAsync(new Empty());

            await UpdateSideChainRentalDefaultProposalAsync(
                nameof(TokenContractImplContainer.TokenContractImplStub.UpdateRental), updateRentalInput);
        }
Пример #3
0
        private async Task InitialTokenContract(bool issueToken = true)
        {
            if (!ParliamentStubs.Any())
            {
                InitialAcs3Stubs();
            }

            await ParliamentStubs.First().Initialize.SendAsync(new Parliament.InitializeInput
            {
            });

            var defaultOrganizationAddress =
                await ParliamentStubs.First().GetDefaultOrganizationAddress.CallAsync(new Empty());

            await CreateToken(
                GetRequiredService <IOptionsSnapshot <HostSmartContractBridgeContextOptions> >().Value
                .ContextVariables[ContextVariableDictionary.NativeSymbolName], ResourceSupply, true);

            await ParliamentReachAnAgreementAsync(new CreateProposalInput
            {
                ToAddress          = ContractAddresses[TokenSmartContractAddressNameProvider.Name],
                ContractMethodName = nameof(TokenContractImplContainer.TokenContractImplStub.InitializeFromParentChain),
                Params             = new InitializeFromParentChainInput()
                {
                    ResourceAmount =
                    {
                        { "CPU",  CpuAmount  },
                        { "RAM",  RamAmount  },
                        { "DISK", DiskAmount },
                        { "NET",  NetAmount  }
                    },
                    Creator = Creator
                }.ToByteString(),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddDays(1),
                OrganizationAddress = defaultOrganizationAddress
            });

            var updateRentalInput = new UpdateRentalInput
            {
                Rental =
                {
                    { "CPU",  Rental },
                    { "RAM",  Rental },
                    { "DISK", Rental },
                    { "NET",  Rental },
                }
            };
            var sideCreator          = Address.FromPublicKey(SampleECKeyPairs.KeyPairs[0].PublicKey);
            var parliamentOrgAddress = defaultOrganizationAddress;
            var twoProposers         = new List <Address> {
                parliamentOrgAddress, sideCreator
            };
            var createOrganizationInput2 = new CreateOrganizationInput
            {
                ProposerWhiteList = new ProposerWhiteList
                {
                    Proposers = { twoProposers }
                },
                OrganizationMemberList = new OrganizationMemberList
                {
                    OrganizationMembers = { twoProposers }
                },
                ProposalReleaseThreshold = new ProposalReleaseThreshold
                {
                    MinimalApprovalThreshold   = twoProposers.Count,
                    MinimalVoteThreshold       = twoProposers.Count,
                    MaximalRejectionThreshold  = 0,
                    MaximalAbstentionThreshold = 0
                }
            };
            var associationAddressRet = await AssociationStub.CreateOrganization.SendAsync(createOrganizationInput2);

            var associationAddress = new Address();

            associationAddress.MergeFrom(associationAddressRet.TransactionResult.ReturnValue);
            var toAssociationProposal = new CreateProposalInput
            {
                ToAddress           = ContractAddresses[TokenSmartContractAddressNameProvider.Name],
                ContractMethodName  = nameof(TokenContractImplContainer.TokenContractImplStub.UpdateRental),
                Params              = updateRentalInput.ToByteString(),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddDays(1),
                OrganizationAddress = associationAddress
            };
            var associationProposalRet = (await AssociationStub.CreateProposal.SendAsync(toAssociationProposal)).TransactionResult;
            var associationProposalId  = new Hash();

            associationProposalId.MergeFrom(associationProposalRet.ReturnValue);

            await ParliamentReachAnAgreementAsync(new CreateProposalInput
            {
                ToAddress           = ContractAddresses[AssociationSmartContractAddressNameProvider.Name],
                ContractMethodName  = nameof(AssociationContractContainer.AssociationContractStub.Approve),
                Params              = associationProposalId.ToByteString(),
                ExpiredTime         = TimestampHelper.GetUtcNow().AddDays(1),
                OrganizationAddress = parliamentOrgAddress
            });

            await AssociationStub.Approve.SendAsync(associationProposalId);

            await AssociationStub.Release.SendAsync(associationProposalId);

            await CreateToken("CPU", ResourceSupply, issueToken);
            await CreateToken("RAM", ResourceSupply, issueToken);
            await CreateToken("DISK", ResourceSupply, issueToken);
            await CreateToken("NET", ResourceSupply, issueToken);
        }