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

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

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

origin: UniversaBlockchain/universa

/**
 * Register a paying parcel.
 *
 * @param contract              must be a sealed binary.
 */
public static Parcel prepareForRegisterPayingParcel(Contract contract, Contract u, int amount, int amountStorage, Set<PrivateKey> uKeys, boolean withTestPayment) throws IOException {
  List<ErrorRecord> errors = contract.getErrors();
  if (errors.size() > 0) {
    report("contract has errors and can't be submitted for registration");
    report("contract id: " + contract.getId().toBase64String());
    addErrors(errors);
  } else {
    Set<PrivateKey> keys = new HashSet<>(keysMapContract().values());
    if (keys != null && keys.size() > 0)
      contract.addSignerKeys(keys);
    Parcel parcel = ContractsService.createPayingParcel(contract.getTransactionPack(), u, amount, amountStorage, uKeys, withTestPayment);
    return parcel;
  }
  return null;
}
origin: UniversaBlockchain/universa

/**
 * Register a specified contract.
 *
 * @param contract              must be a sealed binary.
 */
public static Parcel prepareForRegisterContract(Contract contract, Contract u, int amount, Set<PrivateKey> uKeys, boolean withTestPayment) throws IOException {
  List<ErrorRecord> errors = contract.getErrors();
  if (errors.size() > 0) {
    report("contract has errors and can't be submitted for registration");
    report("contract id: " + contract.getId().toBase64String());
    addErrors(errors);
  } else {
    Parcel parcel = ContractsService.createParcel(contract, u, amount,  uKeys, withTestPayment);
    return parcel;
  }
  return null;
}
origin: UniversaBlockchain/universa

          contract.getErrors().get(contract.getErrors().size() - 1).getMessage()));
} else {
  System.out.println("approve ERROR: command needs client key from whitelist");
origin: UniversaBlockchain/universa

/**
 * Save specified parcel to file.
 *
 * @param parcel              - parcel to save.
 * @param fileName              - name of file to save to.
 *
 */
public static boolean saveParcel(Parcel parcel, String fileName) throws IOException {
  if (fileName == null) {
    fileName = "Universa_" + DateTimeFormatter.ofPattern("yyyy-MM-ddTHH:mm:ss").format(parcel.getPayloadContract().getCreatedAt()) + ".uniparcel";
  }
  byte[] data = parcel.pack();
  String newFileName = FileTool.writeFileContentsWithRenaming(fileName, data);
  report("Parcel is saved to: " + newFileName);
  report("Parcel size: " + data.length);
  try {
    if (parcel.getPaymentContract().check() && parcel.getPayloadContract().check()) {
      report("Parcel has no errors");
    } else {
      addErrors(parcel.getPaymentContract().getErrors());
      addErrors(parcel.getPayloadContract().getErrors());
    }
  } catch (Quantiser.QuantiserException e) {
    addError("QUANTIZER_COST_LIMIT", parcel.toString(), e.getMessage());
  }
  return (newFileName!=null);
}
origin: UniversaBlockchain/universa

    report("Sealed contract has no errors");
  } else
    addErrors(contract.getErrors());
} catch (Quantiser.QuantiserException e) {
  addError("QUANTIZER_COST_LIMIT", contract.toString(), e.getMessage());
origin: UniversaBlockchain/universa

@Test
public void badRevoke() throws Exception {
  Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
  c.addSignerKeyFromFile(rootPath+"_xer0yfe2nn1xthc.private.unikey");
  c.seal();
  PrivateKey issuer = TestKeys.privateKey(2);
  Contract tc = c.createRevocation(issuer);
  // c can't be revoked with this key!
  boolean result = tc.check();
  assertFalse(result);
  assertEquals(1, tc.getErrors().size());
  assertEquals(Errors.FORBIDDEN, tc.getErrors().get(0).getError());
}
origin: UniversaBlockchain/universa

/**
 * Check bytes is contract. And if bytes is, check contract for errors. Print errors if found.
 *
 * @param data - data to check.
 *
 * @return true if bytes is Contract and Contract is valid.
 */
private static Boolean checkBytesIsValidContract(byte[] data) {
  try {
    Contract contract = new Contract(data);
    if (!contract.isOk()) {
      reporter.message("The capsule is not sealed");
      contract.getErrors().forEach(e -> reporter.error(e.getError().toString(), e.getObjectName(), e.getMessage()));
    }
    checkContract(contract);
  } catch (RuntimeException e) {
    addError(Errors.BAD_VALUE.name(), "byte[] data", e.getMessage());
    return false;
  } catch (Quantiser.QuantiserException e) {
    addError("QUANTIZER_COST_LIMIT", "", e.toString());
  } catch (IOException e) {
    addError(Errors.BAD_VALUE.name(), "byte[] data", e.getMessage());
    return false;
  }
  return true;
}
origin: UniversaBlockchain/universa

@Test
public void checkCreatingRootContract() throws Exception {
  Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
  c.seal();
  boolean ok = c.check();
  assertFalse(ok);
  List<ErrorRecord> errors = c.getErrors();
  // It is just ok but not signed
  assertEquals(2, errors.size());
  assertEquals(errors.get(0).getError(), Errors.NOT_SIGNED);
  c.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey");
  c.getErrors().clear();
  c.seal();
  ok = c.check();
  if (errors.isEmpty()) {
    assertTrue(ok);
    assertTrue(c.isOk());
  } else {
    for (ErrorRecord e : errors) {
      System.out.println(e);
      fail("errors in contract");
    }
  }
  assertTrue(c.check());
  Files.write(Paths.get(rootPath + "simple_root_contract.unc"), c.seal());
  Yaml yaml = new Yaml();
  Files.write(Paths.get(rootPath + "simple_root_contract.raw.yaml"),
      yaml.dump(DefaultBiMapper.serialize(c)).getBytes()
  );
}
origin: UniversaBlockchain/universa

  /**
   * Register a specified contract.
   *
   * @param contract              must be a sealed binary.
   * @param waitTime - wait time for responce.
   * @param fromPackedTransaction - register contract with Contract.getPackedTransaction()
   */
  @Deprecated
  public static void registerContract(Contract contract, int waitTime, Boolean fromPackedTransaction) throws IOException {
//        checkContract(contract);
    List<ErrorRecord> errors = contract.getErrors();
    if (errors.size() > 0) {
      report("contract has errors and can't be submitted for registration");
      report("contract id: " + contract.getId().toBase64String());
      addErrors(errors);
    } else {
//            contract.seal();

      ItemResult r;
      if (fromPackedTransaction) {
        r = getClientNetwork().register(contract.getPackedTransaction(), waitTime);
      } else {
        r = getClientNetwork().register(contract.getLastSealedBinary(), waitTime);
      }
      report("submitted with result:");
      report(r.toString());
    }
  }

origin: UniversaBlockchain/universa

((Contract)revokingItem).getErrors().clear();
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

c1.check();
c1.traceErrors();
assertEquals(1, c1.getErrors().size());
for(ErrorRecord error : c1.getErrors()) {
  assertThat(error.getError(), anyOf(equalTo(Errors.FORBIDDEN), equalTo(Errors.FAILED_CHECK)));
c2.check();
c2.traceErrors();
assertEquals(1, c2.getErrors().size());
for(ErrorRecord error : c1.getErrors()) {
  assertThat(error.getError(), anyOf(equalTo(Errors.FORBIDDEN), equalTo(Errors.FAILED_CHECK)));
origin: UniversaBlockchain/universa

c1.check();
c1.traceErrors();
assertEquals(1, c1.getErrors().size());
for(ErrorRecord error : c1.getErrors()) {
  assertThat(error.getError(), anyOf(equalTo(Errors.FORBIDDEN), equalTo(Errors.FAILED_CHECK)));
c2.check();
c2.traceErrors();
assertEquals(1, c2.getErrors().size());
for(ErrorRecord error : c1.getErrors()) {
  assertThat(error.getError(), anyOf(equalTo(Errors.FORBIDDEN), equalTo(Errors.FAILED_CHECK)));
origin: UniversaBlockchain/universa

  @Test
  public void checkSealingRootContract() throws Exception {
    Contract c = Contract.fromDslFile(rootPath + "simple_root_contract.yml");
    c.addSignerKeyFromFile(rootPath + "_xer0yfe2nn1xthc.private.unikey");
    byte[] sealed = c.seal();
    assertTrue(c.check());
//        Bytes.dump(sealed);
//        System.out.println(sealed.length);
    Contract c2 = new Contract(sealed);
    assertProperSimpleRootContract(c2);

    boolean ok = c2.check();
    List<ErrorRecord> errors = c2.getErrors();

    if (errors.isEmpty()) {
      assertTrue(ok);
      assertTrue(c.isOk());
    } else {
      for (ErrorRecord e : errors) {
        System.out.println(e);
        fail("errors in contract");
      }
    }
    assertTrue(c.check());
  }

origin: UniversaBlockchain/universa

@Test
public void issuerTest() throws Exception {
  KeyAddress keyAddress1 = TestKeys.privateKey(0).getPublicKey().getShortAddress();
  KeyAddress keyAddress2 = TestKeys.privateKey(1).getPublicKey().getShortAddress();
  Contract contract = new Contract(TestKeys.privateKey(2));
  contract.setCreatorKeys(keyAddress1);
  contract.setIssuerKeys(keyAddress2);
  contract.addSignerKey(TestKeys.privateKey(0));
  contract.seal();
  assertFalse(contract.check());
  contract.setIssuerKeys(keyAddress1);
  contract.getErrors().clear();
  contract.seal();
  assertTrue(contract.check());
}
origin: UniversaBlockchain/universa

if (ItemState.APPROVED != itemResult.state)
  fail("Wrong state on repetition " + i + ": " + itemResult + ", " + itemResult.errors +
      " \r\ncontract_errors: " + contract.getErrors());
origin: UniversaBlockchain/universa

c1.check();
c1.traceErrors();
assertEquals(1, c1.getErrors().size());
ErrorRecord error = c1.getErrors().get(0);
assertEquals(Errors.FORBIDDEN, error.getError());
origin: UniversaBlockchain/universa

@Test
public void testJoinSum() throws Exception {
  Contract c = createCoin();
  c.addSignerKeyFromFile(PRIVATE_KEY_PATH);
  Binder d = c.getStateData();
  int a = 1000000;
  assertEquals(a, d.getIntOrThrow(FIELD_NAME));
  c.seal();
  c.check();
  c.traceErrors();
  assertTrue(c.check());
  // bad split: no changes
  Contract c1 = c.createRevision(ownerKey2);
  sealCheckTrace(c1, false);
  // Good split
  Contract c2 = c1.splitValue(FIELD_NAME, new Decimal(500));
  assertEquals(a - 500, c1.getStateData().getIntOrThrow(FIELD_NAME));
  assertEquals(500, c2.getStateData().getIntOrThrow(FIELD_NAME));
  c1.getErrors().clear();
  sealCheckTrace(c1, true);
  Contract c3 = c1.createRevision(ownerKey2);
  c3.getRevokingItems().add(c2);
  c3.getStateData().set(FIELD_NAME, new Decimal(a));
  sealCheckTrace(c3, true);
}
origin: UniversaBlockchain/universa

assertEquals(500, c2.getStateData().getIntOrThrow(FIELD_NAME));
c1.getErrors().clear();
sealCheckTrace(c1, true);
origin: UniversaBlockchain/universa

changed.getErrors().clear();
changed.getStateData().set("value", "1");
changed.seal();
com.icodici.universa.contractContractgetErrors

Javadoc

Get list of errors found during contract check

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,
  • getKeysToSignWith,
  • getLastSealedBinary,
  • getNew,
  • getNewItems

Popular in Java

  • Finding current android device location
  • requestLocationUpdates (LocationManager)
  • setRequestProperty (URLConnection)
  • getSystemService (Context)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Kernel (java.awt.image)
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • BoxLayout (javax.swing)
  • 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