Tabnine Logo
Contract.<init>
Code IndexAdd Tabnine to your IDE (free)

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

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

origin: UniversaBlockchain/universa

/**
 * Create contract importing its parameters with passed .yaml file. No signatures are added automatically. It is required to add signatures before check.
 * @param fileName path to file containing Yaml representation of contract.
 */
public static Contract fromDslFile(String fileName) throws IOException {
  Yaml yaml = new Yaml();
  try (FileReader r = new FileReader(fileName)) {
    Binder binder = Binder.from(DefaultBiMapper.deserialize((Map) yaml.load(r)));
    return new Contract().initializeWithDsl(binder);
  }
}
origin: UniversaBlockchain/universa

/**
 * Construct contract from sealed binary stored in given file name
 * @param contractFileName file name to get binary from
 * @return extracted contract
 * @throws IOException
 */
public static Contract fromSealedFile(String contractFileName) throws IOException {
  return new Contract(Do.read(contractFileName), new TransactionPack());
}
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

static Contract createSimpleContract(PrivateKey key) {
  Contract result = new Contract();
  // default expiration date
  result.setExpiresAt(ZonedDateTime.now().plusDays(90));
  // issuer role is a key for a new contract
  result.setIssuerKeys(key.getPublicKey().getShortAddress());
  // issuer is owner, link roles
  result.registerRole(new RoleLink("owner", "issuer"));
  result.registerRole(new RoleLink("creator", "issuer"));
  return result;
}
origin: UniversaBlockchain/universa

@Test
public void testFiles() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  contract.seal();
  String newFilename = FileTool.writeFileContentsWithRenaming(System.getProperty("java.io.tmpdir")+"/testFile_2.file", contract.getPackedTransaction());
  System.out.println("write done, new filename=" + newFilename);
}
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

@Test
public void packedContractNotContainsOtherItems() throws Exception {
  // if we seal and load a contract without a pack, it should have empty
  // containers for new and revoking items - these should be fill separately.
  Contract c2 = new Contract(c.seal());
  assertEquals(0, c2.getRevokingItems().size());
  assertEquals(0, c2.getNewItems().size());
}
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 registerSimpleContractNormal() throws Exception {
  Contract simpleContract = new Contract(TestKeys.privateKey(0));
  simpleContract.seal();
  registerAndCheckApproved(simpleContract);
}
origin: UniversaBlockchain/universa

@Test
public void jsInContract_execZeroParams() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  String js = "";
  js += "print('jsApiParams.length: ' + jsApiParams.length);";
  js += "result = jsApiParams.length;";
  contract.getDefinition().setJS(js.getBytes(), "client script.js", new JSApiScriptParameters());
  contract.seal();
  assertEquals(0, contract.execJS(js.getBytes()));
}
origin: UniversaBlockchain/universa

@Test
public void shouldPerformRoleWithAnyMode() {
  Contract c = new Contract();
  SimpleRole s1 = new SimpleRole("owner");
  SimpleRole s2 = new SimpleRole("owner2");
  s1.addKeyRecord(new KeyRecord(keys.get(1).getPublicKey()));
  s2.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
  c.registerRole(s1);
  c.registerRole(s2);
  ListRole roleList = new ListRole("listAnyMode", ListRole.Mode.ANY, Do.listOf(s1, s2));
  assertTrue(roleList.isAllowedForKeys(new HashSet<>(Do.listOf(keys.get(1).getPublicKey()))));
}
origin: UniversaBlockchain/universa

@Test
public void createFromSealedWithRealContract() throws Exception {
  String fileName = "./src/test_contracts/subscription.yml";
  Contract c = Contract.fromDslFile(fileName);
  c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
  sealCheckTrace(c, true);
  // Contract from seal
  byte[] seal = c.seal();
  Contract sealedContract = new Contract(seal);
  sealedContract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
  sealCheckTrace(sealedContract, true);
}
origin: UniversaBlockchain/universa

@Test
public void createFromSealedWithRealContractData() throws Exception {
  String fileName = "./src/test_contracts/subscription_with_data.yml";
  Contract c = Contract.fromDslFile(fileName);
  c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
  sealCheckTrace(c, true);
  // Contract from seal
  byte[] seal = c.seal();
  Contract sealedContract = new Contract(seal);
  sealedContract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
  sealCheckTrace(sealedContract, true);
}
origin: UniversaBlockchain/universa

@Test
public void detectsCirculars() throws Exception {
  Contract c = new Contract();
  RoleLink r1 = new RoleLink("bar", "foo");
  RoleLink r2 = new RoleLink("foo", "bar");
  c.registerRole(r1);
  c.registerRole(r2);
  assertNull(r2.resolve());
}
origin: UniversaBlockchain/universa

@Test
public void transactionalData() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  String testValue = HashId.createRandom().toBase64String();
  contract.getTransactionalData().set("test_value", testValue);
  contract.seal();
  byte[] packedData = contract.getPackedTransaction();
  Contract unpackedContract = Contract.fromPackedTransaction(packedData);
  System.out.println("unpackedContract.transactional.data.test_value: " + unpackedContract.getTransactionalData().getStringOrThrow("test_value"));
  assertEquals(testValue, unpackedContract.getTransactionalData().getStringOrThrow("test_value"));
}
origin: UniversaBlockchain/universa

@Test
public void resolve() throws Exception {
  Contract c = new Contract();
  SimpleRole s1 = new SimpleRole("owner");
  c.registerRole(s1);
  RoleLink r1 = new RoleLink("lover", "owner");
  c.registerRole(r1);
  RoleLink r2 = r1.linkAs("mucker");
  assertSame(s1, s1.resolve());
  assertSame(s1, r1.resolve());
  assertSame(s1, r2.resolve());
}
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

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

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

@Test(timeout = 15000)
public void resyncOther() throws Exception {
  Contract c = new Contract(TestKeys.privateKey(0));
  c.seal();
  addToAllLedgers(c, ItemState.PENDING_POSITIVE);
  node.getLedger().getRecord(c.getId()).destroy();
  assertEquals(ItemState.UNDEFINED, node.checkItem(c.getId()).state);
  node.resync(c.getId());
  assertEquals(ItemState.PENDING, node.checkItem(c.getId()).state);
  assertEquals(ItemState.UNDEFINED, node.waitItem(c.getId(), 12000).state);
}
com.icodici.universa.contractContract<init>

Javadoc

Create an empty new contract

Popular methods of Contract

  • 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
  • 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

  • Reading from database using SQL prepared statement
  • getExternalFilesDir (Context)
  • compareTo (BigDecimal)
  • getResourceAsStream (ClassLoader)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Top plugins for WebStorm
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