Tabnine Logo
Contract.execJSByName
Code IndexAdd Tabnine to your IDE (free)

How to use
execJSByName
method
in
com.icodici.universa.contract.Contract

Best Java code snippets using com.icodici.universa.contract.Contract.execJSByName (Showing top 5 results out of 315)

origin: UniversaBlockchain/universa

public Object execJSByName(String jsFileName, String... params) throws Exception {
  return execJSByName(new JSApiExecOptions(), jsFileName, params);
}
origin: UniversaBlockchain/universa

private static void doExecJs() throws Exception {
  String contractFile = (String) options.valueOf("exec-js");
  String scriptName = null;
  if (options.has("script-name"))
    scriptName = (String)options.valueOf("script-name");
  Contract c = Contract.fromPackedTransaction(Files.readAllBytes(Paths.get(contractFile)));
  if(c != null) {
    ItemResult itemResult = getClientNetwork().client.getState(c.getId(), reporter);
    if (itemResult.state == ItemState.APPROVED) {
      if (scriptName != null) {
        c.execJSByName(scriptName);
      }
      else {
        List<String> scriptNames = c.extractJSNames();
        if (scriptNames.size() == 1)
          c.execJSByName(scriptNames.get(0));
        else if (scriptNames.size() > 1)
          report("error: contract has " + scriptNames.size() + " scripts attached, specify script filename please");
        else
          report("error: contract has no scripts attached");
      }
    } else {
      report("error: contract should be approved");
    }
  }
  finish();
}
origin: UniversaBlockchain/universa

@Test
public void jsInStateAndDefinition() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  contract.setOwnerKeys(TestKeys.publicKey(1), TestKeys.publicKey(2), TestKeys.publicKey(3));
  contract.setCreatorKeys(TestKeys.publicKey(4), TestKeys.publicKey(5).getLongAddress());
  String jsDefinitionA = "print('hello world from definition A'); result = 'dA';";
  String jsDefinitionB = "print('hello world from definition B'); result = 'dB';";
  String jsStateA = "print('hello world from state A'); result = 'sA';";
  String jsStateB = "print('hello world from state B'); result = 'sB';";
  contract.getDefinition().setJS(jsDefinitionA.getBytes(), "script1.js", new JSApiScriptParameters(), true);
  contract.getDefinition().setJS(jsDefinitionB.getBytes(), "script2.js", new JSApiScriptParameters(), true);
  contract.getState().setJS(jsStateA.getBytes(), "script3.js", new JSApiScriptParameters(), true);
  contract.getState().setJS(jsStateB.getBytes(), "script4.js", new JSApiScriptParameters(), true);
  contract.seal();
  String res1 = (String)contract.execJSByName("script1.js");
  String res2 = (String)contract.execJSByName("script2.js");
  String res3 = (String)contract.execJSByName("script3.js");
  String res4 = (String)contract.execJSByName("script4.js");
  assertEquals("dA", res1);
  assertEquals("dB", res2);
  assertEquals("sA", res3);
  assertEquals("sB", res4);
}
origin: UniversaBlockchain/universa

httpClientContract.seal();
httpClientContract = Contract.fromPackedTransaction(httpClientContract.getPackedTransaction());
ScriptObjectMirror res = (ScriptObjectMirror)httpClientContract.execJSByName("client script.js");
System.out.println("res0: " + res.get("0"));
System.out.println("res1: " + res.get("1"));
origin: UniversaBlockchain/universa

@Test
public void jsFileContentInContract_byFilename() throws Exception {
  String fileName = "somescript.zip";
  String scriptDump = "UEsDBBQAAgAIAEGVA02XbF8YbAEAAPoEAAANAAAAc29tZXNjcmlwdC5qc62UXU+DMBSG7038D9yVRUOckTk1XkzmzMiY+xJ0y7JU6KATKLYF9vNlyj6cUtR42/O+z3vSntOI4pDLwEO+T6SUUN8BlavDgwRSyY4pRSHXSMgptLl0LS1YI8KKi7j2uSSvLNEHac+1UrcduXIpAelIKiiK7QOUYIZJKIBsJWKURhHkyGlwAWtHI4bdU+xiUVdrgRjTg6sTAWYtEGOGPOu6CTlsYeQ7MiMBmiXQj1ExeM8Cth7whzAPMm+GnV/G5a6ywCaa4xDz7Il3Um2KI86KA78zgdxVFthmLEZUNLe5oGRG0lBIyes/mFpCy2aW7IGg73/Rsk2koijvm16omIAxZNyKrG7PeE1MvWEQmxkPI909U3G9QzTVYAE97/CLW6jrg9Q8XZrgWAKwypbewuF3XhctcH1o6d3eS2qqQc1xrTnt34Qebiyf++l4VHtSW+yxCab/dokUsdjffFXZ5sCATU6mmW/3oDrNpG9QSwECFAAUAAIACABBlQNNl2xfGGwBAAD6BAAADQAAAAAAAAAAACAAAAAAAAAAc29tZXNjcmlwdC5qc1BLBQYAAAAAAQABADsAAACXAQAAAAA=";
  Contract contract = new Contract(TestKeys.privateKey(0));
  contract.getStateData().set("some_value", HashId.createRandom().toBase64String());
  contract.getStateData().set("some_hash_id", HashId.createRandom());
  JSApiScriptParameters scriptParameters = new JSApiScriptParameters();
  scriptParameters.isCompressed = true;
  contract.getDefinition().setJS(Base64.decodeLines(scriptDump), fileName, scriptParameters, true);
  contract.seal();
  String res = (String)contract.execJSByName("somescript.zip", "3", "6");
  System.out.println("res: " + res);
  assertEquals("36", res);
  String compression = contract.getDefinition().getData().getOrThrow("scripts", JSApiHelpers.fileName2fileKey(fileName), "compression");
  System.out.println("compression: " + compression);
  assertEquals(JSApiCompressionEnum.ZIP, JSApiCompressionEnum.valueOf(compression));
}
com.icodici.universa.contractContractexecJSByName

Javadoc

Executes attached javascript if only one js is attached. Also, it should be attached with putContentIntoContract == true.

Popular methods of Contract

  • <init>
    Extract old, deprecated v2 self-contained binary partially unpacked by the TransactionPack, and fill
  • addNewItems
    Add one or more siblings to the contract. Note that those must be sealed before calling #seal() or #
  • addSignerKey
    Add private key to keys contract binary to be signed with when sealed next time. It is called before
  • getExpiresAt
    Get contract expiration time
  • getId
    Get the id sealing self if need
  • getPackedTransaction
    Pack the contract to the most modern .unicon format, same as TransactionPack#pack(). Uses bounded Tr
  • registerRole
    Register new role. Name must be unique otherwise existing role will be overwritten
  • seal
    Seal contract to binary. This call adds signatures from #getKeysToSignWith()
  • addSignatureToSeal
    Add signature to sealed (before) contract. Do not deserializing or changing contract bytes, but will
  • check
  • createRevision
    Create new revision to be changed, signed sealed and then ready to approve. Created "revision" contr
  • fromDslFile
    Create contract importing its parameters with passed .yaml file. No signatures are added automatical
  • createRevision,
  • fromDslFile,
  • fromPackedTransaction,
  • getCreatedAt,
  • getDefinition,
  • getErrors,
  • getKeysToSignWith,
  • getLastSealedBinary,
  • getNew,
  • getNewItems

Popular in Java

  • Running tasks concurrently on multiple threads
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getContentResolver (Context)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now