net.sergeych.biserializer.BiSerializable
public class TransactionPack
extends java.lang.Object
implements net.sergeych.biserializer.BiSerializable
setContract(Contract)
,
and obtained by getContract()
. The subItems are: new items (f. e. from split operation),
revoking contracts (f. e. from creating new revision, joining contracts and so on), all of them stores
in the subItems
. Referenced contracts needed for main contract stores
in the referencedItems
. Also you may need to store keys in the transaction pack
(f. e. when using addresses or anonymous ids), use keysForPack
for it.
Packed format of transaction pack could be very well used instead of Contract.seal()
binaries as it holds
together the window around the contract graph (parent and siblings) needed to approve its state. It is advised to use
Contract.getPackedTransaction()
to save the Contract and Contract.fromPackedTransaction(byte[])
to
restore, respectively, as it holds together all relevant data. The file extension for it should be .unicon, as the
latter function is able to read and reconstruct legacy v2 sealed contracts, current v3 sealed contracts and packed
TransactionPack instances, it is a universal format and a universal routine to load it. See Contract.fromPackedTransaction(byte[])
for more.
Indeed, it is possible to keep all contract binaries separately and put them together for submission only, thus saving the space.
The legacy v2 self-contained format is no more in use as the size of the hashed binary constantly grows.
Using Contract.getTransactionPack()
will create transaction pack with needed subItems, referencedItems and keys.
But if you need to add some objects manually use addSubItem(Contract)
to add subItem,
use addReferencedItem(Contract)
to add referenced contracts
and addKeys(PublicKey...)
to add needed keys manually.
A word of terminology.
We name as the transaction contract any contract that is going to be passed to the network for verification and approval; it could and should contain other contracts as revoking as well as new items (siblings) to create. These subItems do not need to be added separately.
Note. To put several operations in an atomic transaction, put iy all into a single top-level contract.
Modifier and Type | Class | Description |
---|---|---|
class |
TransactionPack.ContractDependencies |
Class that extracts subItems from given contract bytes and build dependencies.
|
Modifier and Type | Field | Description |
---|---|---|
static java.lang.String |
TAG_PREFIX_RESERVED |
Constructor | Description |
---|---|
TransactionPack() |
|
TransactionPack(Contract contract) |
Create a transaction pack and add a contract to it.
|
Modifier and Type | Method | Description |
---|---|---|
void |
addKeys(com.icodici.crypto.PublicKey... keys) |
Add public key to
TransactionPack that will match with anonymous ids or addresses in the Contract roles. |
void |
addReferencedItem(Contract referencedItem) |
Direct add the referenced items.
|
void |
addSubItem(Contract subItem) |
Direct add the subItem.
|
void |
addTag(java.lang.String tag,
HashId itemId) |
Add tag to an item of transaction pack by its id
Note: item with given id should exist in transaction pack as either main contract or subitem or referenced item
|
void |
deserialize(net.sergeych.tools.Binder data,
net.sergeych.biserializer.BiDeserializer deserializer) |
|
protected void |
extractAllSubItemsAndReferenced(Contract c) |
Method add found contracts in the new items and revoking items to
subItems and do it
again for each new item. |
Contract |
findContract(java.util.function.Predicate<Contract> function) |
Find contract in transaction pack by given predicate
Note: if there is more than one contract that matches predicate a random one will be returned
|
Contract |
getContract() |
The main contract of this
TransactionPack . |
java.util.Set<com.icodici.crypto.PublicKey> |
getKeysForPack() |
|
java.util.Map<HashId,Contract> |
getReferencedItems() |
|
Contract |
getSubItem(HashId id) |
|
Contract |
getSubItem(HashIdentifiable hid) |
|
java.util.Map<HashId,Contract> |
getSubItems() |
|
java.util.Map<java.lang.String,Contract> |
getTags() |
|
HashId |
getUbotId() |
|
boolean |
isReconstructed() |
|
byte[] |
pack() |
Shortcut to
Boss.pack(Object) for this. |
protected void |
putSubItem(Contract subItem) |
Store the subItem.
|
net.sergeych.tools.Binder |
serialize(net.sergeych.biserializer.BiSerializer serializer) |
|
void |
setContract(Contract c) |
Add contract that already includes all its subItems, referenced items and keys.
|
void |
setReferenceContextKeys(java.util.Set<com.icodici.crypto.PublicKey> referenceEffectiveKeys) |
|
void |
setUbotId(HashId ubotId) |
|
void |
trace() |
Trace the tree of contracts subItems on the stdout.
|
static TransactionPack |
unpack(byte[] packOrContractBytes) |
Unpack either old contract binary (all included), or newer transaction pack.
|
static TransactionPack |
unpack(byte[] packOrContractBytes,
boolean allowNonTransactions) |
Unpack either old contract binary (all included), or newer transaction pack.
|
public static final java.lang.String TAG_PREFIX_RESERVED
public TransactionPack(Contract contract)
TransactionPack()
and setContract(Contract)
for more information.contract
- is Contract
to be send with this TransactionPack
public TransactionPack()
public void setUbotId(HashId ubotId)
public HashId getUbotId()
public Contract getContract()
TransactionPack
.Contract
public Contract getSubItem(HashIdentifiable hid)
public java.util.Set<com.icodici.crypto.PublicKey> getKeysForPack()
public void setContract(Contract c)
This is extremely important that the contract is properly sealed as well as its possibly new items, revoking items and referenced items have binary image attached. Do not ever seal the approved contract: it will break it's id and cancel the approval blockchain, so the new state will not be approved. If it was done by mistake, reload the packed contract to continue.
c
- is a contract to append to the list of transactions.protected void extractAllSubItemsAndReferenced(Contract c)
subItems
and do it
again for each new item.
Also method add to referencedItems
referenced contracts from given.c
- - given contract to extract from.public void addSubItem(Contract subItem)
setContract(Contract)
already does it for all subItems.
Use it to add subItems not mentioned in the added contracts.subItem
- is Contract
for addingpublic void addReferencedItem(Contract referencedItem)
referencedItem
- is Contract
for addingpublic void addTag(java.lang.String tag, HashId itemId)
tag
- tag to additemId
- id of an item to set tag forpublic void addKeys(com.icodici.crypto.PublicKey... keys)
TransactionPack
that will match with anonymous ids or addresses in the Contract
roles.keys
- is PublicKey
that will be compare with anonymous ids or addresses.protected void putSubItem(Contract subItem)
setContract(Contract)
and only useful if the latter is
overriden. SubItems are not processed by themselves but only as parts of the contracts add with
setContract(Contract)
subItem
- is Contract
for puttingpublic void deserialize(net.sergeych.tools.Binder data, net.sergeych.biserializer.BiDeserializer deserializer) throws java.io.IOException
deserialize
in interface net.sergeych.biserializer.BiSerializable
java.io.IOException
public net.sergeych.tools.Binder serialize(net.sergeych.biserializer.BiSerializer serializer)
serialize
in interface net.sergeych.biserializer.BiSerializable
public final boolean isReconstructed()
public static TransactionPack unpack(byte[] packOrContractBytes, boolean allowNonTransactions) throws java.io.IOException
packOrContractBytes
- is binary that was packed by pack()
allowNonTransactions
- if false, non-transaction pack data will cause IOException.java.io.IOException
- if something went wrongpublic static TransactionPack unpack(byte[] packOrContractBytes) throws java.io.IOException
packOrContractBytes
- binary that was packed by pack()
java.io.IOException
- if something went wrongpublic byte[] pack()
Boss.pack(Object)
for this.public java.util.Map<HashId,Contract> getSubItems()
public java.util.Map<HashId,Contract> getReferencedItems()
public java.util.Map<java.lang.String,Contract> getTags()
public void trace()
public void setReferenceContextKeys(java.util.Set<com.icodici.crypto.PublicKey> referenceEffectiveKeys)
public Contract findContract(java.util.function.Predicate<Contract> function)
function
- predicate to match contract bynull
if no contract found