Successfully changing owner and account keys information
This commit is contained in:
parent
e0b0330e54
commit
7eb6a15c7e
7 changed files with 56 additions and 46 deletions
|
@ -36,6 +36,7 @@ public class AccountUpdateOperation extends BaseOperation {
|
||||||
this(account, owner, active, new AssetAmount(UnsignedLong.valueOf(0), new Asset("1.3.0")));
|
this(account, owner, active, new AssetAmount(UnsignedLong.valueOf(0), new Asset("1.3.0")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setFee(AssetAmount fee){
|
public void setFee(AssetAmount fee){
|
||||||
this.fee = fee;
|
this.fee = fee;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,5 +18,7 @@ public abstract class BaseOperation implements ByteSerializable, JsonSerializabl
|
||||||
return (byte) this.type.ordinal();
|
return (byte) this.type.ordinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void setFee(AssetAmount assetAmount);
|
||||||
|
|
||||||
public abstract byte[] toBytes();
|
public abstract byte[] toBytes();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ public class Main {
|
||||||
// Brain key from Nelson's app referencing the bilthon-83 account
|
// Brain key from Nelson's app referencing the bilthon-83 account
|
||||||
public static final String BRAIN_KEY = "PUMPER ISOTOME SERE STAINER CLINGER MOONLIT CHAETA UPBRIM AEDILIC BERTHER NIT SHAP SAID SHADING JUNCOUS CHOUGH";
|
public static final String BRAIN_KEY = "PUMPER ISOTOME SERE STAINER CLINGER MOONLIT CHAETA UPBRIM AEDILIC BERTHER NIT SHAP SAID SHADING JUNCOUS CHOUGH";
|
||||||
|
|
||||||
|
public static final String BILTHON_5_BRAIN_KEY = "UNMATE AURIGAL NAVET WAVICLE REWOVE ABBOTCY COWHERB OUTKICK STOPPER JUSSORY BEAMLET WIRY";
|
||||||
|
|
||||||
//public static final String BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER";
|
//public static final String BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER";
|
||||||
//public static final String BRAIN_KEY = "SIVER TIKKER FOGO HOMINAL PRAYER LUTEIN SMALLY ACARID MEROPIA TRANCE BOGONG IDDAT HICKORY SOUTANE MOOD DOWSER";
|
//public static final String BRAIN_KEY = "SIVER TIKKER FOGO HOMINAL PRAYER LUTEIN SMALLY ACARID MEROPIA TRANCE BOGONG IDDAT HICKORY SOUTANE MOOD DOWSER";
|
||||||
public static final String BIP39_KEY = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
|
public static final String BIP39_KEY = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
|
||||||
|
@ -17,7 +19,7 @@ public class Main {
|
||||||
// public static final String WIF = "5J96pne45qWM1WpektoeazN6k9Mt93jQ7LyueRxFfEMTiy6yxjM";
|
// public static final String WIF = "5J96pne45qWM1WpektoeazN6k9Mt93jQ7LyueRxFfEMTiy6yxjM";
|
||||||
// Brain key from an empty account created by the cli_wallet
|
// Brain key from an empty account created by the cli_wallet
|
||||||
// public static final String BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER";
|
// public static final String BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER";
|
||||||
// WIF from an emty account created by the cli_wallet
|
// WIF from an empty account created by the cli_wallet
|
||||||
public static final String WIF = "5KMzB2GqGhnh7ufhgddmz1eKPHS72uTLeL9hHjSvPb1UywWknF5";
|
public static final String WIF = "5KMzB2GqGhnh7ufhgddmz1eKPHS72uTLeL9hHjSvPb1UywWknF5";
|
||||||
|
|
||||||
public static final String EXTERNAL_SIGNATURE = "1f36c41acb774fcbc9c231b5895ec9701d6872729098d8ea56d78dda72a6b54252694db85d7591de5751b7aea06871da15d63a1028758421607ffc143e53ef3306";
|
public static final String EXTERNAL_SIGNATURE = "1f36c41acb774fcbc9c231b5895ec9701d6872729098d8ea56d78dda72a6b54252694db85d7591de5751b7aea06871da15d63a1028758421607ffc143e53ef3306";
|
||||||
|
@ -61,7 +63,7 @@ public class Main {
|
||||||
// test.testingInvoiceGeneration();
|
// test.testingInvoiceGeneration();
|
||||||
// test.testCompression();
|
// test.testCompression();
|
||||||
// test.testCreateBinFile();
|
// test.testCreateBinFile();
|
||||||
test.testAccountUpdateSerialization();
|
// test.testAccountUpdateSerialization();
|
||||||
// test.testAccountUpdateOperationSerialization();
|
test.testAccountUpdateOperationBroadcast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,8 @@ public class Test {
|
||||||
AssetAmount amount = new AssetAmount(UnsignedLong.valueOf(100), new Asset("1.3.120"));
|
AssetAmount amount = new AssetAmount(UnsignedLong.valueOf(100), new Asset("1.3.120"));
|
||||||
AssetAmount fee = new AssetAmount(UnsignedLong.valueOf(264174), new Asset("1.3.0"));
|
AssetAmount fee = new AssetAmount(UnsignedLong.valueOf(264174), new Asset("1.3.0"));
|
||||||
operations.add(new TransferOperation(from, to, amount, fee));
|
operations.add(new TransferOperation(from, to, amount, fee));
|
||||||
this.transaction = new Transaction(Main.WIF, blockData, operations);
|
BrainKey brainKey = new BrainKey(Main.BRAIN_KEY, 0);
|
||||||
|
this.transaction = new Transaction(brainKey.getWalletImportFormat(), blockData, operations);
|
||||||
byte[] serializedTransaction = this.transaction.toBytes();
|
byte[] serializedTransaction = this.transaction.toBytes();
|
||||||
System.out.println("Serialized transaction");
|
System.out.println("Serialized transaction");
|
||||||
System.out.println(Util.bytesToHex(serializedTransaction));
|
System.out.println(Util.bytesToHex(serializedTransaction));
|
||||||
|
@ -426,7 +427,7 @@ public class Test {
|
||||||
.setAmount(new AssetAmount(UnsignedLong.valueOf(100), new Asset("1.3.120")))
|
.setAmount(new AssetAmount(UnsignedLong.valueOf(100), new Asset("1.3.120")))
|
||||||
.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))
|
.setBlockData(new BlockData(43408, 1430521623, 1479231969))
|
||||||
.setPrivateKey(DumpedPrivateKey.fromBase58(null, Main.WIF).getKey())
|
.setPrivateKey(DumpedPrivateKey.fromBase58(null, Main.BILTHON_5_BRAIN_KEY).getKey())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ArrayList<Serializable> transactionList = new ArrayList<>();
|
ArrayList<Serializable> transactionList = new ArrayList<>();
|
||||||
|
@ -441,7 +442,7 @@ public class Test {
|
||||||
|
|
||||||
WebSocket mWebSocket = factory.createSocket(OPENLEDGER_WITNESS_URL);
|
WebSocket mWebSocket = factory.createSocket(OPENLEDGER_WITNESS_URL);
|
||||||
|
|
||||||
mWebSocket.addListener(new TransactionBroadcastSequence(transaction, listener));
|
mWebSocket.addListener(new TransactionBroadcastSequence(transaction, new Asset("1.3.0"), listener));
|
||||||
mWebSocket.connect();
|
mWebSocket.connect();
|
||||||
|
|
||||||
} catch (MalformedTransactionException e) {
|
} catch (MalformedTransactionException e) {
|
||||||
|
@ -591,7 +592,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 {
|
||||||
brainKey = new BrainKey(Main.BRAIN_KEY, 0);
|
brainKey = new BrainKey(Main.BILTHON_5_BRAIN_KEY, 0);
|
||||||
}
|
}
|
||||||
ECKey key = brainKey.getPrivateKey();
|
ECKey key = brainKey.getPrivateKey();
|
||||||
System.out.println("Private key");
|
System.out.println("Private key");
|
||||||
|
@ -755,8 +756,6 @@ public class Test {
|
||||||
ArrayList<BaseOperation> operations = new ArrayList<BaseOperation>();
|
ArrayList<BaseOperation> operations = new ArrayList<BaseOperation>();
|
||||||
operations.add(operation);
|
operations.add(operation);
|
||||||
Transaction transaction = new Transaction(Main.WIF, blockData, operations);
|
Transaction transaction = new Transaction(Main.WIF, blockData, operations);
|
||||||
System.out.println("Json format of transaction");
|
|
||||||
System.out.println(transaction.toJsonString());
|
|
||||||
} catch(MalformedAddressException e){
|
} catch(MalformedAddressException e){
|
||||||
System.out.println("MalformedAddressException. Msg: "+e.getMessage());
|
System.out.println("MalformedAddressException. Msg: "+e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -776,7 +775,7 @@ public class Test {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
UserAccount account = new UserAccount("1.2.138632");
|
UserAccount account = new UserAccount("1.2.139313");
|
||||||
AssetAmount fee = new AssetAmount(UnsignedLong.valueOf("200"), new Asset("1.3.0"));
|
AssetAmount fee = new AssetAmount(UnsignedLong.valueOf("200"), new Asset("1.3.0"));
|
||||||
HashMap<String, Integer> keyAuths = new HashMap<>();
|
HashMap<String, Integer> keyAuths = new HashMap<>();
|
||||||
keyAuths.put("BTS8RiFgs8HkcVPVobHLKEv6yL3iXcC9SWjbPVS15dDAXLG9GYhnY", 1);
|
keyAuths.put("BTS8RiFgs8HkcVPVobHLKEv6yL3iXcC9SWjbPVS15dDAXLG9GYhnY", 1);
|
||||||
|
@ -786,12 +785,8 @@ public class Test {
|
||||||
AccountUpdateOperation operation = new AccountUpdateOperation(account, owner, active, fee);
|
AccountUpdateOperation operation = new AccountUpdateOperation(account, owner, active, fee);
|
||||||
ArrayList<BaseOperation> operations = new ArrayList<BaseOperation>();
|
ArrayList<BaseOperation> operations = new ArrayList<BaseOperation>();
|
||||||
operations.add(operation);
|
operations.add(operation);
|
||||||
Transaction transaction = new Transaction(Main.WIF, null, operations);
|
BrainKey brainKey = new BrainKey(Main.BILTHON_5_BRAIN_KEY, 0);
|
||||||
|
Transaction transaction = new Transaction(brainKey.getWalletImportFormat(), null, operations);
|
||||||
ArrayList<Serializable> transactionList = new ArrayList<>();
|
|
||||||
transactionList.add(transaction);
|
|
||||||
|
|
||||||
ApiCall call = new ApiCall(4, "call", "broadcast_transaction", transactionList, RPC.VERSION, 1);
|
|
||||||
|
|
||||||
SSLContext context = null;
|
SSLContext context = null;
|
||||||
context = NaiveSSLContext.getInstance("TLS");
|
context = NaiveSSLContext.getInstance("TLS");
|
||||||
|
@ -802,7 +797,7 @@ public class Test {
|
||||||
|
|
||||||
WebSocket mWebSocket = factory.createSocket(OPENLEDGER_WITNESS_URL);
|
WebSocket mWebSocket = factory.createSocket(OPENLEDGER_WITNESS_URL);
|
||||||
|
|
||||||
mWebSocket.addListener(new TransactionBroadcastSequence(transaction, listener));
|
mWebSocket.addListener(new TransactionBroadcastSequence(transaction, new Asset("1.3.0"), listener));
|
||||||
mWebSocket.connect();
|
mWebSocket.connect();
|
||||||
} catch (MalformedAddressException e) {
|
} catch (MalformedAddressException e) {
|
||||||
System.out.println("MalformedAddressException. Msg: "+e.getMessage());
|
System.out.println("MalformedAddressException. Msg: "+e.getMessage());
|
||||||
|
|
|
@ -69,6 +69,11 @@ public class Transaction implements ByteSerializable, JsonSerializable {
|
||||||
this.blockData = blockData;
|
this.blockData = blockData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFees(List<AssetAmount> fees){
|
||||||
|
for(int i = 0; i < operations.size(); i++)
|
||||||
|
operations.get(i).setFee(fees.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
public ECKey getPrivateKey(){
|
public ECKey getPrivateKey(){
|
||||||
return this.privateKey;
|
return this.privateKey;
|
||||||
}
|
}
|
||||||
|
@ -90,8 +95,6 @@ public class Transaction implements ByteSerializable, JsonSerializable {
|
||||||
|
|
||||||
while(!isGrapheneCanonical) {
|
while(!isGrapheneCanonical) {
|
||||||
byte[] serializedTransaction = this.toBytes();
|
byte[] serializedTransaction = this.toBytes();
|
||||||
System.out.println("Signing serialized transaction");
|
|
||||||
System.out.println(Util.bytesToHex(serializedTransaction));
|
|
||||||
Sha256Hash hash = Sha256Hash.wrap(Sha256Hash.hash(serializedTransaction));
|
Sha256Hash hash = Sha256Hash.wrap(Sha256Hash.hash(serializedTransaction));
|
||||||
int recId = -1;
|
int recId = -1;
|
||||||
ECKey.ECDSASignature sig = privateKey.sign(hash);
|
ECKey.ECDSASignature sig = privateKey.sign(hash);
|
||||||
|
|
|
@ -40,6 +40,7 @@ public class TransferOperation extends BaseOperation {
|
||||||
this.memo = new Memo();
|
this.memo = new Memo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setFee(AssetAmount newFee){
|
public void setFee(AssetAmount newFee){
|
||||||
this.fee = newFee;
|
this.fee = newFee;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package com.luminiasoft.bitshares.ws;
|
package com.luminiasoft.bitshares.ws;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.luminiasoft.bitshares.BlockData;
|
import com.luminiasoft.bitshares.*;
|
||||||
import com.luminiasoft.bitshares.RPC;
|
|
||||||
import com.luminiasoft.bitshares.Transaction;
|
|
||||||
import com.luminiasoft.bitshares.interfaces.WitnessResponseListener;
|
import com.luminiasoft.bitshares.interfaces.WitnessResponseListener;
|
||||||
import com.luminiasoft.bitshares.models.ApiCall;
|
import com.luminiasoft.bitshares.models.ApiCall;
|
||||||
import com.luminiasoft.bitshares.models.BaseResponse;
|
import com.luminiasoft.bitshares.models.BaseResponse;
|
||||||
|
@ -18,11 +17,7 @@ import com.neovisionaries.ws.client.WebSocketFrame;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that will handle the transaction publication procedure.
|
* Class that will handle the transaction publication procedure.
|
||||||
|
@ -33,8 +28,12 @@ public class TransactionBroadcastSequence extends WebSocketAdapter {
|
||||||
private final static int LOGIN_ID = 1;
|
private final static int LOGIN_ID = 1;
|
||||||
private final static int GET_NETWORK_BROADCAST_ID = 2;
|
private final static int GET_NETWORK_BROADCAST_ID = 2;
|
||||||
private final static int GET_NETWORK_DYNAMIC_PARAMETERS = 3;
|
private final static int GET_NETWORK_DYNAMIC_PARAMETERS = 3;
|
||||||
private final static int BROADCAST_TRANSACTION = 4;
|
private final static int GET_REQUIRED_FEES = 4;
|
||||||
|
private final static int BROADCAST_TRANSACTION = 5;
|
||||||
|
|
||||||
|
// private Transaction transaction;
|
||||||
|
// private ArrayList<Serializable> transactions;
|
||||||
|
private Asset feeAsset;
|
||||||
private Transaction transaction;
|
private Transaction transaction;
|
||||||
private WitnessResponseListener mListener;
|
private WitnessResponseListener mListener;
|
||||||
|
|
||||||
|
@ -48,8 +47,9 @@ public class TransactionBroadcastSequence extends WebSocketAdapter {
|
||||||
* be implemented by the party interested in being notified about the success/failure
|
* be implemented by the party interested in being notified about the success/failure
|
||||||
* of the transaction broadcast operation.
|
* of the transaction broadcast operation.
|
||||||
*/
|
*/
|
||||||
public TransactionBroadcastSequence(Transaction transaction, WitnessResponseListener listener){
|
public TransactionBroadcastSequence(Transaction transaction, Asset feeAsset, WitnessResponseListener listener){
|
||||||
this.transaction = transaction;
|
this.transaction = transaction;
|
||||||
|
this.feeAsset = feeAsset;
|
||||||
this.mListener = listener;
|
this.mListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,30 +94,36 @@ public class TransactionBroadcastSequence extends WebSocketAdapter {
|
||||||
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
Date date = dateFormat.parse(dynamicProperties.time);
|
Date date = dateFormat.parse(dynamicProperties.time);
|
||||||
|
|
||||||
// Obtained block data
|
// Adjusting dynamic block data to every transaction
|
||||||
long expirationTime = (date.getTime() / 1000) + Transaction.DEFAULT_EXPIRATION_TIME;
|
long expirationTime = (date.getTime() / 1000) + Transaction.DEFAULT_EXPIRATION_TIME;
|
||||||
String headBlockId = dynamicProperties.head_block_id;
|
String headBlockId = dynamicProperties.head_block_id;
|
||||||
long headBlockNumber = dynamicProperties.head_block_number;
|
long headBlockNumber = dynamicProperties.head_block_number;
|
||||||
transaction.setBlockData(new BlockData(headBlockNumber, headBlockId, expirationTime));
|
transaction.setBlockData(new BlockData(headBlockNumber, headBlockId, expirationTime));
|
||||||
|
|
||||||
ArrayList<Serializable> transactionList = new ArrayList<>();
|
ArrayList<Serializable> accountParams = new ArrayList<>();
|
||||||
transactionList.add(transaction);
|
accountParams.add((Serializable) transaction.getOperations());
|
||||||
ApiCall call = new ApiCall(broadcastApiId,
|
accountParams.add(this.feeAsset.getObjectId());
|
||||||
RPC.CALL_BROADCAST_TRANSACTION,
|
ApiCall getRequiredFees = new ApiCall(0, RPC.CALL_GET_REQUIRED_FEES, accountParams, RPC.VERSION, currentId);
|
||||||
transactionList,
|
|
||||||
RPC.VERSION,
|
|
||||||
currentId);
|
|
||||||
|
|
||||||
System.out.println("Json of transaction");
|
|
||||||
System.out.println(transaction.toJsonString());
|
|
||||||
|
|
||||||
//TODO: Remove this debug code
|
|
||||||
String jsonCall = call.toJsonString();
|
|
||||||
System.out.println("json call");
|
|
||||||
System.out.println(jsonCall);
|
|
||||||
|
|
||||||
// Finally sending transaction
|
// Finally sending transaction
|
||||||
// websocket.sendText(call.toJsonString());
|
websocket.sendText(getRequiredFees.toJsonString());
|
||||||
|
}else if(baseResponse.id == GET_REQUIRED_FEES){
|
||||||
|
Type GetRequiredFeesResponse = new TypeToken<WitnessResponse<List<AssetAmount>>>(){}.getType();
|
||||||
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||||
|
gsonBuilder.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetDeserializer());
|
||||||
|
WitnessResponse<List<AssetAmount>> requiredFeesResponse = gsonBuilder.create().fromJson(response, GetRequiredFeesResponse);
|
||||||
|
|
||||||
|
transaction.setFees(requiredFeesResponse.result);
|
||||||
|
ArrayList<Serializable> transactions = new ArrayList<>();
|
||||||
|
transactions.add(transaction);
|
||||||
|
|
||||||
|
ApiCall call = new ApiCall(broadcastApiId,
|
||||||
|
RPC.CALL_BROADCAST_TRANSACTION,
|
||||||
|
transactions,
|
||||||
|
RPC.VERSION,
|
||||||
|
currentId);
|
||||||
|
websocket.sendText(call.toJsonString());
|
||||||
|
// websocket.disconnect();
|
||||||
}else if(baseResponse.id >= BROADCAST_TRANSACTION){
|
}else if(baseResponse.id >= BROADCAST_TRANSACTION){
|
||||||
Type WitnessResponseType = new TypeToken<WitnessResponse<String>>(){}.getType();
|
Type WitnessResponseType = new TypeToken<WitnessResponse<String>>(){}.getType();
|
||||||
WitnessResponse<WitnessResponse<String>> witnessResponse = gson.fromJson(response, WitnessResponseType);
|
WitnessResponse<WitnessResponse<String>> witnessResponse = gson.fromJson(response, WitnessResponseType);
|
||||||
|
|
Loading…
Reference in a new issue