Java Code Examples for org.web3j.rlp.RlpString

The following examples show how to use org.web3j.rlp.RlpString. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public Single<byte[]> getSignature(ETHWallet wallet, byte[] message, String password) {
    return  Single.fromCallable(() -> {
        Credentials credentials = WalletUtils.loadCredentials(password, wallet.getKeystorePath());
        Sign.SignatureData signatureData = Sign.signMessage(
                message, credentials.getEcKeyPair());

        List<RlpType> result = new ArrayList<>();
        result.add(RlpString.create(message));

        if (signatureData != null) {
            result.add(RlpString.create(signatureData.getV()));
            result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getR())));
            result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getS())));
        }

        RlpList rlpList = new RlpList(result);
        return RlpEncoder.encode(rlpList);
    });
}
 
Example 2
Source Project: client-sdk-java   Source File: DelegateContract.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *  获得解除委托时所提取的委托收益(当减持/撤销委托成功时调用)
 *
 * @param transactionReceipt
 * @return
 * @throws TransactionException
 */
public BigInteger decodeUnDelegateLog(TransactionReceipt transactionReceipt) throws TransactionException {
    List<Log> logs = transactionReceipt.getLogs();
    if(logs==null||logs.isEmpty()){
        throw new TransactionException("TransactionReceipt logs is empty");
    }

    String logData = logs.get(0).getData();
    if(null == logData || "".equals(logData) ){
        throw new TransactionException("TransactionReceipt logs[0].data is empty");
    }

    RlpList rlp = RlpDecoder.decode(Numeric.hexStringToByteArray(logData));
    List<RlpType> rlpList = ((RlpList)(rlp.getValues().get(0))).getValues();
    String decodedStatus = new String(((RlpString)rlpList.get(0)).getBytes());
    int statusCode = Integer.parseInt(decodedStatus);

    if(statusCode != ErrorCode.SUCCESS){
        throw new TransactionException("TransactionResponse code is 0");
    }

    return  ((RlpString)((RlpList)RlpDecoder.decode(((RlpString)rlpList.get(1)).getBytes())).getValues().get(0)).asPositiveBigInteger();
}
 
Example 3
Source Project: client-sdk-java   Source File: BaseContract.java    License: Apache License 2.0 6 votes vote down vote up
private TransactionResponse getResponseFromTransactionReceipt(TransactionReceipt transactionReceipt) throws TransactionException {
	List<Log> logs = transactionReceipt.getLogs();
       if(logs==null||logs.isEmpty()){
       	 throw new TransactionException("TransactionReceipt logs is empty");
       }

	String logData = logs.get(0).getData();
	if(null == logData || "".equals(logData) ){
		throw new TransactionException("TransactionReceipt log data is empty");
	}

       RlpList rlp = RlpDecoder.decode(Numeric.hexStringToByteArray(logData));
       List<RlpType> rlpList = ((RlpList)(rlp.getValues().get(0))).getValues();
       String decodedStatus = new String(((RlpString)rlpList.get(0)).getBytes());
       int statusCode = Integer.parseInt(decodedStatus);
       
       TransactionResponse transactionResponse = new TransactionResponse();
       transactionResponse.setCode(statusCode);
       transactionResponse.setTransactionReceipt(transactionReceipt);
       
       return transactionResponse;
}
 
Example 4
public static RawTransaction decode(String hexTransaction) {
    byte[] transaction = Numeric.hexStringToByteArray(hexTransaction);
    RlpList rlpList = RlpDecoder.decode(transaction);
    RlpList values = (RlpList) rlpList.getValues().get(0);
    BigInteger nonce = ((RlpString) values.getValues().get(0)).asBigInteger();
    BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asBigInteger();
    BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asBigInteger();
    String to = ((RlpString) values.getValues().get(3)).asString();
    BigInteger value = ((RlpString) values.getValues().get(4)).asBigInteger();
    String data = ((RlpString) values.getValues().get(5)).asString();
    if (values.getValues().size() > 6) {
        byte v = ((RlpString) values.getValues().get(6)).getBytes()[0];
        byte[] r = zeroPadded(((RlpString) values.getValues().get(7)).getBytes(), 32);
        byte[] s = zeroPadded(((RlpString) values.getValues().get(8)).getBytes(), 32);
        Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s);
        return new SignedRawTransaction(nonce, gasPrice, gasLimit,
            to, value, data, signatureData);
    } else {
        return RawTransaction.createTransaction(nonce,
            gasPrice, gasLimit, to, value, data);
    }
}
 
Example 5
Source Project: web3j   Source File: PrivateTransactionEncoder.java    License: Apache License 2.0 6 votes vote down vote up
public static List<RlpType> asRlpValues(
        final RawPrivateTransaction privateTransaction,
        final Sign.SignatureData signatureData) {

    final List<RlpType> result =
            new ArrayList<>(
                    TransactionEncoder.asRlpValues(
                            privateTransaction.asRawTransaction(), signatureData));

    result.add(privateTransaction.getPrivateFrom().asRlp());

    privateTransaction
            .getPrivateFor()
            .ifPresent(privateFor -> result.add(Base64String.unwrapListToRlp(privateFor)));

    privateTransaction.getPrivacyGroupId().map(Base64String::asRlp).ifPresent(result::add);

    result.add(RlpString.create(privateTransaction.getRestriction().getRestriction()));

    return result;
}
 
Example 6
Source Project: client-sdk-java   Source File: TransactionEncoder.java    License: Apache License 2.0 5 votes vote down vote up
static List<RlpType> asRlpValues(
        RawTransaction rawTransaction, Sign.SignatureData signatureData) {
    List<RlpType> result = new ArrayList<>();

    result.add(RlpString.create(rawTransaction.getNonce()));
    result.add(RlpString.create(rawTransaction.getGasPrice()));
    result.add(RlpString.create(rawTransaction.getGasLimit()));

    // an empty to address (contract creation) should not be encoded as a numeric 0 value
    String to = rawTransaction.getTo();
    if (to != null && to.length() > 0) {
        // addresses that start with zeros should be encoded with the zeros included, not
        // as numeric values
        result.add(RlpString.create(Numeric.hexStringToByteArray(to)));
    } else {
        result.add(RlpString.create(""));
    }

    result.add(RlpString.create(rawTransaction.getValue()));

    // value field will already be hex encoded, so we need to convert into binary first
    byte[] data = Numeric.hexStringToByteArray(rawTransaction.getData());
    result.add(RlpString.create(data));

    if (signatureData != null) {
        result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getV())));
        result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getR())));
        result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getS())));
    }

    return result;
}
 
Example 7
Source Project: client-sdk-java   Source File: ContractUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *  Generate a smart contract address. This enables you to identify what address a
 *  smart contract will be deployed to on the network.
 *
 * @param address of sender
 * @param nonce of transaction
 * @return the generated smart contract address
 */
public static byte[] generateContractAddress(byte[] address, BigInteger nonce) {
    List<RlpType> values = new ArrayList<>();

    values.add(RlpString.create(address));
    values.add(RlpString.create(nonce));
    RlpList rlpList = new RlpList(values);

    byte[] encoded = RlpEncoder.encode(rlpList);
    byte[] hashed = Hash.sha3(encoded);
    return Arrays.copyOfRange(hashed, 12, hashed.length);
}
 
Example 8
Source Project: client-sdk-java   Source File: TransactionDecoder.java    License: Apache License 2.0 5 votes vote down vote up
public static RawTransaction decode(String hexTransaction) {
    byte[] transaction = Numeric.hexStringToByteArray(hexTransaction);
    RlpList rlpList = RlpDecoder.decode(transaction);
    RlpList values = (RlpList) rlpList.getValues().get(0);
    BigInteger nonce = ((RlpString) values.getValues().get(0)).asPositiveBigInteger();
    BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asPositiveBigInteger();
    BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asPositiveBigInteger();
    String to = ((RlpString) values.getValues().get(3)).asString();
    BigInteger value = ((RlpString) values.getValues().get(4)).asPositiveBigInteger();
    String data = ((RlpString) values.getValues().get(5)).asString();
    if (values.getValues().size() == 6
            || (values.getValues().size() == 8
                    && ((RlpString) values.getValues().get(7)).getBytes().length == 10)
            || (values.getValues().size() == 9
                    && ((RlpString) values.getValues().get(8)).getBytes().length == 10)) {
        // the 8th or 9nth element is the hex
        // representation of "restricted" for private transactions
        return RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data);
    } else {
        final byte[] v = ((RlpString) values.getValues().get(6)).getBytes();
        final byte[] r =
                Numeric.toBytesPadded(
                        Numeric.toBigInt(((RlpString) values.getValues().get(7)).getBytes()),
                        32);
        final byte[] s =
                Numeric.toBytesPadded(
                        Numeric.toBigInt(((RlpString) values.getValues().get(8)).getBytes()),
                        32);
        final Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s);
        return new SignedRawTransaction(
                nonce, gasPrice, gasLimit, to, value, data, signatureData);
    }
}
 
Example 9
Source Project: client-sdk-java   Source File: TransactionEncoderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEtherTransactionAsRlpValues() {
    List<RlpType> rlpStrings = TransactionEncoder.asRlpValues(createEtherTransaction(),
            new Sign.SignatureData((byte) 0, new byte[32], new byte[32]));
    assertThat(rlpStrings.size(), is(9));
    assertThat(rlpStrings.get(3), equalTo(RlpString.create(new BigInteger("add5355", 16))));
}
 
Example 10
Source Project: client-sdk-java   Source File: TransactionEncoderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testContractAsRlpValues() {
    List<RlpType> rlpStrings = TransactionEncoder.asRlpValues(
            createContractTransaction(), null);
    assertThat(rlpStrings.size(), is(6));
    assertThat(rlpStrings.get(3), is(RlpString.create("")));
}
 
Example 11
Source Project: client-sdk-java   Source File: NodeIdTool.java    License: Apache License 2.0 5 votes vote down vote up
static List<RlpType> asRlpValues(PlatonBlock.Block block) {
    List<RlpType> result = new ArrayList<>();
    //ParentHash  common.Hash    `json:"parentHash"       gencodec:"required"`
    result.add(RlpString.create(decodeHash(block.getParentHash())));
    //Coinbase    common.Address `json:"miner"            gencodec:"required"`
    result.add(RlpString.create(decodeHash(block.getMiner())));
    //Root        common.Hash    `json:"stateRoot"        gencodec:"required"`
    result.add(RlpString.create(decodeHash(block.getStateRoot())));
    //TxHash      common.Hash    `json:"transactionsRoot" gencodec:"required"`
    result.add(RlpString.create(decodeHash(block.getTransactionsRoot())));
    //ReceiptHash common.Hash    `json:"receiptsRoot"     gencodec:"required"`
    result.add(RlpString.create(decodeHash(block.getReceiptsRoot())));
    //Bloom       Bloom          `json:"logsBloom"        gencodec:"required"`
    result.add(RlpString.create(decodeHash(block.getLogsBloom())));
    //Number      *big.Int       `json:"number"           gencodec:"required"`
    result.add(RlpString.create(block.getNumber()));
    //GasLimit    uint64         `json:"gasLimit"         gencodec:"required"`
    result.add(RlpString.create(block.getGasLimit()));
    //GasUsed     uint64         `json:"gasUsed"          gencodec:"required"`
    result.add(RlpString.create(block.getGasUsed()));
    //Time        *big.Int       `json:"timestamp"        gencodec:"required"`
    result.add(RlpString.create(block.getTimestamp()));
    //Extra       []byte         `json:"extraData"        gencodec:"required"`
    result.add(RlpString.create(decodeHash(block.getExtraData().substring(0, 66))));
    //Nonce       BlockNonce     `json:"nonce"`
    result.add(RlpString.create(decodeHash(block.getNonceRaw())));
    return result;
}
 
Example 12
Source Project: client-sdk-java   Source File: EncoderUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static String functionEncoder(Function function){
    List<RlpType> result = new ArrayList<>();

    result.add(RlpString.create(RlpEncoder.encode(RlpString.create(function.getType()))));

    List<Type> parameters = function.getInputParameters();

    if (parameters != null && parameters.size() > 0) {

        for (Type parameter : parameters) {
            if (parameter instanceof IntType) {
                result.add(RlpString.create(RlpEncoder.encode(RlpString.create(((IntType) parameter).getValue()))));
            } else if (parameter instanceof BytesType) {
                result.add(RlpString.create(RlpEncoder.encode(RlpString.create(((BytesType) parameter).getValue()))));
            } else if (parameter instanceof Utf8String) {
                result.add(RlpString.create(RlpEncoder.encode(RlpString.create(((Utf8String) parameter).getValue()))));
            } else if (parameter instanceof CustomStaticArray) {
                result.add(((CustomStaticArray) parameter).getRlpEncodeData());
            } else if (parameter instanceof CustomType) {
                result.add(((CustomType) parameter).getRlpEncodeData());
            }
        }
    }

    String data = Hex.toHexString(RlpEncoder.encode(new RlpList(result)));
    return data;
}
 
Example 13
Source Project: client-sdk-java   Source File: CustomStaticArray.java    License: Apache License 2.0 5 votes vote down vote up
public RlpType getRlpEncodeData() {
    if (list != null ) {
        List<RlpType> rlpListList = new ArrayList<>();
        for (T t : list) {
            rlpListList.add(t.getRlpEncodeData());
        }
        return RlpString.create(RlpEncoder.encode(new RlpList(rlpListList)));
    }
    throw new RuntimeException("unsupported types");
}
 
Example 14
Source Project: client-sdk-java   Source File: RewardContract.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *  获得提取的明细(当提取账户当前所有的可提取的委托奖励成功时调用)
 *
 * @param transactionReceipt
 * @return
 * @throws TransactionException
 */
public List<Reward> decodeWithdrawDelegateRewardLog(TransactionReceipt transactionReceipt) throws TransactionException {
    List<Log> logs = transactionReceipt.getLogs();
    if(logs==null||logs.isEmpty()){
        throw new TransactionException("TransactionReceipt logs is empty");
    }

    String logData = logs.get(0).getData();
    if(null == logData || "".equals(logData) ){
        throw new TransactionException("TransactionReceipt logs[0].data is empty");
    }

    RlpList rlp = RlpDecoder.decode(Numeric.hexStringToByteArray(logData));
    List<RlpType> rlpList = ((RlpList)(rlp.getValues().get(0))).getValues();
    String decodedStatus = new String(((RlpString)rlpList.get(0)).getBytes());
    int statusCode = Integer.parseInt(decodedStatus);

    if(statusCode != ErrorCode.SUCCESS){
        throw new TransactionException("TransactionResponse code is 0");
    }

    List<Reward> rewards = new ArrayList<>();
    ((RlpList)((RlpList)RlpDecoder.decode(((RlpString)rlpList.get(1)).getBytes())).getValues().get(0)).getValues()
            .stream()
            .forEach(rl -> {
                RlpList rlpL = (RlpList)rl;
                Reward reward = new Reward();
                reward.setNodeId(((RlpString)rlpL.getValues().get(0)).asString());
                reward.setStakingNum(((RlpString)rlpL.getValues().get(1)).asPositiveBigInteger());
                reward.setRewardBigIntegerValue((((RlpString)rlpL.getValues().get(2)).asPositiveBigInteger()));
                rewards.add(reward);
            });

    return  rewards;
}
 
Example 15
Source Project: client-sdk-java   Source File: TransferTest.java    License: Apache License 2.0 5 votes vote down vote up
public String sendTransaction(String privateKey, String toAddress, BigDecimal amount, long gasPrice, long gasLimit) {

        BigInteger GAS_PRICE = BigInteger.valueOf(gasPrice);
        BigInteger GAS_LIMIT = BigInteger.valueOf(gasLimit);

        Credentials credentials = Credentials.create(privateKey);

        try {

            List<RlpType> result = new ArrayList<>();
            result.add(RlpString.create(Numeric.hexStringToByteArray(PlatOnTypeEncoder.encode(new Int64(0)))));
            String txType = Hex.toHexString(RlpEncoder.encode(new RlpList(result)));

            RawTransaction rawTransaction = RawTransaction.createTransaction(getNonce(), GAS_PRICE, GAS_LIMIT, toAddress, amount.toBigInteger(),
                    txType);

            byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, new Byte("100"), credentials);
            String hexValue = Numeric.toHexString(signedMessage);

            PlatonSendTransaction transaction = web3j.platonSendRawTransaction(hexValue).send();

            return transaction.getTransactionHash();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
Example 16
static List<RlpType> asRlpValues(
        RawTransaction rawTransaction, Sign.SignatureData signatureData) {
    List<RlpType> result = new ArrayList<>();

    result.add(RlpString.create(rawTransaction.getNonce()));
    result.add(RlpString.create(rawTransaction.getGasPrice()));
    result.add(RlpString.create(rawTransaction.getGasLimit()));

    // an empty to address (contract creation) should not be encoded as a numeric 0 value
    String to = rawTransaction.getTo();
    if (to != null && to.length() > 0) {
        // addresses that start with zeros should be encoded with the zeros included, not
        // as numeric values
        result.add(RlpString.create(Numeric.hexStringToByteArray(to)));
    } else {
        result.add(RlpString.create(""));
    }

    result.add(RlpString.create(rawTransaction.getValue()));

    // value field will already be hex encoded, so we need to convert into binary first
    byte[] data = Numeric.hexStringToByteArray(rawTransaction.getData());
    result.add(RlpString.create(data));

    if (signatureData != null) {
        result.add(RlpString.create(signatureData.getV()));
        result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getR())));
        result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getS())));
    }

    return result;
}
 
Example 17
/**
 *  Generate a smart contract address. This enables you to identify what address a
 *  smart contract will be deployed to on the network.
 *
 * @param address of sender
 * @param nonce of transaction
 * @return the generated smart contract address
 */
public static byte[] generateContractAddress(byte[] address, BigInteger nonce) {
    List<RlpType> values = new ArrayList<>();

    values.add(RlpString.create(address));
    values.add(RlpString.create(nonce));
    RlpList rlpList = new RlpList(values);

    byte[] encoded = RlpEncoder.encode(rlpList);
    byte[] hashed = Hash.sha3(encoded);
    return Arrays.copyOfRange(hashed, 12, hashed.length);
}
 
Example 18
@Test
public void testEtherTransactionAsRlpValues() {
    List<RlpType> rlpStrings = TransactionEncoder.asRlpValues(createEtherTransaction(),
            new Sign.SignatureData((byte) 0, new byte[32], new byte[32]));
    assertThat(rlpStrings.size(), is(9));
    assertThat(rlpStrings.get(3), equalTo(RlpString.create(new BigInteger("add5355", 16))));
}
 
Example 19
@Test
public void testContractAsRlpValues() {
    List<RlpType> rlpStrings = TransactionEncoder.asRlpValues(
            createContractTransaction(), null);
    assertThat(rlpStrings.size(), is(6));
    assertThat(rlpStrings.get(3), is(RlpString.create("")));
}
 
Example 20
Source Project: web3j   Source File: PrivacyGroupUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Base64String generateLegacyGroup(
        final Base64String privateFrom, final List<Base64String> privateFor) {
    final List<byte[]> stringList = new ArrayList<>();
    stringList.add(Base64.getDecoder().decode(privateFrom.toString()));
    privateFor.forEach(item -> stringList.add(item.raw()));

    final List<RlpType> rlpList =
            stringList.stream()
                    .distinct()
                    .sorted(Comparator.comparing(Arrays::hashCode))
                    .map(RlpString::create)
                    .collect(Collectors.toList());

    return Base64String.wrap(Hash.sha3(RlpEncoder.encode(new RlpList(rlpList))));
}
 
Example 21
Source Project: web3j   Source File: TransactionEncoder.java    License: Apache License 2.0 5 votes vote down vote up
public static List<RlpType> asRlpValues(
        RawTransaction rawTransaction, Sign.SignatureData signatureData) {
    List<RlpType> result = new ArrayList<>();

    result.add(RlpString.create(rawTransaction.getNonce()));
    result.add(RlpString.create(rawTransaction.getGasPrice()));
    result.add(RlpString.create(rawTransaction.getGasLimit()));

    // an empty to address (contract creation) should not be encoded as a numeric 0 value
    String to = rawTransaction.getTo();
    if (to != null && to.length() > 0) {
        // addresses that start with zeros should be encoded with the zeros included, not
        // as numeric values
        result.add(RlpString.create(Numeric.hexStringToByteArray(to)));
    } else {
        result.add(RlpString.create(""));
    }

    result.add(RlpString.create(rawTransaction.getValue()));

    // value field will already be hex encoded, so we need to convert into binary first
    byte[] data = Numeric.hexStringToByteArray(rawTransaction.getData());
    result.add(RlpString.create(data));

    // add gas premium and fee cap if this is an EIP-1559 transaction
    if (rawTransaction.isEIP1559Transaction()) {
        result.add(RlpString.create(rawTransaction.getGasPremium()));
        result.add(RlpString.create(rawTransaction.getFeeCap()));
    }

    if (signatureData != null) {
        result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getV())));
        result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getR())));
        result.add(RlpString.create(Bytes.trimLeadingZeroes(signatureData.getS())));
    }

    return result;
}
 
Example 22
Source Project: web3j   Source File: ContractUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Generate a smart contract address. This enables you to identify what address a smart contract
 * will be deployed to on the network.
 *
 * @param address of sender
 * @param nonce of transaction
 * @return the generated smart contract address
 */
public static byte[] generateContractAddress(byte[] address, BigInteger nonce) {
    List<RlpType> values = new ArrayList<>();

    values.add(RlpString.create(address));
    values.add(RlpString.create(nonce));
    RlpList rlpList = new RlpList(values);

    byte[] encoded = RlpEncoder.encode(rlpList);
    byte[] hashed = Hash.sha3(encoded);
    return Arrays.copyOfRange(hashed, 12, hashed.length);
}
 
Example 23
Source Project: web3j   Source File: TransactionDecoder.java    License: Apache License 2.0 5 votes vote down vote up
public static RawTransaction decode(final String hexTransaction) {
    final byte[] transaction = Numeric.hexStringToByteArray(hexTransaction);
    final RlpList rlpList = RlpDecoder.decode(transaction);
    final RlpList values = (RlpList) rlpList.getValues().get(0);
    final BigInteger nonce = ((RlpString) values.getValues().get(0)).asPositiveBigInteger();
    final BigInteger gasPrice = ((RlpString) values.getValues().get(1)).asPositiveBigInteger();
    final BigInteger gasLimit = ((RlpString) values.getValues().get(2)).asPositiveBigInteger();
    final String to = ((RlpString) values.getValues().get(3)).asString();
    final BigInteger value = ((RlpString) values.getValues().get(4)).asPositiveBigInteger();
    final String data = ((RlpString) values.getValues().get(5)).asString();
    if (values.getValues().size() == 6
            || (values.getValues().size() == 8
                    && ((RlpString) values.getValues().get(7)).getBytes().length == 10)
            || (values.getValues().size() == 9
                    && ((RlpString) values.getValues().get(8)).getBytes().length == 10)) {
        // the 8th or 9nth element is the hex
        // representation of "restricted" for private transactions
        return RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data);
    } else {
        final byte[] v = ((RlpString) values.getValues().get(6)).getBytes();
        final byte[] r =
                Numeric.toBytesPadded(
                        Numeric.toBigInt(((RlpString) values.getValues().get(7)).getBytes()),
                        32);
        final byte[] s =
                Numeric.toBytesPadded(
                        Numeric.toBigInt(((RlpString) values.getValues().get(8)).getBytes()),
                        32);
        final Sign.SignatureData signatureData = new Sign.SignatureData(v, r, s);
        return new SignedRawTransaction(
                nonce, gasPrice, gasLimit, to, value, data, signatureData);
    }
}
 
Example 24
Source Project: web3j   Source File: TransactionEncoderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEtherTransactionAsRlpValues() {
    List<RlpType> rlpStrings =
            TransactionEncoder.asRlpValues(
                    createEtherTransaction(),
                    new Sign.SignatureData((byte) 0, new byte[32], new byte[32]));
    assertEquals(rlpStrings.size(), (9));
    assertEquals(rlpStrings.get(3), (RlpString.create(new BigInteger("add5355", 16))));
}
 
Example 25
Source Project: web3j   Source File: TransactionEncoderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testContractAsRlpValues() {
    List<RlpType> rlpStrings =
            TransactionEncoder.asRlpValues(createContractTransaction(), null);
    assertEquals(rlpStrings.size(), (6));
    assertEquals(rlpStrings.get(3), (RlpString.create("")));
}
 
Example 26
Source Project: client-sdk-java   Source File: RestrictingPlan.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public RlpType getRlpEncodeData() {
    return new RlpList(RlpString.create(epoch), RlpString.create(amount));
}
 
Example 27
Source Project: client-sdk-java   Source File: NodeId.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public RlpType getRlpEncodeData() {
    return RlpString.create(Numeric.hexStringToByteArray(nodeId));
}
 
Example 28
Source Project: web3j   Source File: PrivateTransactionDecoder.java    License: Apache License 2.0 4 votes vote down vote up
private static Restriction extractRestriction(final RlpType value) {
    return Restriction.fromString(new String(((RlpString) value).getBytes(), UTF_8));
}
 
Example 29
Source Project: web3j   Source File: PrivateTransactionDecoder.java    License: Apache License 2.0 4 votes vote down vote up
private static Base64String extractBase64(final RlpType value) {
    return Base64String.wrap(((RlpString) value).getBytes());
}
 
Example 30
Source Project: web3j   Source File: Base64String.java    License: Apache License 2.0 4 votes vote down vote up
public RlpString asRlp() {
    return RlpString.create(raw());
}