Exemplo n.º 1
0
        private static async Task <PayableContract> InternalSetupAsync(NetworkCredentials networkCredentials)
        {
            var fx = new PayableContract();

            fx.Network    = networkCredentials;
            fx.FileParams = new CreateFileParams
            {
                Expiration   = Generator.TruncatedFutureDate(12, 24),
                Endorsements = new Endorsement[] { networkCredentials.PublicKey },
                Contents     = Encoding.UTF8.GetBytes(PAYABLE_CONTRACT_BYTECODE)
            };
            fx.Client     = networkCredentials.NewClient();
            fx.FileRecord = await fx.Client.CreateFileWithRecordAsync(fx.FileParams, ctx =>
            {
                ctx.Memo = "Payable Contract Create: Uploading Contract File " + Generator.Code(10);
            });

            Assert.Equal(ResponseCode.Success, fx.FileRecord.Status);
            fx.ContractParams = new CreateContractParams
            {
                File           = fx.FileRecord.File,
                Administrator  = networkCredentials.PublicKey,
                Gas            = 500_000,
                InitialBalance = 1_000_000,
                RenewPeriod    = TimeSpan.FromDays(Generator.Integer(2, 4))
            };
            return(fx);
        }
Exemplo n.º 2
0
        public static async Task <PayableContract> CreateAsync(NetworkCredentials networkCredentials, Action <PayableContract> customize = null)
        {
            var fx = new PayableContract();

            networkCredentials.Output?.WriteLine("STARTING SETUP: Creating Payable Contract Instance");
            (fx.PublicKey, fx.PrivateKey) = Generator.KeyPair();
            fx.Network    = networkCredentials;
            fx.FileParams = new CreateFileParams
            {
                Expiration   = DateTime.UtcNow.AddSeconds(7890000),
                Endorsements = new Endorsement[] { networkCredentials.PublicKey },
                Contents     = Encoding.UTF8.GetBytes(PAYABLE_CONTRACT_BYTECODE)
            };
            fx.Client     = networkCredentials.NewClient();
            fx.FileRecord = await fx.Client.CreateFileWithRecordAsync(fx.FileParams, ctx =>
            {
                ctx.Memo = "Payable Contract Create: Uploading Contract File " + Generator.Code(10);
            });

            Assert.Equal(ResponseCode.Success, fx.FileRecord.Status);
            fx.ContractParams = new CreateContractParams
            {
                File           = fx.FileRecord.File,
                Administrator  = fx.PublicKey,
                Signatory      = fx.PrivateKey,
                Gas            = await networkCredentials.TinybarsFromGas(200),
                InitialBalance = 1_000_000,
                RenewPeriod    = TimeSpan.FromSeconds(7890000),
                Memo           = "Payable Contract " + Generator.Code(10)
            };
            customize?.Invoke(fx);
            fx.ContractRecord = await fx.Client.CreateContractWithRecordAsync(fx.ContractParams, ctx =>
            {
                ctx.Memo = "Payable Contract Create: Instantiating Payable Instance " + Generator.Code(10);
            });

            Assert.Equal(ResponseCode.Success, fx.FileRecord.Status);
            fx.Network.Output?.WriteLine("SETUP COMPLETED: Payable Contract Instance Created");
            return(fx);
        }