use of org.ethereum.util.RLPList in project rskj by rsksmart.
the class StatusMessage method parse.
protected void parse() {
RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
this.protocolVersion = paramsList.get(0).getRLPData()[0];
byte[] networkIdBytes = paramsList.get(1).getRLPData();
this.networkId = networkIdBytes == null ? 0 : ByteUtil.byteArrayToInt(networkIdBytes);
byte[] diff = paramsList.get(2).getRLPData();
this.totalDifficulty = (diff == null) ? ZERO_BYTE_ARRAY : diff;
this.bestHash = paramsList.get(3).getRLPData();
this.genesisHash = paramsList.get(4).getRLPData();
parsed = true;
}
use of org.ethereum.util.RLPList in project rskj by rsksmart.
the class TransactionsMessage method parse.
private void parse() {
RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
transactions = new ArrayList<>();
for (int i = 0; i < paramsList.size(); ++i) {
RLPList rlpTxData = (RLPList) paramsList.get(i);
Transaction tx = new ImmutableTransaction(rlpTxData.getRLPData());
transactions.add(tx);
}
parsed = true;
}
use of org.ethereum.util.RLPList in project rskj by rsksmart.
the class DisconnectMessage method parse.
private void parse() {
RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
byte[] reasonBytes = paramsList.get(0).getRLPData();
if (reasonBytes == null) {
this.reason = REQUESTED;
} else {
this.reason = ReasonCode.fromInt(reasonBytes[0]);
}
parsed = true;
}
use of org.ethereum.util.RLPList in project rskj by rsksmart.
the class PeersMessage method parse.
private void parse() {
RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
peers = new LinkedHashSet<>();
for (int i = 1; i < paramsList.size(); ++i) {
RLPList peerParams = (RLPList) paramsList.get(i);
byte[] ipBytes = peerParams.get(0).getRLPData();
byte[] portBytes = peerParams.get(1).getRLPData();
byte[] peerIdRaw = peerParams.get(2).getRLPData();
try {
int peerPort = ByteUtil.byteArrayToInt(portBytes);
InetAddress address = InetAddress.getByAddress(ipBytes);
String peerId = peerIdRaw == null ? "" : Hex.toHexString(peerIdRaw);
Peer peer = new Peer(address, peerPort, peerId);
peers.add(peer);
} catch (UnknownHostException e) {
throw new RuntimeException("Malformed ip", e);
}
}
this.parsed = true;
}
use of org.ethereum.util.RLPList in project rskj by rsksmart.
the class AuthInitiateMessageV4 method decode.
static AuthInitiateMessageV4 decode(byte[] wire) {
AuthInitiateMessageV4 message = new AuthInitiateMessageV4();
RLPList params = (RLPList) RLP.decode2OneItem(wire, 0);
byte[] signatureBytes = params.get(0).getRLPData();
int offset = 0;
byte[] r = new byte[32];
byte[] s = new byte[32];
System.arraycopy(signatureBytes, offset, r, 0, 32);
offset += 32;
System.arraycopy(signatureBytes, offset, s, 0, 32);
offset += 32;
int v = signatureBytes[offset] + 27;
message.signature = ECKey.ECDSASignature.fromComponents(r, s, (byte) v);
byte[] publicKeyBytes = params.get(1).getRLPData();
byte[] bytes = new byte[65];
System.arraycopy(publicKeyBytes, 0, bytes, 1, 64);
// uncompressed
bytes[0] = 0x04;
message.publicKey = ECKey.CURVE.getCurve().decodePoint(bytes);
message.nonce = params.get(2).getRLPData();
byte[] versionBytes = params.get(3).getRLPData();
message.version = ByteUtil.byteArrayToInt(versionBytes);
return message;
}
Aggregations