Skip to content

Instantly share code, notes, and snippets.

@Karasiq
Created July 3, 2020 11:16
Show Gist options
  • Save Karasiq/d23d3ebefb5f7c1899718f2e7ddccab0 to your computer and use it in GitHub Desktop.
Save Karasiq/d23d3ebefb5f7c1899718f2e7ddccab0 to your computer and use it in GitHub Desktop.
scala waves transactions test
import com.wavesplatform.account.Address;
import com.wavesplatform.account.KeyPair;
import com.wavesplatform.common.state.ByteStr;
import com.wavesplatform.lang.script.Script;
import com.wavesplatform.lang.v1.FunctionHeader;
import com.wavesplatform.lang.v1.compiler.Terms;
import com.wavesplatform.lang.v1.estimator.ScriptEstimator;
import com.wavesplatform.state.DataEntry;
import com.wavesplatform.state.IntegerDataEntry;
import com.wavesplatform.state.StringDataEntry;
import com.wavesplatform.transaction.Asset;
import com.wavesplatform.transaction.DataTransaction;
import com.wavesplatform.transaction.smart.InvokeScriptTransaction;
import com.wavesplatform.transaction.smart.SetScriptTransaction;
import com.wavesplatform.transaction.smart.script.ScriptCompiler;
import com.wavesplatform.transaction.transfer.TransferTransaction;
import scala.Option;
import scala.collection.JavaConverters;
import scala.collection.immutable.List$;
import scala.collection.immutable.Map$;
import scala.collection.immutable.Seq;
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
final KeyPair keyPair = KeyPair.apply("test".getBytes());
Address address = Address.fromPublicKey(keyPair.publicKey(), (byte) 'W');
TransferTransaction transfer = TransferTransaction.selfSigned((byte) 1, keyPair, address, Asset.waves(), 100, Asset.waves(), 100, ByteStr.empty(), 100).right().get();
System.out.println(transfer.json().apply().toString());
Seq<DataEntry<?>> entries = JavaConverters.asScala(Arrays.<DataEntry<?>>asList(
new StringDataEntry("test", "test"),
new IntegerDataEntry("test1", 123)
)).toList();
DataTransaction data = DataTransaction.selfSigned((byte) 1, keyPair, entries, 100, 100).right().get();
System.out.println(data.json().apply().toString());
Script script = ScriptCompiler.compile("true", ScriptEstimator.V3(), Map$.MODULE$.empty()).right().get()._1;
SetScriptTransaction setScript = SetScriptTransaction.selfSigned((byte) 1, keyPair, Option.apply(script), 100, 100).right().get();
System.out.println(setScript.json().apply().toString());
Option<Terms.FUNCTION_CALL> functionCall = Option.apply(new Terms.FUNCTION_CALL(new FunctionHeader.User("test", "test"), JavaConverters.asScala(Arrays.<Terms.EXPR>asList(new Terms.CONST_STRING("test"))).toList()));
InvokeScriptTransaction invoke = InvokeScriptTransaction.selfSigned((byte) 1, keyPair, address, functionCall, List$.MODULE$.empty(), 100, Asset.waves(), 100).right().get();
System.out.println(invoke.json().apply().toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment