diff --git a/pom.xml b/pom.xml index ddbfade..a1fa332 100644 --- a/pom.xml +++ b/pom.xml @@ -1,91 +1,91 @@ - - 4.0.0 - BitcoindClient4J - jar - A client for the bincoind node - BitcoindClient4j - com.37coins - 0.2.2 - - - - github - UTF-8 - - - - com.googlecode - jsonrpc4j - 0.28 - - - jackson-core - com.fasterxml.jackson.core - - - jackson-databind - com.fasterxml.jackson.core - - - - - com.fasterxml.jackson.core - jackson-databind - 2.2.3 - - - com.fasterxml.jackson.core - jackson-annotations - 2.2.3 - - - org.slf4j - slf4j-simple - 1.7.5 - - - junit - junit - 4.11 - - - - - - jsonrpc4j-webdav-maven-repo - jsonrpc4j maven repository - http://jsonrpc4j.googlecode.com/svn/maven/repo/ - default - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - - - - - - org.springframework.build - aws-maven - 5.0.0.RELEASE - - - - - - - 37coins.myMavenRepo.write - http://repo.mymavenrepo.com/8HyTMtil2kKL4arfqWnf/ - - - - + + 4.0.0 + BitcoindClient4J + jar + A client for the bincoind node + BitcoindClient4j + com.37coins + 0.2.2 + + + + github + UTF-8 + + + + com.fasterxml.jackson.core + jackson-databind + 2.2.3 + + + com.fasterxml.jackson.core + jackson-annotations + 2.2.3 + + + org.slf4j + slf4j-simple + 1.7.5 + + + junit + junit + 4.11 + + + com.github.briandilley.jsonrpc4j + jsonrpc4j + 1.5.3 + + + cash.bitcoinj + bitcoinj-core + 0.14.5.2 + + + org.apache.commons + commons-lang3 + 3.7 + + + + + + jsonrpc4j-webdav-maven-repo + jsonrpc4j maven repository + http://jsonrpc4j.googlecode.com/svn/maven/repo/ + default + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + + + org.springframework.build + aws-maven + 5.0.0.RELEASE + + + + + + + 37coins.myMavenRepo.write + http://repo.mymavenrepo.com/8HyTMtil2kKL4arfqWnf/ + + + + diff --git a/src/main/java/com/_37coins/bcJsonRpc/BitcoindClientFactory.java b/src/main/java/com/_37coins/bcJsonRpc/BitcoindClientFactory.java index e31f002..aaa309d 100644 --- a/src/main/java/com/_37coins/bcJsonRpc/BitcoindClientFactory.java +++ b/src/main/java/com/_37coins/bcJsonRpc/BitcoindClientFactory.java @@ -1,135 +1,133 @@ -package com._37coins.bcJsonRpc; - -import java.io.File; -import java.io.IOException; -import java.net.ServerSocket; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.googlecode.jsonrpc4j.Base64; -import com.googlecode.jsonrpc4j.JsonRpcHttpClient; -import com.googlecode.jsonrpc4j.ProxyUtil; - -public class BitcoindClientFactory { - - public static ServerSocket blockSocket; - public static ServerSocket walletSocket; - public static ServerSocket alertSocket; - - private static Logger LOG = LoggerFactory.getLogger(BitcoindClientFactory.class); - private static String OS = System.getProperty("os.name").toLowerCase(); - - private static String convertStream(java.io.InputStream is) { - java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); - return s.hasNext() ? s.next() : ""; - } - - private static boolean isWindows() { - return (OS.indexOf("win") >= 0); - } - - private final JsonRpcHttpClient client; - - /** - * - * for the listener to work bitcoin has to be started like this: - * - * ./bitcoind -blocknotify="echo '%s' | nc 127.0.0.1 4001" - * -walletnotify="echo '%s' | nc 127.0.0.1 4002" - * -alertnotify="echo '%s' | nc 127.0.0.1 4003" - * -daemon - * - * @param url - * @param username - * @param password - * @throws IOException - */ - public BitcoindClientFactory(URL url, String username, String password) - throws IOException { - String cred = Base64 - .encodeBytes((username + ":" + password).getBytes()); - Map headers = new HashMap<>(1); - headers.put("Authorization", "Basic " + cred); - client = new JsonRpcHttpClient(url, headers); - } - - public BitcoindClientFactory(String path, final List cmd) throws IOException{ - if (isWindows()){ - throw new RuntimeException("OS not supported"); - } - //prepare sockets - blockSocket = new ServerSocket(0); - walletSocket = new ServerSocket(0); - alertSocket = new ServerSocket(0); - //prepare user - String[] uuid = UUID.randomUUID().toString().split("-"); - String user = uuid[0]+uuid[2]; - String pw = uuid[4]+uuid[3]+uuid[1]; - //prepare command - List l = new ArrayList(); - for (String s: cmd){ - if (s.contains("notify")){ - LOG.warn(s + " ommited from cmd due to possible collision"); - }else{ - l.add(s); - } - } - l.add("-rpcuser="+user); - l.add("-rpcpassword="+pw); - l.add("-checklevel=2"); - l.add("-blocknotify=\"echo '%s' | nc 127.0.0.1 "+blockSocket.getLocalPort()+"\""); - l.add("-walletnotify=\"echo '%s' | nc 127.0.0.1 "+walletSocket.getLocalPort()+"\""); - l.add("-alertnotify=\"echo '%s' | nc 127.0.0.1 "+alertSocket.getLocalPort()+"\""); - l.add("-daemon"); - l.add("-server"); - //execute command - ProcessBuilder pb = new ProcessBuilder(l); - pb.directory(new File(path)); - Process p = pb.start(); - try { - p.waitFor(); - } catch (InterruptedException e) { - e.printStackTrace(); - throw new RuntimeException(convertStream(p.getErrorStream())); - } - //start client - String cred = Base64.encodeBytes((user + ":" + pw).getBytes()); - Map headers = new HashMap<>(1); - headers.put("Authorization", "Basic " + cred); - client = new JsonRpcHttpClient(new URL("http://localhost:8332/"), headers); - //wait for node startup - boolean success =false; - for (int i = 10; i > 0; i--){ - try{ - ProxyUtil.createClientProxy(BitcoindInterface.class.getClassLoader(), - BitcoindInterface.class, client).getinfo(); - success = true; - }catch(Exception e){ - try { - LOG.info("server not yet available, waiting another "+i+" secords."); - Thread.sleep(1000); - } catch (InterruptedException e1) {} - } - if (success){ - break; - } - } - if (!success){ - throw new IOException("could not connect to bitcoind"); - } - } - - public BitcoindInterface getClient() { - return ProxyUtil.createClientProxy( - BitcoindInterface.class.getClassLoader(), - BitcoindInterface.class, client); - } - -} +package com._37coins.bcJsonRpc; + +import java.io.File; +import java.io.IOException; +import java.net.ServerSocket; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.googlecode.jsonrpc4j.JsonRpcHttpClient; +import com.googlecode.jsonrpc4j.ProxyUtil; + +public class BitcoindClientFactory { + + public static ServerSocket blockSocket; + public static ServerSocket walletSocket; + public static ServerSocket alertSocket; + + private static Logger LOG = LoggerFactory.getLogger(BitcoindClientFactory.class); + private static String OS = System.getProperty("os.name").toLowerCase(); + + private static String convertStream(java.io.InputStream is) { + java.util.Scanner s = new java.util.Scanner(is); + s.useDelimiter("\\A"); + String v =s.hasNext() ? s.next() : ""; + s.close(); + return v; + } + + private static boolean isWindows() { + return (OS.indexOf("win") >= 0); + } + + private final JsonRpcHttpClient client; + + /** + * + * for the listener to work bitcoin has to be started like this: + * + * ./bitcoind -blocknotify="echo '%s' | nc 127.0.0.1 4001" -walletnotify="echo + * '%s' | nc 127.0.0.1 4002" -alertnotify="echo '%s' | nc 127.0.0.1 4003" + * -daemon + * + * @param url + * @param username + * @param password + * @throws IOException + */ + public BitcoindClientFactory(URL url, String username, String password) throws IOException { + String cred = java.util.Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); + Map headers = new HashMap<>(1); + headers.put("Authorization", "Basic " + cred); + client = new JsonRpcHttpClient(url, headers); + } + + public BitcoindClientFactory(String path, final List cmd) throws IOException { + if (isWindows()) { + throw new RuntimeException("OS not supported"); + } + // prepare sockets + blockSocket = new ServerSocket(0); + walletSocket = new ServerSocket(0); + alertSocket = new ServerSocket(0); + // prepare user + String[] uuid = UUID.randomUUID().toString().split("-"); + String user = uuid[0] + uuid[2]; + String pw = uuid[4] + uuid[3] + uuid[1]; + // prepare command + List l = new ArrayList(); + for (String s : cmd) { + if (s.contains("notify")) { + LOG.warn(s + " ommited from cmd due to possible collision"); + } else { + l.add(s); + } + } + l.add("-rpcuser=" + user); + l.add("-rpcpassword=" + pw); + l.add("-checklevel=2"); + l.add("-blocknotify=\"echo '%s' | nc 127.0.0.1 " + blockSocket.getLocalPort() + "\""); + l.add("-walletnotify=\"echo '%s' | nc 127.0.0.1 " + walletSocket.getLocalPort() + "\""); + l.add("-alertnotify=\"echo '%s' | nc 127.0.0.1 " + alertSocket.getLocalPort() + "\""); + l.add("-daemon"); + l.add("-server"); + // execute command + ProcessBuilder pb = new ProcessBuilder(l); + pb.directory(new File(path)); + Process p = pb.start(); + try { + p.waitFor(); + } catch (InterruptedException e) { + e.printStackTrace(); + throw new RuntimeException(convertStream(p.getErrorStream())); + } + // start client + String cred = java.util.Base64.getEncoder().encodeToString((user + ":" + pw).getBytes()); + Map headers = new HashMap<>(1); + headers.put("Authorization", "Basic " + cred); + client = new JsonRpcHttpClient(new URL("http://localhost:8332/"), headers); + // wait for node startup + boolean success = false; + for (int i = 10; i > 0; i--) { + try { + ProxyUtil.createClientProxy(BitcoindInterface.class.getClassLoader(), BitcoindInterface.class, client) + .getinfo(); + success = true; + } catch (Exception e) { + try { + LOG.info("server not yet available, waiting another " + i + " secords."); + Thread.sleep(1000); + } catch (InterruptedException e1) { + } + } + if (success) { + break; + } + } + if (!success) { + throw new IOException("could not connect to bitcoind"); + } + } + + public BitcoindInterface getClient() { + return ProxyUtil.createClientProxy(BitcoindInterface.class.getClassLoader(), BitcoindInterface.class, client); + } + +} diff --git a/src/main/java/com/_37coins/bcJsonRpc/BitcoindInterface.java b/src/main/java/com/_37coins/bcJsonRpc/BitcoindInterface.java index c99655b..1c4b6d9 100644 --- a/src/main/java/com/_37coins/bcJsonRpc/BitcoindInterface.java +++ b/src/main/java/com/_37coins/bcJsonRpc/BitcoindInterface.java @@ -1,98 +1,104 @@ -package com._37coins.bcJsonRpc; - -import java.math.BigDecimal; -import java.util.List; -import java.util.Map; - -import com._37coins.bcJsonRpc.pojo.Account; -import com._37coins.bcJsonRpc.pojo.Address; -import com._37coins.bcJsonRpc.pojo.AddressInformation; -import com._37coins.bcJsonRpc.pojo.Block; -import com._37coins.bcJsonRpc.pojo.Info; -import com._37coins.bcJsonRpc.pojo.LastBlock; -import com._37coins.bcJsonRpc.pojo.Transaction; - - - -public interface BitcoindInterface { - //Add a nrequired-to-sign multisignature address to the wallet. Each key is a bitcoin address or hex-encoded public key. - public String addmultisigaddress(int nrequired, String keys); - //If [account] is specified, assign address to [account]. - public String addmultisigaddress(int nrequired, String keys, String account); - - //Returns an object containing various state info. - public Info getinfo(); - //Safely copies wallet.dat to destination, which can be a directory or a path with filename. - public boolean backupwallet(); - //Removes the wallet encryption key from memory, locking the wallet. After calling this method, you will need to call walletpassphrase again before being able to call any methods which require the wallet to be unlocked. - public void walletlock(); //? - //rounded to the nearest 0.00000001 - public boolean settxfee(BigDecimal fee); - //Sets the account associated with the given address. Assigning address that is already assigned to the same account will create a new address associated with that account. - public boolean setaccount(String bitcoinAddress, String accountLabel); - //Returns the account associated with the given address. - public String getaccount(String bitcoinAddress); - //Returns the current bitcoin address for receiving payments to this account. - public String getaccountaddress(String accountLabel); - //Returns the list of addresses for the given account. - public List getaddressesbyaccount(String accountLabel); - //If [account] is not specified, returns the server's total available balance. - public BigDecimal getbalance(); - //If [account] is specified, returns the balance in the account. - public BigDecimal getbalance(String account); - // - public BigDecimal getbalance(String account, int minimumConfirmations); - //Returns information about the block with the given hash. - public Block getblock(String blockHash); - //Returns the number of blocks in the longest block chain. - public long getblockcount(); - //Returns hash of block in best-block-chain at ; index 0 is the genesis block - public String getblockhash(long blockHeight); - //Returns the number of connections to other nodes. - public int getconnectioncount(); - //Returns the proof-of-work difficulty as a multiple of the minimum difficulty. - public BigDecimal getdifficulty(); - //Returns true or false whether bitcoind is currently generating hashes - public boolean getgenerate(); - //Returns a recent hashes per second performance measurement while generating. - public long gethashespersec(); - //Returns an object about the given transaction hash. - public Transaction gettransaction(String hash); - //Returns Object that has account names as keys, account balances as values. - public Map listaccounts(long confirmations); - //Returns an array of objects containing:"account" : the account of the receiving addresses,"amount" : total amount received by addresses with this account,"confirmations" : number of confirmations of the most recent transaction included - public List listreceivedbyaccount(long minConfirmations, boolean includeEmpty); - //Returns an array of objects containing:"address" : receiving address,"account" : the account of the receiving address,"amount" : total amount received by the address,"confirmations" : number of confirmations of the most recent transaction included,To get a list of accounts on the system, execute bitcoind listreceivedbyaddress 0 true - public List
listreceivedbyaddress(long minConfirmations, boolean includeEmpty); - //Get all transactions in blocks since block [blockhash], or all transactions if omitted. - public List listsinceblock(String blockhash, int minConfirmations); - //Returns up to [count] most recent transactions skipping the first [from] transactions for account [account]. If [account] not provided will return recent transaction from all accounts. - public List listtransactions(String account, int count, int offset); - // Import a private key into your bitcoin wallet. Private key must be in wallet import format (Sipa) beginning with a '5'. - public boolean importprivkey(String privateKey); - //Move funds from one account in your wallet to another. - public boolean move(String fromAccount, String toAccount, BigDecimal amount); - public boolean move(String fromAccount, String toAccount, BigDecimal amount, long minconf, String comment); - //amount is a real and is rounded to 8 decimal places. Will send the given amount to the given address, ensuring the account has a valid balance using [minconf] confirmations. Returns the transaction ID if successful (not in JSON object). - public String sendfrom(String fromAccount, String bitcoinAddress, BigDecimal amount); - public String sendfrom(String fromAccount, String bitcoinAddress, BigDecimal amount, long minconf, String comment, String commentTo); - //amounts are BigDecimal-precision floating point numbers. - public String sendmany(String fromAccount, Map addressAmountPairs); - //amounts are BigDecimal-precision floating point numbers. - public String sendmany(String fromAccount, Map addressAmountPairs, int minconf, String comment); - //amount is a real and is rounded to 8 decimal places. Returns the transaction hash if successful. - public String sendtoaddress(String bitcoinAddress, BigDecimal amount); - public void setgenerate (boolean generate); - public void setgenerate (boolean generate, int genproclimit); - // Return information about bitcoinaddress. - public AddressInformation validateaddress(String bitcoinAddress); - //Returns a new bitcoin address for receiving payments. If [account] is specified (recommended), it is added to the address book so payments received with the address will be credited to [account]. - public String getnewaddress(String label); - //Returns a Base64 encoded signature used to verify the provided message was signed by the owner of bitcoinaddress - public String signmessage(String bitcoinaddress, String message); - //Verifies the signature and message matches the bitcoin address provided (See signmessage) - public boolean verifymessage(String bitcoinaddress, String signature, String message); - //stop - public String stop(); - -} +package com._37coins.bcJsonRpc; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +import com._37coins.bcJsonRpc.pojo.Account; +import com._37coins.bcJsonRpc.pojo.Address; +import com._37coins.bcJsonRpc.pojo.AddressInformation; +import com._37coins.bcJsonRpc.pojo.Block; +import com._37coins.bcJsonRpc.pojo.Info; +import com._37coins.bcJsonRpc.pojo.LastBlock; +import com._37coins.bcJsonRpc.pojo.RawTransaction; +import com._37coins.bcJsonRpc.pojo.Transaction; + + + +public interface BitcoindInterface { + //Add a nrequired-to-sign multisignature address to the wallet. Each key is a bitcoin address or hex-encoded public key. + public String addmultisigaddress(int nrequired, String keys); + //If [account] is specified, assign address to [account]. + public String addmultisigaddress(int nrequired, String keys, String account); + // Returns hash of block in best-block-chain at height provided. + public String getblockhash(int height); + //Returns an object containing various state info. + public Info getinfo(); + //Safely copies wallet.dat to destination, which can be a directory or a path with filename. + public boolean backupwallet(); + //Removes the wallet encryption key from memory, locking the wallet. After calling this method, you will need to call walletpassphrase again before being able to call any methods which require the wallet to be unlocked. + public void walletlock(); //? + //rounded to the nearest 0.00000001 + public boolean settxfee(BigDecimal fee); + //Sets the account associated with the given address. Assigning address that is already assigned to the same account will create a new address associated with that account. + public boolean setaccount(String bitcoinAddress, String accountLabel); + //Returns the account associated with the given address. + public String getaccount(String bitcoinAddress); + //Returns the current bitcoin address for receiving payments to this account. + public String getaccountaddress(String accountLabel); + //Returns the list of addresses for the given account. + public List getaddressesbyaccount(String accountLabel); + //If [account] is not specified, returns the server's total available balance. + public BigDecimal getbalance(); + //If [account] is specified, returns the balance in the account. + public BigDecimal getbalance(String account); + // + public BigDecimal getbalance(String account, int minimumConfirmations); + //Returns information about the block with the given hash. + public Block getblock(String blockHash); + //Returns the number of blocks in the longest block chain. + public long getblockcount(); + //Returns hash of block in best-block-chain at ; index 0 is the genesis block + public String getblockhash(long blockHeight); + //Returns the number of connections to other nodes. + public int getconnectioncount(); + //Returns the proof-of-work difficulty as a multiple of the minimum difficulty. + public BigDecimal getdifficulty(); + //Returns true or false whether bitcoind is currently generating hashes + public boolean getgenerate(); + //Returns a recent hashes per second performance measurement while generating. + public long gethashespersec(); + //Returns an object about the given transaction hash. + public Transaction gettransaction(String hash); + //Returns an object about the given transaction hash. + public String getrawtransaction(String hash); + //Returns an object about the given transaction hash. + public RawTransaction decoderawtransaction(String transactonScript); + //Returns Object that has account names as keys, account balances as values. + public Map listaccounts(long confirmations); + //Returns an array of objects containing:"account" : the account of the receiving addresses,"amount" : total amount received by addresses with this account,"confirmations" : number of confirmations of the most recent transaction included + public List listreceivedbyaccount(long minConfirmations, boolean includeEmpty); + //Returns an array of objects containing:"address" : receiving address,"account" : the account of the receiving address,"amount" : total amount received by the address,"confirmations" : number of confirmations of the most recent transaction included,To get a list of accounts on the system, execute bitcoind listreceivedbyaddress 0 true + public List
listreceivedbyaddress(long minConfirmations, boolean includeEmpty); + //Get all transactions in blocks since block [blockhash], or all transactions if omitted. + public List listsinceblock(String blockhash, int minConfirmations); + //Returns up to [count] most recent transactions skipping the first [from] transactions for account [account]. If [account] not provided will return recent transaction from all accounts. + public List listtransactions(String account, int count, int offset); + // Import a private key into your bitcoin wallet. Private key must be in wallet import format (Sipa) beginning with a '5'. + public boolean importprivkey(String privateKey); + //Move funds from one account in your wallet to another. + public boolean move(String fromAccount, String toAccount, BigDecimal amount); + public boolean move(String fromAccount, String toAccount, BigDecimal amount, long minconf, String comment); + //amount is a real and is rounded to 8 decimal places. Will send the given amount to the given address, ensuring the account has a valid balance using [minconf] confirmations. Returns the transaction ID if successful (not in JSON object). + public String sendfrom(String fromAccount, String bitcoinAddress, BigDecimal amount); + public String sendfrom(String fromAccount, String bitcoinAddress, BigDecimal amount, long minconf, String comment, String commentTo); + //amounts are BigDecimal-precision floating point numbers. + public String sendmany(String fromAccount, Map addressAmountPairs); + //amounts are BigDecimal-precision floating point numbers. + public String sendmany(String fromAccount, Map addressAmountPairs, int minconf, String comment); + //amount is a real and is rounded to 8 decimal places. Returns the transaction hash if successful. + public String sendtoaddress(String bitcoinAddress, BigDecimal amount); + public void setgenerate (boolean generate); + public void setgenerate (boolean generate, int genproclimit); + // Return information about bitcoinaddress. + public AddressInformation validateaddress(String bitcoinAddress); + //Returns a new bitcoin address for receiving payments. If [account] is specified (recommended), it is added to the address book so payments received with the address will be credited to [account]. + public String getnewaddress(String label); + //Returns a Base64 encoded signature used to verify the provided message was signed by the owner of bitcoinaddress + public String signmessage(String bitcoinaddress, String message); + //Verifies the signature and message matches the bitcoin address provided (See signmessage) + public boolean verifymessage(String bitcoinaddress, String signature, String message); + //stop + public String stop(); + +} diff --git a/src/main/java/com/_37coins/bcJsonRpc/events/AlertListener.java b/src/main/java/com/_37coins/bcJsonRpc/events/AlertListener.java index 23d827e..4287c0a 100644 --- a/src/main/java/com/_37coins/bcJsonRpc/events/AlertListener.java +++ b/src/main/java/com/_37coins/bcJsonRpc/events/AlertListener.java @@ -1,44 +1,44 @@ -package com._37coins.bcJsonRpc.events; - -import java.io.IOException; -import java.util.Observable; -import java.util.Observer; - -import com._37coins.bcJsonRpc.BitcoindClientFactory; - - -public class AlertListener extends Observable implements Observer { - - final private Observable alertListener; - public Thread listener = null; - - public AlertListener() throws IOException { - if (BitcoindClientFactory.alertSocket!=null){ - alertListener = new BitcoinDListener(BitcoindClientFactory.alertSocket); - }else{ - alertListener = new BitcoinDListener(4003); - } - } - - @Override - public synchronized void addObserver(Observer o) { - if (null == listener) { - alertListener.addObserver(this); - listener = new Thread((Runnable) alertListener, "alertListener"); - listener.start(); - } - super.addObserver(o); - } - - @Override - public void update(Observable o, Object arg) { - final String value = ((String) arg).trim(); - setChanged(); - notifyObservers(value); - } - - public void stop(){ - listener.interrupt(); - } - -} +package com._37coins.bcJsonRpc.events; + +import java.io.IOException; +import java.util.Observable; +import java.util.Observer; + +import com._37coins.bcJsonRpc.BitcoindClientFactory; + + +public class AlertListener extends Observable implements Observer { + + final private Observable alertListener; + public Thread listener = null; + + public AlertListener() throws IOException { + if (BitcoindClientFactory.alertSocket!=null){ + alertListener = new BitcoinDListener(BitcoindClientFactory.alertSocket); + }else{ + alertListener = new BitcoinDListener(4003); + } + } + + @Override + public synchronized void addObserver(Observer o) { + if (null == listener) { + alertListener.addObserver(this); + listener = new Thread((Runnable) alertListener, "alertListener"); + listener.start(); + } + super.addObserver(o); + } + + @Override + public void update(Observable o, Object arg) { + final String value = ((String) arg).trim(); + setChanged(); + notifyObservers(value); + } + + public void stop(){ + listener.interrupt(); + } + +} diff --git a/src/main/java/com/_37coins/bcJsonRpc/events/BitcoinDListener.java b/src/main/java/com/_37coins/bcJsonRpc/events/BitcoinDListener.java index 6166764..7b72329 100644 --- a/src/main/java/com/_37coins/bcJsonRpc/events/BitcoinDListener.java +++ b/src/main/java/com/_37coins/bcJsonRpc/events/BitcoinDListener.java @@ -1,69 +1,69 @@ -package com._37coins.bcJsonRpc.events; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.Observable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BitcoinDListener extends Observable implements Runnable { - public static Logger log = LoggerFactory.getLogger(BitcoinDListener.class); - private final ServerSocket server; - private int port; - - public BitcoinDListener(int port) throws IOException { - server = new ServerSocket(port); - this.port = port; - } - - public BitcoinDListener(ServerSocket server) throws IOException { - this.server = server; - this.port = server.getLocalPort(); - } - - @Override - public void run() { - log.info("Thread " + Thread.currentThread().getName() - + "started lintening on " + port); - while (!Thread.currentThread().isInterrupted()) { - Socket connection = null; - try { - connection = server.accept(); - } catch (IOException e1) { - e1.printStackTrace(); - break; - } - try { - BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String line; - if ((line = reader.readLine()) != null) { - setChanged(); - notifyObservers(line); - connection.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - // sockets are closed when complete. - try { - if (connection != null) - connection.close(); - } catch (IOException e) { - } - } - } - log.warn("Thread " + Thread.currentThread().getName() + " exited"); - } - - @Override - protected void finalize() throws Throwable { - server.close(); - log.info("Thread " + Thread.currentThread().getName() + " shutting down."); - super.finalize(); - } - -} +package com._37coins.bcJsonRpc.events; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.Observable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BitcoinDListener extends Observable implements Runnable { + public static Logger log = LoggerFactory.getLogger(BitcoinDListener.class); + private final ServerSocket server; + private int port; + + public BitcoinDListener(int port) throws IOException { + server = new ServerSocket(port); + this.port = port; + } + + public BitcoinDListener(ServerSocket server) throws IOException { + this.server = server; + this.port = server.getLocalPort(); + } + + @Override + public void run() { + log.info("Thread " + Thread.currentThread().getName() + + "started lintening on " + port); + while (!Thread.currentThread().isInterrupted()) { + Socket connection = null; + try { + connection = server.accept(); + } catch (IOException e1) { + e1.printStackTrace(); + break; + } + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String line; + if ((line = reader.readLine()) != null) { + setChanged(); + notifyObservers(line); + connection.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + // sockets are closed when complete. + try { + if (connection != null) + connection.close(); + } catch (IOException e) { + } + } + } + log.warn("Thread " + Thread.currentThread().getName() + " exited"); + } + + @Override + protected void finalize() throws Throwable { + server.close(); + log.info("Thread " + Thread.currentThread().getName() + " shutting down."); + super.finalize(); + } + +} diff --git a/src/main/java/com/_37coins/bcJsonRpc/events/BlockListener.java b/src/main/java/com/_37coins/bcJsonRpc/events/BlockListener.java index cd2b16c..37c4fee 100644 --- a/src/main/java/com/_37coins/bcJsonRpc/events/BlockListener.java +++ b/src/main/java/com/_37coins/bcJsonRpc/events/BlockListener.java @@ -1,53 +1,53 @@ -package com._37coins.bcJsonRpc.events; - -import java.io.IOException; -import java.util.Observable; -import java.util.Observer; - -import com._37coins.bcJsonRpc.BitcoindClientFactory; -import com._37coins.bcJsonRpc.BitcoindInterface; -import com._37coins.bcJsonRpc.pojo.Block; - - -public class BlockListener extends Observable implements Observer { - - final private Observable blockListener; - final private BitcoindInterface client; - public Thread listener = null; - - public BlockListener(final BitcoindInterface client) throws IOException { - if (BitcoindClientFactory.blockSocket!=null){ - blockListener = new BitcoinDListener(BitcoindClientFactory.blockSocket); - }else{ - blockListener = new BitcoinDListener(4001); - } - this.client = client; - } - - @Override - public synchronized void addObserver(Observer o) { - if (null == listener) { - blockListener.addObserver(this); - listener = new Thread((Runnable) blockListener, "blockListener"); - listener.start(); - } - super.addObserver(o); - } - - @Override - public void update(Observable o, Object arg) { - final String value = ((String) arg).trim(); - (new Thread() { - public void run() { - Block block = client.getblock(value); - setChanged(); - notifyObservers(block); - } - }).start(); - } - - public void stop(){ - listener.interrupt(); - } - -} +package com._37coins.bcJsonRpc.events; + +import java.io.IOException; +import java.util.Observable; +import java.util.Observer; + +import com._37coins.bcJsonRpc.BitcoindClientFactory; +import com._37coins.bcJsonRpc.BitcoindInterface; +import com._37coins.bcJsonRpc.pojo.Block; + + +public class BlockListener extends Observable implements Observer { + + final private Observable blockListener; + final private BitcoindInterface client; + public Thread listener = null; + + public BlockListener(final BitcoindInterface client) throws IOException { + if (BitcoindClientFactory.blockSocket!=null){ + blockListener = new BitcoinDListener(BitcoindClientFactory.blockSocket); + }else{ + blockListener = new BitcoinDListener(4001); + } + this.client = client; + } + + @Override + public synchronized void addObserver(Observer o) { + if (null == listener) { + blockListener.addObserver(this); + listener = new Thread((Runnable) blockListener, "blockListener"); + listener.start(); + } + super.addObserver(o); + } + + @Override + public void update(Observable o, Object arg) { + final String value = ((String) arg).trim(); + (new Thread() { + public void run() { + Block block = client.getblock(value); + setChanged(); + notifyObservers(block); + } + }).start(); + } + + public void stop(){ + listener.interrupt(); + } + +} diff --git a/src/main/java/com/_37coins/bcJsonRpc/events/WalletListener.java b/src/main/java/com/_37coins/bcJsonRpc/events/WalletListener.java index 7c36dc3..5f17379 100644 --- a/src/main/java/com/_37coins/bcJsonRpc/events/WalletListener.java +++ b/src/main/java/com/_37coins/bcJsonRpc/events/WalletListener.java @@ -1,53 +1,53 @@ -package com._37coins.bcJsonRpc.events; - -import java.io.IOException; -import java.util.Observable; -import java.util.Observer; - -import com._37coins.bcJsonRpc.BitcoindClientFactory; -import com._37coins.bcJsonRpc.BitcoindInterface; -import com._37coins.bcJsonRpc.pojo.Transaction; - - -public class WalletListener extends Observable implements Observer { - - final private Observable walletListener; - final private BitcoindInterface client; - public Thread listener = null; - - public WalletListener(final BitcoindInterface client) throws IOException { - if (BitcoindClientFactory.walletSocket!=null){ - walletListener = new BitcoinDListener(BitcoindClientFactory.walletSocket); - }else{ - walletListener = new BitcoinDListener(4002); - } - this.client = client; - } - - @Override - public synchronized void addObserver(Observer o) { - if (null == listener) { - walletListener.addObserver(this); - listener = new Thread((Runnable) walletListener, "walletListener"); - listener.start(); - } - super.addObserver(o); - } - - @Override - public void update(Observable o, Object arg) { - final String value = ((String) arg).trim(); - (new Thread() { - public void run() { - Transaction tx = client.gettransaction(value); - setChanged(); - notifyObservers(tx); - } - }).start(); - } - - public void stop(){ - listener.interrupt(); - } - -} +package com._37coins.bcJsonRpc.events; + +import java.io.IOException; +import java.util.Observable; +import java.util.Observer; + +import com._37coins.bcJsonRpc.BitcoindClientFactory; +import com._37coins.bcJsonRpc.BitcoindInterface; +import com._37coins.bcJsonRpc.pojo.Transaction; + + +public class WalletListener extends Observable implements Observer { + + final private Observable walletListener; + final private BitcoindInterface client; + public Thread listener = null; + + public WalletListener(final BitcoindInterface client) throws IOException { + if (BitcoindClientFactory.walletSocket!=null){ + walletListener = new BitcoinDListener(BitcoindClientFactory.walletSocket); + }else{ + walletListener = new BitcoinDListener(4002); + } + this.client = client; + } + + @Override + public synchronized void addObserver(Observer o) { + if (null == listener) { + walletListener.addObserver(this); + listener = new Thread((Runnable) walletListener, "walletListener"); + listener.start(); + } + super.addObserver(o); + } + + @Override + public void update(Observable o, Object arg) { + final String value = ((String) arg).trim(); + (new Thread() { + public void run() { + Transaction tx = client.gettransaction(value); + setChanged(); + notifyObservers(tx); + } + }).start(); + } + + public void stop(){ + listener.interrupt(); + } + +} diff --git a/src/main/java/com/_37coins/bcJsonRpc/pojo/Account.java b/src/main/java/com/_37coins/bcJsonRpc/pojo/Account.java index 302071a..3fece8c 100644 --- a/src/main/java/com/_37coins/bcJsonRpc/pojo/Account.java +++ b/src/main/java/com/_37coins/bcJsonRpc/pojo/Account.java @@ -1,39 +1,39 @@ -package com._37coins.bcJsonRpc.pojo; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; - -@JsonInclude(Include.NON_NULL) -//@JsonIgnoreProperties(ignoreUnknown=true) -public class Account { - private String amount; - private long confirmations; - private String account; - private String label; - public String getAmount() { - return amount; - } - public void setAmount(String amount) { - this.amount = amount; - } - public long getConfirmations() { - return confirmations; - } - public void setConfirmations(long confirmations) { - this.confirmations = confirmations; - } - public String getAccount() { - return account; - } - public void setAccount(String account) { - this.account = account; - } - public String getLabel() { - return label; - } - public void setLabel(String label) { - this.label = label; - } - - -} +package com._37coins.bcJsonRpc.pojo; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +@JsonInclude(Include.NON_NULL) +//@JsonIgnoreProperties(ignoreUnknown=true) +public class Account { + private String amount; + private long confirmations; + private String account; + private String label; + public String getAmount() { + return amount; + } + public void setAmount(String amount) { + this.amount = amount; + } + public long getConfirmations() { + return confirmations; + } + public void setConfirmations(long confirmations) { + this.confirmations = confirmations; + } + public String getAccount() { + return account; + } + public void setAccount(String account) { + this.account = account; + } + public String getLabel() { + return label; + } + public void setLabel(String label) { + this.label = label; + } + + +} diff --git a/src/main/java/com/_37coins/bcJsonRpc/pojo/Address.java b/src/main/java/com/_37coins/bcJsonRpc/pojo/Address.java index a5e23d0..49c7ab9 100644 --- a/src/main/java/com/_37coins/bcJsonRpc/pojo/Address.java +++ b/src/main/java/com/_37coins/bcJsonRpc/pojo/Address.java @@ -1,40 +1,40 @@ -package com._37coins.bcJsonRpc.pojo; - -import java.math.BigDecimal; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; - -@JsonInclude(Include.NON_NULL) -//@JsonIgnoreProperties(ignoreUnknown=true) -public class Address { - private BigDecimal amount; - private long confirmations; - private String address; - private String account; - public BigDecimal getAmount() { - return amount; - } - public void setAmount(BigDecimal amount) { - this.amount = amount; - } - public long getConfirmations() { - return confirmations; - } - public void setConfirmations(long confirmations) { - this.confirmations = confirmations; - } - public String getAddress() { - return address; - } - public void setAddress(String address) { - this.address = address; - } - public String getAccount() { - return account; - } - public void setAccount(String account) { - this.account = account; - } - -} +package com._37coins.bcJsonRpc.pojo; + +import java.math.BigDecimal; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +@JsonInclude(Include.NON_NULL) +//@JsonIgnoreProperties(ignoreUnknown=true) +public class Address { + private BigDecimal amount; + private long confirmations; + private String address; + private String account; + public BigDecimal getAmount() { + return amount; + } + public void setAmount(BigDecimal amount) { + this.amount = amount; + } + public long getConfirmations() { + return confirmations; + } + public void setConfirmations(long confirmations) { + this.confirmations = confirmations; + } + public String getAddress() { + return address; + } + public void setAddress(String address) { + this.address = address; + } + public String getAccount() { + return account; + } + public void setAccount(String account) { + this.account = account; + } + +} diff --git a/src/main/java/com/_37coins/bcJsonRpc/pojo/AddressInformation.java b/src/main/java/com/_37coins/bcJsonRpc/pojo/AddressInformation.java index 137c71c..d680875 100644 --- a/src/main/java/com/_37coins/bcJsonRpc/pojo/AddressInformation.java +++ b/src/main/java/com/_37coins/bcJsonRpc/pojo/AddressInformation.java @@ -1,53 +1,53 @@ -package com._37coins.bcJsonRpc.pojo; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; - -@JsonInclude(Include.NON_NULL) -//@JsonIgnoreProperties(ignoreUnknown=true) -public class AddressInformation { - - private String address; - private boolean iscompressed; - private String account; - private String pubkey; - private boolean ismine; - private boolean isvalid; - - public String getAddress() { - return address; - } - public void setAddress(String address) { - this.address = address; - } - public boolean isIscompressed() { - return iscompressed; - } - public void setIscompressed(boolean iscompressed) { - this.iscompressed = iscompressed; - } - public String getAccount() { - return account; - } - public void setAccount(String account) { - this.account = account; - } - public String getPubkey() { - return pubkey; - } - public void setPubkey(String pubkey) { - this.pubkey = pubkey; - } - public boolean isIsmine() { - return ismine; - } - public void setIsmine(boolean ismine) { - this.ismine = ismine; - } - public boolean isIsvalid() { - return isvalid; - } - public void setIsvalid(boolean isvalid) { - this.isvalid = isvalid; - } -} +package com._37coins.bcJsonRpc.pojo; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +@JsonInclude(Include.NON_NULL) +//@JsonIgnoreProperties(ignoreUnknown=true) +public class AddressInformation { + + private String address; + private boolean iscompressed; + private String account; + private String pubkey; + private boolean ismine; + private boolean isvalid; + + public String getAddress() { + return address; + } + public void setAddress(String address) { + this.address = address; + } + public boolean isIscompressed() { + return iscompressed; + } + public void setIscompressed(boolean iscompressed) { + this.iscompressed = iscompressed; + } + public String getAccount() { + return account; + } + public void setAccount(String account) { + this.account = account; + } + public String getPubkey() { + return pubkey; + } + public void setPubkey(String pubkey) { + this.pubkey = pubkey; + } + public boolean isIsmine() { + return ismine; + } + public void setIsmine(boolean ismine) { + this.ismine = ismine; + } + public boolean isIsvalid() { + return isvalid; + } + public void setIsvalid(boolean isvalid) { + this.isvalid = isvalid; + } +} diff --git a/src/main/java/com/_37coins/bcJsonRpc/pojo/Block.java b/src/main/java/com/_37coins/bcJsonRpc/pojo/Block.java index 86804cb..0cb4f11 100644 --- a/src/main/java/com/_37coins/bcJsonRpc/pojo/Block.java +++ b/src/main/java/com/_37coins/bcJsonRpc/pojo/Block.java @@ -1,106 +1,165 @@ -package com._37coins.bcJsonRpc.pojo; - -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; - -@JsonInclude(Include.NON_NULL) -//@JsonIgnoreProperties(ignoreUnknown=true) -public class Block { - - private List tx; - private long time; - private long height; - private long nonce; - private String hash; - private String bits; - private long difficulty; - private String merkleroot; - private String previousblockhash; - private String nextblockhash; - private long confirmations; - private long version; - private long size; - - - public List getTx() { - return tx; - } - public void setTx(List tx) { - this.tx = tx; - } - public long getTime() { - return time; - } - public void setTime(long time) { - this.time = time; - } - public long getHeight() { - return height; - } - public void setHeight(long height) { - this.height = height; - } - public long getNonce() { - return nonce; - } - public void setNonce(long nonce) { - this.nonce = nonce; - } - public String getHash() { - return hash; - } - public void setHash(String hash) { - this.hash = hash; - } - public String getBits() { - return bits; - } - public void setBits(String bits) { - this.bits = bits; - } - public long getDifficulty() { - return difficulty; - } - public void setDifficulty(long difficulty) { - this.difficulty = difficulty; - } - public String getMerkleroot() { - return merkleroot; - } - public void setMerkleroot(String merkleroot) { - this.merkleroot = merkleroot; - } - public long getVersion() { - return version; - } - public void setVersion(long version) { - this.version = version; - } - public long getSize() { - return size; - } - public void setSize(long size) { - this.size = size; - } - public long getConfirmations() { - return confirmations; - } - public void setConfirmations(long confirmations) { - this.confirmations = confirmations; - } - public String getPreviousblockhash() { - return previousblockhash; - } - public void setPreviousblockhash(String previousblockhash) { - this.previousblockhash = previousblockhash; - } - public String getNextblockhash() { - return nextblockhash; - } - public void setNextblockhash(String nextblockhash) { - this.nextblockhash = nextblockhash; - } - -} +package com._37coins.bcJsonRpc.pojo; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +@JsonInclude(Include.NON_NULL) +//@JsonIgnoreProperties(ignoreUnknown=true) +public class Block { + + private List tx; + private long time; + private long height; + private long nonce; + private String hash; + private String bits; + private long difficulty; + private String merkleroot; + private String previousblockhash; + private String nextblockhash; + private long confirmations; + private long version; + private long size; + + private long strippedsize; + private long weight; + private String versionHex; + private long mediantime; + private String chainwork; + + public List getTx() { + return tx; + } + public void setTx(List tx) { + this.tx = tx; + } + public long getTime() { + return time; + } + public void setTime(long time) { + this.time = time; + } + public long getHeight() { + return height; + } + public void setHeight(long height) { + this.height = height; + } + public long getNonce() { + return nonce; + } + public void setNonce(long nonce) { + this.nonce = nonce; + } + public String getHash() { + return hash; + } + public void setHash(String hash) { + this.hash = hash; + } + public String getBits() { + return bits; + } + public void setBits(String bits) { + this.bits = bits; + } + public long getDifficulty() { + return difficulty; + } + public void setDifficulty(long difficulty) { + this.difficulty = difficulty; + } + public String getMerkleroot() { + return merkleroot; + } + public void setMerkleroot(String merkleroot) { + this.merkleroot = merkleroot; + } + public long getVersion() { + return version; + } + public void setVersion(long version) { + this.version = version; + } + public long getSize() { + return size; + } + public void setSize(long size) { + this.size = size; + } + public long getConfirmations() { + return confirmations; + } + public void setConfirmations(long confirmations) { + this.confirmations = confirmations; + } + public String getPreviousblockhash() { + return previousblockhash; + } + public void setPreviousblockhash(String previousblockhash) { + this.previousblockhash = previousblockhash; + } + public String getNextblockhash() { + return nextblockhash; + } + public void setNextblockhash(String nextblockhash) { + this.nextblockhash = nextblockhash; + } + + public long getStrippedsize() { + return strippedsize; + } + public void setStrippedsize(long strippedsize) { + this.strippedsize = strippedsize; + } + public long getWeight() { + return weight; + } + public void setWeight(long weight) { + this.weight = weight; + } + public String getVersionHex() { + return versionHex; + } + public void setVersionHex(String versionHex) { + this.versionHex = versionHex; + } + public long getMediantime() { + return mediantime; + } + public void setMediantime(long mediantime) { + this.mediantime = mediantime; + } + public String getChainwork() { + return chainwork; + } + public void setChainwork(String chainwork) { + this.chainwork = chainwork; + } + @Override + public String toString() { + return "Block [\n" + + "hash = "+hash+",\n" + + "tx=" + tx +",\n" + + "time=" + time +",\n" + + "height=" + height +",\n" + + "nonce=" + nonce +",\n" + + "hash=" + hash+",\n" + + "bits=" + bits +",\n" + + "difficulty=" + difficulty+",\n" + + "merkleroot=" + merkleroot+",\n" + + "previousblockhash=" + previousblockhash+",\n" + + "nextblockhash=" + nextblockhash +",\n" + + "confirmations=" + confirmations +",\n" + + "version=" + version +",\n" + + "size=" + size +",\n" + + "strippedsize=" + strippedsize +",\n" + + "weight=" + weight +",\n" + + "versionHex=" + versionHex +",\n" + + "mediantime=" + mediantime +",\n" + + "chainwork=" + chainwork +",\n" + + "]"; + } +} diff --git a/src/main/java/com/_37coins/bcJsonRpc/pojo/Detail.java b/src/main/java/com/_37coins/bcJsonRpc/pojo/Detail.java new file mode 100644 index 0000000..770381a --- /dev/null +++ b/src/main/java/com/_37coins/bcJsonRpc/pojo/Detail.java @@ -0,0 +1,157 @@ +package com._37coins.bcJsonRpc.pojo; + +import java.util.HashMap; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ "account", "address", "category", "amount", "label", "vout", "fee", "abandoned" }) +public class Detail { + + @JsonProperty("account") + private String account; + @JsonProperty("address") + private String address; + @JsonProperty("category") + private String category; + @JsonProperty("amount") + private Double amount; + @JsonProperty("label") + private String label; + @JsonProperty("vout") + private Integer vout; + @JsonProperty("fee") + private Double fee; + @JsonProperty("abandoned") + private Boolean abandoned; + @JsonIgnore + private Map additionalProperties = new HashMap(); + + @JsonProperty("account") + public String getAccount() { + return account; + } + + @JsonProperty("account") + public void setAccount(String account) { + this.account = account; + } + + @JsonProperty("address") + public String getAddress() { + return address; + } + + @JsonProperty("address") + public void setAddress(String address) { + this.address = address; + } + + @JsonProperty("category") + public String getCategory() { + return category; + } + + @JsonProperty("category") + public void setCategory(String category) { + this.category = category; + } + + @JsonProperty("amount") + public Double getAmount() { + return amount; + } + + @JsonProperty("amount") + public void setAmount(Double amount) { + this.amount = amount; + } + + @JsonProperty("label") + public String getLabel() { + return label; + } + + @JsonProperty("label") + public void setLabel(String label) { + this.label = label; + } + + @JsonProperty("vout") + public Integer getVout() { + return vout; + } + + @JsonProperty("vout") + public void setVout(Integer vout) { + this.vout = vout; + } + + @JsonProperty("fee") + public Double getFee() { + return fee; + } + + @JsonProperty("fee") + public void setFee(Double fee) { + this.fee = fee; + } + + @JsonProperty("abandoned") + public Boolean getAbandoned() { + return abandoned; + } + + @JsonProperty("abandoned") + public void setAbandoned(Boolean abandoned) { + this.abandoned = abandoned; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("account", account).append("address", address) + .append("category", category).append("amount", amount).append("label", label).append("vout", vout) + .append("fee", fee).append("abandoned", abandoned).append("additionalProperties", additionalProperties) + .toString(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(fee).append(amount).append(category).append(address) + .append(additionalProperties).append(vout).append(account).append(label).append(abandoned).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof Detail) == false) { + return false; + } + Detail rhs = ((Detail) other); + return new EqualsBuilder().append(fee, rhs.fee).append(amount, rhs.amount).append(category, rhs.category) + .append(address, rhs.address).append(additionalProperties, rhs.additionalProperties) + .append(vout, rhs.vout).append(account, rhs.account).append(label, rhs.label) + .append(abandoned, rhs.abandoned).isEquals(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/_37coins/bcJsonRpc/pojo/Info.java b/src/main/java/com/_37coins/bcJsonRpc/pojo/Info.java index 3b5a23c..d10f12e 100644 --- a/src/main/java/com/_37coins/bcJsonRpc/pojo/Info.java +++ b/src/main/java/com/_37coins/bcJsonRpc/pojo/Info.java @@ -1,119 +1,120 @@ -package com._37coins.bcJsonRpc.pojo; - -import java.math.BigDecimal; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; - -@JsonInclude(Include.NON_NULL) -//@JsonIgnoreProperties(ignoreUnknown=true) -public class Info { - - private long version; - private long protocolversion; - private long walletversion; - private BigDecimal balance; - private long blocks; - private long timeoffset; - private long connections; - private String proxy; - private BigDecimal difficulty; - private boolean testnet; - private long keypoololdest; - private long keypoolsize; - private BigDecimal paytxfee; - private BigDecimal relayfee; - private String errors; - public long getVersion() { - return version; - } - public void setVersion(long version) { - this.version = version; - } - public long getProtocolversion() { - return protocolversion; - } - public void setProtocolversion(long protocolversion) { - this.protocolversion = protocolversion; - } - public long getWalletversion() { - return walletversion; - } - public void setWalletversion(long walletversion) { - this.walletversion = walletversion; - } - public BigDecimal getBalance() { - return balance; - } - public void setBalance(BigDecimal balance) { - this.balance = balance; - } - public long getBlocks() { - return blocks; - } - public void setBlocks(long blocks) { - this.blocks = blocks; - } - public long getTimeoffset() { - return timeoffset; - } - public void setTimeoffset(long timeoffset) { - this.timeoffset = timeoffset; - } - public long getConnections() { - return connections; - } - public void setConnections(long connections) { - this.connections = connections; - } - public String getProxy() { - return proxy; - } - public void setProxy(String proxy) { - this.proxy = proxy; - } - public BigDecimal getDifficulty() { - return difficulty; - } - public void setDifficulty(BigDecimal difficulty) { - this.difficulty = difficulty; - } - public boolean isTestnet() { - return testnet; - } - public void setTestnet(boolean testnet) { - this.testnet = testnet; - } - public long getKeypoololdest() { - return keypoololdest; - } - public void setKeypoololdest(long keypoololdest) { - this.keypoololdest = keypoololdest; - } - public long getKeypoolsize() { - return keypoolsize; - } - public void setKeypoolsize(long keypoolsize) { - this.keypoolsize = keypoolsize; - } - public BigDecimal getPaytxfee() { - return paytxfee; - } - public void setPaytxfee(BigDecimal paytxfee) { - this.paytxfee = paytxfee; - } - public String getErrors() { - return errors; - } - public void setErrors(String errors) { - this.errors = errors; - } - - public BigDecimal getRelayfee() { - return relayfee; - } - - public void setRelayfee(BigDecimal relayfee) { - this.relayfee = relayfee; - } -} +package com._37coins.bcJsonRpc.pojo; + +import java.math.BigDecimal; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +@JsonInclude(Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown=true) +public class Info { + + private long version; + private long protocolversion; + private long walletversion; + private BigDecimal balance; + private long blocks; + private long timeoffset; + private long connections; + private String proxy; + private BigDecimal difficulty; + private boolean testnet; + private long keypoololdest; + private long keypoolsize; + private BigDecimal paytxfee; + private BigDecimal relayfee; + private String errors; + public long getVersion() { + return version; + } + public void setVersion(long version) { + this.version = version; + } + public long getProtocolversion() { + return protocolversion; + } + public void setProtocolversion(long protocolversion) { + this.protocolversion = protocolversion; + } + public long getWalletversion() { + return walletversion; + } + public void setWalletversion(long walletversion) { + this.walletversion = walletversion; + } + public BigDecimal getBalance() { + return balance; + } + public void setBalance(BigDecimal balance) { + this.balance = balance; + } + public long getBlocks() { + return blocks; + } + public void setBlocks(long blocks) { + this.blocks = blocks; + } + public long getTimeoffset() { + return timeoffset; + } + public void setTimeoffset(long timeoffset) { + this.timeoffset = timeoffset; + } + public long getConnections() { + return connections; + } + public void setConnections(long connections) { + this.connections = connections; + } + public String getProxy() { + return proxy; + } + public void setProxy(String proxy) { + this.proxy = proxy; + } + public BigDecimal getDifficulty() { + return difficulty; + } + public void setDifficulty(BigDecimal difficulty) { + this.difficulty = difficulty; + } + public boolean isTestnet() { + return testnet; + } + public void setTestnet(boolean testnet) { + this.testnet = testnet; + } + public long getKeypoololdest() { + return keypoololdest; + } + public void setKeypoololdest(long keypoololdest) { + this.keypoololdest = keypoololdest; + } + public long getKeypoolsize() { + return keypoolsize; + } + public void setKeypoolsize(long keypoolsize) { + this.keypoolsize = keypoolsize; + } + public BigDecimal getPaytxfee() { + return paytxfee; + } + public void setPaytxfee(BigDecimal paytxfee) { + this.paytxfee = paytxfee; + } + public String getErrors() { + return errors; + } + public void setErrors(String errors) { + this.errors = errors; + } + + public BigDecimal getRelayfee() { + return relayfee; + } + + public void setRelayfee(BigDecimal relayfee) { + this.relayfee = relayfee; + } +} diff --git a/src/main/java/com/_37coins/bcJsonRpc/pojo/RawTransaction.java b/src/main/java/com/_37coins/bcJsonRpc/pojo/RawTransaction.java new file mode 100644 index 0000000..1c45a07 --- /dev/null +++ b/src/main/java/com/_37coins/bcJsonRpc/pojo/RawTransaction.java @@ -0,0 +1,160 @@ +package com._37coins.bcJsonRpc.pojo; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ "txid", "hash", "version", "size", "vsize", "locktime", "vin", "vout" }) +public class RawTransaction { + + @JsonProperty("txid") + private String txid; + @JsonProperty("hash") + private String hash; + @JsonProperty("version") + private Integer version; + @JsonProperty("size") + private Integer size; + @JsonProperty("vsize") + private Integer vsize; + @JsonProperty("locktime") + private Integer locktime; + @JsonProperty("vin") + private List vin = null; + @JsonProperty("vout") + private List vout = null; + @JsonIgnore + private Map additionalProperties = new HashMap(); + + @JsonProperty("txid") + public String getTxid() { + return txid; + } + + @JsonProperty("txid") + public void setTxid(String txid) { + this.txid = txid; + } + + @JsonProperty("hash") + public String getHash() { + return hash; + } + + @JsonProperty("hash") + public void setHash(String hash) { + this.hash = hash; + } + + @JsonProperty("version") + public Integer getVersion() { + return version; + } + + @JsonProperty("version") + public void setVersion(Integer version) { + this.version = version; + } + + @JsonProperty("size") + public Integer getSize() { + return size; + } + + @JsonProperty("size") + public void setSize(Integer size) { + this.size = size; + } + + @JsonProperty("vsize") + public Integer getVsize() { + return vsize; + } + + @JsonProperty("vsize") + public void setVsize(Integer vsize) { + this.vsize = vsize; + } + + @JsonProperty("locktime") + public Integer getLocktime() { + return locktime; + } + + @JsonProperty("locktime") + public void setLocktime(Integer locktime) { + this.locktime = locktime; + } + + @JsonProperty("vin") + public List getVin() { + return vin; + } + + @JsonProperty("vin") + public void setVin(List vin) { + this.vin = vin; + } + + @JsonProperty("vout") + public List getVout() { + return vout; + } + + @JsonProperty("vout") + public void setVout(List vout) { + this.vout = vout; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("txid", txid).append("hash", hash) + .append("version", version).append("size", size).append("vsize", vsize).append("locktime", locktime) + .append("vin", vin).append("vout", vout).append("additionalProperties", additionalProperties) + .toString(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(hash).append(additionalProperties).append(locktime).append(vin).append(vout) + .append(txid).append(vsize).append(size).append(version).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof RawTransaction) == false) { + return false; + } + RawTransaction rhs = ((RawTransaction) other); + return new EqualsBuilder().append(hash, rhs.hash).append(additionalProperties, rhs.additionalProperties) + .append(locktime, rhs.locktime).append(vin, rhs.vin).append(vout, rhs.vout).append(txid, rhs.txid) + .append(vsize, rhs.vsize).append(size, rhs.size).append(version, rhs.version).isEquals(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/_37coins/bcJsonRpc/pojo/ScriptPubKey.java b/src/main/java/com/_37coins/bcJsonRpc/pojo/ScriptPubKey.java new file mode 100644 index 0000000..b7b3ec0 --- /dev/null +++ b/src/main/java/com/_37coins/bcJsonRpc/pojo/ScriptPubKey.java @@ -0,0 +1,120 @@ +package com._37coins.bcJsonRpc.pojo; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ "asm", "hex", "reqSigs", "type", "addresses" }) +public class ScriptPubKey { + + @JsonProperty("asm") + private String asm; + @JsonProperty("hex") + private String hex; + @JsonProperty("reqSigs") + private Integer reqSigs; + @JsonProperty("type") + private String type; + @JsonProperty("addresses") + private List addresses = null; + @JsonIgnore + private Map additionalProperties = new HashMap(); + + @JsonProperty("asm") + public String getAsm() { + return asm; + } + + @JsonProperty("asm") + public void setAsm(String asm) { + this.asm = asm; + } + + @JsonProperty("hex") + public String getHex() { + return hex; + } + + @JsonProperty("hex") + public void setHex(String hex) { + this.hex = hex; + } + + @JsonProperty("reqSigs") + public Integer getReqSigs() { + return reqSigs; + } + + @JsonProperty("reqSigs") + public void setReqSigs(Integer reqSigs) { + this.reqSigs = reqSigs; + } + + @JsonProperty("type") + public String getType() { + return type; + } + + @JsonProperty("type") + public void setType(String type) { + this.type = type; + } + + @JsonProperty("addresses") + public List getAddresses() { + return addresses; + } + + @JsonProperty("addresses") + public void setAddresses(List addresses) { + this.addresses = addresses; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("asm", asm).append("hex", hex).append("reqSigs", reqSigs) + .append("type", type).append("addresses", addresses) + .append("additionalProperties", additionalProperties).toString(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(hex).append(reqSigs).append(additionalProperties).append(addresses) + .append(type).append(asm).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof ScriptPubKey) == false) { + return false; + } + ScriptPubKey rhs = ((ScriptPubKey) other); + return new EqualsBuilder().append(hex, rhs.hex).append(reqSigs, rhs.reqSigs) + .append(additionalProperties, rhs.additionalProperties).append(addresses, rhs.addresses) + .append(type, rhs.type).append(asm, rhs.asm).isEquals(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/_37coins/bcJsonRpc/pojo/ScriptSig.java b/src/main/java/com/_37coins/bcJsonRpc/pojo/ScriptSig.java new file mode 100644 index 0000000..d985f6f --- /dev/null +++ b/src/main/java/com/_37coins/bcJsonRpc/pojo/ScriptSig.java @@ -0,0 +1,80 @@ +package com._37coins.bcJsonRpc.pojo; + +import java.util.HashMap; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ "asm", "hex" }) +public class ScriptSig { + + @JsonProperty("asm") + private String asm; + @JsonProperty("hex") + private String hex; + @JsonIgnore + private Map additionalProperties = new HashMap(); + + @JsonProperty("asm") + public String getAsm() { + return asm; + } + + @JsonProperty("asm") + public void setAsm(String asm) { + this.asm = asm; + } + + @JsonProperty("hex") + public String getHex() { + return hex; + } + + @JsonProperty("hex") + public void setHex(String hex) { + this.hex = hex; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("asm", asm).append("hex", hex) + .append("additionalProperties", additionalProperties).toString(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(hex).append(additionalProperties).append(asm).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof ScriptSig) == false) { + return false; + } + ScriptSig rhs = ((ScriptSig) other); + return new EqualsBuilder().append(hex, rhs.hex).append(additionalProperties, rhs.additionalProperties) + .append(asm, rhs.asm).isEquals(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/_37coins/bcJsonRpc/pojo/Transaction.java b/src/main/java/com/_37coins/bcJsonRpc/pojo/Transaction.java index 41da54e..9e678f8 100644 --- a/src/main/java/com/_37coins/bcJsonRpc/pojo/Transaction.java +++ b/src/main/java/com/_37coins/bcJsonRpc/pojo/Transaction.java @@ -1,207 +1,224 @@ -package com._37coins.bcJsonRpc.pojo; - -import java.math.BigDecimal; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.annotation.JsonValue; - -@JsonInclude(Include.NON_NULL) -//@JsonIgnoreProperties(ignoreUnknown=true) -public class Transaction { - - public enum Category { - RECEIVE("receive"), - SEND("send"), - CONFLICTED("conflicted"), - MOVE("move"); - - private String text; - - Category(String text) { - this.text = text; - } - - @JsonValue - final String value() { - return this.text; - } - - public String getText() { - return this.text; - } - - @JsonCreator - public static Category fromString(String text) { - if (text != null) { - for (Category b : Category.values()) { - if (text.equalsIgnoreCase(b.text)) { - return b; - } - } - } - return null; - } - } - - - private BigDecimal fee; - private BigDecimal amount; - private long blockindex; - private Category category; - private long confirmations; - private long time; - private long timereceived; - private long blocktime; - private List walletconflicts; - private List details; - private String address; - private String txid; - private long block; - private String hex; - private String blockhash; - private String account; - private String otheraccount; - private String comment; - private String to; - - - public String getOtheraccount() { - return otheraccount; - } - public Transaction setOtheraccount(String otheraccount) { - this.otheraccount = otheraccount; - return this; - } - public String getComment() { - return comment; - } - public Transaction setComment(String comment) { - this.comment = comment; - return this; - } - public BigDecimal getFee() { - return fee; - } - public Transaction setFee(BigDecimal fee) { - this.fee = fee; - return this; - } - public BigDecimal getAmount() { - return amount; - } - public Transaction setAmount(BigDecimal amount) { - this.amount = amount; - return this; - } - public long getBlockindex() { - return blockindex; - } - public List getWalletconflicts() { - return walletconflicts; - } - public Transaction setWalletconflicts(List walletconflicts) { - this.walletconflicts = walletconflicts; - return this; - } - public Transaction setBlockindex(long blockindex) { - this.blockindex = blockindex; - return this; - } - public Category getCategory() { - return category; - } - public Transaction setCategory(Category category) { - this.category = category; - return this; - } - public long getConfirmations() { - return confirmations; - } - public Transaction setConfirmations(long confirmations) { - this.confirmations = confirmations; - return this; - } - public String getAddress() { - return address; - } - public Transaction setAddress(String address) { - this.address = address; - return this; - } - public String getTxid() { - return txid; - } - public Transaction setTxid(String txid) { - this.txid = txid; - return this; - } - public long getBlock() { - return block; - } - public Transaction setBlock(long block) { - this.block = block; - return this; - } - - public String getHex() { - return hex; - } - public Transaction setHex(String hex) { - this.hex = hex; - return this; - } - public String getBlockhash() { - return blockhash; - } - public Transaction setBlockhash(String blockhash) { - this.blockhash = blockhash; - return this; - } - public List getDetails() { - return details; - } - public Transaction setDetails(List details) { - this.details = details; - return this; - } - public String getAccount() { - return account; - } - public Transaction setAccount(String account) { - this.account = account; - return this; - } - public long getTime() { - return time; - } - public Transaction setTime(long time) { - this.time = time; - return this; - } - public long getTimereceived() { - return timereceived; - } - public Transaction setTimereceived(long timereceived) { - this.timereceived = timereceived; - return this; - } - public long getBlocktime() { - return blocktime; - } - public Transaction setBlocktime(long blocktime) { - this.blocktime = blocktime; - return this; - } - public String getTo() { - return to; - } - public Transaction setTo(String to) { - this.to = to; - return this; - } - - -} +package com._37coins.bcJsonRpc.pojo; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ "amount", "fee", "confirmations", "blockhash", "blockindex", "blocktime", "txid", + "walletconflicts", "time", "timereceived", "bip125-replaceable", "details", "hex" }) +public class Transaction { + + @JsonProperty("amount") + private Double amount; + @JsonProperty("fee") + private Double fee; + @JsonProperty("confirmations") + private Integer confirmations; + @JsonProperty("blockhash") + private String blockhash; + @JsonProperty("blockindex") + private Integer blockindex; + @JsonProperty("blocktime") + private Integer blocktime; + @JsonProperty("txid") + private String txid; + @JsonProperty("walletconflicts") + private List walletconflicts = null; + @JsonProperty("time") + private Integer time; + @JsonProperty("timereceived") + private Integer timereceived; + @JsonProperty("bip125-replaceable") + private String bip125Replaceable; + @JsonProperty("details") + private List details = null; + @JsonProperty("hex") + private String hex; + @JsonIgnore + private Map additionalProperties = new HashMap(); + + @JsonProperty("amount") + public Double getAmount() { + return amount; + } + + @JsonProperty("amount") + public void setAmount(Double amount) { + this.amount = amount; + } + + @JsonProperty("fee") + public Double getFee() { + return fee; + } + + @JsonProperty("fee") + public void setFee(Double fee) { + this.fee = fee; + } + + @JsonProperty("confirmations") + public Integer getConfirmations() { + return confirmations; + } + + @JsonProperty("confirmations") + public void setConfirmations(Integer confirmations) { + this.confirmations = confirmations; + } + + @JsonProperty("blockhash") + public String getBlockhash() { + return blockhash; + } + + @JsonProperty("blockhash") + public void setBlockhash(String blockhash) { + this.blockhash = blockhash; + } + + @JsonProperty("blockindex") + public Integer getBlockindex() { + return blockindex; + } + + @JsonProperty("blockindex") + public void setBlockindex(Integer blockindex) { + this.blockindex = blockindex; + } + + @JsonProperty("blocktime") + public Integer getBlocktime() { + return blocktime; + } + + @JsonProperty("blocktime") + public void setBlocktime(Integer blocktime) { + this.blocktime = blocktime; + } + + @JsonProperty("txid") + public String getTxid() { + return txid; + } + + @JsonProperty("txid") + public void setTxid(String txid) { + this.txid = txid; + } + + @JsonProperty("walletconflicts") + public List getWalletconflicts() { + return walletconflicts; + } + + @JsonProperty("walletconflicts") + public void setWalletconflicts(List walletconflicts) { + this.walletconflicts = walletconflicts; + } + + @JsonProperty("time") + public Integer getTime() { + return time; + } + + @JsonProperty("time") + public void setTime(Integer time) { + this.time = time; + } + + @JsonProperty("timereceived") + public Integer getTimereceived() { + return timereceived; + } + + @JsonProperty("timereceived") + public void setTimereceived(Integer timereceived) { + this.timereceived = timereceived; + } + + @JsonProperty("bip125-replaceable") + public String getBip125Replaceable() { + return bip125Replaceable; + } + + @JsonProperty("bip125-replaceable") + public void setBip125Replaceable(String bip125Replaceable) { + this.bip125Replaceable = bip125Replaceable; + } + + @JsonProperty("details") + public List getDetails() { + return details; + } + + @JsonProperty("details") + public void setDetails(List details) { + this.details = details; + } + + @JsonProperty("hex") + public String getHex() { + return hex; + } + + @JsonProperty("hex") + public void setHex(String hex) { + this.hex = hex; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("amount", amount).append("fee", fee) + .append("confirmations", confirmations).append("blockhash", blockhash).append("blockindex", blockindex) + .append("blocktime", blocktime).append("txid", txid).append("walletconflicts", walletconflicts) + .append("time", time).append("timereceived", timereceived) + .append("bip125Replaceable", bip125Replaceable).append("details", details).append("hex", hex) + .append("additionalProperties", additionalProperties).toString(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(confirmations).append(blockhash).append(blocktime).append(fee) + .append(amount).append(bip125Replaceable).append(blockindex).append(time).append(hex).append(details) + .append(timereceived).append(additionalProperties).append(txid).append(walletconflicts).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof Transaction) == false) { + return false; + } + Transaction rhs = ((Transaction) other); + return new EqualsBuilder().append(confirmations, rhs.confirmations).append(blockhash, rhs.blockhash) + .append(blocktime, rhs.blocktime).append(fee, rhs.fee).append(amount, rhs.amount) + .append(bip125Replaceable, rhs.bip125Replaceable).append(blockindex, rhs.blockindex) + .append(time, rhs.time).append(hex, rhs.hex).append(details, rhs.details) + .append(timereceived, rhs.timereceived).append(additionalProperties, rhs.additionalProperties) + .append(txid, rhs.txid).append(walletconflicts, rhs.walletconflicts).isEquals(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/_37coins/bcJsonRpc/pojo/Vin.java b/src/main/java/com/_37coins/bcJsonRpc/pojo/Vin.java new file mode 100644 index 0000000..ac67a67 --- /dev/null +++ b/src/main/java/com/_37coins/bcJsonRpc/pojo/Vin.java @@ -0,0 +1,106 @@ +package com._37coins.bcJsonRpc.pojo; + +import java.util.HashMap; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ "txid", "vout", "scriptSig", "sequence" }) +public class Vin { + + @JsonProperty("txid") + private String txid; + @JsonProperty("vout") + private Integer vout; + @JsonProperty("scriptSig") + private ScriptSig scriptSig; + @JsonProperty("sequence") + private Integer sequence; + @JsonIgnore + private Map additionalProperties = new HashMap(); + + @JsonProperty("txid") + public String getTxid() { + return txid; + } + + @JsonProperty("txid") + public void setTxid(String txid) { + this.txid = txid; + } + + @JsonProperty("vout") + public Integer getVout() { + return vout; + } + + @JsonProperty("vout") + public void setVout(Integer vout) { + this.vout = vout; + } + + @JsonProperty("scriptSig") + public ScriptSig getScriptSig() { + return scriptSig; + } + + @JsonProperty("scriptSig") + public void setScriptSig(ScriptSig scriptSig) { + this.scriptSig = scriptSig; + } + + @JsonProperty("sequence") + public Integer getSequence() { + return sequence; + } + + @JsonProperty("sequence") + public void setSequence(Integer sequence) { + this.sequence = sequence; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("txid", txid).append("vout", vout).append("scriptSig", scriptSig) + .append("sequence", sequence).append("additionalProperties", additionalProperties).toString(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(additionalProperties).append(sequence).append(vout).append(txid) + .append(scriptSig).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof Vin) == false) { + return false; + } + Vin rhs = ((Vin) other); + return new EqualsBuilder().append(additionalProperties, rhs.additionalProperties).append(sequence, rhs.sequence) + .append(vout, rhs.vout).append(txid, rhs.txid).append(scriptSig, rhs.scriptSig).isEquals(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/_37coins/bcJsonRpc/pojo/Vout.java b/src/main/java/com/_37coins/bcJsonRpc/pojo/Vout.java new file mode 100644 index 0000000..847c50a --- /dev/null +++ b/src/main/java/com/_37coins/bcJsonRpc/pojo/Vout.java @@ -0,0 +1,94 @@ +package com._37coins.bcJsonRpc.pojo; + +import java.util.HashMap; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ "value", "n", "scriptPubKey" }) +public class Vout { + + @JsonProperty("value") + private Double value; + @JsonProperty("n") + private Integer n; + @JsonProperty("scriptPubKey") + private ScriptPubKey scriptPubKey; + @JsonIgnore + private Map additionalProperties = new HashMap(); + + @JsonProperty("value") + public Double getValue() { + return value; + } + + @JsonProperty("value") + public void setValue(Double value) { + this.value = value; + } + + @JsonProperty("n") + public Integer getN() { + return n; + } + + @JsonProperty("n") + public void setN(Integer n) { + this.n = n; + } + + @JsonProperty("scriptPubKey") + public ScriptPubKey getScriptPubKey() { + return scriptPubKey; + } + + @JsonProperty("scriptPubKey") + public void setScriptPubKey(ScriptPubKey scriptPubKey) { + this.scriptPubKey = scriptPubKey; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("value", value).append("n", n).append("scriptPubKey", scriptPubKey) + .append("additionalProperties", additionalProperties).toString(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(additionalProperties).append(scriptPubKey).append(n).append(value) + .toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof Vout) == false) { + return false; + } + Vout rhs = ((Vout) other); + return new EqualsBuilder().append(additionalProperties, rhs.additionalProperties) + .append(scriptPubKey, rhs.scriptPubKey).append(n, rhs.n).append(value, rhs.value).isEquals(); + } + +} \ No newline at end of file diff --git a/src/test/java/com/_37coins/IntegrationIT.java b/src/test/java/com/_37coins/IntegrationIT.java index 4aa1bbd..37df557 100644 --- a/src/test/java/com/_37coins/IntegrationIT.java +++ b/src/test/java/com/_37coins/IntegrationIT.java @@ -1,44 +1,103 @@ -package com._37coins; - -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.math.BigDecimal; -import java.net.MalformedURLException; -import java.net.URL; - -import org.junit.BeforeClass; -import org.junit.Test; - -import com._37coins.bcJsonRpc.BitcoindClientFactory; -import com._37coins.bcJsonRpc.BitcoindInterface; -import com._37coins.bcJsonRpc.pojo.Info; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class IntegrationIT { - - static BitcoindInterface client; - - @BeforeClass - static public void before() throws MalformedURLException, IOException{ - BitcoindClientFactory clientFactory = new BitcoindClientFactory(new URL("http://localhost:8332/"), "admin", "admin"); - client = clientFactory.getClient(); - } - - @Test - public void testInfo() throws JsonProcessingException{ - Info info = client.getinfo(); - System.out.println(new ObjectMapper().writeValueAsString(info)); - } - - @Test - public void testBalance(){ - BigDecimal balance = client.getbalance(); - - System.out.println("balance = " + balance); - - assertTrue(balance.compareTo(BigDecimal.ZERO) >= 0); - } - -} +package com._37coins; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.math.BigDecimal; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com._37coins.bcJsonRpc.BitcoindClientFactory; +import com._37coins.bcJsonRpc.BitcoindInterface; +import com._37coins.bcJsonRpc.pojo.Block; +import com._37coins.bcJsonRpc.pojo.Info; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class IntegrationIT { + Logger log = LoggerFactory.getLogger(IntegrationIT.class); + + static BitcoindInterface client; + + @BeforeClass + static public void before() throws MalformedURLException, IOException { + BitcoindClientFactory clientFactory = new BitcoindClientFactory(new URL("http://localhost:18332/"), "test", + "test"); + client = clientFactory.getClient(); + } + + @Test + public void testInfo() throws JsonProcessingException { + Info info = client.getinfo(); + System.out.println(new ObjectMapper().writeValueAsString(info)); + } + + @Test + public void testBlock() { + // get last N blocks + // log the block and their transactions + Info info = client.getinfo(); + int currentBlockDepth = (int) info.getBlocks(); + int N = 6; // all transactions of the last 1h + int successfulBlockRetrieves = 0; + for (int i = currentBlockDepth; i > currentBlockDepth - N; i--) { + Block block = null; + String blockHash = null; + try { + blockHash = client.getblockhash(i); + block = client.getblock(blockHash); + successfulBlockRetrieves++; + } catch (Exception e) { + log.error("error getting block: " + i + " with hash: " + blockHash); + continue; + } + log.info("block: " + i + ": " + block.toString()); + List txs = block.getTx(); + for (String txHash : txs) { + log.info("retrieving tx " + txHash); + String txScript = client.getrawtransaction(txHash); + com._37coins.bcJsonRpc.pojo.RawTransaction tx = client.decoderawtransaction(txScript); + log.info("transaction: " + tx); + } + } + log.info("successfulBlockRetrieve: " + successfulBlockRetrieves + " of " + N); + } + + @Test + public void testRawTransaction() { + String txHash = "b8f3c72fb4ba9c25e8e070dc5785856ef17a4fc6ad4870a8ce41127a8c0f090e"; + String txScript = client.getrawtransaction(txHash); + log.info("txScript " + txScript ); + } + + @Test + public void testDecodeRawTransaction() { + String txHash = "b8f3c72fb4ba9c25e8e070dc5785856ef17a4fc6ad4870a8ce41127a8c0f090e"; + String txScript = client.getrawtransaction(txHash); + com._37coins.bcJsonRpc.pojo.RawTransaction tx = client.decoderawtransaction(txScript); + log.info("tx " + tx); + } + + @Test + public void testTransaction() { + String txHash = "f1114ac0d88a47daa8f28573cf539496c69720e4bf4ff42b60b8d8f6902b30ce"; + com._37coins.bcJsonRpc.pojo.Transaction tx = client.gettransaction(txHash); + log.info("tx " + txHash + ": " + tx.toString()); + } + + @Test + public void testBalance() { + BigDecimal balance = client.getbalance(); + + log.info("balance = " + balance); + + assertTrue(balance.compareTo(BigDecimal.ZERO) >= 0); + } + +} diff --git a/src/test/java/com/_37coins/RoundingTest.java b/src/test/java/com/_37coins/RoundingTest.java index 6c28000..8aa9457 100644 --- a/src/test/java/com/_37coins/RoundingTest.java +++ b/src/test/java/com/_37coins/RoundingTest.java @@ -1,44 +1,44 @@ -package com._37coins; - -import static org.junit.Assert.assertEquals; - -import java.math.BigDecimal; -import java.math.RoundingMode; - -import org.junit.Test; - -public class RoundingTest { - - @Test - public void testRoundBitcoinDown() { - BigDecimal dividend = new BigDecimal("1"); - BigDecimal divisor = new BigDecimal("3"); - BigDecimal quotient = dividend.divide(divisor, 8, RoundingMode.HALF_UP); - assertEquals(quotient.compareTo(new BigDecimal("0.33333333")), 0); - } - - @Test - public void testRoundBitcoinUp() { - BigDecimal dividend = new BigDecimal("2"); - BigDecimal divisor = new BigDecimal("3"); - BigDecimal quotient = dividend.divide(divisor, 8, RoundingMode.HALF_UP); - assertEquals(quotient.compareTo(new BigDecimal("0.66666667")), 0); - } - - @Test - public void testRoundFiatDown() { - BigDecimal dividend = new BigDecimal("1"); - BigDecimal divisor = new BigDecimal("3"); - BigDecimal quotient = dividend.divide(divisor, 2, RoundingMode.HALF_UP); - assertEquals(quotient.compareTo(new BigDecimal("0.33")), 0); - } - - @Test - public void testRoundFiatUp() { - BigDecimal dividend = new BigDecimal("2"); - BigDecimal divisor = new BigDecimal("3"); - BigDecimal quotient = dividend.divide(divisor, 2, RoundingMode.HALF_UP); - assertEquals(quotient.compareTo(new BigDecimal("0.67")), 0); - } - -} +package com._37coins; + +import static org.junit.Assert.assertEquals; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +import org.junit.Test; + +public class RoundingTest { + + @Test + public void testRoundBitcoinDown() { + BigDecimal dividend = new BigDecimal("1"); + BigDecimal divisor = new BigDecimal("3"); + BigDecimal quotient = dividend.divide(divisor, 8, RoundingMode.HALF_UP); + assertEquals(quotient.compareTo(new BigDecimal("0.33333333")), 0); + } + + @Test + public void testRoundBitcoinUp() { + BigDecimal dividend = new BigDecimal("2"); + BigDecimal divisor = new BigDecimal("3"); + BigDecimal quotient = dividend.divide(divisor, 8, RoundingMode.HALF_UP); + assertEquals(quotient.compareTo(new BigDecimal("0.66666667")), 0); + } + + @Test + public void testRoundFiatDown() { + BigDecimal dividend = new BigDecimal("1"); + BigDecimal divisor = new BigDecimal("3"); + BigDecimal quotient = dividend.divide(divisor, 2, RoundingMode.HALF_UP); + assertEquals(quotient.compareTo(new BigDecimal("0.33")), 0); + } + + @Test + public void testRoundFiatUp() { + BigDecimal dividend = new BigDecimal("2"); + BigDecimal divisor = new BigDecimal("3"); + BigDecimal quotient = dividend.divide(divisor, 2, RoundingMode.HALF_UP); + assertEquals(quotient.compareTo(new BigDecimal("0.67")), 0); + } + +}