Fixing bug with 'AccountUpdateOperation'

This commit is contained in:
Nelson R. Perez 2016-12-16 15:12:57 -05:00
parent 47fa879ab0
commit 886b5c09ec
4 changed files with 24 additions and 17 deletions

View file

@ -78,9 +78,12 @@ public class AccountUpdateOperation extends BaseOperation {
JsonObject accountUpdate = new JsonObject(); JsonObject accountUpdate = new JsonObject();
accountUpdate.add(KEY_FEE, fee.toJsonObject()); accountUpdate.add(KEY_FEE, fee.toJsonObject());
accountUpdate.addProperty(KEY_ACCOUNT, account.toJsonString()); accountUpdate.addProperty(KEY_ACCOUNT, account.toJsonString());
accountUpdate.add(KEY_OWNER, owner.toJsonObject()); if(owner.isSet())
accountUpdate.add(KEY_ACTIVE, active.toJsonObject()); accountUpdate.add(KEY_OWNER, owner.toJsonObject());
accountUpdate.add(KEY_NEW_OPTIONS, new_options.toJsonObject()); if(active.isSet())
accountUpdate.add(KEY_ACTIVE, active.toJsonObject());
if(new_options.isSet())
accountUpdate.add(KEY_NEW_OPTIONS, new_options.toJsonObject());
accountUpdate.add(KEY_EXTENSIONS, extensions.toJsonObject()); accountUpdate.add(KEY_EXTENSIONS, extensions.toJsonObject());
array.add(accountUpdate); array.add(accountUpdate);
return array; return array;

View file

@ -51,13 +51,13 @@ public class Main {
// test.testRandomNumberGeneration(); // test.testRandomNumberGeneration();
// test.testBrainKeyOperations(false); // test.testBrainKeyOperations(false);
// test.testBip39Opertion(); // test.testBip39Opertion();
test.testAccountNamebyAddress(); // test.testAccountNamebyAddress();
// test.testAccountNameById(); // test.testAccountNameById();
// test.testRelativeAccountHistory(); // test.testRelativeAccountHistory();
// test.testingInvoiceGeneration(); // test.testingInvoiceGeneration();
// test.testCompression(); // test.testCompression();
// test.testAccountUpdateSerialization(); // test.testAccountUpdateSerialization();
// test.testAccountUpdateOperationBroadcast(); test.testAccountUpdateOperationBroadcast();
// test.testCreateBinFile(); // test.testCreateBinFile();
// test.testImportBinFile(); // test.testImportBinFile();
// test.testLookupAccounts(); // test.testLookupAccounts();

View file

@ -21,6 +21,10 @@ public class Optional<T extends GrapheneSerializable> implements GrapheneSeriali
return optionalField.toBytes(); return optionalField.toBytes();
} }
public boolean isSet(){
return this.optionalField != null;
}
@Override @Override
public String toJsonString() { public String toJsonString() {
return optionalField.toJsonString(); return optionalField.toJsonString();

View file

@ -460,7 +460,7 @@ public class Test {
String suggestion = BrainKey.suggest(words); String suggestion = BrainKey.suggest(words);
brainKey = new BrainKey(suggestion, 0); brainKey = new BrainKey(suggestion, 0);
} else { } else {
System.out.println("Using brain key: " + Main.BILTHON_5_BRAIN_KEY); System.out.println("Using brain key: " + Main.BILTHON_83_BRAIN_KEY);
brainKey = new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0); brainKey = new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0);
} }
ECKey key = brainKey.getPrivateKey(); ECKey key = brainKey.getPrivateKey();
@ -515,9 +515,9 @@ public class Test {
}; };
BrainKey brainKey = new BrainKey(Main.BILTHON_83_ORIGINAL_BRAIN_KEY, 0); BrainKey brainKey = new BrainKey(Main.BILTHON_83_ORIGINAL_BRAIN_KEY, 0);
Address address = new Address(ECKey.fromPublicOnly(brainKey.getPrivateKey().getPubKey())); // Address address = new Address(ECKey.fromPublicOnly(brainKey.getPrivateKey().getPubKey()));
try { try {
// Address address = new Address("BTS5BgjNRDeawGSc1NPk91p2BYYEhJWKgsjLZGDmFgY6uwhAYLy9G"); Address address = new Address("BTS5BgjNRDeawGSc1NPk91p2BYYEhJWKgsjLZGDmFgY6uwhAYLy9G");
// Create a custom SSL context. // Create a custom SSL context.
SSLContext context = null; SSLContext context = null;
@ -537,9 +537,9 @@ public class Test {
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
System.out.println("NoSuchAlgorithmException. Msg: " + e.getMessage()); System.out.println("NoSuchAlgorithmException. Msg: " + e.getMessage());
} }
// catch (MalformedAddressException e) { catch (MalformedAddressException e) {
// System.out.println("MalformedAddressException. Msg: "+e.getMessage()); System.out.println("MalformedAddressException. Msg: "+e.getMessage());
// } }
} }
public void testAccountNameById() { public void testAccountNameById() {
@ -642,10 +642,10 @@ public class Test {
authMap.put(address.getPublicKey(), 1); authMap.put(address.getPublicKey(), 1);
Authority authority = new Authority(1, authMap, null); Authority authority = new Authority(1, authMap, null);
AccountOptions options = new AccountOptions(address.getPublicKey()); AccountOptions options = new AccountOptions(address.getPublicKey());
BrainKey brainKey = new BrainKey(Main.BILTHON_7_BRAIN_KEY, 0); BrainKey brainKey = new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0);
Transaction transaction = new AccountUpdateTransactionBuilder(brainKey.getPrivateKey()) Transaction transaction = new AccountUpdateTransactionBuilder(brainKey.getPrivateKey())
.setAccont(new UserAccount("1.2.140994")) .setAccont(new UserAccount("1.2.140994"))
.setOwner(authority) // .setOwner(authority)
.setActive(authority) .setActive(authority)
.setOptions(options) .setOptions(options)
.setBlockData(new BlockData(Main.REF_BLOCK_NUM, Main.REF_BLOCK_PREFIX, Main.RELATIVE_EXPIRATION)) .setBlockData(new BlockData(Main.REF_BLOCK_NUM, Main.REF_BLOCK_PREFIX, Main.RELATIVE_EXPIRATION))
@ -676,17 +676,17 @@ public class Test {
} }
}; };
String newAddress = "BTS8RiFgs8HkcVPVobHLKEv6yL3iXcC9SWjbPVS15dDAXLG9GYhnY"; String newAddress = "BTS5EHEfnQ4CgvTzNqE5TwWUGSLg3urcLVXrvQ2W7apxEqjczk4Ev";
try { try {
Address address = new Address(newAddress); Address address = new Address(newAddress);
HashMap<PublicKey, Integer> authMap = new HashMap<>(); HashMap<PublicKey, Integer> authMap = new HashMap<>();
authMap.put(address.getPublicKey(), 1); authMap.put(address.getPublicKey(), 1);
Authority authority = new Authority(1, authMap, null); Authority authority = new Authority(1, authMap, null);
AccountOptions options = new AccountOptions(address.getPublicKey()); AccountOptions options = new AccountOptions(address.getPublicKey());
BrainKey brainKey = new BrainKey(Main.BILTHON_1_BRAIN_KEY, 0); BrainKey brainKey = new BrainKey(Main.BILTHON_83_ORIGINAL_BRAIN_KEY, 0);
Transaction transaction = new AccountUpdateTransactionBuilder(brainKey.getPrivateKey()) Transaction transaction = new AccountUpdateTransactionBuilder(brainKey.getPrivateKey())
.setAccont(new UserAccount("1.2.139205")) .setAccont(new UserAccount("1.2.138632"))
.setOwner(authority) // .setOwner(authority)
.setActive(authority) .setActive(authority)
.setOptions(options) .setOptions(options)
.build(); .build();