use of com.novi.bcs.BcsSerializer in project starcoin-java by starcoinorg.
the class Helpers method encode_u8vector_argument.
private static Bytes encode_u8vector_argument(Bytes arg) {
try {
BcsSerializer s = new BcsSerializer();
s.serialize_bytes(arg);
return Bytes.valueOf(s.get_bytes());
} catch (SerializationError e) {
throw new IllegalArgumentException("Unable to serialize argument of type u8vector");
}
}
use of com.novi.bcs.BcsSerializer in project starcoin-java by starcoinorg.
the class BcsSerializeHelper method serializeVectorU8ToBytes.
@SneakyThrows
public static Bytes serializeVectorU8ToBytes(String str) {
BcsSerializer s = new BcsSerializer();
s.serialize_str(str);
return Bytes.valueOf(s.get_bytes());
}
use of com.novi.bcs.BcsSerializer in project starcoin-java by starcoinorg.
the class Helpers method encode_u128_argument.
private static Bytes encode_u128_argument(@Unsigned @Int128 BigInteger arg) {
try {
BcsSerializer s = new BcsSerializer();
s.serialize_u128(arg);
return Bytes.valueOf(s.get_bytes());
} catch (SerializationError e) {
throw new IllegalArgumentException("Unable to serialize argument of type u128");
}
}
use of com.novi.bcs.BcsSerializer in project starcoin-java by starcoinorg.
the class Helpers method encode_u64_argument.
private static Bytes encode_u64_argument(@Unsigned Long arg) {
try {
BcsSerializer s = new BcsSerializer();
s.serialize_u64(arg);
return Bytes.valueOf(s.get_bytes());
} catch (SerializationError e) {
throw new IllegalArgumentException("Unable to serialize argument of type u64");
}
}
use of com.novi.bcs.BcsSerializer in project starcoin-java by starcoinorg.
the class StarcoinClientSample method test.
@SneakyThrows
public void test() {
Long l = 92386324538286L;
System.out.println("u64:" + l + ", after:" + Hex.encode(BcsSerializeHelper.serializeU64ToBytes(l)));
String str = "hello";
System.out.println("string:" + str + ", after:" + Hex.encode(BcsSerializeHelper.serializeVectorU8ToBytes(str)));
BigInteger bigInteger = new BigInteger("500000000000000");
System.out.println("u128:" + bigInteger + ", after:" + Hex.encode(BcsSerializeHelper.serializeU128ToBytes(bigInteger)));
List<String> list = Lists.newArrayList("a", "b", "c");
List<Bytes> bytesList = list.stream().map(s -> {
System.out.println("string:" + s + ",after:" + Hex.encode(BcsSerializeHelper.serializeVectorU8ToBytes(s)));
return BcsSerializeHelper.serializeVectorU8ToBytes(s);
}).collect(Collectors.toList());
BcsSerializer s = new BcsSerializer();
s.serialize_len(bytesList.size());
System.out.println(Hex.encode(s.get_bytes()));
for (Bytes item : bytesList) {
s.serialize_bytes(item);
System.out.println(Hex.encode(s.get_bytes()));
}
System.out.println(Hex.encode(s.get_bytes()));
System.out.println("VectorU8(VectorU8):" + Joiner.on(",").join(list) + ",after:" + Hex.encode(BcsSerializeHelper.serializeListToBytes(list)));
String address = "0xf8af03dd08de49d81e4efd9e24c039cc";
System.out.println("address:" + address + ",after:" + Hex.encode(BcsSerializeHelper.serializeAddressToBytes(AccountAddressUtils.create(address))));
}
Aggregations