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

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

Best Java code snippets using com.icodici.universa.contract.Contract.getPackedTransaction (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

@Override
public byte[] getPackedTransaction() {
  return ((Contract) updatingItem).getPackedTransaction();
}
origin: UniversaBlockchain/universa

/**
 * Put contract to the tracking contract's revisions queue.
 * If queue contains more then {@link SlotContract#keepRevisions} revisions then last one will removed.
 * @param c is revision of tracking {@link Contract}.
 */
public void putTrackingContract(Contract c) {
  trackingContracts.addFirst(c);
  packedTrackingContracts.addFirst(c.getPackedTransaction());
  updateTrackingContracts();
}
origin: UniversaBlockchain/universa

private void saveTrackingContractsToState() {
  Binder forState = new Binder();
  for (Contract tc : trackingContracts) {
    forState.set(tc.getId().toBase64String(), tc.getPackedTransaction());
  }
  getStateData().set(TRACKING_CONTRACT_FIELD_NAME, forState);
}
origin: UniversaBlockchain/universa

@Test
public void testFiles() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  contract.seal();
  String newFilename = FileTool.writeFileContentsWithRenaming(System.getProperty("java.io.tmpdir")+"/testFile_2.file", contract.getPackedTransaction());
  System.out.println("write done, new filename=" + newFilename);
}
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

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 checkPaymentContract() throws Exception {
  // to register manually, execute from deploy project:
  // bin/sql_all pro "insert into ledger(hash,state,created_at, expires_at, locked_by_id) values(decode('9186C0A9E9471E4559E74B5DAC3DBBB8445807DF80CAE4CE06FDB6588FAEBA1CE004AD378BEF3C445DECF3375E3CA5FD16227DBE5831A21207BB1BD21C85F30D0CED014E152F77E62082E0442FBD9FD2458C20778F7501B5D425AF9984062E54','hex'),'4','1520977039','1552513039','0');"
  // to erase all ledgers, execute:
  // bin/sql_all pro "truncate table ledger"
  // (after erasing ledgers, items still stay in cache -> need to restart (or redeploy) nodes)
  Contract contract = paymentContract;
  contract.check();
  System.out.println("uno bin: " + Base64.encodeString(contract.getPackedTransaction()));
  System.out.println("uno hashId: " + Bytes.toHex(contract.getId().getDigest()).replace(" ", ""));
  System.out.println("approved ord: " + ItemState.APPROVED.ordinal());
  System.out.println("getCreatedAt: " + StateRecord.unixTime(contract.getCreatedAt()));
  System.out.println("getExpiresAt: " + StateRecord.unixTime(contract.getExpiresAt()));
  ItemResult itemResult = normalClient.getState(contract.getId());
  System.out.println("getState... done! itemResult: " + itemResult.state);
}
origin: UniversaBlockchain/universa

private Binder queryNameContract(Binder params, Session session) throws IOException {
  checkNode(session, true);
  Binder b = new Binder();
  String nameContract = params.getStringOrThrow("name");
  NNameRecord nr = node.getLedger().getNameRecord(nameContract);
  if (nr != null) {
    NImmutableEnvironment env = node.getLedger().getEnvironment(nr.getEnvironmentId());
    if (env != null) {
      byte[] packedContract = env.getContract().getPackedTransaction();
      b.put("packedContract", packedContract);
    }
  }
  return b;
}
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

@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

@Test
public void createRegisterParcel() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  contract.seal();
  String contractFileName = basePath + "createRegisterParcel.unicon";
  new FileOutputStream(contractFileName).write(contract.getPackedTransaction());
  String uContract = getApprovedUContract();
  callMain("--create-parcel", contractFileName, "--verbose",
      "--u", uContract,
      "--k", rootPath + "keys/stepan_mamontov.private.unikey");
  callMain("--register-parcel", new FilenameTool(contractFileName).setExtension("uniparcel").toString());
  Thread.sleep(1500);
  System.out.println("probe after register");
  Contract c = CLIMain.loadContract(contractFileName);
  callMain("--probe", c.getId().toBase64String(), "--verbose");
  System.out.println(output);
  assertEquals(0, errors.size());
  assertTrue (output.indexOf(ItemState.APPROVED.name()) > 0);
}
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 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

@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

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 transactionalData() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  String testValue = HashId.createRandom().toBase64String();
  contract.getTransactionalData().set("test_value", testValue);
  contract.seal();
  byte[] packedData = contract.getPackedTransaction();
  Contract unpackedContract = Contract.fromPackedTransaction(packedData);
  System.out.println("unpackedContract.transactional.data.test_value: " + unpackedContract.getTransactionalData().getStringOrThrow("test_value"));
  assertEquals(testValue, unpackedContract.getTransactionalData().getStringOrThrow("test_value"));
}
origin: UniversaBlockchain/universa

@Test
public void references() throws Exception {
  Contract contract = new Contract(TestKeys.privateKey(0));
  String js = "";
  js += "print('references');";
  js += "var ref = jsApi.getReferenceBuilder().createReference('EXISTING_STATE');";
  js += "ref.setConditions({'all_of':['ref.issuer=="+TestKeys.publicKey(1).getShortAddress().toString()+"']});";
  js += "jsApi.getCurrentContract().addReference(ref);";
  contract.getState().setJS(js.getBytes(), "client script.js", new JSApiScriptParameters());
  contract.seal();
  contract = Contract.fromPackedTransaction(contract.getPackedTransaction());
  Contract batchContract = new Contract(TestKeys.privateKey(3));
  batchContract.addNewItems(contract);
  batchContract.seal();
  assertTrue(batchContract.check());
  contract.execJS(new JSApiExecOptions(), js.getBytes());
  contract.seal();
  batchContract.seal();
  assertFalse(batchContract.check());
}
com.icodici.universa.contractContractgetPackedTransaction

Javadoc

Pack the contract to the most modern .unicon format, same as TransactionPack#pack(). Uses bounded TransactionPack instance to save together the contract, revoking and new items (if any). This is a binary format using to submit for approval. Use #fromPackedTransaction(byte[]) to read this format.

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

  • 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