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

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

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

origin: UniversaBlockchain/universa

public Role setCreator(Role role) {
  return registerRole(role);
}
origin: UniversaBlockchain/universa

/**
 * Create alias role to this one using {@link RoleLink}. If this role has attached to some contract, this method
 * also registers new role in the same contract.
 *
 * @param roleName new role name
 *
 * @return linked {@link RoleLink}
 */
public RoleLink linkAs(String roleName) {
  RoleLink newRole = new RoleLink(roleName, name);
  if (contract != null)
    contract.registerRole(newRole);
  return newRole;
}
origin: UniversaBlockchain/universa

/**
 * Set role with given name to given keys
 * @param name role name
 * @param keys keys to set role to
 * @return registened role
 */
@NonNull
private Role setRole(String name, Collection keys) {
  return registerRole(new SimpleRole(name, keys));
}
origin: UniversaBlockchain/universa

public void registerRole(JSApiRole role) {
  this.currentContract.registerRole(role.extractRole(new JSApiAccessor()));
}
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

/**
 * 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 void deserealizeWith(Binder data, BiDeserializer d) {
  createdAt = data.getZonedDateTimeOrThrow("created_at");
  expiresAt = data.getZonedDateTime("expires_at", null);
  revision = data.getIntOrThrow("revision");
  this.references = d.deserialize(data.getList("references", null));
  if (revision <= 0)
    throw new IllegalArgumentException("illegal revision number: " + revision);
  Role r = registerRole(d.deserialize(data.getBinderOrThrow("owner")));
  if (!r.getName().equals("owner"))
    throw new IllegalArgumentException("bad owner role name");
  r = registerRole(d.deserialize(data.getBinderOrThrow("created_by")));
  if (!r.getName().equals("creator"))
    throw new IllegalArgumentException("bad creator role name");
  this.data = data.getBinder("data", Binder.EMPTY);
  branchId = data.getString("branch_id", null);
  parent = d.deserialize(data.get("parent"));
  origin = d.deserialize(data.get("origin"));
}
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

public void deserializeWith(Binder data, BiDeserializer d) {
  registerRole(d.deserialize(data.getBinderOrThrow("issuer")));
  createdAt = data.getZonedDateTimeOrThrow("created_at");
  expiresAt = data.getZonedDateTime("expires_at", null);
  extendedType = data.getString("extended_type", null);
  this.data = d.deserialize(data.getBinder("data", Binder.EMPTY));
  references = d.deserialize(data.getList("references", null));
  Map<String, Permission> perms = d.deserialize(data.getOrThrow("permissions"));
  perms.forEach((id, perm) -> {
    perm.setId(id);
    addPermission(perm);
  });
}
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 shouldNotPerformRoleWithAllMode() {
  Contract c = new Contract();
  SimpleRole s1 = new SimpleRole("owner");
  SimpleRole s2 = new SimpleRole("owner2");
  s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
  s2.addKeyRecord(new KeyRecord(keys.get(1).getPublicKey()));
  c.registerRole(s1);
  c.registerRole(s2);
  ListRole roleList = new ListRole("listAllMode", ListRole.Mode.ALL, Do.listOf(s1, s2));
  HashSet<AbstractKey> keys = new HashSet<>(Do.listOf(
      ListRoleTest.keys.get(1).getPublicKey()));
  assertFalse(roleList.isAllowedForKeys(keys));
}
origin: UniversaBlockchain/universa

@Test
public void shouldNotPerformRoleWithQuorumMode() {
  Contract c = new Contract();
  SimpleRole s1 = new SimpleRole("owner");
  SimpleRole s2 = new SimpleRole("owner2");
  s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
  s2.addKeyRecord(new KeyRecord(keys.get(1).getPublicKey()));
  c.registerRole(s1);
  c.registerRole(s2);
  ListRole roleList = new ListRole("listQuorumMode");
  roleList.setQuorum(2);
  roleList.addAll(Do.listOf(s1, s2));
  c.registerRole(roleList);
  HashSet<AbstractKey> keys = new HashSet<>(Do.listOf(
      ListRoleTest.keys.get(1).getPublicKey()));
  assertFalse(roleList.isAllowedForKeys(keys));
}
origin: UniversaBlockchain/universa

@Test
public void shouldPerformRoleWithQuorumMode() {
  Contract c = new Contract();
  SimpleRole s1 = new SimpleRole("owner");
  SimpleRole s2 = new SimpleRole("owner2");
  SimpleRole s3 = new SimpleRole("owner3");
  s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
  s2.addKeyRecord(new KeyRecord(keys.get(2).getPublicKey()));
  s3.addKeyRecord(new KeyRecord(keys.get(3).getPublicKey()));
  c.registerRole(s1);
  c.registerRole(s2);
  c.registerRole(s3);
  ListRole roleList = new ListRole("listQuorumMode", 2, Do.listOf(s1, s3, s2));
  HashSet<AbstractKey> keys = new HashSet<>(Do.listOf(
      ListRoleTest.keys.get(0).getPublicKey(),
      ListRoleTest.keys.get(2).getPublicKey()));
  assertTrue(roleList.isAllowedForKeys(keys));
}
origin: UniversaBlockchain/universa

@Test
public void serializeAll() throws Exception {
  Contract c = new Contract();
  SimpleRole s1 = new SimpleRole("owner");
  s1.addRequiredReference("refName", Role.RequiredMode.ALL_OF);
  s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
  ListRole roleList = new ListRole("listAllMode", ListRole.Mode.ALL, Do.listOf(s1));
  c.registerRole(s1);
  c.registerRole(roleList);
  Binder serialized = DefaultBiMapper.serialize(roleList);
  Role r1 = DefaultBiMapper.deserialize(serialized);
  assertEquals(r1, roleList);
}
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
public void shouldNotPerformRoleWithAnyMode() {
  Contract c = new Contract();
  SimpleRole s1 = new SimpleRole("owner");
  SimpleRole s2 = new SimpleRole("owner2");
  s1.addKeyRecord(new KeyRecord(keys.get(0).getPublicKey()));
  s2.addKeyRecord(new KeyRecord(keys.get(2).getPublicKey()));
  c.registerRole(s1);
  c.registerRole(s2);
  ListRole roleList = new ListRole("listAnyMode");
  roleList.setMode(ListRole.Mode.ANY);
  roleList.addRole(s1)
      .addRole(s2);
  assertFalse(roleList.isAllowedForKeys(new HashSet<>(Do.listOf(keys.get(1).getPublicKey()))));
}
origin: UniversaBlockchain/universa

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

private Contract createNetConfigContract(Contract contract, List<NodeInfo> netConfig, Collection<PrivateKey> currentConfigKeys) throws IOException {
  contract = contract.createRevision();
  ListRole listRole = new ListRole("owner");
  for(NodeInfo ni: netConfig) {
    SimpleRole role = new SimpleRole(ni.getName());
    contract.registerRole(role);
    role.addKeyRecord(new KeyRecord(ni.getPublicKey()));
    listRole.addRole(role);
  }
  listRole.setQuorum(netConfig.size()-1);
  contract.registerRole(listRole);
  contract.getStateData().set("net_config",netConfig);
  List<KeyRecord> creatorKeys = new ArrayList<>();
  for(PrivateKey key : currentConfigKeys) {
    creatorKeys.add(new KeyRecord(key.getPublicKey()));
    contract.addSignerKey(key);
  }
  contract.setCreator(creatorKeys);
  contract.seal();
  return contract;
}
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(timeout = 90000)
public void checkPayment_wrongIssuer() throws Exception {
  Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys());
  PrivateKey manufactureFakePrivateKey = new PrivateKey(Do.read(ROOT_PATH + "keys/marty_mcfly.private.unikey"));
  SimpleRole issuerRole = new SimpleRole("issuer");
  KeyRecord kr = new KeyRecord(manufactureFakePrivateKey.getPublicKey());
  issuerRole.addKeyRecord(kr);
  payment.registerRole(issuerRole);
  boolean res = payment.paymentCheck(config.getUIssuerKeys());
  payment.traceErrors();
  assertFalse(res);
}
com.icodici.universa.contractContractregisterRole

Javadoc

Register new role. Name must be unique otherwise existing role will be overwritten

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

  • Start an intent from android
  • 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 Vim 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