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

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

Best Java code snippets using com.icodici.universa.contract.Contract.addNewItems (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

Contract createComplexConctract(PrivateKey key,int subcontracts) {
  Contract root = new Contract(key);
  for(int i = 0; i < subcontracts; i++) {
    Contract c = new Contract(key);
    c.getKeysToSignWith().clear();
    root.addNewItems(c);
  }
  root.seal();
  return root;
}
origin: UniversaBlockchain/universa

/**
 * Create a batch contract, which registers all the included contracts, possibily referencing each other,
 * in the single transaction, saving time and reducing U cost. Note that if any of the batched contracts
 * fails, the whole batch is rejected.
 *
 * @param contracts to register all in one batch. Shuld be prepared and sealed.
 * @param keys to sign batch with.
 * @return batch contract that includes all contracts as new items.
 */
public static Contract createBatch(Collection<PrivateKey> keys, Contract... contracts) {
  Contract batch = new Contract();
  batch.setIssuerKeys(keys);
  batch.registerRole(new RoleLink("creator","issuer"));
  batch.registerRole(new RoleLink("owner","issuer"));
  batch.setExpiresAt(ZonedDateTime.now().plusDays(3));
  for(Contract c : contracts) {
    batch.addNewItems(c);
  }
  batch.addSignerKeys(keys);
  batch.seal();
  return batch;
}
origin: UniversaBlockchain/universa

  public TestContracts invoke() throws EncryptionError, Quantiser.QuantiserException {
    r0 = new Contract(TestKeys.privateKey(0));
    r0.seal();
    c = r0.createRevision(TestKeys.privateKey(0));
    n0 = new Contract(TestKeys.privateKey(0));
    n1 = new Contract(TestKeys.privateKey(0));
    c.addNewItems(n0);
    c.addNewItems(n1);
    c.seal();
    return this;
  }
}
origin: UniversaBlockchain/universa

static Contract createComplexConctract(PrivateKey key, int subcontracts, int n) {
  Contract root = createSimpleContract(key);
  for(int i = 0; i < subcontracts; i++) {
    Contract c = createSimpleContract(key);
    c.setExpiresAt(c.getExpiresAt().plusSeconds(i+1+(subcontracts+1)*n));
    c.seal();
    root.addNewItems(c);
  }
  root.setExpiresAt(root.getExpiresAt().plusSeconds((subcontracts+1)*n));
  root.addSignerKey(key);
  root.seal();
  return root;
}
origin: UniversaBlockchain/universa

  @Test
  public void checkTransactionPack() throws Exception {
    Contract r = new Contract(ownerKey1);
    r.seal();

    Contract c = r.createRevision(ownerKey1);
    Contract n = c.split(1)[0];
    n.seal();
    c.seal();
    c.addNewItems(n);

    String path = rootPath + "/testtranspack.unicon";
//        path = "/Users/sergeych/dev/!/e7810197-d148-4936-866b-44daae182e83.transaction";
    c.seal();
    Files.deleteIfExists(Paths.get(path));
    CLIMain.saveContract(c, path, true, true);
//        try (FileOutputStream fs = new FileOutputStream(path)) {
//            fs.write(c.getPackedTransaction());
//            fs.close();
//        }
    callMain("--check", path, "-v");
    System.out.println(output);
  }

origin: UniversaBlockchain/universa

@Test
public void checkWhiteListKey() throws Exception {
  List<Main> mm = new ArrayList<>();
  for (int i = 0; i < 3; i++) {
    mm.add(createMain("node" + (i + 1), false));
  }
  Main main = mm.get(0);
  PrivateKey myKey = TestKeys.privateKey(3);
  Client client = null;
  try {
    client = new Client(myKey, main.myInfo, null);
  } catch (Exception e) {
    System.out.println("prepareClient exception: " + e.toString());
  }
  Contract testContract = new Contract(myKey);
  for (int i = 0; i < 10; i++) {
    Contract nc = new Contract(myKey);
    nc.seal();
    testContract.addNewItems(nc);
  }
  testContract.seal();
  assertTrue(testContract.isOk());
  Parcel parcel = createParcelWithFreshU(client, testContract,Do.listOf(myKey));
  ItemResult itemResult = client.registerParcelWithState(parcel.pack(), 15000);
  System.out.println(">> state: " + itemResult);
  assertEquals (ItemState.APPROVED, itemResult.state);
  mm.forEach(x -> x.shutdown());
}
origin: UniversaBlockchain/universa

@Test
public void dupesWrongTest() throws Exception {
  PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
  Set<PrivateKey> keys = new HashSet<>();
  keys.add(key);
  Contract c_1 = Contract.fromDslFile(rootPath + "coin100.yml");
  c_1.addSignerKey(key);
  c_1.seal();
  assertTrue(c_1.check());
  c_1.traceErrors();
  Contract c_2_1 = ContractsService.createSplit(c_1, new BigDecimal("20"), "amount", keys);
  Contract c_2_2 = c_2_1.getNew().get(0);
  if(c_2_2 != null) {
    Contract c_2_3 = c_2_2.copy();
    c_2_3.addSignerKey(key);
    c_2_3.seal();
    c_2_1.addNewItems(c_2_3);
  }
  assertEquals(2, c_2_1.getNewItems().size());
  c_2_1.check();
  c_2_1.traceErrors();
  assertFalse(c_2_1.isOk());
  // should be BAD_VALUE duplicated revision id
  assertEquals(2, c_2_1.getErrors().size());
}
origin: UniversaBlockchain/universa

@Ignore
@Test
public void testNewContractSeal() throws Exception {
  testSomeWork(() -> {
    for (int i = 0; i < 10; ++i) {
      PrivateKey myKey = null;
      try {
        myKey = TestKeys.privateKey(3);
      } catch (Exception e) {
      }
      Contract testContract = new Contract(myKey);
      for (int iContract = 0; iContract < 10; ++iContract) {
        Contract nc = new Contract(myKey);
        nc.seal();
        testContract.addNewItems(nc);
      }
      testContract.seal();
    }
  });
}
origin: UniversaBlockchain/universa

@Test
public void refMissingField() throws Exception {
  Contract contractA = new Contract(new PrivateKey(2048));
  contractA.getStateData().put("another_val", 100);
  Contract contractB = new Contract(new PrivateKey(2048));
  Reference ref = new Reference();
  ref.type = Reference.TYPE_EXISTING_STATE;
  ref.setConditions(Binder.of(
      Reference.conditionsModeType.all_of.name(),
      asList("ref.state.data.val>-100")
  ));
  contractB.addReference(ref);
  Contract batch = new Contract(new PrivateKey(2048));
  batch.addNewItems(contractA);
  batch.addNewItems(contractB);
  batch.seal();
  Boolean res = batch.check();
  batch.traceErrors();
  assertEquals(false, res);
}
origin: UniversaBlockchain/universa

@Test
public void refLessOrEquals() throws Exception {
  Contract contractA = new Contract(new PrivateKey(2048));
  contractA.getStateData().put("val", 100);
  Contract contractB = new Contract(new PrivateKey(2048));
  Reference ref = new Reference();
  ref.type = Reference.TYPE_EXISTING_STATE;
  ref.setConditions(Binder.of(
      Reference.conditionsModeType.all_of.name(),
      asList("ref.state.data.val<10")
  ));
  contractB.addReference(ref);
  Contract batch = new Contract(new PrivateKey(2048));
  batch.addNewItems(contractA);
  batch.addNewItems(contractB);
  batch.seal();
  Boolean res = batch.check();
  batch.traceErrors();
  assertEquals(false, res);
}
origin: UniversaBlockchain/universa

@Test
public void refMissingFieldHashIdForEquals() throws Exception {
  Contract contractA = new Contract(new PrivateKey(2048));
  contractA.getStateData().put("another_val", 100);
  Contract contractB = new Contract(new PrivateKey(2048));
  Reference ref = new Reference();
  ref.type = Reference.TYPE_EXISTING_STATE;
  ref.setConditions(Binder.of(
      Reference.conditionsModeType.all_of.name(),
      asList("ref.state.data.val!=ref.id",
          "this.id!=ref.state.data.val")
  ));
  contractB.addReference(ref);
  Contract batch = new Contract(new PrivateKey(2048));
  batch.addNewItems(contractA);
  batch.addNewItems(contractB);
  batch.seal();
  Boolean res = batch.check();
  batch.traceErrors();
  assertEquals(false, res);
}
origin: UniversaBlockchain/universa

@Test
public void refMissingFieldDateTimeForEquals() throws Exception {
  Contract contractA = new Contract(new PrivateKey(2048));
  contractA.getStateData().put("another_val", 100);
  Contract contractB = new Contract(new PrivateKey(2048));
  Reference ref = new Reference();
  ref.type = Reference.TYPE_EXISTING_STATE;
  ref.setConditions(Binder.of(
      Reference.conditionsModeType.all_of.name(),
      asList("ref.state.data.val!=ref.definition.created_at",
          "this.definition.created_at!=ref.state.data.val")
  ));
  contractB.addReference(ref);
  Contract batch = new Contract(new PrivateKey(2048));
  batch.addNewItems(contractA);
  batch.addNewItems(contractB);
  batch.seal();
  Boolean res = batch.check();
  batch.traceErrors();
  assertEquals(false, res);
}
origin: UniversaBlockchain/universa

@Test
public void refMissingFieldRoleForEquals() throws Exception {
  Contract contractA = new Contract(new PrivateKey(2048));
  contractA.getStateData().put("another_val", 100);
  Contract contractB = new Contract(new PrivateKey(2048));
  Reference ref = new Reference();
  ref.type = Reference.TYPE_EXISTING_STATE;
  ref.setConditions(Binder.of(
      Reference.conditionsModeType.all_of.name(),
      asList("ref.state.data.val!=ref.issuer",
          "this.issuer!=ref.state.data.val")
  ));
  contractB.addReference(ref);
  Contract batch = new Contract(new PrivateKey(2048));
  batch.addNewItems(contractA);
  batch.addNewItems(contractB);
  batch.seal();
  Boolean res = batch.check();
  batch.traceErrors();
  assertEquals(false, res);
}
origin: UniversaBlockchain/universa

@Test
public void refMissingFieldConstantForEquals() throws Exception {
  Contract contractA = new Contract(new PrivateKey(2048));
  contractA.getStateData().put("another_val", 100);
  Contract contractB = new Contract(new PrivateKey(2048));
  Reference ref = new Reference();
  ref.type = Reference.TYPE_EXISTING_STATE;
  ref.setConditions(Binder.of(
      Reference.conditionsModeType.all_of.name(),
      asList("ref.state.data.val==false",
          "ref.state.data.ival==0",
          "false==ref.state.data.val",
          "0==ref.state.data.ival")
  ));
  contractB.addReference(ref);
  Contract batch = new Contract(new PrivateKey(2048));
  batch.addNewItems(contractA);
  batch.addNewItems(contractB);
  batch.seal();
  Boolean res = batch.check();
  batch.traceErrors();
  assertEquals(false, res);
}
origin: UniversaBlockchain/universa

@Ignore
@Test
public void testContractCheck() throws Exception {
  PrivateKey key = TestKeys.privateKey(3);
  testSomeWork(() ->  {
    try {
      Contract c = new Contract(key);
      for (int k = 0; k < 500; k++) {
        Contract nc = new Contract(key);
        nc.seal();
        c.addNewItems(nc);
      }
      c.seal();
      c.check();
    } catch (Quantiser.QuantiserException e) {
      e.printStackTrace();
    }
  });
}
origin: UniversaBlockchain/universa

@Test
public void checkTestnetNewItemExpirationDateCriteria() throws Exception {
  PrivateKey key = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey"));
  Contract newItem = Contract.fromDslFile(rootPath + "LamborghiniTestDrive.yml");
  newItem.addSignerKey(key);
  sealCheckTrace(newItem, true);
  newItem.setExpiresAt(ZonedDateTime.now().plusMonths(13));
  Contract contract = Contract.fromDslFile(rootPath + "LamborghiniTestDrive.yml");
  contract.addSignerKey(key);
  contract.setExpiresAt(ZonedDateTime.now().plusMonths(1));
  contract.addNewItems(newItem);
  sealCheckTrace(contract, true);
  assertFalse(contract.isSuitableForTestnet());
  // now set contract limited for testnet
  contract.setLimitedForTestnet(true);
  sealCheckTrace(contract, false);
  assertFalse(contract.isSuitableForTestnet());
}
origin: UniversaBlockchain/universa

@Test
public void checkTestnetCostUCriteria() throws Exception {
  PrivateKey key = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey"));
  Contract contract = Contract.fromDslFile(rootPath + "LamborghiniTestDrive.yml");
  contract.setExpiresAt(ZonedDateTime.now().plusMonths(1));
  contract.addSignerKey(key);
  for (int i = 0; i < 100; i++) {
    Contract newItem = Contract.fromDslFile(rootPath + "LamborghiniTestDrive.yml");
    newItem.setExpiresAt(ZonedDateTime.now().plusMonths(1));
    newItem.addSignerKey(key);
    sealCheckTrace(newItem, true);
    contract.addNewItems(newItem);
  }
  sealCheckTrace(contract, true);
  System.out.println("Processing cost is " + contract.getProcessedCostU());
  assertTrue(contract.getProcessedCostU() > Config.maxCostUInTestMode);
  assertFalse(contract.isSuitableForTestnet());
  // now set contract limited for testnet
  contract.setLimitedForTestnet(true);
  sealCheckTrace(contract, false);
  assertFalse(contract.isSuitableForTestnet());
}
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());
}
origin: UniversaBlockchain/universa

transactionRoot.addNewItems(newContract);
Reference rootReference = new Reference(transactionRoot);
rootReference.setName("ref2");
origin: UniversaBlockchain/universa

smartContract.addNewItems(paymentDecreased);
smartContract.seal();
smartContract.check();
com.icodici.universa.contractContractaddNewItems

Javadoc

Add one or more siblings to the contract. Note that those must be sealed before calling #seal() or #getPackedTransaction(). Do not reseal as it changes the id!

Popular methods of Contract

  • <init>
    Extract old, deprecated v2 self-contained binary partially unpacked by the TransactionPack, and fill
  • 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
  • fromPackedTransaction
    Main .unicon read routine. Load any .unicon version and construct a linked Contract with counterpart
  • fromDslFile,
  • fromPackedTransaction,
  • getCreatedAt,
  • getDefinition,
  • getErrors,
  • getKeysToSignWith,
  • getLastSealedBinary,
  • getNew,
  • getNewItems

Popular in Java

  • Updating database using SQL prepared statement
  • scheduleAtFixedRate (ScheduledExecutorService)
  • scheduleAtFixedRate (Timer)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • JFrame (javax.swing)
  • Runner (org.openjdk.jmh.runner)
  • Top 17 Free Sublime Text 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