Search in sources :

Example 21 with RLPList

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;
}
Also used : RLPList(org.ethereum.util.RLPList)

Example 22 with RLPList

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;
}
Also used : ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction) ImmutableTransaction(org.ethereum.core.ImmutableTransaction) RLPList(org.ethereum.util.RLPList)

Example 23 with RLPList

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;
}
Also used : RLPList(org.ethereum.util.RLPList)

Example 24 with RLPList

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;
}
Also used : UnknownHostException(java.net.UnknownHostException) InetAddress(java.net.InetAddress) RLPList(org.ethereum.util.RLPList)

Example 25 with RLPList

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;
}
Also used : RLPList(org.ethereum.util.RLPList) ECPoint(org.spongycastle.math.ec.ECPoint)

Aggregations

RLPList (org.ethereum.util.RLPList)60 RLPElement (org.ethereum.util.RLPElement)19 Test (org.junit.Test)13 Keccak256 (co.rsk.crypto.Keccak256)8 RskAddress (co.rsk.core.RskAddress)7 BigInteger (java.math.BigInteger)5 RLPItem (org.ethereum.util.RLPItem)5 LogInfo (org.ethereum.vm.LogInfo)5 Script (co.rsk.bitcoinj.script.Script)3 ScriptChunk (co.rsk.bitcoinj.script.ScriptChunk)3 Coin (co.rsk.core.Coin)3 RepositoryImpl (co.rsk.db.RepositoryImpl)3 BridgeEventLogger (co.rsk.peg.utils.BridgeEventLogger)3 BridgeEventLoggerImpl (co.rsk.peg.utils.BridgeEventLoggerImpl)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2