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