From b0411393f5f7f32fdec1176ce7b3f4489d48ed54 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Thu, 13 Nov 2014 12:37:19 +0100 Subject: [PATCH] Polish FeePolicy - Convert static fields to final instance fields - Remove commented code - Rethrow any AddressFormatException as a BitsquareException instead of logging and returning null (doing so would cause NPEs in BitcoinJ internals). --- src/main/java/io/bitsquare/btc/FeePolicy.java | 42 ++++++------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/src/main/java/io/bitsquare/btc/FeePolicy.java b/src/main/java/io/bitsquare/btc/FeePolicy.java index 183be85354..2d96c19b75 100644 --- a/src/main/java/io/bitsquare/btc/FeePolicy.java +++ b/src/main/java/io/bitsquare/btc/FeePolicy.java @@ -17,6 +17,8 @@ package io.bitsquare.btc; +import io.bitsquare.BitsquareException; + import org.bitcoinj.core.Address; import org.bitcoinj.core.AddressFormatException; import org.bitcoinj.core.Coin; @@ -28,27 +30,21 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class FeePolicy { + public static final Coin TX_FEE = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE; - // The min. REGISTRATION_FEE calculated with Transaction.MIN_NONDUST_OUTPUT would be 0.00015460 which might lead - // to problems for the spending wallet. + // The min. REGISTRATION_FEE calculated with Transaction.MIN_NONDUST_OUTPUT would be + // 0.00015460 which might lead to problems for the spending wallet. // Some web wallets don't allow more then 4 decimal places (need more investigation) // So we use 0.0002 as that fits also to our 4 decimal places restriction for BTC values. // The remaining 0.0000454 BTC is given to miners at the moment as it is lower then dust. public static final Coin REGISTRATION_FEE = TX_FEE.add(TX_FEE); - public static final Coin CREATE_OFFER_FEE = REGISTRATION_FEE; // 0.0002 public static final Coin TAKE_OFFER_FEE = CREATE_OFFER_FEE; - private static final Logger log = LoggerFactory.getLogger(FeePolicy.class); - - // those are just dummy yet. trading fees will go probably to arbiters - // Not used at the moment - // private static final String registrationFeeAddress = "mvkDXt4QmN4Nq9dRUsRigBCaovde9nLkZR"; - - private static String createOfferFeeAddress; - private static String takeOfferFeeAddress; private final BitcoinNetwork bitcoinNetwork; + private final String createOfferFeeAddress; + private final String takeOfferFeeAddress; @Inject public FeePolicy(BitcoinNetwork bitcoinNetwork) { @@ -68,28 +64,17 @@ public class FeePolicy { createOfferFeeAddress = "n2upbsaKAe4PD3cc4JfS7UCqPC5oNd7Ckg"; takeOfferFeeAddress = "n2upbsaKAe4PD3cc4JfS7UCqPC5oNd7Ckg"; break; + default: + throw new BitsquareException("Unknown bitcoin network: %s", bitcoinNetwork); } } - //TODO who is receiver? other users or dev address? use donation option list? - // Not used at the moment - // (dev, other users, wikileaks, tor, sub projects (bitcoinj, tomp2p,...)...) - /* public Address getAddressForRegistrationFee() { - try { - return new Address(params, registrationFeeAddress); - } catch (AddressFormatException e) { - e.printStackTrace(); - return null; - } - }*/ - //TODO get address form arbitrator list public Address getAddressForCreateOfferFee() { try { return new Address(bitcoinNetwork.getParameters(), createOfferFeeAddress); - } catch (AddressFormatException e) { - e.printStackTrace(); - return null; + } catch (AddressFormatException ex) { + throw new BitsquareException(ex); } } @@ -97,9 +82,8 @@ public class FeePolicy { public Address getAddressForTakeOfferFee() { try { return new Address(bitcoinNetwork.getParameters(), takeOfferFeeAddress); - } catch (AddressFormatException e) { - e.printStackTrace(); - return null; + } catch (AddressFormatException ex) { + throw new BitsquareException(ex); } } }