congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
Contract.getStateData
Code IndexAdd Tabnine to your IDE (free)

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

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

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
List l =
  • Codota Iconnew ArrayList()
  • Codota Iconnew LinkedList()
  • Smart code suggestions by Tabnine
}
origin: UniversaBlockchain/universa

private boolean checkContractCorrespondsToConfig(Contract contract, List<NodeInfo> netNodes) {
  //check if contract contains net config
  if(!checkIfContractContainsNetConfig(contract)) {
    return false;
  }
  //check if net config equals to current network configuration
  List<NodeInfo> contractNodes = DefaultBiMapper.getInstance().deserializeObject(contract.getStateData().get("net_config"));
  if(contractNodes.size() != netNodes.size() || !contractNodes.stream().allMatch(nodeInfo -> netNodes.contains(nodeInfo))) {
    return false;
  }
  return true;
}
origin: UniversaBlockchain/universa

private Decimal getValue(Contract c, String fieldName) {
  return new Decimal(c.getStateData().getStringOrThrow(fieldName));
}
origin: UniversaBlockchain/universa

@Test
public void shouldModifyStateDataValues() throws  Exception {
  Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2);
  Binder d = c.getStateData();
  Contract c1 = c.createRevision(ownerKey2);
  Binder d1 = c1.getStateData();
  final String oldValue = "An example of smart contract.";
  final String newValue = "UniversaSmartContract";
  final String field = "description";
  setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
  sealCheckTrace(c1, true);
}
origin: UniversaBlockchain/universa

@Test
public void shouldModifyAnyValueForKey() throws  Exception {
  Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2);
  Binder d = c.getStateData();
  Contract c1 = c.createRevision(ownerKey2);
  Binder d1 = c1.getStateData();
  final String oldValue = "35";
  final String newValue = "303434935245";
  final String field = "units";
  setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
  sealCheckTrace(c1, true);
}
origin: UniversaBlockchain/universa

  public Contract createUnsPayment() throws IOException {

    PrivateKey ownerKey = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey"));
    Set<PublicKey> keys = new HashSet();
    keys.add(ownerKey.getPublicKey());
    Contract stepaU = InnerContractsService.createFreshU(100000000, keys);
    Contract paymentDecreased = stepaU.createRevision(ownerKey);
    paymentDecreased.getStateData().set("transaction_units", stepaU.getStateData().getIntOrThrow("transaction_units") - 2000);
    paymentDecreased.seal();

    return paymentDecreased;
  }
}
origin: UniversaBlockchain/universa

  public Contract createSlotPayment() throws IOException {

    PrivateKey ownerKey = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey"));
    Set<PublicKey> keys = new HashSet();
    keys.add(ownerKey.getPublicKey());
    Contract stepaU = InnerContractsService.createFreshU(100000000, keys);
    Contract paymentDecreased = stepaU.createRevision(ownerKey);
    paymentDecreased.getStateData().set("transaction_units", stepaU.getStateData().getIntOrThrow("transaction_units") - 100);
    paymentDecreased.seal();

    return paymentDecreased;
  }
}
origin: UniversaBlockchain/universa

@Test
public void shouldPopulateWithEmptyStateDataValues() throws  Exception {
  PrivateKey ownerKey2 = TestKeys.privateKey(1);
  Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2);
  Binder d = c.getStateData();
  Contract c1 = c.createRevision(ownerKey2);
  Binder d1 = c1.getStateData();
  final String oldValue = "An example of smart contract.";
  final String newValue = "";
  final String field = "description";
  setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
  sealCheckTrace(c1, true);
}
origin: UniversaBlockchain/universa

@Test
public void shouldModifyDescNullStateDataValues() throws  Exception {
  PrivateKey ownerKey2 = TestKeys.privateKey(1);
  Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2);
  Binder d = c.getStateData();
  Contract c1 = c.createRevision(ownerKey2);
  Binder d1 = c1.getStateData();
  final String oldValue = "An example of smart contract.";
  final String newValue = null;
  final String field = "description";
  setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
  sealCheckTrace(c1, true);
}
origin: UniversaBlockchain/universa

@Test
public void shouldNotModifyStateDataValues() throws  Exception {
  PrivateKey ownerKey2 = TestKeys.privateKey(1);
  Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2);
  Binder d = c.getStateData();
  Contract c1 = c.createRevision(ownerKey2);
  Binder d1 = c1.getStateData();
  final String oldValue = "1";
  final String newValue = "2";
  final String field = "option";
  setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
  sealCheckTrace(c1, false);
}
origin: UniversaBlockchain/universa

@Test
public void shouldNotPopulateWithNullStateDataValues() throws  Exception {
  PrivateKey ownerKey2 = TestKeys.privateKey(1);
  Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2);
  Binder d = c.getStateData();
  Contract c1 = c.createRevision(ownerKey2);
  Binder d1 = c1.getStateData();
  final String oldValue = "2";
  final String newValue = null;
  final String field = "direction";
  setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
  sealCheckTrace(c1, false);
}
origin: UniversaBlockchain/universa

@Test
public void shouldNotPopulateWithEmptyStateDataValues() throws  Exception {
  PrivateKey ownerKey2 = TestKeys.privateKey(1);
  Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2);
  Binder d = c.getStateData();
  Contract c1 = c.createRevision(ownerKey2);
  Binder d1 = c1.getStateData();
  final String oldValue = "2";
  final String newValue = "";
  final String field = "direction";
  setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
  sealCheckTrace(c1, false);
}
origin: UniversaBlockchain/universa

@Test
public void shouldNotModifyDescEmptyStateDataValues() throws  Exception {
  PrivateKey ownerKey2 = TestKeys.privateKey(1);
  Contract c = basicContractCreation(SUBSCRIPTION_WITH_DATA, PRIVATE_KEY, ownerKey2);
  Binder d = c.getStateData();
  Contract c1 = c.createRevision(ownerKey2);
  Binder d1 = c1.getStateData();
  final String oldValue = "An example of smart contract.";
  final String newValue = "wrong value.";
  final String field = "description";
  setAndCheckOldNewValues(d, d1, oldValue, newValue, field);
  sealCheckTrace(c1, false);
}
origin: UniversaBlockchain/universa

@Test(timeout = 90000)
public void checkPayment_wrongUname() throws Exception {
  Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys());
  payment.getStateData().set("transaction_units", payment.getStateData().get("transaction_units"));
  payment.getStateData().remove("transaction_units");
  boolean res = payment.paymentCheck(config.getUIssuerKeys());
  payment.traceErrors();
  assertFalse(res);
}
origin: UniversaBlockchain/universa

private List<Contract> createListOfCoinsWithAmount(List<String> values) throws Exception {
  Contract money = createCoin();
  money.getStateData().set(FIELD_NAME, new Decimal(100500));
  money.addSignerKeyFromFile(PRIVATE_KEY_PATH);
  money.seal();
  sealCheckTrace(money, true);
  List<Contract> res = new ArrayList<>();
  for (String value : values) {
    Contract contract = ContractsService.createSplit(money, new BigDecimal(value), FIELD_NAME, new HashSet<PrivateKey>());
    contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
    res.add(contract.getNew().get(0));
  }
  return res;
}
origin: UniversaBlockchain/universa

  protected Contract createCoinWithAmount(String amount, String fieldName) throws Exception {
    Contract contract = createCoin();
    contract.getStateData().set(fieldName, new Decimal(amount));
    contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);

    sealCheckTrace(contract, true);

    return contract;
  }
}
origin: UniversaBlockchain/universa

@Test
public void cheatCreateValue2() throws Exception {
  Contract c = createCoin();
  c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
  Binder d = c.getStateData();
  int a = 1000000;
  assertEquals(a, d.getIntOrThrow(FIELD_NAME));
  c.seal();
  assertTrue(c.check());
  Contract c1 = c.createRevision(ownerKey2);
  c1.getStateData().set(FIELD_NAME, "500.00000001");
  sealCheckTrace(c1, false);
}
origin: UniversaBlockchain/universa

@Test(timeout = 90000)
public void checkPayment_wrongUtype() throws Exception {
  Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys());
  payment.getStateData().set("transaction_units", "33");
  boolean res = payment.paymentCheck(config.getUIssuerKeys());
  payment.traceErrors();
  assertFalse(res);
}
origin: UniversaBlockchain/universa

@Test(timeout = 90000)
public void checkPayment_minusU() throws Exception {
  Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys());
  payment.getStateData().set("transaction_units", -1);
  boolean res = payment.paymentCheck(config.getUIssuerKeys());
  payment.traceErrors();
  assertFalse(res);
}
origin: UniversaBlockchain/universa

@Test
public void defaultParameters() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  contract.getStateData().put("field1", "33.000000000000000001");
  ChangeNumberPermission changeNumberPermission = new ChangeNumberPermission(contract.getRole("owner"), Binder.of("field_name", "field1"));
  contract.addPermission(changeNumberPermission);
  contract.seal();
  Contract changed = contract.createRevision();
  changed.addSignerKey(TestKeys.privateKey(0));
  changed.getStateData().set("field1", "33.000000000000000002");
  changed.seal();
  changed.check();
  assertTrue(changed.isOk());
}
origin: UniversaBlockchain/universa

@Test
public void modifyDataDeclined() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  contract.getStateData().put("field_to_be_changed", "value1");
  ModifyDataPermission modifyDataPermission = new ModifyDataPermission(contract.getRole("owner"), new Binder());
  contract.addPermission(modifyDataPermission);
  contract.seal();
  Contract changed = contract.createRevision();
  changed.addSignerKey(TestKeys.privateKey(0));
  changed.getStateData().set("field_to_be_changed", "value2");
  changed.seal();
  changed.check();
  assertTrue(!changed.isOk());
}
com.icodici.universa.contractContractgetStateData

Javadoc

Get data section of contract state

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

  • Updating database using SQL prepared statement
  • addToBackStack (FragmentTransaction)
  • onCreateOptionsMenu (Activity)
  • startActivity (Activity)
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Top 15 Vim Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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