/** * Pack the contract to the most modern .unicon format, same as {@link TransactionPack#pack()}. Uses bounded {@link * TransactionPack} instance to save together the contract, revoking and new items (if any). This is a binary format * using to submit for approval. Use {@link #fromPackedTransaction(byte[])} to read this format. * * @return packed binary form. */ public byte[] getPackedTransaction() { return getTransactionPack().pack(); }
@Override synchronized public Approvable getItem(HashId itemId, NodeInfo nodeInfo, Duration maxTimeout) throws InterruptedException { Node node = nodes.get(nodeInfo); Approvable item = node.getItem(itemId); if(item instanceof Contract) { TransactionPack tp_before = ((Contract) item).getTransactionPack(); byte[] data = tp_before.pack(); // here we "send" data and "got" it TransactionPack tp_after = null; try { tp_after = TransactionPack.unpack(data); Contract gotMainContract = tp_after.getContract(); return gotMainContract; } catch (IOException e) { e.printStackTrace(); } } return item; }
/** * Imitate of sending contract from one part of swappers to another. * * Method packs sending contracts with main swap contract (can be blank - doesn't matter) into TransactionPack. * Then restore from packed binary main swap contract, contracts sending with. * * @param mainContract * @return * @throws Exception */ public synchronized Contract imitateSendingTransactionToPartner(Contract mainContract) throws Exception { TransactionPack tp_before = mainContract.getTransactionPack(); byte[] data = tp_before.pack(); // here we "send" data and "got" it TransactionPack tp_after = TransactionPack.unpack(data); Contract gotMainContract = tp_after.getContract(); return gotMainContract; }
byte[] packedTp = tp.pack();
@Test public void packAndUnpackWithKeys() throws Exception { TransactionPack tp = new TransactionPack(); tp.setContract(c); // tp.addKeys(publicKey); checkPackWithKeys(tp); assertSame(tp,c.getTransactionPack()); byte[] packedTp = tp.pack(); TransactionPack tp1 = TransactionPack.unpack(packedTp); checkPackWithKeys(tp1); }
byte[] data = tp_before.pack(); TransactionPack tp_after = TransactionPack.unpack(data);
byte[] data = tp_before.pack(); System.out.println("----"); TransactionPack tp_after = TransactionPack.unpack(data);
byte[] data = tp_before.pack(); TransactionPack tp_after = TransactionPack.unpack(data);
byte[] data = tp_before.pack(); TransactionPack tp_after = TransactionPack.unpack(data);
byte[] data = tp_before.pack(); TransactionPack tp_after = TransactionPack.unpack(data);
TransactionPack tp2 = TransactionPack.unpack(new TransactionPack(c1).pack());