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

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

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

@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

/**
 * 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

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

public synchronized static Contract finishSwap(Contract swapContract, Set<PrivateKey> keys) {
  List<Contract> swappingContracts = (List<Contract>) swapContract.getNew();
    boolean willBeMine = c.getOwner().isAllowedForKeys(keys);
      c.addSignatureToSeal(keys);
  swapContract.seal();
  swapContract.addSignatureToSeal(keys);
origin: UniversaBlockchain/universa

@Test
public void checkContractCreatedAtFutureTime() throws Exception{
  Contract futureContract = Contract.fromDslFile(rootPath + "simple_root_contract_future.yml");
  futureContract.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey");
  futureContract.seal();
  futureContract.check();
  futureContract.traceErrors();
  System.out.println("Contract is valid: " + futureContract.isOk());
  assertFalse(futureContract.isOk());
}
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 checkFitTestnetCriteria() 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);
  sealCheckTrace(contract, true);
  System.out.println("Processing cost is " + contract.getProcessedCostU());
  assertTrue(contract.isSuitableForTestnet());
  // now set contract limited for testnet
  contract.setLimitedForTestnet(true);
  sealCheckTrace(contract, true);
  assertTrue(contract.isSuitableForTestnet());
}
origin: UniversaBlockchain/universa

@Test
public void goodNotary() throws Exception {
  Set<PrivateKey> martyPrivateKeys = new HashSet<>();
  Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
  Set<PublicKey> martyPublicKeys = new HashSet<>();
  Set<PublicKey> stepaPublicKeys = new HashSet<>();
  martyPrivateKeys.add(new PrivateKey(Do.read(rootPath + "keys/marty_mcfly.private.unikey")));
  stepaPrivateKeys.add(new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey")));
  for (PrivateKey pk : stepaPrivateKeys)
    stepaPublicKeys.add(pk.getPublicKey());
  for (PrivateKey pk : martyPrivateKeys)
    martyPublicKeys.add(pk.getPublicKey());
  Contract notaryContract = ContractsService.createNotaryContract(martyPrivateKeys, stepaPublicKeys);
  notaryContract.check();
  notaryContract.traceErrors();
  assertTrue(notaryContract.isOk());
  assertTrue(notaryContract.getOwner().isAllowedForKeys(stepaPublicKeys));
  assertTrue(notaryContract.getIssuer().isAllowedForKeys(martyPrivateKeys));
  assertTrue(notaryContract.getCreator().isAllowedForKeys(martyPrivateKeys));
  assertFalse(notaryContract.getOwner().isAllowedForKeys(martyPrivateKeys));
  assertFalse(notaryContract.getIssuer().isAllowedForKeys(stepaPublicKeys));
  assertFalse(notaryContract.getCreator().isAllowedForKeys(stepaPublicKeys));
  assertTrue(notaryContract.getExpiresAt().isAfter(ZonedDateTime.now().plusMonths(3)));
  assertTrue(notaryContract.getCreatedAt().isBefore(ZonedDateTime.now()));
  assertTrue(notaryContract.isPermitted("revoke", stepaPublicKeys));
  assertTrue(notaryContract.isPermitted("revoke", martyPublicKeys));
  assertTrue(notaryContract.isPermitted("change_owner", stepaPublicKeys));
  assertFalse(notaryContract.isPermitted("change_owner", martyPublicKeys));
}
origin: UniversaBlockchain/universa

@Test
public void registerSimpleContractWhite() throws Exception {
  Contract whiteContract = new Contract(TestKeys.privateKey(0));
  whiteContract.seal();
  System.out.println("whiteClient.register(whiteContract)...");
  ItemResult itemResult = whiteClient.register(whiteContract.getPackedTransaction(), 5000);
  System.out.println("whiteClient.register(whiteContract)... done! itemResult: " + itemResult.state);
  itemResult = whiteClient.getState(whiteContract.getId());
  System.out.println("whiteClient.getState(whiteContract): " + itemResult.state);
  assertEquals(ItemState.APPROVED, itemResult.state);
}
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

@Test
public void issuerTest() throws Exception {
  KeyAddress keyAddress1 = TestKeys.privateKey(0).getPublicKey().getShortAddress();
  KeyAddress keyAddress2 = TestKeys.privateKey(1).getPublicKey().getShortAddress();
  Contract contract = new Contract(TestKeys.privateKey(2));
  contract.setCreatorKeys(keyAddress1);
  contract.setIssuerKeys(keyAddress2);
  contract.addSignerKey(TestKeys.privateKey(0));
  contract.seal();
  assertFalse(contract.check());
  contract.setIssuerKeys(keyAddress1);
  contract.getErrors().clear();
  contract.seal();
  assertTrue(contract.check());
}
origin: UniversaBlockchain/universa

@Test
public void registerSimpleContract_getStateOnly() throws Exception {
  Set<PrivateKey> stepaPrivateKeys = new HashSet<>();
  Set<PublicKey> stepaPublicKeys = new HashSet<>();
  stepaPrivateKeys.add(new PrivateKey(Do.read(ROOT_PATH + "keys/stepan_mamontov.private.unikey")));
  for (PrivateKey pk : stepaPrivateKeys) {
    stepaPublicKeys.add(pk.getPublicKey());
  }
  Contract stepaCoins = Contract.fromDslFile(ROOT_PATH + "stepaCoins.yml");
  stepaCoins.addSignerKey(stepaPrivateKeys.iterator().next());
  stepaCoins.seal();
  ItemResult itemResult = nodeClient.getState(stepaCoins.getId());
  System.out.println("nodeClient.getState(stepaCoins): " + itemResult.state);
  assertEquals(ItemState.APPROVED, itemResult.state);
}
origin: UniversaBlockchain/universa

  @Test
  public void goodRevoke() throws Exception {
    Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
    c.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey");
    PrivateKey goodKey = c.getKeysToSignWith().iterator().next();
    c.setOwnerKeys(new KeyRecord(goodKey.getPublicKey()));
    c.seal();

    Contract revokeContract = c.createRevocation(goodKey);

    revokeContract.check();
    assertTrue(revokeContract.isOk());
//        tc.traceErrors();
  }

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

  stepaPublicKeys.add(pk.getPublicKey());
Contract baseContract = Contract.fromDslFile(ROOT_PATH + "DeLoreanOwnership.yml");
PrivateKey manufacturePrivateKey = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
baseContract.addSignerKey(manufacturePrivateKey);
baseContract.seal();
System.out.println("Base contract contract is valid: " + baseContract.isOk());
twoSignContract.addSignatureToSeal(stepaPrivateKeys);
twoSignContract.check();
twoSignContract.traceErrors();
registerAndCheckDeclined(twoSignContract);
twoSignContract.addSignatureToSeal(martyPrivateKeys);
twoSignContract.check();
twoSignContract.traceErrors();
System.out.println("Contract with two signature is valid: " + twoSignContract.isOk());
registerAndCheckApproved(twoSignContract);
origin: UniversaBlockchain/universa

@Test(timeout = 15000)
public void resyncApproved() throws Exception {
  Contract c = new Contract(TestKeys.privateKey(0));
  c.seal();
  addToAllLedgers(c, ItemState.APPROVED);
  node.getLedger().getRecord(c.getId()).destroy();
  assertEquals(ItemState.UNDEFINED, node.checkItem(c.getId()).state);
  node.resync(c.getId());
  assertEquals(ItemState.APPROVED, node.waitItem(c.getId(), 15000).state);
}
origin: UniversaBlockchain/universa

public void asd() throws Exception {
  PrivateKey key = new PrivateKey(Do.read("/Users/romanu/Downloads/ru/roman.uskov.privateKey.unikey"));
  Set<PrivateKey> issuers = new HashSet<>();
  issuers.add(key);
  Set<PublicKey> owners = new HashSet<>();
  owners.add(key.getPublicKey());
  TestSpace testSpace = prepareTestSpace();
  testSpace.nodes.forEach(n->n.config.setIsFreeRegistrationsAllowedFromYaml(true));
  for(int i = 109; i < 110; i++) {
    Contract c = ContractsService.createTokenContract(issuers, owners, new BigDecimal("100000.9"), new BigDecimal("0.01"));
    c.setIssuerKeys(key.getPublicKey().getShortAddress());
    c.setCreatorKeys(key.getPublicKey().getShortAddress());
    c.setExpiresAt(ZonedDateTime.now().plusDays(10));
    c.seal();
    new FileOutputStream("/Users/romanu/Downloads/ru/token"+i+".unicon").write(c.getPackedTransaction());
    assertEquals(testSpace.client.register(Contract.fromPackedTransaction(Do.read("/Users/romanu/Downloads/ru/token"+i+".unicon")).getPackedTransaction(),10000).state,ItemState.APPROVED);
  }
}
origin: UniversaBlockchain/universa

  @Test
  public void checkAnonymizingRole() throws Exception {

    PrivateKey key = new PrivateKey(Do.read(PRIVATE_KEY_PATH));
    Contract contract = createCoin100apiv3();
    contract.addSignerKey(key);
    sealCheckTrace(contract, true);

    assertTrue(contract.getIssuer().getKeys().contains(key.getPublicKey()));

    contract.anonymizeRole("issuer");
    contract.anonymizeRole("owner");
    contract.seal();

    assertFalse(contract.getIssuer().getKeys().contains(key.getPublicKey()));

    Contract anonPublishedContract = new Contract(contract.getLastSealedBinary());

    assertFalse(anonPublishedContract.getIssuer().getKeys().contains(key.getPublicKey()));
//        assertFalse(anonPublishedContract.getSealedByKeys().contains(key.getPublicKey()));
  }

origin: UniversaBlockchain/universa

private Contract basicContractCreation(final String fileName, final String keyFileName, final PrivateKey key) throws Exception {
  Contract c = Contract.fromDslFile(rootPath + fileName);
  c.setOwnerKey(key);
  c.addSignerKeyFromFile(rootPath + keyFileName);
  c.seal();
  c.check();
  c.traceErrors();
  assertTrue(c.check());
  return c;
}
origin: UniversaBlockchain/universa

@Test
public void checkPaymentContract() throws Exception {
  // to register manually, execute from deploy project:
  // bin/sql_all pro "insert into ledger(hash,state,created_at, expires_at, locked_by_id) values(decode('9186C0A9E9471E4559E74B5DAC3DBBB8445807DF80CAE4CE06FDB6588FAEBA1CE004AD378BEF3C445DECF3375E3CA5FD16227DBE5831A21207BB1BD21C85F30D0CED014E152F77E62082E0442FBD9FD2458C20778F7501B5D425AF9984062E54','hex'),'4','1520977039','1552513039','0');"
  // to erase all ledgers, execute:
  // bin/sql_all pro "truncate table ledger"
  // (after erasing ledgers, items still stay in cache -> need to restart (or redeploy) nodes)
  Contract contract = paymentContract;
  contract.check();
  System.out.println("uno bin: " + Base64.encodeString(contract.getPackedTransaction()));
  System.out.println("uno hashId: " + Bytes.toHex(contract.getId().getDigest()).replace(" ", ""));
  System.out.println("approved ord: " + ItemState.APPROVED.ordinal());
  System.out.println("getCreatedAt: " + StateRecord.unixTime(contract.getCreatedAt()));
  System.out.println("getExpiresAt: " + StateRecord.unixTime(contract.getExpiresAt()));
  ItemResult itemResult = normalClient.getState(contract.getId());
  System.out.println("getState... done! itemResult: " + itemResult.state);
}
com.icodici.universa.contractContract

Most used methods

  • <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 12 Jupyter Notebook Extensions
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