From 4c727fa799314ae735350878d8aa0f8bf2618088 Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Fri, 16 Dec 2016 18:49:55 +0100
Subject: [PATCH] =?UTF-8?q?-=20Fix=20sending=20a=20TX=20with=20amount=20li?=
 =?UTF-8?q?ke=2017800100=20(les=20z=C3=A9ro=20du=20millieu=20posait=20prob?=
 =?UTF-8?q?l=C3=A8me)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../client/service/bma/TransactionRemoteServiceImpl.java | 9 ++++++++-
 .../src/test/es-home/config/elasticsearch.yml            | 8 ++++----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/duniter4j-core-client/src/main/java/org/duniter/core/client/service/bma/TransactionRemoteServiceImpl.java b/duniter4j-core-client/src/main/java/org/duniter/core/client/service/bma/TransactionRemoteServiceImpl.java
index 5125270f..053f37ef 100644
--- a/duniter4j-core-client/src/main/java/org/duniter/core/client/service/bma/TransactionRemoteServiceImpl.java
+++ b/duniter4j-core-client/src/main/java/org/duniter/core/client/service/bma/TransactionRemoteServiceImpl.java
@@ -385,7 +385,7 @@ public class TransactionRemoteServiceImpl extends BaseRemoteServiceImpl implemen
 
 		// Avoid to get outputs on lower base
 		if (amountBase < inputs.minBase && !isBase(amount, inputs.minBase)) {
-			amount = truncBase(amount, inputs.minBase);
+			amount = truncBaseOrMinBase(amount, inputs.minBase);
 			log.debug("TX Amount has been truncate to " + amount);
 		}
 		else if (amountBase > 0) {
@@ -427,11 +427,18 @@ public class TransactionRemoteServiceImpl extends BaseRemoteServiceImpl implemen
 	}
 
 	private long truncBase(long amount, int base) {
+		long pow = (long)Math.pow(10, base);
+		if (amount < pow) return 0;
+		return (long)(Math.floor(amount / pow ) * pow);
+	}
+
+	private long truncBaseOrMinBase(long amount, int base) {
 		long pow = (long)Math.pow(10, base);
 		if (amount < pow) return pow;
 		return (long)(Math.floor(amount / pow ) * pow);
 	}
 
+
 	private long powBase(long amount, int base) {
 		if (base <= 0) return amount;
 		return (long) (amount * Math.pow(10, base));
diff --git a/duniter4j-es-assembly/src/test/es-home/config/elasticsearch.yml b/duniter4j-es-assembly/src/test/es-home/config/elasticsearch.yml
index bc8c9dae..4fd157ad 100644
--- a/duniter4j-es-assembly/src/test/es-home/config/elasticsearch.yml
+++ b/duniter4j-es-assembly/src/test/es-home/config/elasticsearch.yml
@@ -139,7 +139,7 @@ duniter.keyring.password: def
 
 # Enable security, to disable HTTP access to the default ES admin API
 #
-duniter.security.enable: false
+duniter.security.enable: true
 #
 # Security token prefix (default: 'duniter-')
 #
@@ -153,9 +153,9 @@ duniter.security.enable: false
 #
 # Should synchronize data using P2P
 #
-duniter.data.sync.enable: false
-#duniter.data.sync.host: data.duniter.fr
-#duniter.data.sync.port: 80
+duniter.data.sync.enable: true
+duniter.data.sync.host: data.duniter.fr
+duniter.data.sync.port: 80
 
 # ---------------------------------- Duniter4j SMTP server -------------------------
 #
-- 
GitLab