Search in sources :

Example 6 with BcsSerializer

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");
    }
}
Also used : BcsSerializer(com.novi.bcs.BcsSerializer)

Example 7 with BcsSerializer

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());
}
Also used : BcsSerializer(com.novi.bcs.BcsSerializer) SneakyThrows(lombok.SneakyThrows)

Example 8 with BcsSerializer

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");
    }
}
Also used : BcsSerializer(com.novi.bcs.BcsSerializer)

Example 9 with BcsSerializer

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");
    }
}
Also used : BcsSerializer(com.novi.bcs.BcsSerializer)

Example 10 with BcsSerializer

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))));
}
Also used : TypeObj(org.starcoin.bean.TypeObj) SneakyThrows(lombok.SneakyThrows) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) BigDecimal(java.math.BigDecimal) BcsSerializer(com.novi.bcs.BcsSerializer) Ed25519PrivateKey(org.starcoin.types.Ed25519PrivateKey) List(java.util.List) JSON(com.alibaba.fastjson.JSON) Lists(com.google.common.collect.Lists) Bytes(com.novi.serde.Bytes) ScriptFunctionObj(org.starcoin.bean.ScriptFunctionObj) JSONObject(com.alibaba.fastjson.JSONObject) ResourceObj(org.starcoin.bean.ResourceObj) BigInteger(java.math.BigInteger) AccountAddress(org.starcoin.types.AccountAddress) Joiner(com.google.common.base.Joiner) RoundingMode(java.math.RoundingMode) BcsSerializer(com.novi.bcs.BcsSerializer) Bytes(com.novi.serde.Bytes) BigInteger(java.math.BigInteger) SneakyThrows(lombok.SneakyThrows)

Aggregations

BcsSerializer (com.novi.bcs.BcsSerializer)10 SneakyThrows (lombok.SneakyThrows)5 Bytes (com.novi.serde.Bytes)2 BigInteger (java.math.BigInteger)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 AccountAddress (org.starcoin.types.AccountAddress)2 JSON (com.alibaba.fastjson.JSON)1 JSONObject (com.alibaba.fastjson.JSONObject)1 Joiner (com.google.common.base.Joiner)1 Lists (com.google.common.collect.Lists)1 BigDecimal (java.math.BigDecimal)1 RoundingMode (java.math.RoundingMode)1 Objects (java.util.Objects)1 Test (org.junit.Test)1 ResourceObj (org.starcoin.bean.ResourceObj)1 ScriptFunctionObj (org.starcoin.bean.ScriptFunctionObj)1 TypeObj (org.starcoin.bean.TypeObj)1 Ed25519PrivateKey (org.starcoin.types.Ed25519PrivateKey)1