com.github.DNAProject.smartcontract.nativevm.abi.NativeBuildParams Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2018 The DNA Authors
* This file is part of The DNA library.
*
* The DNA is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The DNA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with The DNA. If not, see .
*
*/
package com.github.DNAProject.smartcontract.nativevm.abi;
import com.alibaba.fastjson.JSON;
import com.github.DNAProject.common.*;
import com.github.DNAProject.core.dnaid.Attribute;
import com.github.DNAProject.core.scripts.ScriptBuilder;
import com.github.DNAProject.core.scripts.ScriptOp;
import com.github.DNAProject.io.BinaryWriter;
import com.github.DNAProject.sdk.exception.SDKException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
public class NativeBuildParams {
public static byte[] buildParams(Object ...params) throws SDKException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryWriter bw = new BinaryWriter(baos);
try {
for (Object param : params) {
if(param instanceof Integer){
bw.writeInt(((Integer) param).intValue());
}else if(param instanceof byte[]){
bw.writeVarBytes((byte[])param);
}else if(param instanceof String){
bw.writeVarString((String) param);
}else if(param instanceof Attribute[]){
bw.writeSerializableArray((Attribute[])param);
}else if(param instanceof Attribute){
bw.writeSerializable((Attribute)param);
}else if(param instanceof Address){
bw.writeSerializable((Address)param);
}else {
throw new SDKException(ErrorCode.WriteVarBytesError);
}
}
} catch (IOException e) {
throw new SDKException(ErrorCode.WriteVarBytesError);
}
return baos.toByteArray();
}
private static byte[] createCodeParamsScript(ScriptBuilder builder, List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy