use of org.fisco.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.
the class RevertResolver method tryResolveRevertMessage.
/**
* @param status
* @param output
* @return
*/
public static Tuple2<Boolean, String> tryResolveRevertMessage(String status, String output) {
if (!hasRevertMessage(status, output)) {
return new Tuple2<>(false, null);
}
try {
// 00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030497373756572526f6c653a2063616c6c657220646f6573206e6f742068617665207468652049737375657220726f6c6500000000000000000000000000000000
String rawOutput = Numeric.containsHexPrefix(output) ? output.substring(RevertMethodWithHexPrefix.length()) : output.substring(RevertMethod.length());
List<Type> result = FunctionReturnDecoder.decode(rawOutput, revertFunction.getOutputParameters());
if (result.get(0) instanceof Utf8String) {
String message = ((Utf8String) result.get(0)).getValue();
if (logger.isDebugEnabled()) {
logger.debug(" ABI: {} , RevertMessage: {}", output, message);
}
return new Tuple2<>(true, message);
}
} catch (Exception e) {
logger.warn(" ABI: {}, e: {}", output, e);
}
return new Tuple2<>(false, null);
}
use of org.fisco.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.
the class EvidenceVerify method getInsertEvidenceInput.
public Tuple8<String, String, String, String, byte[], BigInteger, byte[], byte[]> getInsertEvidenceInput(TransactionReceipt transactionReceipt) {
String data = transactionReceipt.getInput().substring(10);
final Function function = new Function(FUNC_INSERTEVIDENCE, Arrays.<Type>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
}, new TypeReference<Utf8String>() {
}, new TypeReference<Utf8String>() {
}, new TypeReference<Address>() {
}, new TypeReference<Bytes32>() {
}, new TypeReference<Uint8>() {
}, new TypeReference<Bytes32>() {
}, new TypeReference<Bytes32>() {
}));
List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
;
return new Tuple8<String, String, String, String, byte[], BigInteger, byte[], byte[]>((String) results.get(0).getValue(), (String) results.get(1).getValue(), (String) results.get(2).getValue(), (String) results.get(3).getValue(), (byte[]) results.get(4).getValue(), (BigInteger) results.get(5).getValue(), (byte[]) results.get(6).getValue(), (byte[]) results.get(7).getValue());
}
use of org.fisco.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.
the class ResultEntity method typeToObject.
public static Object typeToObject(Type type) {
Object obj = null;
if (type instanceof NumericType) {
// uint int
obj = ((NumericType) type).getValue();
} else if (type instanceof Bool) {
// bool
obj = ((Bool) type).getValue();
} else if (type instanceof Address) {
// address
obj = type.toString();
} else if (type instanceof Bytes) {
// bytes32
obj = new String(((Bytes) type).getValue()).trim();
} else if (type instanceof DynamicBytes) {
// bytes
obj = new String(((DynamicBytes) type).getValue()).trim();
} else if (type instanceof Utf8String) {
// string
obj = ((Utf8String) type).getValue();
} else if (type instanceof Array) {
// T[] T[k]
List<Object> r = new ArrayList<Object>();
List l = ((Array) type).getValue();
for (int i = 0; i < l.size(); ++i) {
r.add(typeToObject((Type) l.get(i)));
}
obj = (Object) r;
} else {
obj = (Object) obj;
}
return obj;
}
use of org.fisco.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.
the class ABICodecJsonWrapper method encodeNode.
private ABIObject encodeNode(String path, ABIObject template, JsonNode node) {
ABIObject abiObject = template.newObject();
switch(abiObject.getType()) {
case VALUE:
{
if (!node.isValueNode()) {
errorReport(path, abiObject.getType().toString(), node.getNodeType().toString());
}
switch(template.getValueType()) {
case BOOL:
{
if (!node.isBoolean()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
abiObject.setBoolValue(new Bool(node.asBoolean()));
break;
}
case INT:
{
if (!node.isNumber() && !node.isBigInteger()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
if (node.isNumber()) {
abiObject.setNumericValue(new Int256(node.asLong()));
} else {
abiObject.setNumericValue(new Int256(node.bigIntegerValue()));
}
break;
}
case UINT:
{
if (!node.isNumber() && !node.isBigInteger()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
if (node.isNumber()) {
abiObject.setNumericValue(new Uint256(node.asLong()));
} else {
abiObject.setNumericValue(new Uint256(node.bigIntegerValue()));
}
break;
}
case ADDRESS:
{
if (!node.isTextual()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
try {
abiObject.setAddressValue(new Address(node.asText()));
} catch (Exception e) {
errorReport(path, "Invalid address, address value: " + node.asText());
}
break;
}
case BYTES:
{
if (!node.isTextual()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
// Binary data requires base64 encoding
byte[] bytesValue = Base64.getDecoder().decode(node.asText());
abiObject.setBytesValue(new Bytes(bytesValue.length, bytesValue));
break;
}
case DBYTES:
{
if (!node.isTextual()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
byte[] bytesValue = Base64.getDecoder().decode(node.asText());
abiObject.setDynamicBytesValue(new DynamicBytes(bytesValue));
break;
}
case STRING:
{
if (!node.isTextual()) {
errorReport(path, template.getValueType().toString(), node.getNodeType().toString());
}
abiObject.setStringValue(new Utf8String(node.asText()));
break;
}
}
break;
}
case LIST:
{
if (!node.isArray()) {
errorReport(path, abiObject.getType().toString(), node.getNodeType().toString());
}
if ((abiObject.getListType() == ListType.FIXED) && (node.size() != abiObject.getListLength())) {
errorReport("fixed list arguments size", String.valueOf(abiObject.getListLength()), String.valueOf(node.size()));
}
int i = 0;
Iterator<JsonNode> iterator = node.iterator();
while (iterator.hasNext()) {
abiObject.getListValues().add(encodeNode(path + ".<" + String.valueOf(i) + ">", abiObject.getListValueType(), iterator.next()));
}
break;
}
case STRUCT:
{
if (!node.isArray() && !node.isObject()) {
errorReport(path, abiObject.getType().toString(), node.getNodeType().toString());
}
if (node.size() != abiObject.getStructFields().size()) {
errorReport("struct arguments size", String.valueOf(abiObject.getListLength()), String.valueOf(node.size()));
}
if (node.isArray()) {
for (int i = 0; i < abiObject.getStructFields().size(); i++) {
ABIObject field = abiObject.getStructFields().get(i);
abiObject.getStructFields().set(i, encodeNode(path + "." + field.getName(), field, node.get(i)));
}
} else {
for (int i = 0; i < abiObject.getStructFields().size(); ++i) {
ABIObject field = abiObject.getStructFields().get(i);
JsonNode structNode = node.get(field.getName());
if (structNode == null) {
errorReport(path, " Missing struct field, field name: " + field.getName());
}
abiObject.getStructFields().set(i, encodeNode(path + "." + field.getName(), field, structNode));
}
}
break;
}
}
return abiObject;
}
use of org.fisco.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.
the class Permission method getInsertInput.
public Tuple2<String, String> getInsertInput(TransactionReceipt transactionReceipt) {
String data = transactionReceipt.getInput().substring(10);
final Function function = new Function(FUNC_INSERT, Arrays.<Type>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
}, new TypeReference<Utf8String>() {
}));
List<Type> results = FunctionReturnDecoder.decode(data, function.getOutputParameters());
;
return new Tuple2<String, String>((String) results.get(0).getValue(), (String) results.get(1).getValue());
}
Aggregations