Codota Logo
Contract.getNew
Code IndexAdd Codota to your IDE (free)

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

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

  • Common ways to obtain Contract
private void myMethod () {
Contract c =
  • Codota Iconnew Contract()
  • Codota IconString fileName;Contract.fromDslFile(fileName)
  • Codota IconParcel parcel;parcel.getPaymentContract()
  • Smart code suggestions by Codota
}
origin: UniversaBlockchain/universa

/**
 * Get all contracts involved in current contract registration: contract itself, new items and revoking items
 * @return contracts tree
 */
public List<Contract> getAllContractInTree() {
  List<Contract> contracts = new ArrayList<>();
  contracts.add(this);
  for (Contract c : getNew()) {
    contracts.addAll(c.getAllContractInTree());
  }
  for (Contract c : getRevoking()) {
    contracts.addAll(c.getAllContractInTree());
  }
  return contracts;
}
origin: UniversaBlockchain/universa

@Test
public void dupesWrongTest() throws Exception {
  PrivateKey key = new PrivateKey(Do.read(rootPath + "_xer0yfe2nn1xthc.private.unikey"));
  Set<PrivateKey> keys = new HashSet<>();
  keys.add(key);
  Contract c_1 = Contract.fromDslFile(rootPath + "coin100.yml");
  c_1.addSignerKey(key);
  c_1.seal();
  assertTrue(c_1.check());
  c_1.traceErrors();
  Contract c_2_1 = ContractsService.createSplit(c_1, new BigDecimal("20"), "amount", keys);
  Contract c_2_2 = c_2_1.getNew().get(0);
  if(c_2_2 != null) {
    Contract c_2_3 = c_2_2.copy();
    c_2_3.addSignerKey(key);
    c_2_3.seal();
    c_2_1.addNewItems(c_2_3);
  }
  assertEquals(2, c_2_1.getNewItems().size());
  c_2_1.check();
  c_2_1.traceErrors();
  assertFalse(c_2_1.isOk());
  // should be BAD_VALUE duplicated revision id
  assertEquals(2, c_2_1.getErrors().size());
}
origin: UniversaBlockchain/universa

private void markContractTest(Contract contract) {
  ledger.markTestRecord(contract.getId());
  contract.getNew().forEach(c -> markContractTest(c));
}
origin: UniversaBlockchain/universa

news.addAll(contract.getNew());
outcome.append(" -> ");
news.forEach(c -> {
origin: UniversaBlockchain/universa

public synchronized static Contract finishSwap(Contract swapContract, Set<PrivateKey> keys) {
  List<Contract> swappingContracts = (List<Contract>) swapContract.getNew();
origin: UniversaBlockchain/universa

public synchronized Contract finishSwap_wrongKey(Contract swapContract, Set<PrivateKey> keys, PrivateKey wrongKey) {
  List<Contract> swappingContracts = (List<Contract>) swapContract.getNew();
  // looking for contract that will be own
  for (Contract c : swappingContracts) {
    boolean willBeMine = c.getOwner().isAllowedForKeys(keys);
    System.out.println("willBeMine: " + willBeMine + " " + c.getSealedByKeys().size());
    if(willBeMine) {
      c.addSignatureToSeal(wrongKey);
    }
  }
  swapContract.seal();
  return swapContract;
}
origin: UniversaBlockchain/universa

private List<Contract> createListOfCoinsWithAmount(List<String> values) throws Exception {
  Contract money = createCoin();
  money.getStateData().set(FIELD_NAME, new Decimal(100500));
  money.addSignerKeyFromFile(PRIVATE_KEY_PATH);
  money.seal();
  sealCheckTrace(money, true);
  List<Contract> res = new ArrayList<>();
  for (String value : values) {
    Contract contract = ContractsService.createSplit(money, new BigDecimal(value), FIELD_NAME, new HashSet<PrivateKey>());
    contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
    res.add(contract.getNew().get(0));
  }
  return res;
}
origin: UniversaBlockchain/universa

/**
 * Cancels escrow contract. All linked payments are made available to the customer.
 * For registration canceled escrow contract require quorum of 2 of 3 roles: customer, executor and arbitrator.
 *
 * @param escrow contract (external or internal) to cancel. Must be registered for creation new revision
 *
 * @return canceled internal escrow contract or null if error occurred
 */
public static Contract cancelEscrowContract(Contract escrow) {
  Contract escrowInside = escrow;
  if (!escrow.getStateData().getString("status", "null").equals("opened")) {      // external escrow contract (escrow pack)
    // Find internal escrow contract in external escrow contract (escrow pack)
    String escrowOrigin = escrow.getDefinition().getData().getString("EscrowOrigin", null);
    if (escrowOrigin == null)
      return null;
    escrowInside = null;
    for (Contract c : escrow.getNew())
      if (c.getOrigin().toBase64String().equals(escrowOrigin) && c.getStateData().getString("status", "null").equals("opened"))
        escrowInside = c;
    if (escrowInside == null)
      return null;
  }
  Contract revisionEscrow = escrowInside.createRevision();
  revisionEscrow.getStateData().set("status", "canceled");
  revisionEscrow.seal();
  return revisionEscrow;
}
origin: UniversaBlockchain/universa

/**
 * Completes escrow contract. All linked payments are made available to the executor.
 * For registration completed escrow contract require quorum of 2 of 3 roles: customer, executor and arbitrator.
 *
 * @param escrow contract (external or internal) to complete. Must be registered for creation new revision
 *
 * @return completed internal escrow contract or null if error occurred
 */
public static Contract completeEscrowContract(Contract escrow) {
  Contract escrowInside = escrow;
  if (!escrow.getStateData().getString("status", "null").equals("opened")) {      // external escrow contract (escrow pack)
    // Find internal escrow contract in external escrow contract (escrow pack)
    String escrowOrigin = escrow.getDefinition().getData().getString("EscrowOrigin", null);
    if (escrowOrigin == null)
      return null;
    escrowInside = null;
    for (Contract c : escrow.getNew())
      if (c.getOrigin().toBase64String().equals(escrowOrigin) && c.getStateData().getString("status", "null").equals("opened"))
        escrowInside = c;
    if (escrowInside == null)
      return null;
  }
  Contract revisionEscrow = escrowInside.createRevision();
  revisionEscrow.getStateData().set("status", "completed");
  revisionEscrow.seal();
  return revisionEscrow;
}
origin: UniversaBlockchain/universa

/**
 * Method add found contracts in the new items and revoking items to {@link TransactionPack#subItems} and do it
 * again for each new item.
 * Also method add to {@link TransactionPack#referencedItems} referenced contracts from given.
 * @param c - given contract to extract from.
 */
protected synchronized void extractAllSubItemsAndReferenced(Contract c) {
  for (Contract r : c.getRevoking()) {
    putSubItem(r);
    for (Contract ref : r.getReferenced()) {
      addReferencedItem(ref);
    }
  }
  for (Contract n : c.getNew()) {
    putSubItem(n);
    extractAllSubItemsAndReferenced(n);
  }
  for (Contract ref : c.getReferenced()) {
    addReferencedItem(ref);
  }
}
origin: UniversaBlockchain/universa

@Test(timeout = 90000)
public void shouldBreakByQuantizerSplit() throws Exception {
  if(node == null) {
    System.out.println("network not inited");
    return;
  }
  PrivateKey key = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
  // 100
  Contract c = Contract.fromDslFile(ROOT_PATH + "coin100.yml");
  c.addSignerKeyFromFile(ROOT_PATH +"_xer0yfe2nn1xthc.private.unikey");
  c.seal();
  registerAndCheckApproved(c);
  Contract.setTestQuantaLimit(60);
  // 30
  Contract c1 = ContractsService.createSplit(c, new BigDecimal("30"), "amount", new HashSet<PrivateKey>(Arrays.asList(key)));
  Contract c2 = c1.getNew().get(0);
  assertEquals("70", c1.getStateData().get("amount").toString());
  assertEquals("30", c2.getStateData().get("amount").toString());
  node.registerItem(c1);
  ItemResult itemResult = node.waitItem(c1.getId(), 1500);
  System.out.println(itemResult);
  Contract.setTestQuantaLimit(-1);
  assertEquals(ItemState.UNDEFINED, itemResult.state);
}
origin: UniversaBlockchain/universa

@Test
public void serializeDeserialize() throws Exception {
  //serialize
  Binder b1 = serialize(parcel);
  Binder b2 = serialize(parcelFromFile);
  //deserialize
  des_parcel = deserialize(b1);
  des_parcelFromFile = deserialize(b2);
  parcelAssertions(parcel, des_parcel);
  parcelAssertions(des_parcelFromFile, des_parcelFromFile);
  assertEquals(1, des_parcel.getPayload().getSubItems().size());
  assertEquals(1, des_parcel.getPayload().getContract().getNew().size());
}
origin: UniversaBlockchain/universa

  @Test
  public void packUnpack() throws Exception {
    //pack
    byte[] array = parcel.pack();
    byte[] array1 = parcelFromFile.pack();

    //unpack
    des_parcel = Parcel.unpack(array);
    des_parcelFromFile = Parcel.unpack(array1);

    parcelAssertions(parcel, des_parcel);
    parcelAssertions(parcelFromFile, des_parcelFromFile);

    assertEquals(1, des_parcel.getPayload().getSubItems().size());
    assertEquals(1, des_parcel.getPayload().getContract().getNew().size());
  }
}
origin: UniversaBlockchain/universa

@Test
@Ignore("it is snatch test")
public void joinSnatch() throws Exception {
  PrivateKey key = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
  Set<PrivateKey> keys = new HashSet<>();
  keys.add(key);
  Contract c1 = Contract.fromDslFile(ROOT_PATH + "coin100.yml");
  c1.addSignerKey(key);
  assertTrue(c1.check());
  c1.seal();
  registerAndCheckApproved(c1);
  System.out.println("money before split (c1): " + c1.getStateData().getIntOrThrow("amount"));
  Contract c2 = ContractsService.createSplit(c1, new BigDecimal("99"), "amount", keys);
  Contract c3 = c2.getNew().get(0);
  System.out.println("money after split (c2): " + c2.getStateData().getIntOrThrow("amount"));
  System.out.println("money after split (c3): " + c3.getStateData().getIntOrThrow("amount"));
  registerAndCheckApproved(c3);
  Contract c4 = c3.createRevision(keys);
  c4.addRevokingItems(c1);
  c4.getStateData().set("amount", 199);//150);
  c4.seal();
  System.out.println("money after snatch (c4): " + c4.getStateData().getIntOrThrow("amount"));
  System.out.println("check after snatch (c4): " + c4.check());
  c4.traceErrors();
  registerAndCheckDeclined(c4);
}
origin: UniversaBlockchain/universa

@Test(timeout = 90000)
public void shouldDeclineSplit() throws Exception {
  if(node == null) {
    System.out.println("network not inited");
    return;
  }
  PrivateKey key = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
  // 100
  Contract c = Contract.fromDslFile(ROOT_PATH + "coin100.yml");
  c.addSignerKey(key);
  c.seal();
  assertTrue(c.check());
  registerAndCheckApproved(c);
  // 550
  Contract c1 = ContractsService.createSplit(c, new BigDecimal("550"), "amount", new HashSet<PrivateKey>(Arrays.asList(key)));
  Contract c2 = c1.getNew().get(0);
  assertEquals("-450", c1.getStateData().get("amount").toString());
  assertEquals("550", c2.getStateData().get("amount").toString());
  registerAndCheckDeclined(c1);
  assertEquals(ItemState.APPROVED, node.waitItem(c.getId(), 5000).state);
  assertEquals(ItemState.DECLINED, node.waitItem(c1.getId(), 5000).state);
  assertEquals(ItemState.UNDEFINED, node.waitItem(c2.getId(), 5000).state);
}
origin: UniversaBlockchain/universa

@Test(timeout = 90000)
public void shouldApproveSplit() throws Exception {
  if(node == null) {
    System.out.println("network not inited");
    return;
  }
  PrivateKey key = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
  // 100
  Contract c = Contract.fromDslFile(ROOT_PATH + "coin100.yml");
  c.addSignerKey(key);
  c.seal();
  assertTrue(c.check());
  registerAndCheckApproved(c);
  // 100 - 30 = 70
  Contract c1 = ContractsService.createSplit(c, new BigDecimal("30"), "amount", new HashSet<PrivateKey>(Arrays.asList(key)));
  Contract c2 = c1.getNew().get(0);
  assertEquals("70", c1.getStateData().get("amount").toString());
  assertEquals("30", c2.getStateData().get("amount").toString());
  registerAndCheckApproved(c1);
  assertEquals("70", c1.getStateData().get("amount").toString());
  assertEquals("30", c2.getStateData().get("amount").toString());
  assertEquals(ItemState.REVOKED, node.waitItem(c.getId(), 5000).state);
  assertEquals(ItemState.APPROVED, node.waitItem(c1.getId(), 5000).state);
  assertEquals(ItemState.APPROVED, node.waitItem(c2.getId(), 5000).state);
}
origin: UniversaBlockchain/universa

uContract = payingParcel.getPayloadContract().getNew().get(0);
origin: UniversaBlockchain/universa

@Test(timeout = 90000)
public void shouldDeclineSplitAndJoinWithWrongAmount() throws Exception {
  if(node == null) {
    System.out.println("network not inited");
    return;
  }
  PrivateKey key = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
  // 100
  Contract c = Contract.fromDslFile(ROOT_PATH + "coin100.yml");
  c.addSignerKey(key);
  c.seal();
  assertTrue(c.check());
  registerAndCheckApproved(c);
  assertEquals(100, c.getStateData().get("amount"));
  // split 100 - 30 = 70
  Contract c1 = ContractsService.createSplit(c, new BigDecimal("30"), "amount", new HashSet<PrivateKey>(Arrays.asList(key)));
  Contract c2 = c1.getNew().get(0);
  registerAndCheckApproved(c1);
  assertEquals("70", c1.getStateData().get("amount").toString());
  assertEquals("30", c2.getStateData().get("amount").toString());
  //wrong. send 500 out of 2 contracts (70 + 30)
  Contract c3 = c2.createRevision();
  c3.getStateData().set("amount", new Decimal(500));
  c3.addSignerKey(key);
  c3.addRevokingItems(c1);
  c3.seal();
  assertFalse(c3.check());
  registerAndCheckDeclined(c3);
}
origin: UniversaBlockchain/universa

uContract = payingParcel.getPayloadContract().getNew().get(0);
origin: UniversaBlockchain/universa

uContract = payingParcel.getPayloadContract().getNew().get(0);
com.icodici.universa.contractContractgetNew

Javadoc

Get contracts current contract creates upon registration

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

Popular in Java

  • Running tasks concurrently on multiple threads
  • setRequestProperty (URLConnection)
  • findViewById (Activity)
  • scheduleAtFixedRate (Timer)
    Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.
  • InetAddress (java.net)
    This class represents an Internet Protocol (IP) address. An IP address is either a 32-bit or 128-bit
  • KeyStore (java.security)
    This class represents an in-memory collection of keys and certificates. It manages two types of entr
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now