Ejemplo n.º 1
0
        public async Task <ulong> GetBlocksCount()
        {
            RpcRequest <GetBlocksCountData.Request> request = new RpcRequest <GetBlocksCountData.Request>()
            {
                Method    = "getblockcount",
                Arguments = new GetBlocksCountData.Request()
            };

            RpcResponse <GetBlocksCountData.Response> response =
                await PostAsync <RpcResponse <GetBlocksCountData.Response> >(request, Uri + JsonRoot);

            if (response.Error != null)
            {
                throw new RpcException(response.Error.Message);
            }

            return(response.Result.Count);
        }
Ejemplo n.º 2
0
        public async Task <List <TransactionData> > GetTransfers()
        {
            RpcRequest <GetTransfersData.Request> request = new RpcRequest <GetTransfersData.Request>()
            {
                Method    = "get_transfers",
                Arguments = new GetTransfersData.Request()
            };

            RpcResponse <GetTransfersData.Response> response =
                await PostAsync <RpcResponse <GetTransfersData.Response> >(request, Uri + JsonRoot);

            if (response.Error != null)
            {
                throw new RpcException(response.Error.Message);
            }

            return(response.Result.Transfers);
        }
Ejemplo n.º 3
0
        public async Task <string> CreateAddress()
        {
            RpcRequest <CreateAddressData.Request> request = new RpcRequest <CreateAddressData.Request>()
            {
                Method    = "createAddress",
                Arguments = new CreateAddressData.Request()
            };

            RpcResponse <CreateAddressData.Response> response = await PostAsync <RpcResponse <CreateAddressData.Response> >(request, Uri);

            if (response.Error != null)
            {
                throw new RpcException(response.Error.Message);
            }

            string res = response.Result.Address;

            return(res);
        }
Ejemplo n.º 4
0
        public async Task <BlockHeader> GetLastBlockHeader()
        {
            RpcRequest <GetLastBlockHeaderData.Request> request = new RpcRequest <GetLastBlockHeaderData.Request>()
            {
                Method    = "getlastblockheader",
                Arguments = new GetLastBlockHeaderData.Request()
                {
                }
            };

            RpcResponse <GetLastBlockHeaderData.Response> response =
                await PostAsync <RpcResponse <GetLastBlockHeaderData.Response> >(request, Uri + JsonRoot);

            if (response.Error != null)
            {
                throw new RpcException(response.Error.Message);
            }

            return(response.Result.BlockHeader);
        }
Ejemplo n.º 5
0
        public async Task <BlockHeader> GetBlockHeader(string hash)
        {
            RpcRequest <GetBlockHederByHashData.Request> request = new RpcRequest <GetBlockHederByHashData.Request>()
            {
                Method    = "getblockheaderbyhash",
                Arguments = new GetBlockHederByHashData.Request()
                {
                    Hash = hash
                }
            };

            RpcResponse <GetBlockHederByHashData.Response> response =
                await PostAsync <RpcResponse <GetBlockHederByHashData.Response> >(request, Uri + JsonRoot);

            if (response.Error != null)
            {
                throw new RpcException(response.Error.Message);
            }

            return(response.Result.BlockHeader);
        }
Ejemplo n.º 6
0
        public async Task <Balance> GetBalance()
        {
            RpcRequest <GetBalanceData.Request> request = new RpcRequest <GetBalanceData.Request>()
            {
                Method    = "getbalance",
                Arguments = new GetBalanceData.Request()
            };

            RpcResponse <GetBalanceData.Response> response =
                await PostAsync <RpcResponse <GetBalanceData.Response> >(request, Uri + JsonRoot);

            if (response.Error != null)
            {
                throw new RpcException(response.Error.Message);
            }

            return(new Balance()
            {
                Available = response.Result.AvailableAmount,
                Locked = response.Result.LockedAmount
            });
        }
Ejemplo n.º 7
0
        public async Task <string> Transfer(string fromAddress, string toAddress, ulong amount, string paymentId = "", ulong fee = 1000000, ulong mixin = 0, ulong unlockTime = 0)
        {
            SendTransactionData.Request arg = new SendTransactionData.Request()
            {
                Addresses = new string[1]
                {
                    fromAddress
                },
                Transfers = new SendTransactionData.Request.Transfer[1]
                {
                    new SendTransactionData.Request.Transfer()
                    {
                        Address = toAddress,
                        Amount  = amount
                    }
                },
                PaymentId  = paymentId,
                Fee        = fee,
                Mixin      = mixin,
                UnlockTime = unlockTime
            };

            RpcRequest <SendTransactionData.Request> request = new RpcRequest <SendTransactionData.Request>()
            {
                Method    = "sendTransaction",
                Arguments = arg
            };

            RpcResponse <SendTransactionData.Response> response = await PostAsync <RpcResponse <SendTransactionData.Response> >(request, Uri);

            if (response.Error != null)
            {
                throw new RpcException(response.Error.Message);
            }

            return(response.Result.TransactionHash);
        }