From 8027ea7e0420aca15854bc3e8b3886b1f31261e5 Mon Sep 17 00:00:00 2001 From: The rise of Agorism! Date: Sat, 30 Sep 2017 15:27:23 +0300 Subject: [PATCH 1/5] Update LICENSE --- LICENSE | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 5da4c2b..291d816 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License -Copyright (c) 2017 BitShares Munich IVS +Copyright (c) August 11, 2017 to Present - Agorise +Copyright (c) February 09, 2016 to August 11, 2017 - BitShares Munich IVS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From a8510c5e809dd852f3c8ee91573841ed426e711c Mon Sep 17 00:00:00 2001 From: The rise of Agorism! Date: Sat, 30 Sep 2017 19:36:15 +0300 Subject: [PATCH 2/5] Update LICENSE --- LICENSE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 291d816..e997726 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ MIT License -Copyright (c) August 11, 2017 to Present - Agorise -Copyright (c) February 09, 2016 to August 11, 2017 - BitShares Munich IVS +Copyright (c) 2017-2018 Agorise +Copyright (c) 2016-2017 BitShares Munich IVS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From ac52d9b5922d7af14380dd2c4d1aa550b7b4a3eb Mon Sep 17 00:00:00 2001 From: Agorise Date: Mon, 16 Oct 2017 13:44:35 +0300 Subject: [PATCH 3/5] Update LICENSE --- LICENSE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index e997726..ee2accb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ MIT License -Copyright (c) 2017-2018 Agorise -Copyright (c) 2016-2017 BitShares Munich IVS +Copyright (c) 2017 Agorise, IBC. +Contains works from BitShares Munich IVS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From cb24964b0b54f6e704d3d511de03b7d4782dccb3 Mon Sep 17 00:00:00 2001 From: Agorise Date: Wed, 15 Nov 2017 13:10:02 +0200 Subject: [PATCH 4/5] Update LICENSE --- LICENSE | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index ee2accb..b6a8537 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,8 @@ MIT License -Copyright (c) 2017 Agorise, IBC. +Copyright (c) 2017 AGORISE, LTD. +An International Business Company, Cyprus Reg# ΗΕ375959 + Contains works from BitShares Munich IVS Permission is hereby granted, free of charge, to any person obtaining a copy From 4e674117732d2cd4070c48cf6d6593bdaa74d251 Mon Sep 17 00:00:00 2001 From: hvarona Date: Sun, 20 May 2018 11:45:11 -0400 Subject: [PATCH 5/5] implement Account Upgrade Operation --- .../operations/AccountUpgradeOperation.java | 145 ++++++++++++++++++ .../AccountUpgradeOperationBuilder.java | 46 ++++++ 2 files changed, 191 insertions(+) create mode 100644 graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpgradeOperation.java create mode 100644 graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpgradeOperationBuilder.java diff --git a/graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpgradeOperation.java b/graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpgradeOperation.java new file mode 100644 index 0000000..d2681e4 --- /dev/null +++ b/graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpgradeOperation.java @@ -0,0 +1,145 @@ +package cy.agorise.graphenej.operations; + +import com.google.common.primitives.Bytes; +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.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.BaseOperation; +import cy.agorise.graphenej.OperationType; +import cy.agorise.graphenej.UserAccount; + +/** + * Created by henry on 19/5/2018. + */ + +public class AccountUpgradeOperation extends BaseOperation { + + private static final String KEY_ACCOUNT = "account_to_upgrade"; + private static final String KEY_UPGRADE = "upgrade_to_lifetime_member"; + + private AssetAmount fee; + private UserAccount accountToUpgrade; + private boolean upgradeToLifeTimeMember; + + public AccountUpgradeOperation(UserAccount accountToUpgrade, boolean upgradeToLifeTimeMember) { + super(OperationType.ACCOUNT_UPGRADE_OPERATION); + this.accountToUpgrade = accountToUpgrade; + this.upgradeToLifeTimeMember = upgradeToLifeTimeMember; + } + + public AccountUpgradeOperation(UserAccount accountToUpgrade, boolean upgradeToLifeTimeMember, AssetAmount fee) { + super(OperationType.ACCOUNT_UPGRADE_OPERATION); + this.accountToUpgrade = accountToUpgrade; + this.upgradeToLifeTimeMember = upgradeToLifeTimeMember; + this.fee = fee; + } + + public AssetAmount getFee() { + return fee; + } + + public UserAccount getAccountToUpgrade() { + return accountToUpgrade; + } + + public void setAccountToUpgrade(UserAccount accountToUpgrade) { + this.accountToUpgrade = accountToUpgrade; + } + + public boolean isUpgradeToLifeTimeMember() { + return upgradeToLifeTimeMember; + } + + public void setUpgradeToLifeTimeMember(boolean upgradeToLifeTimeMember) { + this.upgradeToLifeTimeMember = upgradeToLifeTimeMember; + } + + @Override + public void setFee(AssetAmount assetAmount) { + this.fee = assetAmount; + } + + @Override + public byte[] toBytes() { + byte[] feeBytes = fee.toBytes(); + byte[] accountBytes = accountToUpgrade.toBytes(); + byte[] upgradeToLifeTimeMemberBytes = this.upgradeToLifeTimeMember ? new byte[]{ 0x1 } : new byte[]{ 0x0 }; + byte[] extensions = this.extensions.toBytes(); + return Bytes.concat(feeBytes, accountBytes, upgradeToLifeTimeMemberBytes, extensions); + } + + @Override + public String toJsonString() { + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.registerTypeAdapter(AccountUpgradeOperation.class, new AccountUpgradeSerializer()); + return gsonBuilder.create().toJson(this); + } + + @Override + public JsonElement toJsonObject() { + JsonArray array = new JsonArray(); + array.add(this.getId()); + JsonObject jsonObject = new JsonObject(); + if(fee != null) + jsonObject.add(KEY_FEE, fee.toJsonObject()); + jsonObject.addProperty(KEY_ACCOUNT, accountToUpgrade.getObjectId()); + jsonObject.addProperty(KEY_UPGRADE, this.upgradeToLifeTimeMember ? "true" : "false"); + jsonObject.add(KEY_EXTENSIONS, new JsonArray()); + array.add(jsonObject); + return array; + } + + public static class AccountUpgradeSerializer implements JsonSerializer { + + @Override + public JsonElement serialize(AccountUpgradeOperation accountUpgrade, Type type, JsonSerializationContext jsonSerializationContext) { + return accountUpgrade.toJsonObject(); + } + } + + + public static class AccountUpgradeDeserializer implements JsonDeserializer { + + @Override + public AccountUpgradeOperation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + if(json.isJsonArray()){ + // This block is used just to check if we are in the first step of the deserialization + // when we are dealing with an array. + JsonArray serializedAccountUpgrade = json.getAsJsonArray(); + if(serializedAccountUpgrade.get(0).getAsInt() != OperationType.ACCOUNT_UPGRADE_OPERATION.ordinal()){ + // If the operation type does not correspond to a transfer operation, we return null + return null; + }else{ + // Calling itself recursively, this is only done once, so there will be no problems. + return context.deserialize(serializedAccountUpgrade.get(1), AccountUpgradeOperation.class); + } + }else{ + JsonObject jsonObject = json.getAsJsonObject(); + + // Deserializing AssetAmount objects + AssetAmount fee = context.deserialize(jsonObject.get(KEY_FEE), AssetAmount.class); + + // Deserializing UserAccount objects + UserAccount accountToUpgrade = new UserAccount(jsonObject.get(KEY_ACCOUNT).getAsString()); + + boolean upgradeToLifeTime = jsonObject.get(KEY_UPGRADE).getAsBoolean(); + AccountUpgradeOperation upgrade = new AccountUpgradeOperation(accountToUpgrade, upgradeToLifeTime, fee); + + return upgrade; + } + } + } + + +} + diff --git a/graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpgradeOperationBuilder.java b/graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpgradeOperationBuilder.java new file mode 100644 index 0000000..d65c3aa --- /dev/null +++ b/graphenej/src/main/java/cy/agorise/graphenej/operations/AccountUpgradeOperationBuilder.java @@ -0,0 +1,46 @@ +package cy.agorise.graphenej.operations; + +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.errors.MalformedOperationException; + +/** + * Created by henry on 19/5/2018. + */ + +public class AccountUpgradeOperationBuilder extends BaseOperationBuilder { + + private UserAccount accountToUpgrade; + private AssetAmount fee; + private boolean isUpgrade = true; + + public AccountUpgradeOperationBuilder setAccountToUpgrade(UserAccount accountToUpgrade) { + this.accountToUpgrade = accountToUpgrade; + return this; + } + + public AccountUpgradeOperationBuilder setFee(AssetAmount fee) { + this.fee = fee; + return this; + } + + public AccountUpgradeOperationBuilder setIsUpgrade(Boolean isUpgrade) { + this.isUpgrade = isUpgrade; + return this; + } + + @Override + public AccountUpgradeOperation build(){ + AccountUpgradeOperation accountUpgrade; + if(accountToUpgrade == null ){ + throw new MalformedOperationException("Missing account to upgrade information"); + } + + if(fee != null){ + accountUpgrade = new AccountUpgradeOperation(accountToUpgrade, isUpgrade, fee); + }else{ + accountUpgrade = new AccountUpgradeOperation(accountToUpgrade, isUpgrade); + } + return accountUpgrade; + } +}