/** * Get transaction pack of the contract * @return transaction pack of the contract */ public synchronized TransactionPack getTransactionPack() { if (transactionPack == null) transactionPack = new TransactionPack(this); return transactionPack; }
/** * Extract contract from v2 or v3 sealed form, getting revoking and new items from sealed unicapsule. * <p> * It is recommended to call {@link #check()} after construction to see the errors. * * @param data binary sealed contract. * * @throws IOException on the various format errors */ public Contract(byte[] data) throws IOException { this(data, new TransactionPack()); }
/** * Construct contract from sealed binary stored in given file name * @param contractFileName file name to get binary from * @return extracted contract * @throws IOException */ public static Contract fromSealedFile(String contractFileName) throws IOException { return new Contract(Do.read(contractFileName), new TransactionPack()); }
/** * Unpack either old contract binary (all included), or newer transaction pack. Could be used to load old contracts * to perform a transaction. * * @param packOrContractBytes is binary that was packed by {@link TransactionPack#pack()} * @param allowNonTransactions if false, non-transaction pack data will cause IOException. * * @return transaction, either unpacked or reconstructed from the self-contained v2 contract * @throws IOException if something went wrong */ public static TransactionPack unpack(byte[] packOrContractBytes, boolean allowNonTransactions) throws IOException { Object x = Boss.load(packOrContractBytes); if (x instanceof TransactionPack) { return (TransactionPack) x; } if (!allowNonTransactions) throw new IOException("expected transaction pack"); // This is an old v2 self-contained contract or a root v3 contract, no revokes, no siblings. TransactionPack tp = new TransactionPack(); tp.reconstructed = true; tp.packedBinary = packOrContractBytes; tp.contract = new Contract(packOrContractBytes, tp); return tp; }
@Test public void serializeNew() throws Exception { TransactionPack tp = new TransactionPack(); tp.setContract(c); checkSimplePack(tp); }
contract3.seal(); TransactionPack tp = new TransactionPack(); tp.setContract(contract1); tp.addSubItem(contract1);
@Test public void deserializeNew() throws Exception { TransactionPack tp = new TransactionPack(); tp.setContract(c); checkSimplePack(tp);
System.out.println("contract2_id: " + contract1.getStateData().get("contract2_id")); TransactionPack tp = new TransactionPack(); tp.setContract(contract1); tp.addSubItem(contract2);
@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); }
TransactionPack tp = new TransactionPack(); tp.setContract(llcProperty); tp.addSubItem(contractCertificate);
contractImported.setKeysToSignWith(signKeys); byte[] sealedContract = contractImported.sealAsV2(); TransactionPack tp = new TransactionPack(); tp.addKeys(creatorPrivateKey.getPublicKey()); tp.addKeys(TestKeys.privateKey(0).getPublicKey());
@Before public void setUp() throws Exception { TransactionPack payloadTpFromFile = new TransactionPack(); TransactionPack paymentTpFromFile = new TransactionPack(); TransactionPack payload_tp = new TransactionPack(); TransactionPack payment_tp = new TransactionPack();
TransactionPack tp = new TransactionPack(c1); TransactionPack tp2 = TransactionPack.unpack(new TransactionPack(c1).pack());