Codota Logo
Contract.getState
Code IndexAdd Codota to your IDE (free)

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

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

  • Common ways to obtain Contract
private void myMethod () {
Contract c =
  • Codota Iconnew Contract()
  • Codota IconString fileName;Contract.fromDslFile(fileName)
  • Codota IconParcel parcel;parcel.getPaymentContract()
  • Smart code suggestions by Codota
}
origin: UniversaBlockchain/universa

public void setOrigin(HashId origin) {
  this.c.getState().origin = origin;
}
origin: UniversaBlockchain/universa

private void checkCreateParcelFotTestNet(String contract_file_payload, String contract_file_payment) throws Exception
{
  final String ROOT_PATH = "./src/test_contracts/contractService/";
  PrivateKey privateKey = TestKeys.privateKey(3);
  Set<PrivateKey> privateKeys = new HashSet<>();
  privateKeys.add(privateKey);
  Set<PublicKey> publicKeys = new HashSet<>();
  publicKeys.add(privateKey.getPublicKey());
  Contract payload = Contract.fromDslFile(ROOT_PATH + contract_file_payload);
  payload.addSignerKey(privateKey);
  payload.seal();
  Contract payment = InnerContractsService.createFreshU(100, publicKeys, true);
  Parcel parcel = ContractsService.createParcel(payload, payment, 20, privateKeys, true);
  assertEquals(parcel.getPayloadContract().getState().getBranchId(), payload.getState().getBranchId());
  assertEquals(parcel.getPaymentContract().getState().getBranchId(), payment.getState().getBranchId());
  assertEquals(parcel.getPayloadContract().getStateData(), payload.getStateData());
  assertEquals(parcel.getPaymentContract().getDefinition().getData(), payment.getDefinition().getData());
  assertEquals(100, parcel.getPaymentContract().getStateData().getIntOrThrow("transaction_units"));
  assertEquals(10000 - 20, parcel.getPaymentContract().getStateData().getIntOrThrow("test_transaction_units"));
  System.out.println("OK");
}
origin: UniversaBlockchain/universa

public void setParent(HashId parent) {
  this.c.getState().parent = parent;
}
origin: UniversaBlockchain/universa

private void checkCreateParcel(String contract_file_payload, String contract_file_payment) throws Exception
{
  final String ROOT_PATH = "./src/test_contracts/contractService/";
  PrivateKey privateKey = TestKeys.privateKey(3);
  Contract payload = Contract.fromDslFile(ROOT_PATH + contract_file_payload);
  payload.addSignerKey(privateKey);
  payload.seal();
  Contract payment = Contract.fromDslFile(ROOT_PATH + contract_file_payment);
  payment.addSignerKey(privateKey);
  payment.seal();
  Set<PrivateKey> PrivateKeys = new HashSet<>();
  PrivateKeys.add(privateKey);
  Parcel parcel = ContractsService.createParcel(payload, payment, 20, PrivateKeys);
  assertEquals(parcel.getPayloadContract().getState().getBranchId(), payload.getState().getBranchId());
  assertEquals(parcel.getPaymentContract().getState().getBranchId(), payment.getState().getBranchId());
  assertEquals(parcel.getPayloadContract().getStateData(), payload.getStateData());
  assertEquals(parcel.getPaymentContract().getDefinition().getData(), payment.getDefinition().getData());
  System.out.println("OK");
}
origin: UniversaBlockchain/universa

public int getRevision() {
  return this.currentContract.getState().getRevision();
}
origin: UniversaBlockchain/universa

public List<String> extractJSNames() {
  List<String> res = new ArrayList<>();
  Binder scriptBinder = getDefinition().getData().getBinder(JSAPI_SCRIPT_FIELD, null);
  if (scriptBinder == null)
    scriptBinder = getState().getData().getBinder(JSAPI_SCRIPT_FIELD, null);
  if (scriptBinder != null)
    res.addAll(JSApiHelpers.getFileNamesFromScriptBinder(scriptBinder));
  return res;
}
origin: UniversaBlockchain/universa

@Test(timeout = 90000)
public void checkPayment_originItself() throws Exception {
  Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys());
  final Field field = payment.getState().getClass().getDeclaredField("origin");
  field.setAccessible(true);
  field.set(payment.getState(), payment.getId());
  final Field field2 = payment.getRevoking().get(0).getState().getClass().getDeclaredField("origin");
  field2.setAccessible(true);
  field2.set(payment.getRevoking().get(0).getState(), payment.getId());
  boolean res = payment.paymentCheck(config.getUIssuerKeys());
  payment.traceErrors();
  assertFalse(res);
}
origin: UniversaBlockchain/universa

@Test(timeout = 20000)
public void checkPayment_revision1() throws Exception {
  Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys());
  final Field field = payment.getState().getClass().getDeclaredField("revision");
  field.setAccessible(true);
  field.set(payment.getState(), 1);
  boolean res = payment.paymentCheck(config.getUIssuerKeys());
  payment.traceErrors();
  assertFalse(res);
}
origin: UniversaBlockchain/universa

@Test(timeout = 90000)
public void checkPayment_originMismatch() throws Exception {
  Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys());
  final Field field2 = payment.getRevoking().get(0).getState().getClass().getDeclaredField("origin");
  field2.setAccessible(true);
  field2.set(payment.getRevoking().get(0).getState(), payment.getId());
  boolean res = payment.paymentCheck(config.getUIssuerKeys());
  payment.traceErrors();
  assertFalse(res);
}
origin: UniversaBlockchain/universa

@Test
public void testSharedFolders_write() throws Exception {
  String f1content = "f1 content";
  String f2content = "f2 content";
  String f3content = "f3 content";
  String f4content = "f4 content";
  List<String> sharedFolders = prepareSharedFoldersForTest(f1content, f2content, f3content);
  Paths.get(sharedFolders.get(0) + "/folder2/f4.txt").toFile().delete();
  Paths.get(sharedFolders.get(0) + "/folder2/f4.txt").toFile().getParentFile().delete();
  Contract contract = new Contract(TestKeys.privateKey(0));
  String js = "";
  js += "print('testSharedFolders_write');";
  js += "var file4Content = '"+f4content+"';";
  js += "jsApi.getSharedFolders().writeNewFile('folder2/f4.txt', jsApi.string2bin(file4Content));";
  JSApiExecOptions execOptions = new JSApiExecOptions();
  execOptions.sharedFolders.addAll(sharedFolders);
  contract.getState().setJS(js.getBytes(), "client script.js", new JSApiScriptParameters());
  contract.seal();
  contract.execJS(execOptions, js.getBytes());
  String f4readed = new String(Files.readAllBytes(Paths.get(sharedFolders.get(0) + "/folder2/f4.txt")));
  System.out.println("f4: " + f4readed);
  assertEquals(f4content, f4readed);
}
origin: UniversaBlockchain/universa

public void updateThisEnvironmentByName(Contract newContract, JSApiExecOptions execOptions) throws Exception {
  JSApiEnvironment env = execJSByName(
      newContract.getDefinition().getData().getBinder(Contract.JSAPI_SCRIPT_FIELD, null),
      newContract.getState().getData().getBinder(Contract.JSAPI_SCRIPT_FIELD, null),
      execOptions,
      jsFileName,
      newContract,
      stringParams
  );
  this.jsApi = env.jsApi;
  this.scriptEngine = env.scriptEngine;
  this.currentContract = env.currentContract;
  this.result = env.result;
}
origin: UniversaBlockchain/universa

/**
 * Executes attached javascript if only one js is attached. Also, it should be attached with putContentIntoContract == true.
 */
public Object execJSByName(JSApiExecOptions execOptions, String jsFileName, String... params) throws Exception {
  JSApiEnvironment env = JSApiEnvironment.execJSByName(
      getDefinition().getData().getBinder(JSAPI_SCRIPT_FIELD, null),
      getState().getData().getBinder(JSAPI_SCRIPT_FIELD, null),
      execOptions,
      jsFileName,
      this,
      params
  );
  return env.callEvent("main", true);
}
origin: UniversaBlockchain/universa

/**
 * Executes javascript, like {@link Contract#execJS(JSApiExecOptions, byte[], String...)},
 * but searches script body in contract. It should be saved previously with {@link Definition#setJS(byte[], String, JSApiScriptParameters, boolean)}
 * or {@link State#setJS(byte[], String, JSApiScriptParameters, boolean)} with putContentIntoContract == true.
 * @param scriptHash is {@link HashId} from js-file content.
 */
public Object execJSByScriptHash(JSApiExecOptions execOptions, HashId scriptHash, String... params) throws Exception {
  JSApiEnvironment env = JSApiEnvironment.execJSByScriptHash(
      getDefinition().getData().getBinder(JSAPI_SCRIPT_FIELD, null),
      getState().getData().getBinder(JSAPI_SCRIPT_FIELD, null),
      execOptions,
      scriptHash,
      this,
      params
  );
  return env.callEvent("main", true);
}
origin: UniversaBlockchain/universa

@Test
public void shouldNotSplitWithAnotherRevision() throws Exception {
  Contract c = createCoin();
  c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
  c.getState().setBranchNumber(1);
  try {
    Contract c2 = c.split(1)[0];
    fail("Expected exception to be thrown.");
  } catch (IllegalArgumentException e) {
    assertTrue(e.getMessage().equalsIgnoreCase("this revision is already split"));
  }
}
origin: UniversaBlockchain/universa

@Test
public void testSharedFolders_restrictedPath() throws Exception {
  String f1content = "f1 content";
  String f2content = "f2 content";
  String f3content = "f3 content";
  List<String> sharedFolders = prepareSharedFoldersForTest(f1content, f2content, f3content);
  Contract contract = new Contract(TestKeys.privateKey(0));
  String js = "";
  js += "print('testSharedFolders_restrictedPath');";
  js += "function bin2string(array){var result = '';for(var i = 0; i < array.length; ++i){result+=(String.fromCharCode(array[i]));}return result;}";
  js += "try {";
  js += "  var file3Content = jsApi.getSharedFolders().readAllBytes('../f3.txt');";
  js += "  print('file3Content: ' + bin2string(file3Content));";
  js += "} catch (err) {";
  js += "  result = err;";
  js += "}";
  JSApiExecOptions execOptions = new JSApiExecOptions();
  execOptions.sharedFolders.addAll(sharedFolders);
  contract.getState().setJS(js.getBytes(), "client script.js", new JSApiScriptParameters());
  contract.seal();
  IOException res = (IOException) contract.execJS(execOptions, js.getBytes());
  System.out.println("IOException from js: " + res);
  assertTrue(res.toString().contains("file '../f3.txt' not found in shared folders"));
}
origin: UniversaBlockchain/universa

/**
 * Executes javascript, that previously should be saved in contract's definition
 * with {@link Definition#setJS(byte[], String, JSApiScriptParameters)} or {@link State#setJS(byte[], String, JSApiScriptParameters)}.
 * Provides instance of {@link JSApi} to this script, as 'jsApi' global var.
 * @param params list of strings, will be passed to javascript
 * @return Object, got it from 'result' global var of javascript.
 * @throws ScriptException if javascript throws some errors
 * @throws IllegalArgumentException if javascript is not defined in contract's definition
 */
public Object execJS(JSApiExecOptions execOptions, byte[] jsFileContent, String... params) throws Exception {
  JSApiEnvironment env = JSApiEnvironment.execJS(
      getDefinition().getData().getBinder(JSAPI_SCRIPT_FIELD, null),
      getState().getData().getBinder(JSAPI_SCRIPT_FIELD, null),
      execOptions,
      jsFileContent,
      this,
      params
  );
  env.callEvent("main", true);
  return env.getResult();
}
origin: UniversaBlockchain/universa

@Test
public void shouldSplitAndMergeOne() throws Exception {
  List<Contract> listOfCoinsWithAmount = createListOfCoinsWithAmount(Arrays.asList(100, 200));
  List<Wallet> wallets = Wallet.determineWallets(listOfCoinsWithAmount);
  //want to send 250
  Wallet wallet = wallets.get(0);
  Contract output = wallet.buildContractWithValue("amount", new Decimal(250));
  output.addSignerKeyFromFile(PRIVATE_KEY_PATH);
  sealCheckTrace(output, true);
  Contract contract = wallet.getContracts().get(0);
  sealCheckTrace(contract, true);
  assertEquals("50", contract.getState().getData().get("amount"));
}
origin: UniversaBlockchain/universa

@Test
public void testTransactionalAccess() throws Exception {
  String t1value = "t1value";
  String t2value = "t2value";
  Contract contract = new Contract(TestKeys.privateKey(0));
  contract.getTransactionalData().set("t1", t1value);
  String js = "";
  js += "print('testTransactionalAccess');";
  js += "var t1 = jsApi.getCurrentContract().getTransactionalDataField('t1');";
  js += "print('t1: ' + t1);";
  js += "jsApi.getCurrentContract().setTransactionalDataField('t2', '"+t2value+"');";
  js += "result = t1;";
  contract.getState().setJS(js.getBytes(), "client script.js", new JSApiScriptParameters());
  contract.seal();
  String res = (String)contract.execJS(js.getBytes());
  assertEquals(t1value, res);
  assertEquals(t2value, contract.getTransactionalData().getStringOrThrow("t2"));
  System.out.println("t2: " + contract.getTransactionalData().getStringOrThrow("t2"));
}
origin: UniversaBlockchain/universa

public void parcelAssertions(Parcel equal1, Parcel equal2 ) throws Exception {
  //few assertions
  assertEquals(equal1.getPayload().getContract().getId(), equal2.getPayload().getContract().getId());
  assertEquals(equal1.getPayment().getContract().getId(), equal2.getPayment().getContract().getId());
  assertEquals(equal1.getPayload().getContract().getState().getBranchId(), equal2.getPayload().getContract().getState().getBranchId());
  assertEquals(equal1.getPayment().getContract().getState().getBranchId(), equal2.getPayment().getContract().getState().getBranchId());
  assertEquals(equal1.getPayload().getContract().getState().getCreatedAt().getSecond(), equal2.getPayload().getContract().getState().getCreatedAt().getSecond());
  assertEquals(equal1.getPayment().getContract().getState().getCreatedAt().getSecond(), equal2.getPayment().getContract().getState().getCreatedAt().getSecond());
  assertEquals(equal1.getPayload().getContract().getExpiresAt().getDayOfYear(), equal2.getPayload().getContract().getExpiresAt().getDayOfYear());
  assertEquals(equal1.getPayment().getContract().getExpiresAt().getDayOfYear(), equal2.getPayment().getContract().getExpiresAt().getDayOfYear());
  assertEquals(equal1.getPayload().getSubItems().size(), equal2.getPayload().getSubItems().size());
  assertEquals(equal1.getPayment().getSubItems(), equal2.getPayment().getSubItems());
}
origin: UniversaBlockchain/universa

@Test
public void references() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  String js = "";
  js += "print('references');";
  js += "var ref = jsApi.getReferenceBuilder().createReference('EXISTING_STATE');";
  js += "ref.setConditions({'all_of':['ref.issuer=="+TestKeys.publicKey(1).getShortAddress().toString()+"']});";
  js += "jsApi.getCurrentContract().addReference(ref);";
  contract.getState().setJS(js.getBytes(), "client script.js", new JSApiScriptParameters());
  contract.seal();
  contract = Contract.fromPackedTransaction(contract.getPackedTransaction());
  Contract batchContract = new Contract(TestKeys.privateKey(3));
  batchContract.addNewItems(contract);
  batchContract.seal();
  assertTrue(batchContract.check());
  contract.execJS(new JSApiExecOptions(), js.getBytes());
  contract.seal();
  batchContract.seal();
  assertFalse(batchContract.check());
}
com.icodici.universa.contractContractgetState

Javadoc

Get state of a contract

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

  • Reactive rest calls using spring rest template
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getResourceAsStream (ClassLoader)
  • notifyDataSetChanged (ArrayAdapter)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • TreeMap (java.util)
    A Red-Black tree based NavigableMap implementation. The map is sorted according to the Comparable of
  • DataSource (javax.sql)
    A factory for connections to the physical data source that this DataSource object represents. An alt
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Option (scala)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now