defmodule Veriumd do require Logger @moduledoc """ Documentation for Veriumd. """ @doc """ Generates the target URL based on the configuration file. """ defp url() do user = Application.get_env(:veriumd, :rpcuser) pass = Application.get_env(:veriumd, :rpcpass) host = Application.get_env(:veriumd, :rpchost) port = Application.get_env(:veriumd, :rpcport) url = "http://#{user}:#{pass}@#{host}:#{port}" url end @doc """ Generic command method to interface with daemon. """ def rpc_command(method, params \\ []) do with command <- %{jsonrpc: "1.0", method: method, params: params}, {:ok, body} <- Poison.encode(command), _ <- Logger.debug("#{inspect body}"), {:ok, resp} <- HTTPoison.post(url(), body), {:ok, meta} <- Poison.decode(resp.body), %{"error" => nil, "result" => result} <- meta do {:ok, result} else %{"error" => reason} -> {:error, reason} error -> error end end @doc """ Stops the daemon. """ def stop, do: rpc_command("stop") @doc """ Verifies the wallet integrity. """ def checkwallet, do: rpc_command("checkwallet") @doc """ Returns the hash of the best (tip) block in the longest block chain. """ def getbestblockhash, do: rpc_command("getbestblockhash") @doc """ Returns the number of blocks in the longest block chain. """ def getblockcount, do: rpc_command("getblockcount") @doc """ fill me in """ def getblocktime, do: rpc_command("getblocktime") @doc """ fill me in """ def getcheckpoint, do: rpc_command("getcheckpoint") @doc """ Returns the total connection count of the daemon. """ def getconnectioncount, do: rpc_command("getconnectioncount") @doc """ Returns the proof-of-work difficulty as a multiple of the minimum difficulty. """ def getdifficulty, do: rpc_command("getdifficulty") @doc """ Returns an object containing various state info. """ def getinfo, do: rpc_command("getinfo") @doc """ Returns an object containing mining-related information: - blocks - currentblocksize - currentblocktx - difficulty - errors - generate - genproclimit - hashespersec - pooledtx - testnet """ def getmininginfo, do: rpc_command("getmininginfo") @doc """ Returns data about each connected node. """ def getpeerinfo, do: rpc_command("getpeerinfo") @doc """ Returns all transaction ids in memory pool """ def getrawmempool, do: rpc_command("getrawmempool") @doc """ Returns all addresses in the wallet and info used for coincontrol. """ def listaddressgroupings, do: rpc_command("listaddressgroupings") @doc """ fill me in """ def repairwallet, do: rpc_command("repairwallet") @doc """ fill me in """ def resendtx, do: rpc_command("resendtx") @doc """ fill me in """ def showalerts, do: rpc_command("showalerts") @doc """ Returns the a list of functions that are supported by the rpc server. """ def help, do: rpc_command("help") @doc """ If [account] is not specified, returns the server's total available balance. If [account] is specified, returns the balance in the account. """ def getbalance(account \\ []) do rpc_command("getbalance", account) end @doc """ Returns the list of addresses for the given account. """ def getaddressesbyaccount(account \\ [""]) do rpc_command("getaddressesbyaccount", account) end @doc """ Returns data needed to construct a block to work on. See BIP_0022 for more info on params. Example: getblocktemplate(["coinbasetx"], "template") """ def getblocktemplate(capabilities \\ [], mode \\ "") do rpc_command("getblocktemplate", [%{:capablities => capabilities, :mode => mode}]) end @doc """ Returns an object about the given transaction containing: - "amount" : total amount of the transaction - "confirmations" : number of confirmations of the transaction - "txid" : the transaction ID - "time" : time associated with the transaction[1]. - "details" - An array of objects containing: - "account" - "address" - "category" - "amount" - "fee" """ def gettransaction(tx) do rpc_command("gettransaction", [tx]) end @doc """ Safely copies wallet.dat to destination, which can be a directory or a path with filename. """ def backupwallet(path) do rpc_command("backupwallet", [path]) end @doc """ Return information about
. """ def validateaddress(address) do rpc_command("validateaddress", [address]) end @doc """ Downloads a boostrap file for the chain and shuts down the server. """ def bootstrap(overwrite \\ false) do rpc_command("bootstrap", [overwrite]) end @doc """ Returns hash of block in best-block-chain at ; index 0 is the genesis block """ def getblockhash(blockid) do rpc_command("getblockhash", [blockid]) end @doc """ Add a nrequired-to-sign multisignature address to the wallet. Each key is a bitcoin address or hex-encoded public key. If [account] is specified, assign address to [account]. Returns a string containing the address. Note: This only works with addresses that belong to this user, because it is impossible to get the public key for a "foreign" address. """ def addmultisigaddress(n, keys) do rpc_command("addmultisigaddress", [n, keys]) end @doc """ Add a P2SH address with a specified redeemScript to the wallet. If [account] is specified, assign address to [account]. """ def addredeemscript(script, account) do rpc_command("addredeemscript", [script, [account]]) end @doc """ Fill me in. """ def createrawtransaction() do raise "TODO: Implement createrawtransaction" end @doc """ Fill me in. """ def decoderawtransaction() do raise "TODO: Implement decoderawtransaction" end @doc """ Fill me in. """ def decodescript() do raise "TODO: Implement decodescript" end @doc """ Fill me in. """ def dumpprivkey() do raise "TODO: Implement dumpprivkey" end @doc """ Fill me in. """ def dumpwallet() do raise "TODO: Implement dumpwallet" end @doc """ Fill me in. """ def encryptwallet() do raise "TODO: Implement encryptwallet" end @doc """ Fill me in. """ def getaccount() do raise "TODO: Implement getaccount" end @doc """ Fill me in. """ def getaccountaddress() do raise "TODO: Implement getaccountaddress" end @doc """ Fill me in. """ def getblock() do raise "TODO: Implement getblock" end @doc """ Fill me in. """ def getblockbynumber() do raise "TODO: Implement getblockbynumber" end @doc """ Fill me in. """ def getnewaddress() do rpc_command("getnewaddress") end @doc """ Fill me in. """ def getnewpubkey() do raise "TODO: Implement getnewpubkey" end @doc """ Fill me in. """ def getreceivedbyaccount() do raise "TODO: Implement getreceivedbyaccount" end @doc """ Fill me in. """ def getreceivedbyaddress() do raise "TODO: Implement getreceivedbyaddress" end @doc """ Fill me in. """ def getsubsidy() do raise "TODO: Implement getsubsidy" end @doc """ Fill me in. """ def gettransaction() do raise "TODO: Implement gettransaction" end @doc """ Fill me in. """ def getwork() do raise "TODO: Implement getwork" end @doc """ Fill me in. """ def getworkex() do raise "TODO: Implement getworkex" end @doc """ Fill me in. """ def importprivkey() do raise "TODO: Implement importprivkey" end @doc """ Fill me in. """ def importwallet() do raise "TODO: Implement importwallet" end @doc """ Fill me in. """ def keypoolrefill() do raise "TODO: Implement keypoolrefill" end @doc """ Fill me in. """ def listaccounts() do raise "TODO: Implement istaccounts" end @doc """ Fill me in. """ def listreceivedbyaccount() do raise "TODO: Implement listreceivedbyaccount" end @doc """ Fill me in. """ def listreceivedbyaddress() do raise "TODO: Implement listreceivedbyaddress" end @doc """ Fill me in. """ def listsinceblock() do raise "TODO: Implement listsinceblock" end @doc """ Fill me in. """ def listtransactions() do raise "TODO: Implement listtransactions" end @doc """ Fill me in. """ def listunspent() do raise "TODO: Implement listunspent" end @doc """ Fill me in. """ def makekeypair() do raise "TODO: Implement makekeypair" end @doc """ Fill me in. """ def move() do raise "TODO: Implement move" end @doc """ Fill me in. """ def sendalert() do raise "TODO: Implement sendalert" end @doc """ Fill me in. """ def sendfrom() do raise "TODO: Implement sendfrom" end @doc """ Fill me in. """ def sendmany() do raise "TODO: Implement sendmany" end @doc """ Fill me in. """ def sendrawtransaction() do raise "TODO: Implement sendrawtransaction" end @doc """ Fill me in. """ def sendtoaddress() do raise "TODO: Implement endtoaddress" end @doc """ Fill me in. """ def setaccount() do raise "TODO: Implement setaccount" end @doc """ Fill me in. """ def settxfee() do raise "TODO: Implement settxfee" end @doc """ Fill me in. """ def signmessage() do raise "TODO: Implement signmessage" end @doc """ Fill me in. """ def signrawtransaction() do raise "TODO: Implement signrawtransaction" end @doc """ Fill me in. """ def submitblock() do raise "TODO: Implement submitblock" end @doc """ Fill me in. """ def validatepubkey() do raise "TODO: Implement validatepubkey" end @doc """ Fill me in. """ def verifymessage() do raise "TODO: Implement verifymessage" end end