mirror of
https://github.com/status-im/ethereumj-personal.git
synced 2025-01-11 12:24:13 +00:00
Use ECDSASignature wrapper for Transaction signature
This commit is contained in:
parent
96773417ff
commit
1f3455f5c6
@ -32,8 +32,8 @@ public class Block {
|
||||
private byte[] extraData;
|
||||
private byte[] nonce;
|
||||
|
||||
List<Transaction> transactionsList = new ArrayList<Transaction>();
|
||||
List<Block> uncleList = new ArrayList<Block>();
|
||||
private List<Transaction> transactionsList = new ArrayList<Transaction>();
|
||||
private List<Block> uncleList = new ArrayList<Block>();
|
||||
|
||||
public Block(RLPList rawData) {
|
||||
this.rawData = rawData;
|
||||
@ -151,7 +151,6 @@ public class Block {
|
||||
}
|
||||
|
||||
// [parent_hash, uncles_hash, coinbase, state_root, tx_list_hash, difficulty, timestamp, extradata, nonce]
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (!parsed) parseRLP();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.ethereum.net.vo;
|
||||
|
||||
import org.ethereum.crypto.ECKey.ECDSASignature;
|
||||
import org.ethereum.crypto.HashUtil;
|
||||
import org.ethereum.net.rlp.RLPItem;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
@ -35,25 +36,21 @@ public class Transaction {
|
||||
private byte[] init;
|
||||
|
||||
// Signature
|
||||
private byte signatureV;
|
||||
private byte[] signatureR;
|
||||
private byte[] signatureS;
|
||||
private ECDSASignature signature;
|
||||
|
||||
public Transaction(RLPList rawData) {
|
||||
this.rawData = rawData;
|
||||
parsed = false;
|
||||
}
|
||||
|
||||
public Transaction(byte[] nonce, byte[] value, byte[] recieveAddress, byte[] gasPrice, byte[] gas, byte[] data, byte signatureV, byte[] signatureR, byte[] signatureS) {
|
||||
public Transaction(byte[] nonce, byte[] value, byte[] recieveAddress, byte[] gasPrice, byte[] gas, byte[] data, byte v, byte[] r, byte[] s) {
|
||||
this.nonce = nonce;
|
||||
this.value = value;
|
||||
this.receiveAddress = recieveAddress;
|
||||
this.gasPrice = gasPrice;
|
||||
this.gas = gas;
|
||||
this.data = data;
|
||||
this.signatureV = signatureV;
|
||||
this.signatureR = signatureR;
|
||||
this.signatureS = signatureS;
|
||||
this.signature = ECDSASignature.fromComponents(r, s, v);
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
@ -68,16 +65,16 @@ public class Transaction {
|
||||
this.data = ((RLPItem) rawData.getElement(5)).getData();
|
||||
|
||||
if (rawData.size() == 9){ // Simple transaction
|
||||
this.signatureV = ((RLPItem) rawData.getElement(6)).getData()[0];
|
||||
this.signatureR = ((RLPItem) rawData.getElement(7)).getData();
|
||||
this.signatureS = ((RLPItem) rawData.getElement(8)).getData();
|
||||
|
||||
byte v = ((RLPItem) rawData.getElement(6)).getData()[0];
|
||||
byte[] r = ((RLPItem) rawData.getElement(7)).getData();
|
||||
byte[] s = ((RLPItem) rawData.getElement(8)).getData();
|
||||
this.signature = ECDSASignature.fromComponents(r, s, v);
|
||||
} else if (rawData.size() == 10){ // Contract creation transaction
|
||||
this.init = ((RLPItem) rawData.getElement(6)).getData();
|
||||
this.signatureV = ((RLPItem) rawData.getElement(7)).getData()[0];
|
||||
this.signatureR = ((RLPItem) rawData.getElement(8)).getData();
|
||||
this.signatureS = ((RLPItem) rawData.getElement(9)).getData();
|
||||
|
||||
byte v = ((RLPItem) rawData.getElement(7)).getData()[0];
|
||||
byte[] r = ((RLPItem) rawData.getElement(8)).getData();
|
||||
byte[] s = ((RLPItem) rawData.getElement(9)).getData();
|
||||
this.signature = ECDSASignature.fromComponents(r, s, v);
|
||||
} else throw new Error("Wrong tx data element list size");
|
||||
|
||||
this.parsed = true;
|
||||
@ -131,19 +128,9 @@ public class Transaction {
|
||||
return init;
|
||||
}
|
||||
|
||||
public byte getSignatureV() {
|
||||
public ECDSASignature getSignature() {
|
||||
if (!parsed) rlpParse();
|
||||
return signatureV;
|
||||
}
|
||||
|
||||
public byte[] getSignatureR() {
|
||||
if (!parsed) rlpParse();
|
||||
return signatureR;
|
||||
}
|
||||
|
||||
public byte[] getSignatureS() {
|
||||
if (!parsed) rlpParse();
|
||||
return signatureS;
|
||||
return signature;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -157,9 +144,9 @@ public class Transaction {
|
||||
", gas=" + Utils.toHexString(gas) +
|
||||
", data=" + Utils.toHexString(data) +
|
||||
", init=" + Utils.toHexString(init) +
|
||||
", signatureV=" + signatureV +
|
||||
", signatureR=" + Utils.toHexString(signatureR) +
|
||||
", signatureS=" + Utils.toHexString(signatureS) +
|
||||
", signatureV=" + signature.v +
|
||||
", signatureR=" + Utils.toHexString(signature.r.toByteArray()) +
|
||||
", signatureS=" + Utils.toHexString(signature.s.toByteArray()) +
|
||||
']';
|
||||
}
|
||||
}
|
||||
|
@ -223,13 +223,13 @@ public class MessagesTest {
|
||||
Utils.toHexString( tx.getInit() ).toUpperCase());
|
||||
|
||||
assertEquals("1B",
|
||||
Utils.toHexString( new byte[] {tx.getSignatureV()} ).toUpperCase());
|
||||
Utils.toHexString( new byte[] {tx.getSignature().v} ).toUpperCase());
|
||||
|
||||
assertEquals("5E3868194605F1647593B842725818CCFA6A38651A728715133A8E97CDCFAC54",
|
||||
Utils.toHexString( tx.getSignatureR() ).toUpperCase());
|
||||
Utils.toHexString( tx.getSignature().r.toByteArray() ).toUpperCase());
|
||||
|
||||
assertEquals("0FF91628D04B215EBCCFD5F4FC34CC1B45DF32F6B4609FBB0DE42E8522264467",
|
||||
Utils.toHexString( tx.getSignatureS() ).toUpperCase());
|
||||
Utils.toHexString( tx.getSignature().s.toByteArray() ).toUpperCase());
|
||||
}
|
||||
|
||||
@Test /* Transactions message 2 */
|
||||
@ -274,13 +274,13 @@ public class MessagesTest {
|
||||
Utils.toHexString( tx.getInit() ).toUpperCase());
|
||||
|
||||
assertEquals("1C",
|
||||
Utils.toHexString( new byte[] {tx.getSignatureV()} ).toUpperCase());
|
||||
Utils.toHexString( new byte[] {tx.getSignature().v} ).toUpperCase());
|
||||
|
||||
assertEquals("7F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4",
|
||||
Utils.toHexString( tx.getSignatureR() ).toUpperCase());
|
||||
Utils.toHexString( tx.getSignature().r.toByteArray() ).toUpperCase());
|
||||
|
||||
assertEquals("6D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CC",
|
||||
Utils.toHexString( tx.getSignatureS() ).toUpperCase());
|
||||
Utils.toHexString( tx.getSignature().s.toByteArray() ).toUpperCase());
|
||||
|
||||
tx = transactionsMessage.getTransactions().get(2);
|
||||
|
||||
@ -309,13 +309,13 @@ public class MessagesTest {
|
||||
Utils.toHexString( tx.getInit() ).toUpperCase());
|
||||
|
||||
assertEquals("1B",
|
||||
Utils.toHexString( new byte[] {tx.getSignatureV()} ).toUpperCase());
|
||||
Utils.toHexString( new byte[] {tx.getSignature().v} ).toUpperCase());
|
||||
|
||||
assertEquals("D05887574456C6DE8F7A0D172342C2CBDD4CF7AFE15D9DBB8B75B748BA6791C9",
|
||||
Utils.toHexString( tx.getSignatureR() ).toUpperCase());
|
||||
Utils.toHexString( tx.getSignature().r.toByteArray() ).toUpperCase());
|
||||
|
||||
assertEquals("1E87172A861F6C37B5A9E3A5D0D7393152A7FBE41530E5BB8AC8F35433E5931B",
|
||||
Utils.toHexString(tx.getSignatureS()).toUpperCase());
|
||||
Utils.toHexString(tx.getSignature().s.toByteArray()).toUpperCase());
|
||||
}
|
||||
|
||||
/* BLOCKS */
|
||||
|
Loading…
x
Reference in New Issue
Block a user