private static async Task InstantiateContract(IClient client)
        {
            var generalApi = new GeneralApi(client);

            // Create gen entry
            var arguments = new[] { "dummy" };
            var entry     = new ContractInstantiate(s_AssemblyId, ContractName, InstanceName, arguments);

            // Create signed transaction with builder. To generate instantiate contract,
            // table admin and contract owner private key is required.
            var txSigned = TransactionCreator.CreateTransactionBuilder(
                new [] { entry },
                new []
            {
                new SignatureCredential(Utils.GetTableAdminKeyPair().PublicKey),
                new SignatureCredential(Utils.GetOwnerKeyPair().PublicKey)
            })
                           .Sign(Utils.GetTableAdminKeyPair().PrivateKey)
                           .Sign(Utils.GetOwnerKeyPair().PrivateKey)
                           .Build();

            await generalApi.SendTransactionAsync(txSigned);

            var result = await Utils.WaitTx(generalApi, txSigned.Id);

            Console.WriteLine($"txid={txSigned.Id}, result={result}");
        }
        private static async Task DeployContract(IClient client)
        {
            // General API has SendTransactionAsync
            var generalApi = new GeneralApi(client);

            // Create entry
            var sources       = new[] { File.ReadAllText(Filename) };
            var dependencies  = new[] { "Miyabi.Binary.Models", "Miyabi.Asset.Models" };
            var instantiators = new[] { new PublicKeyAddress(Utils.GetOwnerKeyPair().PublicKey) };
            var entry         = new ContractDeploy(sources, dependencies, instantiators);

            // Create transaction
            var tx = TransactionCreator.CreateTransaction(
                new[] { entry },
                new[] { new SignatureCredential(Utils.GetContractAdminKeyPair().PublicKey) });

            // Sign transaction. To deploy a smart contract, contract admin private key is
            // required
            var txSigned = TransactionCreator.SignTransaction(
                tx,
                new[] { Utils.GetContractAdminKeyPair().PrivateKey });

            // Send transaction
            await generalApi.SendTransactionAsync(txSigned);

            // Wait until the transaction is stored in a block and get the result
            var result = await Utils.WaitTx(generalApi, tx.Id);

            Console.WriteLine($"txid={tx.Id}, result={result}");
        }
        //participantlist
        //:03c898153e55c32627422466a83ed40b9233c1583023dafa179a4f2a4804306574
        //:027774dc46331602d9cc57da74bfce060d636238f9a0d06f5818ac44800c584538
        //:0390fe3ec4769770ee89da70c72a6ebb7449e6e16cfdf973d9350bb9dd587773f1  //beneficiary
        //:02c31e96cfb1497e3312c28669bbb25bf32a9c28f1cd64a697bbc17ab57ed9e434  //beneficiary (2nd)
        //:03bdfe20157b5aeab5a6c47bf5abe887147fd7fff3ae7d9cd54186c8822711bf4c
        //:03f9e61ae23c85a6eb6b9260591d1793a4d0c2f0970b2d93fbc4434044a9880a4d
        private static async Task InvokeContract(IClient client)
        {
            string argument   = "0338f9e2e7ad512fe039adaa509f7b555fb88719144945bd94f58887d8d54fed78";
            var    generalApi = new GeneralApi(client);

            // Create gen entry
            var entry = new ContractInvoke(s_AssemblyId, ContractName, InstanceName, "vote", new[] { argument });

            // Create signed transaction with builder. To invoke a smart contract,
            // contract owner's private key is required.
            var txSigned = TransactionCreator.CreateTransactionBuilder(
                new [] { entry },
                new []
            {
                new SignatureCredential(Utils.GetContractuser5KeyPair().PublicKey)
            })
                           .Sign(Utils.GetContractuser5KeyPair().PrivateKey)
                           .Build();

            await generalApi.SendTransactionAsync(txSigned);

            var result = await Utils.WaitTx(generalApi, txSigned.Id);

            Console.WriteLine($"txid={txSigned.Id}, result={result}");
        }
        public async Task SendTransaction(Transaction tx)
        {
            try
            {
                var send = await _generalApi.SendTransactionAsync(tx);

                var result_code = send.Value;

                if (result_code != TransactionResultCode.Success &&
                    result_code != TransactionResultCode.Pending)
                {
                    // Log failure here
                    Console.WriteLine($"Transaction failed with result code {result_code}");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception thrown at SendTransaction : {e}");
            }
        }
Exemple #5
0
        /// <summary>
        /// Send Transaction to miyabi blockchain
        /// </summary>
        /// <param name="tx"></param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public async Task SendTransaction(Transaction tx)
        {
            var client        = this.SetClient();
            var generalClient = new GeneralApi(client);

            try
            {
                var send = await generalClient.SendTransactionAsync(tx);

                var result_code = send.Value;

                if (result_code != TransactionResultCode.Success &&
                    result_code != TransactionResultCode.Pending)
                {
                    // Console.WriteLine("取引が拒否されました!:\t{0}", result_code);
                }
            }
            catch (Exception)
            {
                // Console.Write("例外を検知しました!{e}");
            }
        }
Exemple #6
0
        /// <summary>
        /// Send Transaction to miyabi blockchain
        /// </summary>
        /// <param name="tx"></param>
        public static async Task SendTransaction(Transaction tx)
        {
            var config         = new SdkConfig(Utils.ApiUrl);
            var client         = new Client(config);
            var _generalClient = new GeneralApi(client);


            try
            {
                var send = await _generalClient.SendTransactionAsync(tx);

                var result_code = send.Value;
                Console.WriteLine("{0}", result_code);
                if (result_code != TransactionResultCode.Success &&
                    result_code != TransactionResultCode.Pending)
                {
                    Console.WriteLine("取引が拒否されました!:\t{0}", result_code);
                }
            }
            catch (Exception e)
            {
                Console.Write("例外を検知しました!{e}");
            }
        }