Fixing problems with the memo test, but still not working, probably some error with serialization
This commit is contained in:
parent
9aacdc0e15
commit
d594a9b2c2
4 changed files with 37 additions and 28 deletions
|
@ -22,24 +22,31 @@ public class Memo implements ByteSerializable, JsonSerializable {
|
||||||
public static final String KEY_NONCE = "nonce";
|
public static final String KEY_NONCE = "nonce";
|
||||||
public static final String KEY_MESSAGE = "message";
|
public static final String KEY_MESSAGE = "message";
|
||||||
|
|
||||||
//TODO: Give this class a proper implementation
|
|
||||||
private PublicKey from;
|
private PublicKey from;
|
||||||
private PublicKey to;
|
private PublicKey to;
|
||||||
private byte[] nonce = new byte[8];
|
private byte[] nonce = new byte[8];
|
||||||
private byte[] message;
|
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
|
@Override
|
||||||
public byte[] toBytes() {
|
public byte[] toBytes() {
|
||||||
if ((this.from == null) || (this.to == null) || (this.nonce == null) || (this.message == null)) {
|
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) {
|
public void encodeMessage(ECKey fromKey, ECKey toKey, byte[] msg) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class Test {
|
||||||
|
|
||||||
public static final String WITNESS_URL = "ws://api.devling.xyz:8088";
|
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 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";
|
// public static final String WITNESS_URL = "wss://fr.blockpay.ch:8089";
|
||||||
|
|
||||||
private Transaction transaction;
|
private Transaction transaction;
|
||||||
|
@ -292,15 +293,19 @@ public class Test {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
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()
|
Transaction transaction = new TransferTransactionBuilder()
|
||||||
.setSource(new UserAccount("1.2.138632"))
|
.setSource(new UserAccount("1.2.138632")) // bilthon-83
|
||||||
.setDestination(new UserAccount("1.2.129848"))
|
.setDestination(new UserAccount("1.2.139313")) // bilthon-5
|
||||||
.setAmount(new AssetAmount(UnsignedLong.valueOf(1), new Asset("1.3.120")))
|
.setAmount(new AssetAmount(UnsignedLong.valueOf(1), new Asset("1.3.0")))
|
||||||
.setFee(new AssetAmount(UnsignedLong.valueOf(264174), new Asset("1.3.0")))
|
.setFee(new AssetAmount(UnsignedLong.valueOf(264174), new Asset("1.3.0")))
|
||||||
.setBlockData(new BlockData(43408, 1430521623, 1479231969))
|
.setPrivateKey(new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0).getPrivateKey())
|
||||||
//.setPrivateKey(DumpedPrivateKey.fromBase58(null, Main.BILTHON_5_BRAIN_KEY).getKey())
|
.setMemo(memo)
|
||||||
.setPrivateKey(new BrainKey(Main.BILTHON_5_BRAIN_KEY, 0).getPrivateKey())
|
|
||||||
//.setMemo("prueba", new BrainKey(Main.BILTHON_7_BRAIN_KEY, 0).getPrivateKey())
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ArrayList<Serializable> transactionList = new ArrayList<>();
|
ArrayList<Serializable> transactionList = new ArrayList<>();
|
||||||
|
@ -313,7 +318,7 @@ public class Test {
|
||||||
// Set the custom SSL context.
|
// Set the custom SSL context.
|
||||||
factory.setSSLContext(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.addListener(new TransactionBroadcastSequence(transaction, new Asset("1.3.0"), listener));
|
||||||
mWebSocket.connect();
|
mWebSocket.connect();
|
||||||
|
|
|
@ -87,17 +87,17 @@ public class TransferOperation extends BaseOperation {
|
||||||
array.add(this.getId());
|
array.add(this.getId());
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
jsonObject.add(KEY_FEE, fee.toJsonObject());
|
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_FROM, from.toJsonString());
|
||||||
jsonObject.addProperty(KEY_TO, to.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);
|
array.add(jsonObject);
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMemo(ECKey fromKey, ECKey toKey, byte[] memo) {
|
public void setMemo(Memo memo) {
|
||||||
this.memo.encodeMessage(fromKey, toKey, memo);
|
this.memo = memo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TransferSerializer implements JsonSerializer<TransferOperation> {
|
public static class TransferSerializer implements JsonSerializer<TransferOperation> {
|
||||||
|
|
|
@ -15,8 +15,7 @@ public class TransferTransactionBuilder extends TransactionBuilder {
|
||||||
private UserAccount destinationAccount;
|
private UserAccount destinationAccount;
|
||||||
private AssetAmount transferAmount;
|
private AssetAmount transferAmount;
|
||||||
private AssetAmount feeAmount;
|
private AssetAmount feeAmount;
|
||||||
private String memo;
|
private Memo memo;
|
||||||
private ECKey memoPublicKey;
|
|
||||||
|
|
||||||
public TransferTransactionBuilder(){}
|
public TransferTransactionBuilder(){}
|
||||||
|
|
||||||
|
@ -54,9 +53,8 @@ public class TransferTransactionBuilder extends TransactionBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransferTransactionBuilder setMemo(String memo,ECKey publicKey){
|
public TransferTransactionBuilder setMemo(Memo memo){
|
||||||
this.memo = memo;
|
this.memo = memo;
|
||||||
this.memoPublicKey = publicKey;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,8 +91,7 @@ public class TransferTransactionBuilder extends TransactionBuilder {
|
||||||
transferOperation = new TransferOperation(sourceAccount, destinationAccount, transferAmount, feeAmount);
|
transferOperation = new TransferOperation(sourceAccount, destinationAccount, transferAmount, feeAmount);
|
||||||
}
|
}
|
||||||
if(memo != null){
|
if(memo != null){
|
||||||
|
transferOperation.setMemo(this.memo);
|
||||||
transferOperation.setMemo(this.privateKey,this.memoPublicKey,memo.getBytes());
|
|
||||||
}
|
}
|
||||||
operations.add(transferOperation);
|
operations.add(transferOperation);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue