Commit 75187195 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[enh] Use lombok for beans (getter/setter and builder, and log)

[enh] use a new Converter interface, for compatibility with Spring-data (need by Cesium+ Pod v2)
[enh] Use a new CrudRepository, for compatibility with Spring-data (need by Cesium+ Pod v2)
[enh] Remove DataContext.accountId
[enh] Add DividendService and repository
parent 4f0f86ff
Pipeline #11757 passed with stage
in 27 seconds
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>duniter4j</artifactId>
<groupId>org.duniter</groupId>
......
......@@ -32,7 +32,10 @@ import org.duniter.client.actions.TransactionAction;
import org.apache.commons.io.FileUtils;
import org.duniter.core.client.config.Configuration;
import org.duniter.core.client.config.ConfigurationOption;
import org.duniter.core.client.model.bma.jackson.JacksonUtils;
import org.duniter.core.client.service.DataContext;
import org.duniter.core.client.service.ServiceLocator;
import org.duniter.core.util.Preconditions;
import org.duniter.core.util.StringUtils;
import org.nuiton.i18n.I18n;
import org.nuiton.i18n.init.DefaultI18nInitializer;
......@@ -76,11 +79,11 @@ public class Main {
// Parsing args
JCommander jc = new JCommander(this);
actions.entrySet().forEach(entry -> jc.addCommand(entry.getKey(), entry.getValue()));
actions.forEach(jc::addCommand);
try {
jc.parse(args);
jc.getParameters().stream().forEach(param -> {
jc.getParameters().forEach(param -> {
if (param.getParameter().password()
&& param.getParameter().required()
&& param.getParameter().echoInput()
......@@ -94,7 +97,6 @@ public class Main {
catch(ParameterException e) {
System.err.println(e.getMessage());
System.err.println("Try --help for usage");
//jc.usage();
System.exit(-1);
}
......@@ -122,7 +124,11 @@ public class Main {
}
// Set a default account id, then load cache
ServiceLocator.instance().getDataContext().setAccountId(0);
// TODO: load data context (e.g. from a data file, or from config file)
DataContext context = loadDataContext();
if (context != null) {
ServiceLocator.instance().getDataContext().copy(context);
}
// Initialize service locator
ServiceLocator.instance().init();
......@@ -196,4 +202,22 @@ public class Main {
return configArgs.toArray(new String[configArgs.size()]);
}
protected DataContext loadDataContext() {
File dataDirectory = Configuration.instance().getDataDirectory();
if (!dataDirectory.exists()) return null; // Skip if not exists
Preconditions.checkArgument(dataDirectory.isDirectory(), "Invalid directory: " + dataDirectory.getAbsolutePath());
File dataFile = new File(dataDirectory, "data.json");
if (!dataFile.exists()) return null; // Skip if not exists
Preconditions.checkArgument(dataFile.canRead(), "Cannot read data file: " + dataFile.getAbsolutePath());
try {
return JacksonUtils.getThreadObjectMapper().readValue(dataFile, DataContext.class);
} catch (Exception e) {
System.err.println(String.format("Cannot read data file: %s. Skipping.", dataFile.getAbsolutePath()));
return null;
}
}
}
......@@ -109,11 +109,9 @@ public class NetworkAction extends AbstractAction {
service.addPeersChangeListener(mainPeer, peers -> showPeersTable(peers, true));
try {
while(true) {
Thread.sleep(10000); // 10 s
}
while (true) Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
// end
}
}
......
......@@ -50,6 +50,7 @@ import org.slf4j.LoggerFactory;
import java.util.List;
/**
* Created by blavenie on 22/03/17.
*/
......@@ -127,7 +128,6 @@ public class TransactionAction extends AbstractAction {
null,
keypair.getPubKey(),
keypair.getSecKey());
wallet.setCurrencyId(currency.getId());
// Parse TX parameters
parseTransactionParameters();
......
......@@ -59,12 +59,12 @@ public class PeerParameters {
String host = parts[0];
Integer port = parts.length == 2 ? Integer.parseInt(parts[1]) : null;
Peer.Builder peerBuilder = Peer.newBuilder().setHost(host);
Peer.Builder peerBuilder = Peer.builder().host(host);
if (port != null) {
peerBuilder.setPort(port);
peerBuilder.port(port);
}
if (useSsl){
peerBuilder.setUseSsl(useSsl);
peerBuilder.useSsl(useSsl);
}
peer = peerBuilder.build();
......@@ -72,8 +72,8 @@ public class PeerParameters {
}
else {
Configuration config = Configuration.instance();
peer = Peer.newBuilder().setHost(config.getNodeHost())
.setPort(config.getNodePort())
peer = Peer.builder().host(config.getNodeHost())
.port(config.getNodePort())
.build();
log.info(I18n.t("duniter4j.client.info.peer.fallback", peer.getHost(), peer.getPort()));
}
......
......@@ -2,12 +2,12 @@ org.duniter.core.client.service.bma.BlockchainRemoteServiceImpl
org.duniter.core.client.service.bma.NetworkRemoteServiceImpl
org.duniter.core.client.service.bma.WotRemoteServiceImpl
org.duniter.core.client.service.bma.TransactionRemoteServiceImpl
org.duniter.core.client.service.elasticsearch.CurrencyRegistryRemoteServiceImpl
org.duniter.core.client.service.elasticsearch.CurrencyPodRemoteServiceImpl
org.duniter.core.service.Ed25519CryptoServiceImpl
org.duniter.core.client.service.HttpServiceImpl
org.duniter.core.client.service.DataContext
org.duniter.core.client.service.local.PeerServiceImpl
org.duniter.core.client.service.local.CurrencyServiceImpl
org.duniter.core.client.service.local.NetworkServiceImpl
org.duniter.core.client.dao.mem.MemoryCurrencyDaoImpl
org.duniter.core.client.dao.mem.MemoryPeerDaoImpl
\ No newline at end of file
org.duniter.core.client.repositories.mem.MemoryCurrencyRepositoryImpl
org.duniter.core.client.repositories.mem.MemoryPeerRepositoryImpl
\ No newline at end of file
duniter4j.client.info.peer=Noeud Duniter {%s\:%s}
duniter4j.client.info.peer.fallback=Noeud Duniter par défaut {%s\:%d}
duniter4j.client.network.action=Afficher les noeuds Duniter
duniter4j.client.network.cesiumPlus=Cs+
duniter4j.client.network.error.outputFieNotWritable=Fichier de sortie non inscriptible
duniter4j.client.network.executionTime=Temps d'execution \: %s ms
duniter4j.client.network.header=Branche principale\: bloc {%1$s} calculé à %2$s (heure UTC) validé par {%3$3.2f%%} des noeuds
duniter4j.client.network.loadingPeers=Lecture des noeuds du réseau... (Délai d'attente \: %s ms)
duniter4j.client.network.mirror=Mirroir
duniter4j.client.network.noPeers=Aucun noeud trouvé
duniter4j.client.network.params.continue=Continue scanning? (Will refresh on new peer/block).
duniter4j.client.network.params.output=Output CSV file
duniter4j.client.network.ssl=SSL
duniter4j.client.params.authScrypt=Authentification par salage Scrypt ?
duniter4j.client.params.authScrypt.ask.passwd=Veuillez entrer votre mot de passe Scrypt (password) \:
duniter4j.client.params.authScrypt.ask.salt=Veuillez entrer votre identifiant secret Scrypt (Salt)\:
duniter4j.client.params.authScrypt.ask.scryptParams=Veuillez entrer les paramètres de Scrypt (N,r,p)\: [%d,%d,%d]
duniter4j.client.params.authScrypt.error.scryptParams=Paramètre Scrypt non valide (3 valeurs attendues - format 'N,r,p')"
duniter4j.client.params.authScrypt.passwd=Mot de passe
duniter4j.client.params.authScrypt.salt=Identifiant secret (salt)
duniter4j.client.params.authScrypt.scryptParams=Paramètre de salage Scrypt (N,r,p)
duniter4j.client.params.config=Fichier de configuration
duniter4j.client.params.debug=Activer les logs de debuggage
duniter4j.client.params.error.invalidOption=Valeur d'option [%s] invalid
duniter4j.client.params.help=Affichage de l'aide
duniter4j.client.params.peer=Noeud Duniter (hôte\:port)
duniter4j.client.params.peer.fallback=
duniter4j.client.params.peer.timeout=Délai de réponse max. d'un noeud, en millisecondes
duniter4j.client.params.peer.useSsl=Utiliser une connection SSL ?
duniter4j.client.transaction.action=Effectuer une transaction
duniter4j.client.transaction.broadcast.failed=Transaction NON envoyée. Aucun noeud n'a accepté la transaction.
duniter4j.client.transaction.broadcast.memberPeerCount=%d noeud membres trouvé, pour l'envoi multiple
duniter4j.client.transaction.broadcast.success=Transaction envoyée avec succès (à %d noeuds de la branche principale de la chaine de blocs)
duniter4j.client.transaction.broadcast.successOnForkOnly=Transaction NON envoyée sur la branche principale, mais seulement sur %d noeud d'une branche secondaire de la cheine de blocs
duniter4j.client.transaction.broadcast.summary=Envoi de la transation\:\n\t- De\: %s\n\t- A\: %s\n\t- Montant\: %s %s
duniter4j.client.transaction.error.broadcast.noMemberPeer=Aucun noeud membre trouvé \! L'option --broadcast va être ignorée
duniter4j.client.transaction.error.unknownAuth=Type d'authentification inconnue
duniter4j.client.transaction.loadingMemberPeers=Récupération des noeuds membres...
duniter4j.client.transaction.params.amount.ask=Veuillez entrer le montant (valeur entière) \:
duniter4j.client.transaction.params.output.ask=Veuillez entrer le destinataire (clef publique) \:
duniter4j.client.transaction.sent=Transaction envoyé avec succès.
......@@ -20,7 +20,7 @@ duniter4j.client.params.authScrypt.passwd=Mot de passe
duniter4j.client.params.authScrypt.salt=Identifiant secret (salt)
duniter4j.client.params.authScrypt.scryptParams=Paramètre de salage Scrypt (N,r,p)
duniter4j.client.params.config=Fichier de configuration
duniter4j.client.params.debug=Activer les logs de débuggage
duniter4j.client.params.debug=Activer les logs de debuggage
duniter4j.client.params.error.invalidOption=Valeur d'option [%s] invalid
duniter4j.client.params.help=Affichage de l'aide
duniter4j.client.params.peer=Noeud Duniter (hôte\:port)
......
lombok.fieldnameconstants.uppercase=true
clear lombok.log.fieldName
lombok.log.fieldName = log
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
......@@ -22,11 +24,18 @@
</properties>
<dependencies>
<!-- Compile -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.duniter</groupId>
<artifactId>duniter4j-core-shared</artifactId>
<version>${project.version}</version>
</dependency>
<!-- LOGGING DEPENDENCIES - SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
......
......@@ -24,6 +24,7 @@ package org.duniter.core.client.config;
import com.google.common.base.Charsets;
import lombok.extern.slf4j.Slf4j;
import org.duniter.core.exception.TechnicalException;
import org.nuiton.config.ApplicationConfig;
import org.nuiton.config.ApplicationConfigHelper;
......@@ -47,9 +48,17 @@ import static org.nuiton.i18n.I18n.t;
* @author Benoit Lavenier <benoit.lavenier@e-is.pro>
* @since 1.0
*/
@Slf4j
public class Configuration {
/** Logger. */
private static final Logger log = LoggerFactory.getLogger(Configuration.class);
protected static String[] args = null;
/**
* <p>remember app args.</p>
*/
public static void setArgs(String[] sourceArgs) {
args = sourceArgs;
}
/**
* Delegate application config.
......
......@@ -36,16 +36,14 @@ public class Example1 {
Configuration config = new Configuration(configFilename, args);
Configuration.setInstance(config);
// Set a wallet id (an identifier required for cache)
ServiceLocator.instance().getDataContext().setAccountId(0);
// Initialize service locator
ServiceLocator.instance().init();
// Create a peer, from configuration
Peer aPeer = Peer.newBuilder()
.setHost(config.getNodeHost())
.setPort(config.getNodePort())
Peer aPeer = Peer.builder()
.host(config.getNodeHost())
.port(config.getNodePort())
.build();
// Do something fun !
......
......@@ -23,12 +23,12 @@ package org.duniter.core.client.model;
*/
import org.duniter.core.client.model.local.LocalEntity;
import org.duniter.core.model.IEntity;
/**
* Created by eis on 07/02/15.
*/
public class Account implements LocalEntity<Long> {
public class Account implements IEntity<Long> {
private Long id;
private String uid;
......
......@@ -24,7 +24,6 @@ package org.duniter.core.client.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.duniter.core.client.model.local.LocalEntity;
import java.io.Serializable;
......@@ -35,7 +34,7 @@ import java.io.Serializable;
* @since 1.0
*
*/
public class BasicIdentity implements Serializable {
public abstract class BaseIdentity implements Serializable {
private static final long serialVersionUID = 8080689271400316984L;
......
package org.duniter.core.client.model;
/*
* #%L
* Duniter4j :: Core API
* %%
* Copyright (C) 2014 - 2015 EIS
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import org.duniter.core.client.model.local.Peer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* Created by eis on 05/02/15.
*/
public class Currency implements Serializable {
private List<Peer> peers = new ArrayList<Peer>();
private Long id;
private String currencyName;
private Integer membersCount;
private String firstBlockSignature;
private Account account;
private Long accountId;
private String[] tags;
private String senderPubkey;
private Long lastUD;
public Currency() {
}
public Currency(String currencyName,
String firstBlockSignature,
int membersCount,
List<Peer> peers) {
this.currencyName = currencyName;
this.firstBlockSignature = firstBlockSignature;
this.membersCount = membersCount;
this.peers = peers;
}
public Currency(String currencyName,
String firstBlockSignature,
List<Peer> peers) {
this.currencyName = currencyName;
this.firstBlockSignature = firstBlockSignature;
this.membersCount = null;
this.peers = peers;
}
public Long getId() {
return id;
}
public String getCurrencyName()
{
return currencyName;
}
public Integer getMembersCount() {
return membersCount;
}
public String getFirstBlockSignature() {
return firstBlockSignature;
}
public List<Peer> getPeers() {
return peers;
}
public void addPeer(Peer peer) {
this.peers.add(peer);
}
public void setPeers(List<Peer> peers) {
this.peers = peers;
}
public void setId(Long id) {
this.id = id;
}
public void setCurrencyName(String currencyName) {
this.currencyName = currencyName;
}
public void setMembersCount(Integer membersCount) {
this.membersCount = membersCount;
}
public void setFirstBlockSignature(String firstBlockSignature) {
this.firstBlockSignature = firstBlockSignature;
}
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
public Long getAccountId() {
return accountId;
}
public void setAccountId(Long accountId) {
this.accountId = accountId;
}
public String toString() {
return currencyName;
}
public String[] getTags() {
return tags;
}
public void setTags(String[] tags) {
this.tags = tags;
}
public String getSenderPubkey() {
return senderPubkey;
}
public void setSenderPubkey(String senderPubkey) {
this.senderPubkey = senderPubkey;
}
}
\ No newline at end of file
......@@ -22,12 +22,11 @@ package org.duniter.core.client.model;
* #L%
*/
import java.util.*;
import org.duniter.core.util.Preconditions;
import org.duniter.core.client.model.local.Certification;
import org.duniter.core.client.model.local.Movement;
import org.duniter.core.util.CollectionUtils;
import org.duniter.core.util.Preconditions;
import java.util.Comparator;
import java.util.Set;
/**
* Helper class on model entities
......
......@@ -28,6 +28,11 @@ import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;
import java.io.Serializable;
import java.math.BigInteger;
......@@ -39,39 +44,13 @@ import java.math.BigInteger;
* @since 1.0
*/
@JsonIgnoreProperties(ignoreUnknown=true)
@Data
@FieldNameConstants
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BlockchainBlock implements Serializable {
public static final String PROPERTY_VERSION = "version";
public static final String PROPERTY_NONCE = "nonce";
public static final String PROPERTY_NUMBER = "number";
public static final String PROPERTY_POW_MIN = "powMin";
public static final String PROPERTY_TIME = "time";
public static final String PROPERTY_MEDIAN_TIME = "medianTime";
public static final String PROPERTY_MEMBERS_COUNT = "membersCount";
public static final String PROPERTY_MONETARY_MASS = "monetaryMass";
public static final String PROPERTY_UNIT_BASE = "unitbase";
public static final String PROPERTY_ISSUERS_COUNT = "issuersCount";
public static final String PROPERTY_ISSUERS_FRAME = "issuersFrame";
public static final String PROPERTY_ISSUERS_FRAME_VAR = "issuersFrameVar";
public static final String PROPERTY_CURRENCY = "currency";
public static final String PROPERTY_ISSUER = "issuer";
public static final String PROPERTY_HASH = "hash";
public static final String PROPERTY_PARAMETERS = "parameters";
public static final String PROPERTY_PREVIOUS_HASH = "previousHash";
public static final String PROPERTY_PREVIOUS_ISSUER = "previousIssuer";
public static final String PROPERTY_INNER_HASH = "innerHash";
public static final String PROPERTY_DIVIDEND = "dividend";
public static final String PROPERTY_IDENTITIES = "identities";
public static final String PROPERTY_JOINERS = "joiners";
public static final String PROPERTY_ACTIVES = "actives";
public static final String PROPERTY_LEAVERS = "leavers";
public static final String PROPERTY_REVOKED = "revoked";
public static final String PROPERTY_EXCLUDED = "excluded";
public static final String PROPERTY_CERTIFICATIONS = "certifications";
public static final String PROPERTY_TRANSACTIONS = "transactions";
public static final String PROPERTY_SIGNATURE = "signature";
private static final long serialVersionUID = -5598140972293452669L;
private Integer version;
......@@ -93,7 +72,7 @@ public class BlockchainBlock implements Serializable {
private String previousHash;
private String previousIssuer;
private String innerHash;
private BigInteger dividend;
private Long dividend;
private Identity[] identities;
private Joiner[] joiners;
private Joiner[] leavers;
......@@ -103,134 +82,8 @@ public class BlockchainBlock implements Serializable {
private Certification[] certifications;
private Transaction[] transactions;
private String signature;
// raw": "Version: 1\nType: Block\nCurrency: zeta_brouzouf\nNonce: 8233\nNumber: 1\nDate: 1416589860\nConfirmedDate: 1416589860\nIssuer: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk\nPreviousHash: 00006CD96A01378465318E48310118AC6B2F3625\nPreviousIssuer: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk\nMembersCount: 4\nIdentities:\nJoiners:\nActives:\nLeavers:\nExcluded:\nCertifications:\nTransactions:\n"
private String raw;
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public Long getNonce() {
return nonce;
}
public void setNonce(Long nonce) {
this.nonce = nonce;