コード例 #1
0
        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}");
        }
コード例 #2
0
        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}");
        }
コード例 #3
0
        /// <summary>
        /// Send Asset Method
        /// </summary>
        /// <param name="client"></param>
        /// <returns>tx.Id</returns>
        public async Task <Tuple <string, string> > Send(Address myaddress, Address opponetaddress, decimal amount)
        {
            var client     = SetClient();
            var generalApi = new GeneralApi(client);
            var from       = myaddress;
            var to         = opponetaddress;

            System.Diagnostics.Debug.WriteLine(myaddress);
            System.Diagnostics.Debug.WriteLine(opponetaddress);
            System.Diagnostics.Debug.WriteLine(amount);
            var privatekey = new[] { PrivateKey.Parse("263b6a4606168f64aca7c5ac1640ecb52a36142b0d96b07cb520de2eb4d237e5") };

            System.Diagnostics.Debug.WriteLine(PrivateKey.Parse("263b6a4606168f64aca7c5ac1640ecb52a36142b0d96b07cb520de2eb4d237e5"));
            // enter the send amount
            var moveCoin = new AssetMove(TableName, amount, from, to);

            System.Diagnostics.Debug.WriteLine(moveCoin);
            var move = new ITransactionEntry[] { moveCoin };

            System.Diagnostics.Debug.WriteLine(move);
            Transaction tx = TransactionCreator.SimpleSignedTransaction(moveCoin, privatekey);

            await this.SendTransaction(tx);

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

            return(new Tuple <string, string>(tx.Id.ToString(), result));
        }
コード例 #4
0
        //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}");
        }
コード例 #5
0
ファイル: WalletService.cs プロジェクト: sskgik/cookiePoint
 public async Task Send(decimal amount, Address to)
 {
     var from     = GetAddress();
     var moveCoin = new AssetMove("CookiePoint", amount, from, to);
     var tx       = TransactionCreator.SimpleSignedTransaction(
         new ITransactionEntry[] { moveCoin },
         new [] { _keyPair.PrivateKey });
     await _transactionService.SendTransaction(tx);
 }
コード例 #6
0
ファイル: Program.cs プロジェクト: sskgik/cookiePoint
            /**
             * Mint asset to Alice address
             */
            async Task <string> GenerateAsset()
            {
                var aliceAddress  = _aliceWallet.GetAddress();
                var generateAsset = new AssetGen(TOKEN_NAME, 1000000m, aliceAddress);
                var memo          = new MemoEntry(new[] { "Generate 1000000m CookiePoints." });

                var tx = TransactionCreator.SimpleSignedTransaction(
                    new ITransactionEntry[] { generateAsset, memo },
                    new[] { _aliceWallet.GetPrivateKey() });

                await _transactionService.SendTransaction(tx);

                return(tx.Id.ToString());
            }
コード例 #7
0
ファイル: Program.cs プロジェクト: sskgik/miyabi_making
        /// <summary>
        /// Generation Asset
        /// </summary>
        /// <param name="client"></param>
        /// <returns>tx.Id</returns>
        public static async Task <string> Assetgenerate(IClient client)
        {
            //Asset infomation
            var generateAsset = new AssetGen(TableName, 1000000m,
                                             new PublicKeyAddress(Utils.GetUser0KeyPair().PublicKey));

            var tx = TransactionCreator.SimpleSignedTransaction(
                new ITransactionEntry[] { generateAsset },
                new[] { Utils.GetOwnerKeyPair().PrivateKey });


            await SendTransaction(tx);

            return(tx.Id.ToString());;
        }
コード例 #8
0
        /// <summary>
        ///  Make NFT Table Method
        /// </summary>
        /// <param name="client"></param>
        /// <returns>tx.Id</returns>
        private static async Task <string> CreateNFTTable(IClient client)
        {
            //Get PublicKey from Utils's GetOwnerKeyPair()
            var tableownerAddress = new PublicKeyAddress(Utils.GetOwnerKeyPair().PublicKey);
            var assetTable        = new CreateTable(new NFTTableDescriptor(
                                                        TableName, false, false, new[] { tableownerAddress }));

            //var memo = new MemoEntry(new[] { "NFT_TEST" });
            var tx = TransactionCreator.SimpleSignedTransaction(
                new ITransactionEntry[] { assetTable },
                new[] { Utils.GetTableAdminKeyPair().PrivateKey });

            await SendTransaction(tx);

            return(tx.Id.ToString());
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: sskgik/miyabi_making
        /// <summary>
        /// Send Asset Method
        /// </summary>
        /// <param name="client"></param>
        /// <returns>tx.Id</returns>
        public static async Task <string> Send(IClient client)
        {
            var from = new PublicKeyAddress(Utils.GetUser0KeyPair());
            var to   = new PublicKeyAddress(Utils.GetUser1KeyPair());

            var amount = Inputjudgement();

            var moveCoin = new AssetMove(TableName, amount, from, to);
            var tx       = TransactionCreator.SimpleSignedTransaction(
                new ITransactionEntry[] { moveCoin },
                new [] { Utils.GetUser0KeyPair().PrivateKey });

            await SendTransaction(tx);

            return(tx.Id.ToString());
        }
コード例 #10
0
        /// <summary>
        /// Generation NFT
        /// </summary>
        /// <param name="client"></param>
        /// <returns>tx.Id</returns>
        public static async Task <string> NFTgenerate(IClient client)
        {
            //Asset infomation
            Console.WriteLine("Please Types NFT TokenID");
            string Tokenid     = Console.ReadLine();
            var    generateNFT = new NFTAdd(TableName, Tokenid,
                                            new PublicKeyAddress(Utils.GetUser0KeyPair().PublicKey));

            var tx = TransactionCreator.SimpleSignedTransaction(
                new ITransactionEntry[] { generateNFT },
                new[] { Utils.GetOwnerKeyPair().PrivateKey });


            await SendTransaction(tx);

            return(tx.Id.ToString());;
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: sskgik/cookiePoint
            /**
             * Create the Asset table for Alice.
             */
            async Task <string> CreateTable()
            {
                var aliceAddress = _aliceWallet.GetAddress();

                // Create a new asset table with alice's address set as a owner.
                // A Table admin key is required to send this transaction.
                var assetTable = new CreateTable(new AssetTableDescriptor(
                                                     TOKEN_NAME, false, false, new[] { aliceAddress }));
                var memo = new MemoEntry(new[] { "Point system for Alice's shops" });

                var tx = TransactionCreator.SimpleSignedTransaction(
                    new ITransactionEntry[] { assetTable, memo },
                    new[] { PrivateKey.Parse(TABLE_ADMIN_PRIVATE_KEY) });

                await _transactionService.SendTransaction(tx);

                return(tx.Id.ToString());
            }
コード例 #12
0
        /// <summary>
        /// Send Asset Method
        /// </summary>
        /// <param name="client"></param>
        /// <returns>tx.Id</returns>
        public async Task <Tuple <string, string> > Send(KeyPair formerprivatekey, Address myaddress, Address opponetaddress, decimal amount)
        {
            var client     = this.SetClient();
            var generalApi = new GeneralApi(client);
            var from       = myaddress;
            var to         = opponetaddress;

            // enter the send amount
            var moveCoin = new AssetMove(TableName, amount, from, to);
            var tx       = TransactionCreator.SimpleSignedTransaction(
                new ITransactionEntry[] { moveCoin },
                new[] { formerprivatekey.PrivateKey });

            await this.SendTransaction(tx);

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

            return(new Tuple <string, string>(tx.Id.ToString(), result));
        }
コード例 #13
0
        /// <summary>
        /// Send Asset Method
        /// </summary>
        /// <param name="client"></param>
        /// <returns>tx.Id</returns>
        public static async Task <string> NFTSend(IClient client)
        {
            var _generalClient = new GeneralApi(client);

            Console.WriteLine("Please Types NFT TokenID");
            string Tokenid = Console.ReadLine();
            var    to      = new PublicKeyAddress(Utils.GetUser1KeyPair());
            //enter the send amount

            var moveCoin = new NFTMove(TableName, Tokenid, to);
            var tx       = TransactionCreator.SimpleSignedTransaction(
                new ITransactionEntry[] { moveCoin },
                new [] { Utils.GetUser0KeyPair().PrivateKey });//Sender Privatekey

            await SendTransaction(tx);

            var result = await Utils.WaitTx(_generalClient, tx.Id);

            return(result);
        }
コード例 #14
0
        private static void StartConsole(NetworkStream stream)
        {
            string lineOfCocain;
            string message;

            while (!(lineOfCocain = Console.ReadLine()).Equals("EXIT;"))
            {
                message = "Go to f**k yourself stupid shitty idiot";
                if (QueryVerifier.GetQueryVerifier().EvaluateQuery(lineOfCocain))
                {
                    SendAndReceive.SendMessage(stream, TransactionCreator.GetTransactionCreator().CreateGroupDependingXML(QueryVerifier.GetQueryVerifier().queryMatch));
                    message = (new XmlMessage(SendAndReceive.ReceiveMessage(stream, 256))).GetElementsContentByTagName("payload")[0];
                }
                Console.WriteLine(message);
            }
            QueryVerifier.GetQueryVerifier().EvaluateQuery(lineOfCocain);
            SendAndReceive.SendMessage(stream, TransactionCreator.GetTransactionCreator().CreateGroupDependingXML(QueryVerifier.GetQueryVerifier().queryMatch));
            message = (new XmlMessage(SendAndReceive.ReceiveMessage(stream, 256))).GetElementsContentByTagName("payload")[0];
            Console.WriteLine(message);
            tcpClient.Close();
        }
コード例 #15
0
    public void Test_file_gets_does_not_get_created_on_rollback()
    {
        TransactionCreator creator = null;

        try
        {
            using (var scope = new TransactionScope())
            {
                creator = Substitute.For <TransactionCreator>();
                var failed = Substitute.For <TransactionCreator>();
                failed.When(x => x.Execute()).Do(x => { throw new Exception(); });
                scope.Complete();
            }
        }
        catch (TransactionAbortedException ex)
        {
            Console.Out.WriteLine(ex);
        }


        creator.Received().Execute();
        creator.Received().Revert();
    }
コード例 #16
0
        public static void DoTheTest(string filePath, string outFilePath)
        {
            StreamReader reader       = new StreamReader(filePath);
            int          numberOfTest = 1;
            string       textLine;
            string       result  = "# TEST" + numberOfTest + "\n";
            double       seconds = 0;
            double       diff;
            DateTime     date;

            while ((textLine = reader.ReadLine()) != null)
            {
                if (!textLine.Equals(""))
                {
                    if (QueryVerifier.GetQueryVerifier().EvaluateQuery(textLine))
                    {
                        date    = DateTime.Now;
                        result  = result + DirectRequester.GetRequester().SendRequest(TransactionCreator.GetTransactionCreator().CreateGroupDependingXML(QueryVerifier.GetQueryVerifier().queryMatch));
                        diff    = GetDiffAndAct(date, DateTime.Now);
                        result  = result + " (" + diff + "s)\n";
                        seconds = seconds + diff;
                    }
                    else
                    {
                        result = result + "bad sintax\n";
                    }
                }
                else
                {
                    numberOfTest = numberOfTest + 1;
                    result       = result + "TOTAL TIME:" + seconds + "s\n\n" + "# TEST " + numberOfTest + "\n";
                    seconds      = 0;
                }
            }
            result = result + "TOTAL TIME:" + seconds + "s";
            File.WriteAllText(outFilePath, result);
            Console.WriteLine(result);
            FakeServer.GetFakeServer().SaveShit();
        }
コード例 #17
0
        public async Task InsertTransaction_WhenTransactionNotNull_ShouldInsertSuccessfully(Transaction transaction, TransactionCreator sut)
        {
            await sut.InsertAsync(transaction);

            await sut.TransactionRepository.Received(1).InsertAsync(Arg.Is(transaction));
        }
コード例 #18
0
        public async Task InsertTransaction_WhenTransactionIsNull_ShouldNotInsert(TransactionCreator sut)
        {
            await sut.InsertAsync(null);

            await sut.TransactionRepository.DidNotReceive().InsertAsync(Arg.Any <Transaction>());
        }
コード例 #19
0
 public override Transaction CreateTransaction(decimal ammount, TransactionType transactionType)
 {
     return(TransactionCreator.Create(ammount, transactionType));
 }