diff --git a/README.md b/README.md index e6bcb63..e24059d 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ In yout app module, add the following dependency: ```Groovy dependencies { - compile 'com.github.kenCode-de:graphenej:0.4.1' + compile 'com.github.bilthon:graphenej:0.4.2' } ``` diff --git a/build.gradle b/build.gradle index 18d4faf..676dacc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,3 @@ -allprojects { - task hello << { task -> println "I'm $task.project.name" } -} - subprojects { repositories { mavenCentral() diff --git a/gradle.properties b/gradle.properties index 2dc6a3e..1c0fbdd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,17 +17,17 @@ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -VERSION_NAME=0.4.1-SNAPSHOT -VERSION_CODE=3 -GROUP=com.github.kenCode-de +VERSION_NAME=0.4.2-SNAPSHOT +VERSION_CODE=4 +GROUP=com.github.bilthon POM_DESCRIPTION=A Java library for mobile app Developers; Graphene/Bitshares blockchain. -POM_URL=https://github.com/kenCode-de/graphenej -POM_SCM_URL=https://github.com/kenCode-de/graphenej -POM_SCM_CONNECTION=scm:git@github.com:kenCode-de/graphenej.git -POM_SCM_DEV_CONNECTION=scm:git@github.com:kenCode-de/graphenej.git +POM_URL=https://github.com/bilthon/graphenej +POM_SCM_URL=https://github.com/bilthon/graphenej +POM_SCM_CONNECTION=scm:git@github.com:bilthon/graphenej.git +POM_SCM_DEV_CONNECTION=scm:git@github.com:bilthon/graphenej.git POM_LICENCE_NAME=MIT License -POM_LICENCE_URL=https://github.com/kenCode-de/graphenej/blob/master/LICENSE +POM_LICENCE_URL=https://github.com/bilthon/graphenej/blob/master/LICENSE POM_LICENCE_DIST=repo POM_DEVELOPER_ID=bilthon POM_DEVELOPER_NAME=bilthon \ No newline at end of file diff --git a/graphenej/build.gradle b/graphenej/build.gradle index e194d62..e4badbf 100644 --- a/graphenej/build.gradle +++ b/graphenej/build.gradle @@ -1,5 +1,5 @@ group 'de.bitsharesmunich' -version '0.4.0-SNAPSHOT' +version '0.4.2-SNAPSHOT' apply plugin: 'com.android.library' apply from: 'maven-push.gradle' @@ -21,8 +21,8 @@ android { defaultConfig { minSdkVersion 3 targetSdkVersion 24 - versionCode 3 - versionName "0.4.1" + versionCode 4 + versionName "0.4.2" vectorDrawables.useSupportLibrary = true } diff --git a/graphenej/src/main/AndroidManifest.xml b/graphenej/src/main/AndroidManifest.xml index ee81480..441efd0 100644 --- a/graphenej/src/main/AndroidManifest.xml +++ b/graphenej/src/main/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="3" + android:versionName="0.4.2" > diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Authority.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/Authority.java index 2224225..3bd4dc2 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/Authority.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/Authority.java @@ -59,6 +59,14 @@ public class Authority implements GrapheneSerializable { this.account_auths = new HashMap<>(); } + public long getWeightThreshold() { + return weight_threshold; + } + + public void setWeightThreshold(long weight_threshold) { + this.weight_threshold = weight_threshold; + } + public void setKeyAuthorities(HashMap keyAuths){ if(keyAuths != null){ for(Address address : keyAuths.keySet()){ diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/FileBin.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/FileBin.java index ab2023b..703102f 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/FileBin.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/FileBin.java @@ -4,7 +4,8 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import de.bitsharesmunich.graphenej.crypto.SecureRandomStrengthener; + +import org.bitcoinj.core.ECKey; import java.io.UnsupportedEncodingException; import java.math.BigInteger; @@ -12,8 +13,8 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; +import de.bitsharesmunich.graphenej.crypto.SecureRandomStrengthener; import de.bitsharesmunich.graphenej.models.backup.WalletBackup; -import org.bitcoinj.core.ECKey; /** * Class to manage the backup files @@ -89,9 +90,9 @@ public abstract class FileBin { secureRandom.nextBytes(randomKey); ECKey randomECKey = ECKey.fromPrivate(md.digest(randomKey)); byte[] randPubKey = randomECKey.getPubKey(); - byte[] finalKey = randomECKey.getPubKeyPoint().multiply(ECKey.fromPrivate(md.digest(password.getBytes("UTF-8"))).getPrivKey()).normalize().getXCoord().getEncoded(); + byte[] sharedSecret = randomECKey.getPubKeyPoint().multiply(ECKey.fromPrivate(md.digest(password.getBytes("UTF-8"))).getPrivKey()).normalize().getXCoord().getEncoded(); MessageDigest md1 = MessageDigest.getInstance("SHA-512"); - finalKey = md1.digest(finalKey); + byte[] finalKey = md1.digest(sharedSecret); checksummed = Util.encryptAES(checksummed, Util.byteToString(finalKey).getBytes()); byte[] finalPayload = new byte[checksummed.length + randPubKey.length]; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java index 88f20a4..aaee8b5 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java @@ -1,5 +1,7 @@ package de.bitsharesmunich.graphenej; +import com.google.gson.annotations.Expose; + /** *

* Generic class used to represent a graphene object as defined in @@ -13,7 +15,9 @@ public class GrapheneObject { public static final int PROTOCOL_SPACE = 1; public static final int IMPLEMENTATION_SPACE = 2; + @Expose protected String id; + protected int space; protected int type; protected long instance; diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/PublicKey.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/PublicKey.java index b331c3d..5b9e7eb 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/PublicKey.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/PublicKey.java @@ -1,13 +1,16 @@ package de.bitsharesmunich.graphenej; -import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; import org.bitcoinj.core.ECKey; import org.spongycastle.math.ec.ECPoint; +import java.io.Serializable; + +import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; + /** * Created by nelson on 11/30/16. */ -public class PublicKey implements ByteSerializable { +public class PublicKey implements ByteSerializable, Serializable { private ECKey publicKey; public PublicKey(ECKey key) { diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/UserAccount.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/UserAccount.java index 49b66b0..4ad4b12 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/UserAccount.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/UserAccount.java @@ -1,11 +1,14 @@ package de.bitsharesmunich.graphenej; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; +import com.google.gson.annotations.Expose; import java.io.ByteArrayOutputStream; import java.io.DataOutput; @@ -20,8 +23,7 @@ import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; /** - * Class tha represents a graphene user account. - * Created by nelson on 11/8/16. + * Class that represents a graphene user account. */ public class UserAccount extends GrapheneObject implements ByteSerializable, JsonSerializable { @@ -46,19 +48,43 @@ public class UserAccount extends GrapheneObject implements ByteSerializable, Jso public static final String KEY_ACTIVE_SPECIAL_AUTHORITY = "active_special_authority"; public static final String KEY_N_CONTROL_FLAGS = "top_n_control_flags"; - private long membershipExpirationDate; - private String registrar; - private String referrer; - private String lifetimeReferrer; - private long networkFeePercentage; - private long lifetimeReferrerFeePercentage; - private long referrerRewardsPercentage; + @Expose private String name; + + @Expose private Authority owner; + + @Expose private Authority active; + + @Expose private AccountOptions options; + + @Expose private String statistics; + @Expose + private long membershipExpirationDate; + + @Expose + private String registrar; + + @Expose + private String referrer; + + @Expose + private String lifetimeReferrer; + + @Expose + private long networkFeePercentage; + + @Expose + private long lifetimeReferrerFeePercentage; + + @Expose + private long referrerRewardsPercentage; + + /** * Constructor that expects a user account in the string representation. @@ -120,7 +146,8 @@ public class UserAccount extends GrapheneObject implements ByteSerializable, Jso @Override public String toJsonString() { - return this.getObjectId(); + Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); + return gson.toJson(this); } @Override diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/UserAccountTest.java b/graphenej/src/test/java/de/bitsharesmunich/graphenej/UserAccountTest.java new file mode 100644 index 0000000..644c6f6 --- /dev/null +++ b/graphenej/src/test/java/de/bitsharesmunich/graphenej/UserAccountTest.java @@ -0,0 +1,60 @@ +package de.bitsharesmunich.graphenej; + +import com.neovisionaries.ws.client.WebSocketException; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import de.bitsharesmunich.graphenej.api.BaseApiTest; +import de.bitsharesmunich.graphenej.api.GetObjects; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.BaseResponse; +import de.bitsharesmunich.graphenej.models.WitnessResponse; + +/** + * Created by nelson on 5/20/17. + */ +public class UserAccountTest extends BaseApiTest { + private final UserAccount bilthon_25 = new UserAccount("1.2.151069"); + + @Test + public void testToJsonString() { + try{ + ArrayList ids = new ArrayList<>(); + ids.add(bilthon_25.getObjectId()); + mWebSocket.addListener(new GetObjects(ids, new WitnessResponseListener() { + + @Override + public void onSuccess(WitnessResponse response) { + System.out.println("onSuccess"); + List result = (List) response.result; + UserAccount userAccount = (UserAccount) result.get(0); + System.out.println("user account: "+userAccount.toJsonString()); + + synchronized (UserAccountTest.this){ + UserAccountTest.this.notifyAll(); + } + } + + @Override + public void onError(BaseResponse.Error error) { + System.out.println("onError"); + synchronized (UserAccountTest.this){ + UserAccountTest.this.notifyAll(); + } + } + })); + + mWebSocket.connect(); + synchronized (this){ + wait(); + } + }catch (WebSocketException e) { + System.out.println("WebSocketException. Msg: " + e.getMessage()); + } catch (InterruptedException e) { + System.out.println("InterruptedException. Msg: "+e.getMessage()); + } + } +} \ No newline at end of file