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();
accountUpdate.add(KEY_FEE, fee.toJsonObject());
accountUpdate.addProperty(KEY_ACCOUNT, account.toJsonString());
accountUpdate.add(KEY_OWNER, owner.toJsonObject());
accountUpdate.add(KEY_ACTIVE, active.toJsonObject());
accountUpdate.add(KEY_NEW_OPTIONS, new_options.toJsonObject());
if(owner.isSet())
accountUpdate.add(KEY_OWNER, owner.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());
array.add(accountUpdate);
return array;

View file

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

View file

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

View file

@ -460,7 +460,7 @@ public class Test {
String suggestion = BrainKey.suggest(words);
brainKey = new BrainKey(suggestion, 0);
} 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);
}
ECKey key = brainKey.getPrivateKey();
@ -515,9 +515,9 @@ public class Test {
};
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 {
// Address address = new Address("BTS5BgjNRDeawGSc1NPk91p2BYYEhJWKgsjLZGDmFgY6uwhAYLy9G");
Address address = new Address("BTS5BgjNRDeawGSc1NPk91p2BYYEhJWKgsjLZGDmFgY6uwhAYLy9G");
// Create a custom SSL context.
SSLContext context = null;
@ -537,9 +537,9 @@ public class Test {
} catch (NoSuchAlgorithmException e) {
System.out.println("NoSuchAlgorithmException. Msg: " + e.getMessage());
}
// catch (MalformedAddressException e) {
// System.out.println("MalformedAddressException. Msg: "+e.getMessage());
// }
catch (MalformedAddressException e) {
System.out.println("MalformedAddressException. Msg: "+e.getMessage());
}
}
public void testAccountNameById() {
@ -642,10 +642,10 @@ public class Test {
authMap.put(address.getPublicKey(), 1);
Authority authority = new Authority(1, authMap, null);
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())
.setAccont(new UserAccount("1.2.140994"))
.setOwner(authority)
// .setOwner(authority)
.setActive(authority)
.setOptions(options)
.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 {
Address address = new Address(newAddress);
HashMap<PublicKey, Integer> authMap = new HashMap<>();
authMap.put(address.getPublicKey(), 1);
Authority authority = new Authority(1, authMap, null);
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())
.setAccont(new UserAccount("1.2.139205"))
.setOwner(authority)
.setAccont(new UserAccount("1.2.138632"))
// .setOwner(authority)
.setActive(authority)
.setOptions(options)
.build();