diff --git a/src/main/java/com/luminiasoft/bitshares/Memo.java b/src/main/java/com/luminiasoft/bitshares/Memo.java index 0dd6982..c79023c 100644 --- a/src/main/java/com/luminiasoft/bitshares/Memo.java +++ b/src/main/java/com/luminiasoft/bitshares/Memo.java @@ -22,24 +22,31 @@ public class Memo implements ByteSerializable, JsonSerializable { public static final String KEY_NONCE = "nonce"; public static final String KEY_MESSAGE = "message"; - //TODO: Give this class a proper implementation private PublicKey from; private PublicKey to; private byte[] nonce = new byte[8]; private byte[] message; + public Memo(){ + this.from = null; + this.to = null; + this.nonce = null; + this.message = null; + } + + public Memo(PublicKey from, PublicKey to, String message){ + this.from = from; + this.to = to; + this.message = message.getBytes(); + } + @Override public byte[] toBytes() { if ((this.from == null) || (this.to == null) || (this.nonce == null) || (this.message == null)) { - return new byte[]{(byte) 0}; + return new byte[] { (byte) 0}; + }else{ + return Bytes.concat(this.from.toBytes(), this.to.toBytes(), this.nonce, this.message); } - return Bytes.concat(this.from.toBytes(), this.to.toBytes(), this.nonce, this.message); - } - - public Memo() { - this.from = null; - this.to = null; - this.message = null; } public void encodeMessage(ECKey fromKey, ECKey toKey, byte[] msg) { diff --git a/src/main/java/com/luminiasoft/bitshares/Test.java b/src/main/java/com/luminiasoft/bitshares/Test.java index 1f9b352..43e4d99 100644 --- a/src/main/java/com/luminiasoft/bitshares/Test.java +++ b/src/main/java/com/luminiasoft/bitshares/Test.java @@ -30,6 +30,7 @@ public class Test { public static final String WITNESS_URL = "ws://api.devling.xyz:8088"; public static final String OPENLEDGER_WITNESS_URL = "wss://bitshares.openledger.info/ws"; + public static final String BLOCK_PAY_DE = "wss://de.blockpay.ch:8089"; // public static final String WITNESS_URL = "wss://fr.blockpay.ch:8089"; private Transaction transaction; @@ -292,15 +293,19 @@ public class Test { }; try { + // Creating memo + PublicKey from = new PublicKey(ECKey.fromPublicOnly(new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0).getPublicKey())); + PublicKey to = new PublicKey(ECKey.fromPublicOnly(new BrainKey(Main.BILTHON_5_BRAIN_KEY, 0).getPublicKey())); + Memo memo = new Memo(from, to, "sample message"); + + // Creating transaction Transaction transaction = new TransferTransactionBuilder() - .setSource(new UserAccount("1.2.138632")) - .setDestination(new UserAccount("1.2.129848")) - .setAmount(new AssetAmount(UnsignedLong.valueOf(1), new Asset("1.3.120"))) + .setSource(new UserAccount("1.2.138632")) // bilthon-83 + .setDestination(new UserAccount("1.2.139313")) // bilthon-5 + .setAmount(new AssetAmount(UnsignedLong.valueOf(1), new Asset("1.3.0"))) .setFee(new AssetAmount(UnsignedLong.valueOf(264174), new Asset("1.3.0"))) - .setBlockData(new BlockData(43408, 1430521623, 1479231969)) - //.setPrivateKey(DumpedPrivateKey.fromBase58(null, Main.BILTHON_5_BRAIN_KEY).getKey()) - .setPrivateKey(new BrainKey(Main.BILTHON_5_BRAIN_KEY, 0).getPrivateKey()) - //.setMemo("prueba", new BrainKey(Main.BILTHON_7_BRAIN_KEY, 0).getPrivateKey()) + .setPrivateKey(new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0).getPrivateKey()) + .setMemo(memo) .build(); ArrayList transactionList = new ArrayList<>(); @@ -313,7 +318,7 @@ public class Test { // Set the custom SSL context. factory.setSSLContext(context); - WebSocket mWebSocket = factory.createSocket(OPENLEDGER_WITNESS_URL); + WebSocket mWebSocket = factory.createSocket(BLOCK_PAY_DE); mWebSocket.addListener(new TransactionBroadcastSequence(transaction, new Asset("1.3.0"), listener)); mWebSocket.connect(); diff --git a/src/main/java/com/luminiasoft/bitshares/TransferOperation.java b/src/main/java/com/luminiasoft/bitshares/TransferOperation.java index 03655cd..47e3586 100644 --- a/src/main/java/com/luminiasoft/bitshares/TransferOperation.java +++ b/src/main/java/com/luminiasoft/bitshares/TransferOperation.java @@ -87,17 +87,17 @@ public class TransferOperation extends BaseOperation { array.add(this.getId()); JsonObject jsonObject = new JsonObject(); jsonObject.add(KEY_FEE, fee.toJsonObject()); - jsonObject.add(KEY_AMOUNT, amount.toJsonObject()); - //jsonObject.add(KEY_MEMO, memo.toJsonObject()); - jsonObject.add(KEY_EXTENSIONS, new JsonArray()); jsonObject.addProperty(KEY_FROM, from.toJsonString()); jsonObject.addProperty(KEY_TO, to.toJsonString()); + jsonObject.add(KEY_AMOUNT, amount.toJsonObject()); + jsonObject.add(KEY_MEMO, memo.toJsonObject()); + jsonObject.add(KEY_EXTENSIONS, new JsonArray()); array.add(jsonObject); return array; } - public void setMemo(ECKey fromKey, ECKey toKey, byte[] memo) { - this.memo.encodeMessage(fromKey, toKey, memo); + public void setMemo(Memo memo) { + this.memo = memo; } public static class TransferSerializer implements JsonSerializer { diff --git a/src/main/java/com/luminiasoft/bitshares/TransferTransactionBuilder.java b/src/main/java/com/luminiasoft/bitshares/TransferTransactionBuilder.java index 0e8ce7b..d191040 100644 --- a/src/main/java/com/luminiasoft/bitshares/TransferTransactionBuilder.java +++ b/src/main/java/com/luminiasoft/bitshares/TransferTransactionBuilder.java @@ -15,8 +15,7 @@ public class TransferTransactionBuilder extends TransactionBuilder { private UserAccount destinationAccount; private AssetAmount transferAmount; private AssetAmount feeAmount; - private String memo; - private ECKey memoPublicKey; + private Memo memo; public TransferTransactionBuilder(){} @@ -54,9 +53,8 @@ public class TransferTransactionBuilder extends TransactionBuilder { return this; } - public TransferTransactionBuilder setMemo(String memo,ECKey publicKey){ + public TransferTransactionBuilder setMemo(Memo memo){ this.memo = memo; - this.memoPublicKey = publicKey; return this; } @@ -93,8 +91,7 @@ public class TransferTransactionBuilder extends TransactionBuilder { transferOperation = new TransferOperation(sourceAccount, destinationAccount, transferAmount, feeAmount); } if(memo != null){ - - transferOperation.setMemo(this.privateKey,this.memoPublicKey,memo.getBytes()); + transferOperation.setMemo(this.memo); } operations.add(transferOperation); }