Tabnine Logo
Client.register
Code IndexAdd Tabnine to your IDE (free)

How to use
register
method
in
com.icodici.universa.node2.network.Client

Best Java code snippets using com.icodici.universa.node2.network.Client.register (Showing top 20 results out of 315)

origin: UniversaBlockchain/universa

/**
 * Register packed binary contract and wait for the consensus.
 *
 * @param packedContract
 * @param millisToWait wait for the consensus as long as specified time, <= 0 means no wait (returns some pending
 *                     state from registering).
 * @return last item status returned by the network
 * @throws ClientError
 */
public ItemResult register(byte[] packedContract, long millisToWait) throws ClientError {
  return client.register(packedContract, millisToWait);
}
origin: UniversaBlockchain/universa

@Ignore
@Test
public void registerSimpleContractWithPayment() throws Exception {
  Contract contractToRegister = new Contract(TestKeys.privateKey(10));
  contractToRegister.seal();
  ItemResult itemResult = normalClient.register(contractToRegister.getPackedTransaction(), 5000);
  System.out.println("register... done! itemResult: " + itemResult.state);
  assertEquals(ItemState.UNDEFINED, itemResult.state);
  Parcel parcel = ContractsService.createParcel(contractToRegister, paymentContract, 1, Stream.of(paymentContractPrivKey).collect(Collectors.toSet()), true);
  normalClient.registerParcelWithState(parcel.pack(), 5000);
  itemResult = normalClient.getState(parcel.getPaymentContract().getId());
  if (itemResult.state == ItemState.APPROVED)
    paymentContract = parcel.getPaymentContract();
  System.out.println("registerParcel... done!");
  System.out.println("parcel.paymentContract.itemResult: " + itemResult);
  assertEquals(ItemState.APPROVED, itemResult.state);
  itemResult = normalClient.getState(contractToRegister.getId());
  System.out.println("contractToRegister.itemResult: " + itemResult);
  assertEquals(ItemState.APPROVED, itemResult.state);
}
origin: UniversaBlockchain/universa

/**
 * Register contract on the network without payment. May require special client key / network configuration
 * @param packed {@link com.icodici.universa.contract.TransactionPack} binary
 * @return result of registration
 * @throws ClientError
 */
public ItemResult register(byte[] packed) throws ClientError {
  return register(packed, 0);
}
origin: UniversaBlockchain/universa

@Ignore
@Test
public void registerSeveralSimpleContractWithPayment() throws Exception {
  for (int i = 0; i < 20; ++i) {
    System.out.println("\ni = " + i);
    Contract contractToRegister = new Contract(TestKeys.privateKey(10));
    contractToRegister.seal();
    ItemResult itemResult = normalClient.register(contractToRegister.getPackedTransaction(), 5000);
    System.out.println("register... done! itemResult: " + itemResult.state);
    assertEquals(ItemState.UNDEFINED, itemResult.state);
    Parcel parcel = ContractsService.createParcel(contractToRegister, paymentContract, 1, Stream.of(paymentContractPrivKey).collect(Collectors.toSet()), true);
    normalClient.registerParcelWithState(parcel.pack(), 5000);
    itemResult = normalClient.getState(parcel.getPaymentContract().getId());
    if (itemResult.state == ItemState.APPROVED)
      paymentContract = parcel.getPaymentContract();
    System.out.println("registerParcel... done!");
    System.out.println("parcel.paymentContract.itemResult: " + itemResult);
    assertEquals(ItemState.APPROVED, itemResult.state);
    itemResult = normalClient.getState(contractToRegister.getId());
    System.out.println("contractToRegister.itemResult: " + itemResult);
    assertEquals(ItemState.APPROVED, itemResult.state);
  }
}
origin: UniversaBlockchain/universa

public ItemResult register(byte[] packedContract) throws ClientError {
  return client.register(packedContract, 0);
}
origin: UniversaBlockchain/universa

@Test
public void paymentTest1() throws Exception {
  List<Main> mm = new ArrayList<>();
  for (int i = 0; i < 4; i++)
    mm.add(createMain("node" + (i + 1), false));
  Main main = mm.get(0);
  main.config.setIsFreeRegistrationsAllowedFromYaml(true);
  Client client = new Client(TestKeys.privateKey(20), main.myInfo, null);
  Contract simpleContract = new Contract(TestKeys.privateKey(1));
  simpleContract.seal();
  Contract stepaU = InnerContractsService.createFreshU(100000000, new HashSet<>(Arrays.asList(TestKeys.publicKey(1))));
  ItemResult itemResult = client.register(stepaU.getPackedTransaction(), 5000);
  System.out.println("stepaU itemResult: " + itemResult);
  assertEquals(ItemState.APPROVED, itemResult.state);
  main.config.setIsFreeRegistrationsAllowedFromYaml(false);
  Parcel parcel = ContractsService.createParcel(simpleContract, stepaU, 1, new HashSet<>(Arrays.asList(TestKeys.privateKey(1))), false);
  client.registerParcelWithState(parcel.pack(), 5000);
  assertEquals(ItemState.APPROVED, client.getState(simpleContract.getId()).state);
  mm.forEach(x -> x.shutdown());
}
protected static final String ROOT_PATH = "./src/test_contracts/";
origin: UniversaBlockchain/universa

@Test
public void registerSimpleContract() 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();
  System.out.println("nodeClient.register(stepaCoins)...");
  //ItemResult itemResult = nodeClient.register(stepaCoins.getLastSealedBinary(), 5000);
  ItemResult itemResult = nodeClient.register(stepaCoins.getPackedTransaction(), 5000);
  System.out.println("nodeClient.register(stepaCoins)... done! itemResult: " + itemResult.state);
  itemResult = nodeClient.getState(stepaCoins.getId());
  System.out.println("nodeClient.getState(stepaCoins): " + itemResult.state);
  assertEquals(ItemState.APPROVED, itemResult.state);
}
origin: UniversaBlockchain/universa

@Test
public void freeRegistrationsAllowedFromCoreVersion() throws Exception {
  List<Main> mm = new ArrayList<>();
  for (int i = 0; i < 4; i++)
    mm.add(createMain("node" + (i + 1), false));
  Main main = mm.get(0);
  Client client = new Client(TestKeys.privateKey(20), main.myInfo, null);
  Contract contract = new Contract(TestKeys.privateKey(0));
  contract.seal();
  ItemState expectedState = ItemState.UNDEFINED;
  if (Core.VERSION.contains("private"))
    expectedState = ItemState.APPROVED;
  System.out.println("Core.VERSION: " + Core.VERSION);
  System.out.println("expectedState: " + expectedState);
  ItemResult itemResult = client.register(contract.getPackedTransaction(), 5000);
  System.out.println("itemResult: " + itemResult);
  assertEquals(expectedState, itemResult.state);
  mm.forEach(x -> x.shutdown());
}
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 freeRegistrationsAllowedFromConfigOrVersion() throws Exception {
  List<Main> mm = new ArrayList<>();
  for (int i = 0; i < 4; i++)
    mm.add(createMain("node" + (i + 1), false));
  Main main = mm.get(0);
  main.config.setIsFreeRegistrationsAllowedFromYaml(true);
  Client client = new Client(TestKeys.privateKey(20), main.myInfo, null);
  Contract contract = new Contract(TestKeys.privateKey(0));
  contract.seal();
  ItemState expectedState = ItemState.APPROVED;
  System.out.println("expectedState: " + expectedState);
  ItemResult itemResult = client.register(contract.getPackedTransaction(), 5000);
  System.out.println("itemResult: " + itemResult);
  assertEquals(expectedState, itemResult.state);
  main.config.setIsFreeRegistrationsAllowedFromYaml(false);
  contract = new Contract(TestKeys.privateKey(0));
  contract.seal();
  expectedState = ItemState.UNDEFINED;
  if (Core.VERSION.contains("private"))
    expectedState = ItemState.APPROVED;
  System.out.println("Core.VERSION: " + Core.VERSION);
  System.out.println("expectedState: " + expectedState);
  itemResult = client.register(contract.getPackedTransaction(), 5000);
  System.out.println("itemResult: " + itemResult);
  assertEquals(expectedState, itemResult.state);
  mm.forEach(x -> x.shutdown());
}
origin: UniversaBlockchain/universa

  @Test
  public void registerSimpleContractWhite() throws Exception {
//        Contract whiteContract = new Contract();
//        whiteContract.setIssuerKeys(TestKeys.privateKey(0));
//        whiteContract.setOwnerKeys(TestKeys.privateKey(0));
//        whiteContract.setCreatorKeys(TestKeys.privateKey(0));
//        whiteContract.addSignerKey(TestKeys.privateKey(0));
//        whiteContract.seal();

    Contract whiteContract = new Contract(TestKeys.privateKey(0));
    whiteContract.seal();

    System.out.println("nodeClient.register(whiteContract)...");
    //ItemResult itemResult = nodeClient.register(whiteContract.getLastSealedBinary(), 5000);
    ItemResult itemResult = nodeClient.register(whiteContract.getPackedTransaction(), 5000);
    System.out.println("nodeClient.register(whiteContract)... done! itemResult: " + itemResult.state);

    itemResult = nodeClient.getState(whiteContract.getId());
    System.out.println("nodeClient.getState(whiteContract): " + itemResult.state);
    assertEquals(ItemState.APPROVED, itemResult.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 verboseLevelTest() throws Exception {
  PrivateKey issuerKey = new PrivateKey(Do.read("./src/test_contracts/keys/reconfig_key.private.unikey"));
  TestSpace testSpace = prepareTestSpace(issuerKey);
  Contract contract = new Contract(TestKeys.privateKey(3));
  contract.seal();
  testSpace.client.register(contract.getPackedTransaction(),8000);
  Thread.sleep(2000);
  testSpace.client.setVerboseLevel(DatagramAdapter.VerboseLevel.NOTHING,DatagramAdapter.VerboseLevel.DETAILED,DatagramAdapter.VerboseLevel.NOTHING);
  contract = new Contract(TestKeys.privateKey(3));
  contract.seal();
  testSpace.client.register(contract.getPackedTransaction(),8000);
  testSpace.nodes.forEach(x -> x.shutdown());
}
origin: UniversaBlockchain/universa

  public synchronized Parcel createParcelWithFreshU(Client client, Contract c, Collection<PrivateKey> keys) throws Exception {
    Set<PublicKey> ownerKeys = new HashSet();
    keys.stream().forEach(key->ownerKeys.add(key.getPublicKey()));
    Contract stepaU = InnerContractsService.createFreshU(100000000, ownerKeys);
    stepaU.check();
    //stepaU.setIsU(true);
    stepaU.traceErrors();

    PrivateKey clientPrivateKey = client.getSession().getPrivateKey();
    PrivateKey newPrivateKey = new PrivateKey(Do.read("./src/test_contracts/keys/u_key.private.unikey"));
    client.getSession().setPrivateKey(newPrivateKey);
    client.restart();

    Thread.sleep(8000);

    ItemResult itemResult = client.register(stepaU.getPackedTransaction(), 5000);
//        node.registerItem(stepaU);
//        ItemResult itemResult = node.waitItem(stepaU.getId(), 18000);

    client.getSession().setPrivateKey(clientPrivateKey);
    client.restart();

    Thread.sleep(8000);

    assertEquals(ItemState.APPROVED, itemResult.state);
    Set<PrivateKey> keySet = new HashSet<>();
    keySet.addAll(keys);
    return ContractsService.createParcel(c, stepaU, 150, keySet);
  }

origin: UniversaBlockchain/universa

@Test
public void testRevocationContractsApi() throws Exception {
  List<Main> mm = new ArrayList<>();
  for (int i = 0; i < 4; i++)
    mm.add(createMain("node" + (i + 1), false));
  Main main = mm.get(0);
  main.config.setIsFreeRegistrationsAllowedFromYaml(true);
  Client client = new Client(TestKeys.privateKey(20), main.myInfo, null);
  Set<PrivateKey> issuerPrivateKeys = new HashSet<>(Arrays.asList(TestKeys.privateKey(1)));
  Set<PublicKey> ownerPublicKeys = new HashSet<>(Arrays.asList(TestKeys.publicKey(2)));
  Contract sourceContract = ContractsService.createShareContract(issuerPrivateKeys, ownerPublicKeys, new BigDecimal("100"));
  sourceContract.check();
  sourceContract.traceErrors();
  ItemResult itemResult = client.register(sourceContract.getPackedTransaction(), 5000);
  System.out.println("sourceContract : " + itemResult);
  assertEquals(ItemState.APPROVED, client.getState(sourceContract.getId()).state);
  Contract revokeContract = ContractsService.createRevocation(sourceContract, TestKeys.privateKey(1));
  revokeContract.check();
  revokeContract.traceErrors();
  itemResult = client.register(revokeContract.getPackedTransaction(), 5000);
  System.out.println("revokeContract : " + itemResult);
  assertEquals(ItemState.APPROVED, client.getState(revokeContract.getId()).state);
  assertEquals(ItemState.REVOKED, client.getState(sourceContract.getId()).state);
  mm.forEach(x -> x.shutdown());
 }
origin: UniversaBlockchain/universa

public synchronized Parcel createParcelWithFreshU(Client client, Contract c, Collection<PrivateKey> keys) throws Exception {
  Set<PublicKey> ownerKeys = new HashSet();
  keys.stream().forEach(key->ownerKeys.add(key.getPublicKey()));
  Contract stepaU = InnerContractsService.createFreshU(100000000, ownerKeys);
  stepaU.check();
  stepaU.traceErrors();
  PrivateKey clientPrivateKey = client.getSession().getPrivateKey();
  PrivateKey newPrivateKey = new PrivateKey(Do.read("./src/test_contracts/keys/u_key.private.unikey"));
  client.getSession().setPrivateKey(newPrivateKey);
  client.restart();
  ItemResult itemResult = client.register(stepaU.getPackedTransaction(), 5000);
  client.getSession().setPrivateKey(clientPrivateKey);
  client.restart();
  assertEquals(ItemState.APPROVED, itemResult.state);
  Set<PrivateKey> keySet = new HashSet<>();
  keySet.addAll(keys);
  return ContractsService.createParcel(c, stepaU, 150, keySet);
}
origin: UniversaBlockchain/universa

protected static String getApprovedUContract() throws Exception {
  synchronized (uContractLock) {
    if (uContract == null) {
      PrivateKey manufacturePrivateKey = new PrivateKey(Do.read(rootPath + "keys/u_key.private.unikey"));
      Contract stepaU = Contract.fromDslFile(rootPath + "StepaU.yml");
      stepaU.addSignerKey(manufacturePrivateKey);
      stepaU.seal();
      stepaU.check();
      //stepaU.setIsU(true);
      stepaU.traceErrors();
      Files.deleteIfExists(Paths.get(basePath + "stepaU.unicon"));
      CLIMain.saveContract(stepaU, basePath + "stepaU.unicon");
      System.out.println("--- register new u --- " + stepaU.getId());
      Client client = CLIMain.getClientNetwork().client;
      client.register(stepaU.getPackedTransaction(), 5000);
      //callMain2("--register", basePath + "stepaU.unicon", "-v", "-wait", "5000");
      uContract = stepaU;
    }
    return basePath + "stepaU.unicon";
  }
}
origin: UniversaBlockchain/universa

@Test
public void getStateWithNoLedgerCache() throws Exception {
  TestSpace testSpace = prepareTestSpace(TestKeys.privateKey(0));
  testSpace.nodes.forEach(m -> m.config.setIsFreeRegistrationsAllowedFromYaml(true));
  testSpace.nodes.forEach(m -> ((PostgresLedger)m.node.getLedger()).enableCache(false));
  //SHUTDOWN LAST NODE
  testSpace.nodes.remove(testSpace.nodes.size()-1).shutdown();
  Thread.sleep(4000);
  Contract rev1 = new Contract(TestKeys.privateKey(0));
  rev1.getStateData().set("field1", 33);
  Permission permission = new ChangeNumberPermission(rev1.getOwner(), Binder.of("field_name", "field1"));
  rev1.addPermission(permission);
  rev1.seal();
  ItemResult ir1 = testSpace.client.register(rev1.getPackedTransaction(), 5000);
  assertEquals(ItemState.APPROVED, ir1.state);
  Contract rev2 = rev1.createRevision();
  rev2.getStateData().set("field1", 34);
  rev2.addSignerKey(TestKeys.privateKey(0));
  rev2.seal();
  ItemResult ir2 = testSpace.client.register(rev2.getPackedTransaction(), 5000);
  assertEquals(ItemState.APPROVED, ir2.state);
  ir1 = testSpace.client.register(rev1.getPackedTransaction(), 5000);
  assertEquals(ItemState.REVOKED, ir1.state);
  testSpace.nodes.forEach(m -> m.shutdown());
}
origin: UniversaBlockchain/universa

@Test
public void jsAddPermission() throws Exception {
  TestSpace testSpace = prepareTestSpace(TestKeys.privateKey(0));
  testSpace.nodes.forEach(m -> m.config.setIsFreeRegistrationsAllowedFromYaml(true));
  KeyAddress k0 = TestKeys.publicKey(0).getShortAddress();
  Contract contract = new Contract(TestKeys.privateKey(0));
  contract.getStateData().set("testval", 3);
  String js = "";
  js += "print('addPermission');";
  js += "var simpleRole = jsApi.getRoleBuilder().createSimpleRole('owner', '"+k0.toString()+"');";
  js += "var changeNumberPermission = jsApi.getPermissionBuilder().createChangeNumberPermission(simpleRole, " +
      "{field_name: 'testval', min_value: 3, max_value: 80, min_step: 1, max_step: 3}" +
      ");";
  js += "jsApi.getCurrentContract().addPermission(changeNumberPermission);";
  contract.getState().setJS(js.getBytes(), "client script.js", new JSApiScriptParameters());
  contract.execJS(js.getBytes());
  contract.seal();
  ItemResult ir = testSpace.client.register(contract.getPackedTransaction(), 5000);
  assertEquals(ItemState.APPROVED, ir.state);
  Contract newRev = contract.createRevision();
  newRev.addSignerKey(TestKeys.privateKey(0));
  newRev.getStateData().set("testval", 5);
  newRev.seal();
  ir = testSpace.client.register(newRev.getPackedTransaction(), 5000);
  assertEquals(ItemState.APPROVED, ir.state);
  testSpace.nodes.forEach(m -> m.shutdown());
}
origin: UniversaBlockchain/universa

@Test
public void registerContractWithAnonymousId() throws Exception {
  TestSpace ts = prepareTestSpace();
  PrivateKey newPrivateKey = new PrivateKey(Do.read("./src/test_contracts/keys/u_key.private.unikey"));
  byte[] myAnonId = newPrivateKey.createAnonymousId();
  Contract contract = new Contract();
  contract.setExpiresAt(ZonedDateTime.now().plusDays(90));
  Role r = contract.setIssuerKeys(AnonymousId.fromBytes(myAnonId));
  contract.registerRole(new RoleLink("owner", "issuer"));
  contract.registerRole(new RoleLink("creator", "issuer"));
  contract.addPermission(new ChangeOwnerPermission(r));
  contract.addSignerKey(newPrivateKey);
  contract.seal();
  assertTrue(contract.isOk());
  System.out.println("contract.check(): " + contract.check());
  contract.traceErrors();
  ts.client.getSession().setPrivateKey(newPrivateKey);
  ts.client.restart();
  ItemResult itemResult = ts.client.register(contract.getPackedTransaction(), 5000);
  assertEquals(ItemState.APPROVED, itemResult.state);
  ts.nodes.forEach(x -> x.shutdown());
}
com.icodici.universa.node2.networkClientregister

Javadoc

Register contract on the network without payment. May require special client key / network configuration

Popular methods of Client

  • getState
  • <init>
    Create new client protocol session. It loads network configuration and creates client protocol sessi
  • getClient
  • getNodes
    Get list of nodes in
  • ping
  • command
    Execude custom command on the node
  • getNodeNumber
    Get number of node cliet connection is established with
  • getVersion
    Get network version
  • registerParcelWithState
    Register contract on the network with parcel (includes payment) and wait for some of the final ItemS
  • getParcelProcessingState
    Get processing state of given parcel
  • getSession
    Get session of http client connected to node with given number
  • getStats
    Get extended statistics of the node including by-day payments in "U". Accessible to node owners (wit
  • getSession,
  • getStats,
  • queryContract,
  • resyncItem,
  • setVerboseLevel,
  • size,
  • followerGetRate,
  • getBody,
  • getContract

Popular in Java

  • Running tasks concurrently on multiple threads
  • getSystemService (Context)
  • setContentView (Activity)
  • compareTo (BigDecimal)
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • 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