Ejemplo n.º 1
0
  public TransactionInfo(byte[] rlp) {
    RLPList params = RLP.decode2(rlp);
    RLPList txInfo = (RLPList) params.get(0);
    RLPList receiptRLP = (RLPList) txInfo.get(0);
    RLPItem blockHashRLP = (RLPItem) txInfo.get(1);
    RLPItem indexRLP = (RLPItem) txInfo.get(2);

    receipt = new TransactionReceipt(receiptRLP.getRLPData());
    blockHash = blockHashRLP.getRLPData();
    if (indexRLP.getRLPData() == null) index = 0;
    else index = new BigInteger(1, indexRLP.getRLPData()).intValue();
  }
Ejemplo n.º 2
0
  public AccountState(byte[] rlpData) {
    this.rlpEncoded = rlpData;

    RLPList items = (RLPList) RLP.decode2(rlpEncoded).get(0);
    this.nonce =
        items.get(0).getRLPData() == null
            ? BigInteger.ZERO
            : new BigInteger(1, items.get(0).getRLPData());
    this.balance =
        items.get(1).getRLPData() == null
            ? BigInteger.ZERO
            : new BigInteger(1, items.get(1).getRLPData());
    this.stateRoot = items.get(2).getRLPData();
    this.codeHash = items.get(3).getRLPData();
  }
Ejemplo n.º 3
0
  @Override
  public void decode(byte[] rlpCode) {
    RLPList data = RLP.decode2(rlpCode);
    RLPList rlpList = (RLPList) data.get(0);

    RLPList keys = (RLPList) rlpList.get(0);
    RLPList values = (RLPList) rlpList.get(1);
    RLPElement code = rlpList.get(2);

    for (int i = 0; i < keys.size(); ++i) {

      RLPItem key = (RLPItem) keys.get(i);
      RLPItem value = (RLPItem) values.get(i);

      storage.put(new DataWord(key.getRLPData()), new DataWord(value.getRLPData()));
    }

    this.code = (code.getRLPData() == null) ? ByteUtil.EMPTY_BYTE_ARRAY : code.getRLPData();
  }
Ejemplo n.º 4
0
  public void rlpParse() {

    RLPList decodedTxList = RLP.decode2(rlpEncoded);
    RLPList transaction = (RLPList) decodedTxList.get(0);

    this.nonce = transaction.get(0).getRLPData();
    this.gasPrice = transaction.get(1).getRLPData();
    this.gasLimit = transaction.get(2).getRLPData();
    this.receiveAddress = transaction.get(3).getRLPData();
    this.value = transaction.get(4).getRLPData();
    this.data = transaction.get(5).getRLPData();
    // only parse signature in case tx is signed
    if (transaction.get(6).getRLPData() != null) {
      byte v = transaction.get(6).getRLPData()[0];
      byte[] r = transaction.get(7).getRLPData();
      byte[] s = transaction.get(8).getRLPData();
      this.signature = ECDSASignature.fromComponents(r, s, v);
    } else {
      logger.debug("RLP encoded tx is not signed!");
    }
    this.parsed = true;
    this.hash = getHash();
  }