Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.fisco.bcos.sdk.model.TransactionReceipt.Logs;
import org.fisco.bcos.sdk.transaction.model.dto.TransactionResponse;
import org.fisco.bcos.sdk.transaction.model.exception.TransactionException;
import org.fisco.bcos.sdk.transaction.model.po.RawTransaction;

/**
* TransactionDecoderInterface @Description: TransactionDecoderInterface
Expand All @@ -30,6 +31,12 @@
*/
public interface TransactionDecoderInterface {

/**
* @param encodedTx
* @return
*/
RawTransaction decode(byte[] encodedTx);

/**
* parse revert message from receipt
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@
import org.fisco.bcos.sdk.model.RetCode;
import org.fisco.bcos.sdk.model.TransactionReceipt;
import org.fisco.bcos.sdk.model.TransactionReceipt.Logs;
import org.fisco.bcos.sdk.rlp.RlpDecoder;
import org.fisco.bcos.sdk.rlp.RlpList;
import org.fisco.bcos.sdk.rlp.RlpString;
import org.fisco.bcos.sdk.transaction.model.dto.TransactionResponse;
import org.fisco.bcos.sdk.transaction.model.exception.ContractException;
import org.fisco.bcos.sdk.transaction.model.exception.TransactionException;
import org.fisco.bcos.sdk.transaction.model.po.RawTransaction;
import org.fisco.bcos.sdk.transaction.tools.JsonUtils;
import org.fisco.bcos.sdk.transaction.tools.ReceiptStatusUtil;
import org.slf4j.Logger;
Expand Down Expand Up @@ -209,6 +213,57 @@ public Map<String, List<List<Object>>> decodeEvents(String abi, List<Logs> logs)
return result;
}

@Override
public RawTransaction decode(byte[] encodedTx) {
return fromRlpValues(encodedTx);
}

/**
* @param encoded
* @return
*/
public static RawTransaction fromRlpValues(byte[] encoded) {
try {
RlpList rlpList = RlpDecoder.decode(encoded);

RlpList values = (RlpList) (rlpList.getValues().get(0));

RlpString randomID = (RlpString) values.getValues().get(0);
RlpString gasPrice = (RlpString) values.getValues().get(1);
RlpString gasLimit = (RlpString) values.getValues().get(2);
RlpString blockLimit = (RlpString) values.getValues().get(3);
RlpString to = (RlpString) values.getValues().get(4);
RlpString value = (RlpString) values.getValues().get(5);
RlpString data = (RlpString) values.getValues().get(6);
RlpString chainID = (RlpString) values.getValues().get(7);
RlpString groupID = (RlpString) values.getValues().get(8);
RlpString extraData = (RlpString) values.getValues().get(9);
// RlpString signData = (RlpString) rlpList.getValues().get(10);

RawTransaction rawTransaction =
RawTransaction.createTransaction(
randomID.asPositiveBigInteger(),
gasPrice.asPositiveBigInteger(),
gasLimit.asPositiveBigInteger(),
blockLimit.asPositiveBigInteger(),
to.asString(),
value.asPositiveBigInteger(),
data.asString(),
chainID.asPositiveBigInteger(),
groupID.asPositiveBigInteger(),
extraData.asString());

logger.debug(" rawTransaction: {}", rawTransaction);

return rawTransaction;

} catch (Exception e) {
logger.warn(" rawTransaction: {}", e);
}

return null;
}

private String decodeMethodSign(ABIDefinition ABIDefinition) {
List<NamedType> inputTypes = ABIDefinition.getInputs();
StringBuilder methodSign = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ public interface TransactionEncoderInterface {
*/
byte[] encode(RawTransaction rawTransaction, SignatureResult signature);

/**
* @param encodedTx
* @return
*/
RawTransaction decode(byte[] encodedTx);

/**
* Rlp encode and sign based on RawTransaction
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.fisco.bcos.sdk.crypto.keypair.CryptoKeyPair;
import org.fisco.bcos.sdk.crypto.signature.Signature;
import org.fisco.bcos.sdk.crypto.signature.SignatureResult;
import org.fisco.bcos.sdk.rlp.RlpDecoder;
import org.fisco.bcos.sdk.rlp.RlpEncoder;
import org.fisco.bcos.sdk.rlp.RlpList;
import org.fisco.bcos.sdk.rlp.RlpString;
Expand Down Expand Up @@ -80,57 +79,6 @@ public byte[] encode(RawTransaction rawTransaction, SignatureResult signature) {
return RlpEncoder.encode(rlpList);
}

@Override
public RawTransaction decode(byte[] encodedTx) {
return fromRlpValues(encodedTx);
}

/**
* @param encoded
* @return
*/
public static RawTransaction fromRlpValues(byte[] encoded) {
try {;
RlpList rlpList = RlpDecoder.decode(encoded);

RlpList values = (RlpList) (rlpList.getValues().get(0));

RlpString randomID = (RlpString) values.getValues().get(0);
RlpString gasPrice = (RlpString) values.getValues().get(1);
RlpString gasLimit = (RlpString) values.getValues().get(2);
RlpString blockLimit = (RlpString) values.getValues().get(3);
RlpString to = (RlpString) values.getValues().get(4);
RlpString value = (RlpString) values.getValues().get(5);
RlpString data = (RlpString) values.getValues().get(6);
RlpString chainID = (RlpString) values.getValues().get(7);
RlpString groupID = (RlpString) values.getValues().get(8);
RlpString extraData = (RlpString) values.getValues().get(9);
// RlpString signData = (RlpString) rlpList.getValues().get(10);

RawTransaction rawTransaction =
RawTransaction.createTransaction(
randomID.asPositiveBigInteger(),
gasPrice.asPositiveBigInteger(),
gasLimit.asPositiveBigInteger(),
blockLimit.asPositiveBigInteger(),
to.asString(),
value.asPositiveBigInteger(),
data.asString(),
chainID.asPositiveBigInteger(),
groupID.asPositiveBigInteger(),
extraData.asString());

logger.debug(" rawTransaction: {}", rawTransaction);

return rawTransaction;

} catch (Exception e) {
logger.warn(" rawTransaction: {}", e);
}

return null;
}

/**
* Rlp encode and sign based on RawTransaction
*
Expand Down