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}");
        }
        //TODO: refactor this into custom service.
        public static byte[] GetClipboardDataBytes(uint format)
        {
            var dataPointer = GetClipboardDataPointer(format);

            var length = GetPointerDataLength(dataPointer);

            if (length == UIntPtr.Zero)
            {
                return(null);
            }

            var lockedMemory = GetLockedMemoryBlockPointer(dataPointer);

            if (lockedMemory == IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            var buffer = new byte[(int)length];

            Marshal.Copy(lockedMemory, buffer, 0, (int)length);
            GeneralApi.GlobalUnlock(dataPointer);

            return(buffer);
        }
        //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}");
        }
        static void Main(string[] args)
        {
            ulong  kdtId  = 0;
            Silent silent = new Silent("client_id", "client_appsecret", kdtId);

            OauthToken.TokenData silenToken = silent.GetToken();
            string token = silenToken.Token;

            //构建请求API
            GeneralApi generalApi = new GeneralApi();
            //设置请求参数
            GeneralApiParams apiParams = new GeneralApiParams();

            apiParams.AddParam("page_no", "1");
            apiParams.AddParam("page_size", "100");
            generalApi.SetAPIParams(apiParams);
            //设置API名称
            generalApi.SetName("youzan.ump.coupon.search");
            //设置API版本号
            generalApi.SetVersion("3.0.0");
            //指定鉴权类型
            generalApi.SetOAuthType(OAuthEnum.TOKEN);
            IYouZanClient defaultYZClient = new DefaultYZClient();
            //请求接口
            string result = defaultYZClient.Invoke(generalApi, new Token(token), null, null);

            Console.WriteLine("request result *******************" + result);
        }
Exemple #5
0
        static BitmapFrame CreateBitmapVersionOne(byte[] bitmapVersionOneBytes, BITMAPINFOHEADER bitmapVersionOneHeader)
        {
            var fileHeaderSize = Marshal.SizeOf(typeof(BITMAPFILEHEADER));
            var infoHeaderSize = bitmapVersionOneHeader.biSize;
            var fileSize       = fileHeaderSize + bitmapVersionOneHeader.biSize + bitmapVersionOneHeader.biSizeImage;

            var fileHeader = new BITMAPFILEHEADER();

            fileHeader.bfType      = BITMAPFILEHEADER.BM;
            fileHeader.bfSize      = fileSize;
            fileHeader.bfReserved1 = 0;
            fileHeader.bfReserved2 = 0;
            fileHeader.bfOffBits   = fileHeaderSize + infoHeaderSize + bitmapVersionOneHeader.biClrUsed * 4;

            var fileHeaderBytes = GeneralApi.StructureToByteArray(fileHeader);

            var bitmapStream = new MemoryStream();

            bitmapStream.Write(fileHeaderBytes, 0, fileHeaderSize);
            bitmapStream.Write(bitmapVersionOneBytes, 0, bitmapVersionOneBytes.Length);
            bitmapStream.Seek(0, SeekOrigin.Begin);

            var bitmap = BitmapFrame.Create(bitmapStream);

            return(bitmap);
        }
        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}");
        }
        /// <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));
        }
Exemple #8
0
 public BitmovinApi(IBitmovinApiClientFactory apiClientFactory)
 {
     Account       = new AccountApi(apiClientFactory);
     Analytics     = new AnalyticsApi(apiClientFactory);
     Encoding      = new EncodingApi(apiClientFactory);
     General       = new GeneralApi(apiClientFactory);
     Notifications = new NotificationsApi(apiClientFactory);
     Player        = new PlayerApi(apiClientFactory);
 }
        public MainWindow()
        {
            InitializeComponent();
            this.generalApi = new GeneralApi(this.apiKey, this.secret, this.passPhrase);
            this.futureApi  = new FuturesApi(this.apiKey, this.secret, this.passPhrase);
            this.accountApi = new AccountApi(this.apiKey, this.secret, this.passPhrase);


            this.DataContext = new MainViewModel();
        }
Exemple #10
0
        /// <summary>
        /// Send Transaction with all info
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Button1_Click(object sender, EventArgs e)
        {
            this.count++;
            var config         = new SdkConfig(Utils.ApiUrl);
            var client         = new Client(config);
            var _generalClient = new GeneralApi(client);

            // Get textBox1 string
            string  text1       = this.textBox1.Text;
            Address mypublickey = this.Inputjudgement(text1);

            if (mypublickey == null)
            {
                this.count--;
                return;
            }

            // get textBox2 string
            string  text2            = this.textBox2.Text;
            Address opponetpublickey = this.Inputjudgement(text2);

            if (opponetpublickey == null)
            {
                this.count--;
                return;
            }

            // get textBox3 string
            string  text3  = this.textBox3.Text;
            decimal amount = this.Inputnumjudgement(text3);

            if (amount == 0m)
            {
                this.count--;
                return;
            }

            // throw amount to form1
            this.Showtransaction(amount);

            // send coin BroadCast Miyabi
            WAction send = new WAction();

            (string transaction, string result) = await send.Send(mypublickey, opponetpublickey, amount);

            // Open Form6
            Form6 frmForm6 = new Form6();

            frmForm6.TxId      = transaction;
            frmForm6.Tx_result = result;
            frmForm6.ShowDialog();
            this.Close();
        }
Exemple #11
0
        public static async Task <string> WaitTx(GeneralApi api, ByteString id)
        {
            while (true)
            {
                var result = await api.GetTransactionResultAsync(id);

                if (result.Value.ResultCode != TransactionResultCode.Pending)
                {
                    return(result.Value.ResultCode.ToString());
                }
            }
        }
Exemple #12
0
        async partial void Send_bottun_TouchUpInsideAsync(UIButton sender)
        {
            var client         = WAction.SetClient();
            var _generalClient = new GeneralApi(client);

            //mypublickey
            string  text1       = "0338f9e2e7ad512fe039adaa509f7b555fb88719144945bd94f58887d8d54fed78";
            Address mypublickey = this.Inputjudgement(text1);

            if (mypublickey == null)
            {
                return;
            }
            // Get destinationpublickey string
            string  text2            = this.destinationpubkey.Text;
            Address opponetpublickey = this.Inputjudgement(text2);

            if (opponetpublickey == null)
            {
                return;
            }

            // get textBox3 string
            string  text3  = this.amount.Text;
            decimal amount = this.Inputnumjudgement(text3);

            if (amount == 0m)
            {
                return;
            }

            // throw amount to form1
            //this.Showtransaction(amount);

            // send coin BroadCast Miyabi
            WAction send = new WAction();

            (string transaction, string result) = await send.Send(mypublickey, opponetpublickey, amount);

            //Transaction result
            //Create Alert
            var okAlertController = UIAlertController.Create("Result:\t" + result, "tx:\t" + transaction, UIAlertControllerStyle.Alert);

            //Add Action
            okAlertController.AddAction(UIAlertAction.Create("confirm", UIAlertActionStyle.Default, null));

            // Present Alert
            PresentViewController(okAlertController, true, null);
        }
Exemple #13
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));
        }
Exemple #14
0
        public byte[] UnwrapStructure(uint format)
        {
            //TODO: it is very sad that we invoke System.Drawing here to get the job done. probably not very optimal.

            var bitmapVersionFivePointer = ClipboardApi.GetClipboardData(ClipboardApi.CF_DIBV5);
            var bitmapVersionFiveHeader  = (BITMAPV5HEADER)Marshal.PtrToStructure(bitmapVersionFivePointer, typeof(BITMAPV5HEADER));

            if (bitmapVersionFiveHeader.bV5Compression == BI_RGB)
            {
                var bitmapVersionOneBytes  = ClipboardApi.GetClipboardDataBytes(ClipboardApi.CF_DIB);
                var bitmapVersionOneHeader = GeneralApi.ByteArrayToStructure <BITMAPINFOHEADER>(bitmapVersionOneBytes);

                return(HandleBitmapVersionOne(bitmapVersionOneBytes, bitmapVersionOneHeader));
            }
            else
            {
                return(HandleBitmapVersionFive(bitmapVersionFivePointer, bitmapVersionFiveHeader));
            }
        }
Exemple #15
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);
        }
Exemple #16
0
        static async Task Main(string[] args)
        {
            var config         = new SdkConfig(Utils.ApiUrl);
            var client         = new Client(config);
            var _generalClient = new GeneralApi(client);

            // Ver2 implements module system. To enable modules, register is required.
            NFTTypesRegisterer.RegisterTypes();

            //string txID_1 = await CreateNFTTable(client);
            //string txID_2 = await NFTgenerate(client);
            //string txID_3 = await NFTSend(client);
            await ShowNFT(client);

            //Console.WriteLine($"txid={txID_1}");
            //Console.WriteLine($"txid={txID_2}");
            //Console.WriteLine($"txid={txID_3}");

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }
Exemple #17
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 #18
0
        void InjectClipboardData(IClipboardData clipboardData)
        {
            using (var memoryHandle = memoryHandleFactory.AllocateInMemory(clipboardData.RawData))
            {
                var globalPointer = AllocateInMemory(clipboardData);

                var target = GeneralApi.GlobalLock(globalPointer);
                if (target == IntPtr.Zero)
                {
                    throw new InvalidOperationException("Could not allocate memory.");
                }

                GeneralApi.CopyMemory(target, memoryHandle.Pointer, (uint)clipboardData.RawData.Length);

                GeneralApi.GlobalUnlock(target);

                if (ClipboardApi.SetClipboardData(clipboardData.RawFormat, globalPointer) == IntPtr.Zero)
                {
                    GeneralApi.GlobalFree(globalPointer);
                    throw new Exception("Could not set clipboard data.");
                }
            }
        }
Exemple #19
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}");
            }
        }
Exemple #20
0
        static void Main(string[] args)
        {
            //AuthorizationCode authorization = new AuthorizationCode("bifrost-console", "bifrost-console")
            //{
            //    Code = "ad43719a9b612347af08ac8b5e43acb8"
            //};
            //OauthToken.TokenData  tokenData=  authorization.GetToken();
            //string token = tokenData.Token;
            //Dictionary<String, String> pList = new Dictionary<String, String>();
            //List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();


            //GeneralApi generalApi = new GeneralApi();
            //GeneralApiParams apiParams = new GeneralApiParams();
            //generalApi.SetName("youzan.retail.open.online.spu.release");
            //generalApi.SetVersion("3.0.0");
            //generalApi.SetOAuthType(common.constant.OAuthEnum.TOKEN);
            //apiParams.AddParam("retail_source", "DAOYAN");
            //apiParams.AddParam("content", "<p>432<imgdata-origin-width=\\\"1224\\\"data-origin-height=\\\"924\\\"src=\\\"//img.yzcdn.cn/upload_files/2019/09/19/FtjyJv_Gr_Ti9H7rYiNn7s0OqbxW.png!730x0.jpg\\\"/></p>");
            //apiParams.AddParam("pre_sale", "False");
            //apiParams.AddParam("delivery_template_id", "782231");
            //apiParams.AddParam("is_virtual", "0");
            //apiParams.AddParam("components_extra_id", "64848302");
            //apiParams.AddParam("sold_time", "0");
            //apiParams.AddParam("purchase_right", "False");
            //apiParams.AddParam("spu_code", "BM49570907669");
            //apiParams.AddParam("price", "11.00");
            //apiParams.AddParam("title", "艾斯测试网店");
            //apiParams.AddParam("goods_no", "123");
            //apiParams.AddParam("total_stock", "1");
            //apiParams.AddParam("is_display", "0");
            //apiParams.AddParam("picture", "[{'url':'https://img.yzcdn.cn/upload_files/2017/06/19/Fme9JZz7T1rB8sSLnsnCk2gILNp_.png'}]");
            //generalApi.SetAPIParams(apiParams);
            //IYouZanClient defaultYZClient = new DefaultYZClient();
            //string result  =  defaultYZClient.Invoke(generalApi,new Token("f9650e560c2ec67fd5941f91df1db7a"), null, null,true);
            //Console.WriteLine("request result *******************"+result);


            //Console.WriteLine("Hello World!");
            //Console.WriteLine("获取Token"+token);
            //string content = "{\n    \"client_id\": \"bifrost-console\",\n    \"client_secret\": \"bifrost-console\",\n    \"authorize_type\": \"authorization_code\",\n    \"code\": \"ad43719a9b612347af08ac8b5e43acb8\"\n}";
            //var client = new RestClient("http://open.youzanyun.com");
            //var request = new RestRequest("/auth/token",Method.POST);
            //List<Parameter> parameter = request.Parameters;
            //string jsonStr = JsonConvert.SerializeObject(parameter);
            //request.AddParameter("application/json", content, ParameterType.RequestBody);
            //IRestResponse response = client.Execute(request);
            //var conterent = response.Content;
            //Console.WriteLine("request result *******************"+ conterent);

            //RefreshToken refresh = new RefreshToken("db9fe36d892719e921", "be58f76bbd80ee4af32c4f4655d20e9e")
            //{
            //    FreshToken = ""
            //};
            //OauthToken.TokenData tokenData = refresh.GetToken();

            //Silent silent = new Silent("8d47c12fa8d4914c5e", "57df61dc21c391bfc6cb6a6d3b540dfb", 43005315);
            //OauthToken.TokenData silenToken  =silent.GetToken();
            //string token = silenToken.Token;
            //Console.WriteLine("request result *******************" + token);

            GeneralApi       generalApi = new GeneralApi();
            GeneralApiParams apiParams  = new GeneralApiParams();

            generalApi.SetName("youzan.shop.get");
            generalApi.SetVersion("3.0.0");
            generalApi.SetOAuthType(common.constant.OAuthEnum.TOKEN);
            generalApi.SetAPIParams(apiParams);
            IYouZanClient defaultYZClient = new DefaultYZClient();
            //升级前
            string result = defaultYZClient.Invoke(generalApi, new Token("f9650e560c2ec67fd5941f91df1db7a"), null, null);
            //升级后
            string result2 = defaultYZClient.Invoke(generalApi, new Token("f9650e560c2ec67fd5941f91df1db7a"), null, null, true);

            Console.WriteLine("request result *******************" + result);



            //Silent silent = new Silent("bifrost-console", "bifrost-console", 2003777768);
            //OauthToken.TokenData silenToken = silent.GetToken();
            //string token = silenToken.Token;
        }
Exemple #21
0
 static IntPtr AllocateInMemory(IClipboardData clipboardData)
 {
     return(GeneralApi.GlobalAlloc(
                GeneralApi.GMEM_ZEROINIT | GeneralApi.GMEM_MOVABLE,
                (UIntPtr)clipboardData.RawData.Length));
 }
 public TransactionService(IClient miyabiClient)
 {
     _generalApi = new GeneralApi(miyabiClient);
 }
Exemple #23
0
 static UIntPtr GetPointerDataLength(IntPtr dataPointer)
 {
     return(GeneralApi.GlobalSize(dataPointer));
 }
Exemple #24
0
 static IntPtr GetLockedMemoryBlockPointer(IntPtr dataPointer)
 {
     return(GeneralApi.GlobalLock(dataPointer));
 }
Exemple #25
0
 /// <summary>
 ///     Decrements the ref-counter and when it reaches ZERO, unloads NVAPI library.
 /// </summary>
 public static void Unload()
 {
     GeneralApi.Unload();
 }
Exemple #26
0
 /// <summary>
 ///     Initializes the NvAPI library (if not already initialized) but always increments the ref-counter.
 /// </summary>
 public static void Initialize()
 {
     GeneralApi.Initialize();
 }
Exemple #27
0
 public void Init()
 {
     instance = new GeneralApi();
 }
Exemple #28
0
 static ImageMetaInformation ConvertByteArrayToMetaInformation(byte[] data)
 {
     return(GeneralApi.ByteArrayToStructure <ImageMetaInformation>(data));
 }
Exemple #29
0
 byte[] ConvertMetaInformationToByteArray(ImageMetaInformation metaInformation)
 {
     return(GeneralApi.StructureToByteArray(metaInformation));
 }