Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Console.WriteLine(new GetBalanceParams()
            {
                Account = "mattf"
            });

            JsonRPCClient client = new JsonRPCClient("http://127.0.0.1:18332", "bitcoinrpc", "123456", "");

            /*
             * var resp0 = client.Call<GetNewAddressResponse>(JsonRPCMethods.GetNewAddress, new GetNewAddressParams());
             * Console.WriteLine(resp0);
             *
             *
             * var resp1 = client.Call<GetBalanceResponse>(JsonRPCMethods.GetBalance, new GetBalanceParams());
             * Console.WriteLine(resp1);
             *
             * var resp2 = client.Call<GetBestBlockHashResponse>(JsonRPCMethods.GetBestBlockHash, new GetBestBlockHashParams() );
             * Console.WriteLine(resp2);
             *
             * var resp3 = client.Call<GetBlockResponse>(JsonRPCMethods.GetBlock, new GetBlockParams() { HeaderHash = resp2.Result });
             * Console.WriteLine(resp3);
             *
             * var resp4 = client.Call<GetChainTipsResponse>(JsonRPCMethods.GetChainTips, new GetChainTipsParams());
             * Console.WriteLine(resp4);
             *
             * var resp5 = client.Call<GetRawTransactionResponse>(JsonRPCMethods.GetRawTransaction, new GetRawTransactionParams()
             * {
             * TxId = resp3.Result.Tx[0]
             * });
             * Console.WriteLine(resp5);
             */

            /*
             * var resp7 = client.Call<WalletPassphraseResponse>(JsonRPCMethods.WalletPassphrase, new WalletPassphraseParams()
             * {
             *  Passphrase = "fslong25!@#",
             *  Seconds = 30
             * });
             * Console.WriteLine(resp7);
             *
             * var resp8 = client.Call<SetTxFeeResponse>(JsonRPCMethods.SetTxFee, new SetTxFeeParams()
             * {
             *  TransactionFeePerKilobyte = 0.003m
             * });
             * Console.WriteLine(resp8);
             *
             * var resp6 = client.Call<SendManyResponse>(JsonRPCMethods.SendMany, new SendManyParams()
             * {
             *  FromAccount = "testnet",
             *  Outputs = new Dictionary<string, decimal>()
             *  {
             *      { "n2bypZoP7QuNHBvSq5QUT11ccMQJ2ZCajy", 0.0001m }
             *  },
             *  Confirmations = 1,
             *  Comment = "testsendmany"
             * });
             * Console.WriteLine(resp6);
             */

            var resp9 = client.Call <ListUnspentResponse>(JsonRPCMethods.ListUnspent, new ListUnspentParams()
            {
            });

            Console.WriteLine(resp9);

            var resp10 = client.Call <ListUnspentResponse>(JsonRPCMethods.ListUnspent, new ListUnspentParams()
            {
                Addresses = new List <string>()
                {
                    "myuuAQtmqBNHC9iYeUke1nCn1kV6NPK2QT"
                }
            });

            Console.WriteLine(resp10);
        }
Example #2
0
 public WalletServiceImpl(CoinsWalletDbContext coinsWalletDbContext,
                          JsonRPCClient jsonRPCClient)
 {
     context   = coinsWalletDbContext;
     rpcClient = jsonRPCClient;
 }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            JsonRPCClient client = new JsonRPCClient("http://192.168.1.123:8101", "Ulysseys", "YourSuperGreatPasswordNumber", "123.asd");

            var de = new HexBigInteger("0x8670e9ec6598c0000").HexToEther();

            var decc = "0x8670e9ec6598c0000".HexToEther();

            var list = client.ListAccount();

            if (list != null)
            {
                foreach (var item in list)
                {
                    var balance = client.GetBalance(item);
                    Console.WriteLine($"address[{item}] has {new HexBigInteger(balance).HexToEther()} .");
                }
            }

            var blocknumber = client.BlockNumber();

            Console.WriteLine($"最新块编号 {blocknumber} .");

            if (!string.IsNullOrWhiteSpace(blocknumber))
            {
                var block = client.GetBlockByNumber(blocknumber);
                if (block != null)
                {
                    Console.WriteLine($"block number[{blocknumber}]: {JsonConvert.SerializeObject(block)}");

                    if (block.Transactions != null && block.Transactions.Count > 0)
                    {
                        foreach (var item in block.Transactions)
                        {
                            var transaction = client.GetTransactionByHash(item);

                            if (transaction != null)
                            {
                                Console.WriteLine($"交易【hash {item} 】内容 : {JsonConvert.SerializeObject(transaction)}");
                            }

                            var transactionreceipt = client.GetTransactionReceipt(item);

                            if (transactionreceipt != null)
                            {
                                Console.WriteLine($"交易【hash {item} 】回执单信息 : {JsonConvert.SerializeObject(transactionreceipt)}");
                            }
                        }
                    }
                }
            }

            //转账操作
            if (list.Count > 1)
            {
                //账户解锁
                if (client.UnlockAccount(list[0], client.WalletPassphrase, duration: 60))
                {
                    string transactionHash = client.SendTransaction(list[0], list[1], (decimal)1.555);

                    Console.WriteLine($"转账交易的hash {transactionHash} ");
                }
                else
                {
                    Console.WriteLine($"{list[0]}解锁失败");
                }
            }
        }