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

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

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

origin: UniversaBlockchain/universa

/**
 * Get issuer of the contract
 * @return issuer role
 */
public Role getIssuer() {
  // maybe we should cache it
  return getRole("issuer");
}
origin: UniversaBlockchain/universa

/**
 * Get owner role
 * @return owner role
 */
public Role getOwner() {
  return getRole("owner");
}
origin: UniversaBlockchain/universa

/**
 * Get creator role
 * @return creator role
 */
public Role getCreator() {
  return getRole("creator");
}
origin: UniversaBlockchain/universa

/**
 * Get all addresses, used by registered role from the contract. For public keys returns addresses too.
 * @return list of strings with addresses
 */
@Deprecated
public List<String> getRoleAddresses(String roleName) {
  return getRole(roleName).getAllAddresses();
}
origin: UniversaBlockchain/universa

@Deprecated
public KeyRecord testGetOwner() {
  return getRole("owner").getKeyRecords().iterator().next();
}
origin: UniversaBlockchain/universa

/**
 * Return the resolved role taken from a bound contract. A resolved role may be a {@link RoleLink} itself, or null
 * (if a link is incorrect).
 *
 * @return {@link Role}
 */
@Nullable
public Role getRole() {
  return getContract().getRole(roleName);
}
origin: UniversaBlockchain/universa

public Binder serializeWith(BiSerializer serializer) {
  Binder of = Binder.of(
      "created_at", createdAt,
      "revision", revision,
      "owner", getRole("owner"),
      "created_by", getRole("creator"),
      "branch_id", branchId,
      "origin", serializer.serialize(origin),
      "parent", serializer.serialize(parent),
      "data", data
  );
  if (expiresAt != null)
    of.set("expires_at", expiresAt);
  if (references != null)
    of.set("references", references);
  return serializer.serialize(
      of
  );
}
origin: UniversaBlockchain/universa

@Test
public void serializeContractWithListRole() throws Exception {
  Contract c = Contract.fromDslFile("./src/test_contracts/simple_root_contract.yml");
  SimpleRole s1 = new SimpleRole("role");
  ListRole listRole = new ListRole("owner", 1, Do.listOf(s1));
  c.registerRole(listRole);
  Binder b = BossBiMapper.serialize(c);
  Contract c1 = DefaultBiMapper.deserialize(b);
  assertEquals(c.getRole("owner"), c1.getRole("owner"));
}
origin: UniversaBlockchain/universa

@Test
public void createU() throws Exception
{
  PrivateKey privateKey = TestKeys.privateKey(3);
  Set<PublicKey> keys = new HashSet();
  keys.add(privateKey.getPublicKey());
  Contract u = InnerContractsService.createFreshU(100, keys);
  u.check();
  u.traceErrors();
  assertEquals(true, u.getRole("owner").isAllowedForKeys(keys));
  assertEquals(100, u.getStateData().getIntOrThrow("transaction_units"));
  PrivateKey manufacturePrivateKey = new PrivateKey(Do.read( "./src/test_contracts/keys/u_key.private.unikey"));
  Set<PublicKey> badKeys = new HashSet();
  badKeys.add(manufacturePrivateKey.getPublicKey());
  assertEquals(false, u.getRole("owner").isAllowedForKeys(badKeys));
}
origin: UniversaBlockchain/universa

@Test
public void createTestU() throws Exception
{
  PrivateKey privateKey = TestKeys.privateKey(3);
  Set<PublicKey> keys = new HashSet();
  keys.add(privateKey.getPublicKey());
  Contract u = InnerContractsService.createFreshU(100, keys, true);
  u.check();
  u.traceErrors();
  assertEquals(true, u.getRole("owner").isAllowedForKeys(keys));
  assertEquals(100, u.getStateData().getIntOrThrow("transaction_units"));
  assertEquals(10000, u.getStateData().getIntOrThrow("test_transaction_units"));
  PrivateKey manufacturePrivateKey = new PrivateKey(Do.read( "./src/test_contracts/keys/u_key.private.unikey"));
  Set<PublicKey> badKeys = new HashSet();
  badKeys.add(manufacturePrivateKey.getPublicKey());
  assertEquals(false, u.getRole("owner").isAllowedForKeys(badKeys));
}
origin: UniversaBlockchain/universa

@Test
public void getAllAddresses() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  ListRole owner = new ListRole("owner");
  owner.addRole(new SimpleRole("owner", Arrays.asList(TestKeys.publicKey(0), TestKeys.publicKey(1))));
  owner.addRole(new SimpleRole("owner", Arrays.asList(TestKeys.publicKey(2).getLongAddress())));
  owner.addRole(new SimpleRole("owner", Arrays.asList(TestKeys.publicKey(3).getShortAddress(), TestKeys.publicKey(4))));
  contract.registerRole(owner);
  List<String> addresses = contract.getRole("owner").getAllAddresses();
  System.out.println("owner: " + addresses);
  for (String addr : addresses)
    assertThat(addr, Matchers.anyOf(
        Matchers.equalTo(TestKeys.publicKey(0).getShortAddress().toString()),
        Matchers.equalTo(TestKeys.publicKey(1).getShortAddress().toString()),
        Matchers.equalTo(TestKeys.publicKey(2).getLongAddress().toString()),
        Matchers.equalTo(TestKeys.publicKey(3).getShortAddress().toString()),
        Matchers.equalTo(TestKeys.publicKey(4).getShortAddress().toString())
    ));
}
origin: UniversaBlockchain/universa

@Test
public void modifyExpiresAtAllowed() 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());
  modifyDataPermission.addField("/expires_at", null);
  contract.addPermission(modifyDataPermission);
  contract.seal();
  Contract changed = contract.createRevision();
  changed.addSignerKey(TestKeys.privateKey(0));
  changed.setExpiresAt(ZonedDateTime.now().plusDays(1));
  changed.seal();
  changed.check();
  assertTrue(changed.isOk());
}
origin: UniversaBlockchain/universa

@Test
public void modifyExpiresAtDeclined() 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());
  modifyDataPermission.addField("expires_at", null);
  contract.addPermission(modifyDataPermission);
  contract.seal();
  Contract changed = contract.createRevision();
  changed.addSignerKey(TestKeys.privateKey(0));
  changed.setExpiresAt(ZonedDateTime.now().plusDays(1));
  changed.seal();
  changed.check();
  assertTrue(!changed.isOk());
}
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());
}
origin: UniversaBlockchain/universa

@Test
public void changeDeclined() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  contract.getStateData().put("field1", 33);
  ChangeNumberPermission changeNumberPermission = new ChangeNumberPermission(contract.getRole("owner"), Binder.of(
      "field_name", "field1",
      "min_value", 33,
      "max_value", 36,
      "min_step", 1,
      "max_step", 2
  )
  );
  contract.addPermission(changeNumberPermission);
  contract.seal();
  Contract changed = contract.createRevision();
  changed.addSignerKey(TestKeys.privateKey(0));
  changed.getStateData().set("field1", 36);
  changed.seal();
  changed.check();
  assertFalse(changed.isOk());
}
origin: UniversaBlockchain/universa

@Test
public void lessMinValueDeclined() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  contract.getStateData().put("field1", "33.000000000000000012");
  ChangeNumberPermission changeNumberPermission = new ChangeNumberPermission(contract.getRole("owner"), Binder.of(
      "field_name", "field1",
      "min_value", "33.000000000000000008",
      "max_value", "34",
      "min_step", "-0.000000000000000005",
      "max_step", "0.000000000000000005"
  )
  );
  contract.addPermission(changeNumberPermission);
  contract.seal();
  Contract changed = contract.createRevision();
  changed.addSignerKey(TestKeys.privateKey(0));
  changed.getStateData().set("field1", "33.000000000000000007");
  changed.seal();
  changed.check();
  assertFalse(changed.isOk());
}
origin: UniversaBlockchain/universa

@Test
public void modifyDataAllowed() 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());
  modifyDataPermission.addField("field_to_be_changed", null);
  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());
}
origin: UniversaBlockchain/universa

@Test
public void modifyReferencesDeclined() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  ModifyDataPermission modifyDataPermission = new ModifyDataPermission(contract.getRole("owner"),new Binder());
  modifyDataPermission.addField("references", null);
  contract.addPermission(modifyDataPermission);
  contract.seal();
  Contract referencedContract = new Contract(TestKeys.privateKey(1));
  referencedContract.seal();
  Contract changed = contract.createRevision();
  changed.addSignerKey(TestKeys.privateKey(0));
  Reference ref = new Reference(referencedContract);
  ref.addMatchingItem(referencedContract);
  ref.type =  Reference.TYPE_EXISTING_STATE;
  changed.addReference(ref);
  changed.seal();
  changed.check();
  assertTrue(!changed.isOk());
}
origin: UniversaBlockchain/universa

@Test
public void modifyReferencesAllowed() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  ModifyDataPermission modifyDataPermission = new ModifyDataPermission(contract.getRole("owner"),new Binder());
  modifyDataPermission.addField("/references", null);
  contract.addPermission(modifyDataPermission);
  contract.seal();
  Contract referencedContract = new Contract(TestKeys.privateKey(1));
  referencedContract.seal();
  Contract changed = contract.createRevision();
  changed.addSignerKey(TestKeys.privateKey(0));
  Reference ref = new Reference(referencedContract);
  ref.type =  Reference.TYPE_EXISTING_STATE;
  ref.addMatchingItem(referencedContract);
  changed.addReference(ref);
  changed.seal();
  changed.check();
  changed.traceErrors();
  assertTrue(changed.isOk());
}
com.icodici.universa.contractContractgetRole

Javadoc

Get registered role from the 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

  • Making http requests using okhttp
  • compareTo (BigDecimal)
  • scheduleAtFixedRate (Timer)
  • setScale (BigDecimal)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • Best IntelliJ plugins
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