Approvable
, HashIdentifiable
, java.lang.Cloneable
, net.sergeych.biserializer.BiSerializable
NSmartContract
public class Contract extends java.lang.Object implements Approvable, net.sergeych.biserializer.BiSerializable, java.lang.Cloneable
Modifier and Type | Class | Description |
---|---|---|
protected class |
Contract.Context |
Transaction context.
|
class |
Contract.ContractDev |
|
class |
Contract.Definition |
|
class |
Contract.State |
|
class |
Contract.Transactional |
This section of a contract need for complex contracts, that consist of some contracts and need to be register all or no one.
|
static class |
Contract.UnicapsuleExpectedException |
Modifier and Type | Field | Description |
---|---|---|
static java.lang.String |
JSAPI_SCRIPT_FIELD |
Constructor | Description |
---|---|
Contract() |
Create an empty new contract
|
Contract(byte[] data) |
Extract contract from v2 or v3 sealed form, getting revoking and new items from sealed unicapsule.
|
Contract(byte[] sealed,
@NonNull TransactionPack pack) |
Extract contract from v2 or v3 sealed form, getting revoking and new items from sealed unicapsule and referenced items from
the transaction pack supplied.
|
Contract(byte[] sealed,
net.sergeych.tools.Binder data,
TransactionPack pack) |
Extract old, deprecated v2 self-contained binary partially unpacked by the
TransactionPack , and fill the
transaction pack with its contents. |
Contract(com.icodici.crypto.PrivateKey key) |
Create a default empty new contract using a provided key as issuer and owner and sealer.
|
Contract(net.sergeych.tools.Binder data,
@NonNull TransactionPack pack) |
Modifier and Type | Method | Description |
---|---|---|
void |
addError(ErrorRecord er) |
Add error to contract
|
protected void |
addError(Errors code,
java.lang.String field) |
Add error with empty message to contract
|
void |
addError(Errors code,
java.lang.String field,
java.lang.String text) |
Add error to contract
|
void |
addNewItems(Contract... newContracts) |
Add one or more siblings to the contract.
|
void |
addPermission(Permission perm) |
|
void |
addReference(Reference reference) |
Add reference to the references list of the contract.
|
void |
addRevokingItems(Contract... toRevoke) |
Add one or more contracts to revoke.
|
Role |
addRole(Role role) |
Adds new role to contract.
|
@NonNull Role |
addRole(java.lang.String roleName,
java.lang.Object roleObject) |
Resolve object describing role and create either: - new role object - symlink to named role instance, ensure it
is added as persistent named role to a contract and return it.
|
void |
addSignatureToSeal(byte[] signature,
com.icodici.crypto.PublicKey publicKey) |
Add signature to sealed (before) contract.
|
void |
addSignatureToSeal(com.icodici.crypto.PrivateKey privateKey) |
Add signature to sealed (before) contract.
|
void |
addSignatureToSeal(com.icodici.crypto.PrivateKey... privateKeys) |
Add signature to sealed (before) contract.
|
void |
addSignatureToSeal(java.util.Set<com.icodici.crypto.PrivateKey> privateKeys) |
Add signature to sealed (before) contract.
|
void |
addSignerKey(com.icodici.crypto.PrivateKey privateKey) |
Add private key to keys contract binary to be signed with when sealed next time.
|
void |
addSignerKeyFromFile(java.lang.String fileName) |
Add private key from file to keys contract binary to be signed with when sealed next time.
|
void |
addSignerKeys(java.util.Collection<com.icodici.crypto.PrivateKey> keys) |
Add collection of private keys to keys contract binary to be signed with when sealed next time.
|
void |
anonymizeRole(java.lang.String roleName) |
Anonymize existing role.
|
void |
attachToNetwork(Client client) |
Attach current contract to an instance of Universa network.
|
boolean |
canBeRevoked(java.util.Set<com.icodici.crypto.PublicKey> keys) |
|
boolean |
check(java.lang.String prefix) |
Check contract for errors.
|
void |
checkApplicablePermissionQuantized(Permission permission) |
Quantize given permission (add cost for that permission).
|
java.util.Set<java.lang.String> |
checkReferencedItems(java.util.Set<java.lang.String> roleRefsToResolve) |
|
protected void |
checkSubItemQuantized(Contract contract,
java.lang.String prefix) |
|
protected java.lang.Object |
clone() |
|
Contract |
copy() |
Make a valid deep copy of a contract
|
Contract |
createRevision() |
Create new revision to be changed, signed sealed and then ready to approve.
|
Contract |
createRevision(com.icodici.crypto.PrivateKey... keys) |
Create new revision to be changed, signed sealed and then ready to approve.
|
Contract |
createRevision(Contract.Transactional transactional) |
Create new revision to be changed, signed sealed and then ready to approve.
|
Contract |
createRevision(Contract.Transactional transactional,
com.icodici.crypto.PrivateKey... keys) |
Create new revision to be changed, signed sealed and then ready to approve.
|
Contract |
createRevision(java.util.Collection<com.icodici.crypto.PrivateKey> keys) |
Create new revision to be changed, signed sealed and then ready to approve.
|
Contract |
createRevision(java.util.Collection<com.icodici.crypto.PrivateKey> keys,
Contract.Transactional transactional) |
Create new revision to be changed, signed sealed and then ready to approve.
|
Contract |
createRevisionAnonymously(java.util.Collection<?> keys) |
Create new revision to be changed, signed sealed and then ready to approve.
|
Contract |
createRevisionAnonymously(java.util.Collection<?> keys,
Contract.Transactional transactional) |
Create new revision to be changed, signed sealed and then ready to approve.
|
Contract |
createRevisionWithAddress(java.util.Collection<?> keys) |
Create new revision to be changed, signed sealed and then ready to approve.
|
Contract |
createRevisionWithAddress(java.util.Collection<?> keys,
Contract.Transactional transactional) |
Create new revision to be changed, signed sealed and then ready to approve.
|
Contract |
createRevocation(com.icodici.crypto.PrivateKey... keys) |
Create revocation contract.
|
@NonNull Role |
createRole(java.lang.String roleName,
java.lang.Object roleObject) |
Deprecated.
|
Role |
createRole(java.lang.String roleName,
java.lang.Object roleObject,
boolean addToContract) |
Resolve object describing role and create either: - new role object - symlink to named role instance return it.
|
Contract.Transactional |
createTransactionalSection() |
Create new transactional section for the contract
|
static java.time.ZonedDateTime |
decodeDslTime(java.lang.Object t) |
|
void |
deserialize(net.sergeych.tools.Binder data,
net.sergeych.biserializer.BiDeserializer deserializer) |
|
java.lang.Object |
execJS(byte[] jsFileContent,
java.lang.String... params) |
|
java.lang.Object |
execJS(JSApiExecOptions execOptions,
byte[] jsFileContent,
java.lang.String... params) |
Executes javascript, that previously should be saved in contract's definition
with
Contract.Definition.setJS(byte[], String, JSApiScriptParameters) or Contract.State.setJS(byte[], String, JSApiScriptParameters) . |
java.lang.Object |
execJSByName(JSApiExecOptions execOptions,
java.lang.String jsFileName,
java.lang.String... params) |
Executes attached javascript if only one js is attached.
|
java.lang.Object |
execJSByName(java.lang.String jsFileName,
java.lang.String... params) |
|
java.lang.Object |
execJSByScriptHash(JSApiExecOptions execOptions,
HashId scriptHash,
java.lang.String... params) |
Executes javascript, like
execJS(JSApiExecOptions, byte[], String...) ,
but searches script body in contract. |
java.lang.Object |
execJSByScriptHash(HashId scriptHash,
java.lang.String... params) |
|
java.util.List<java.lang.String> |
extractJSNames() |
|
byte[] |
extractTheContract() |
Extract contract binary from sealed unicapsule
|
Reference |
findReferenceByName(java.lang.String name) |
Get contract reference with given name
|
Reference |
findReferenceByName(java.lang.String name,
java.lang.String section) |
Get contract reference with given name in given section
|
boolean |
findSignatureInSeal(com.icodici.crypto.PublicKey publicKey) |
Checks if signature present in sealed binary
|
static Contract |
fromDslFile(java.lang.String fileName) |
Create contract importing its parameters with passed .yaml file.
|
static Contract |
fromDslStream(java.io.InputStream dslStream) |
Create contract importing its parameters with passed yaml stream.
|
static Contract |
fromDslString(java.lang.String dslString) |
Create contract importing its parameters with passed yaml string.
|
static Contract |
fromPackedTransaction(@org.checkerframework.checker.nullness.qual.NonNull byte[] packedItem) |
Main .unicon read routine.
|
static Contract |
fromSealedBinary(byte[] sealedBinary) |
|
static Contract |
fromSealedBinary(byte[] sealedBinary,
TransactionPack tp) |
|
static Contract |
fromSealedFile(java.lang.String contractFileName) |
Construct contract from sealed binary stored in given file name
|
<T> T |
get(java.lang.String name) |
Get the named field in 'dotted' notation, e.g.
|
java.util.List<Contract> |
getAllContractInTree() |
Get all contracts involved in current contract registration: contract itself, new items and revoking items
|
int |
getApiLevel() |
Get current api level of the contract
|
protected Contract.Context |
getContext() |
|
Contract |
getContract() |
|
byte[] |
getContractBytes() |
Get contract bytes from sealed (before) contract.
|
java.time.ZonedDateTime |
getCreatedAt() |
Get contract creation time
|
Role |
getCreator() |
Get creator role
|
java.util.Map<java.lang.String,Role> |
getCustomRoles() |
Get custom roles of the contract stored in state.roles secion
|
Contract.Definition |
getDefinition() |
Get definition of a contract
|
java.time.chrono.ChronoZonedDateTime<?> |
getEarliestCreationTime() |
Get earliest possible creation time of a contract.
|
java.util.Set<com.icodici.crypto.PublicKey> |
getEffectiveKeys() |
|
java.util.List<ErrorRecord> |
getErrors() |
Get list of errors found during contract check
|
java.lang.String |
getErrorsString() |
|
java.time.ZonedDateTime |
getExpiresAt() |
Get contract expiration time
|
HashId |
getId() |
Get the id of the contract
|
HashId |
getId(boolean sealAsNeed) |
Get the id sealing self if need
|
java.time.ZonedDateTime |
getIssuedAt() |
Get contract issue time
|
Role |
getIssuer() |
Get issuer of the contract
|
java.util.Set<com.icodici.crypto.PrivateKey> |
getKeysToSignWith() |
Get private keys contract binary to be signed with when sealed next time.
|
byte[] |
getLastSealedBinary() |
Get the last knwon packed representation pf the contract.
|
byte[] |
getLastSealedBinary(boolean sealAsNeed) |
Get last sealed binary or create it if there is not
|
java.util.List<? extends Contract> |
getNew() |
Get contracts current contract creates upon registration
|
java.util.Set<Approvable> |
getNewItems() |
Get contracts to be registered within current contract registration.
|
HashId |
getOrigin() |
Get the id of origin contract.
|
Role |
getOwner() |
Get owner role
|
byte[] |
getPackedTransaction() |
Pack the contract to the most modern .unicon format, same as
TransactionPack.pack() . |
HashId |
getParent() |
Get the id of the parent contract
|
net.sergeych.collections.Multimap<java.lang.String,Permission> |
getPermissions() |
Get contract permissions
|
java.util.Map<java.lang.String,Role> |
getPredefinedRoles() |
Get predifined roles of the contract (issuer,owner,creator)
|
int |
getProcessedCost() |
Get the cost used for contract processing.
|
int |
getProcessedCostTU() |
Deprecated.
use
getProcessedCostU() instead. |
int |
getProcessedCostU() |
Get the cost used for contract processing.
|
Quantiser |
getQuantiser() |
|
HashId |
getRawOrigin() |
Get the id of origin contract from state.origin field.
|
java.util.Set<com.icodici.crypto.PublicKey> |
getReferenceContextKeys() |
|
java.util.List<? extends Contract> |
getReferenced() |
Get contracts referenced by current contract.
|
java.util.Set<Approvable> |
getReferencedItems() |
Get contracts that match all the reference
|
java.util.HashMap<java.lang.String,Reference> |
getReferences() |
Get map contract's references
|
int |
getRevision() |
Get current revision number of the contract
|
java.lang.String |
getRevisionId() |
Gets complex "id" of current revision
|
java.util.List<Contract> |
getRevoking() |
Get contracts current contract revokes upon registration
|
protected Contract |
getRevokingItem(HashId id) |
Try to find revoking item with a given ID.
|
java.util.Set<Approvable> |
getRevokingItems() |
Get contracts to be revoked within current contract registration.
|
Role |
getRole(java.lang.String roleName) |
Get registered role from the contract
|
java.util.List<java.lang.String> |
getRoleAddresses(java.lang.String roleName) |
Deprecated.
|
java.util.Map<java.lang.String,Role> |
getRoles() |
Get roles of the contract
|
protected HashId |
getRootId() |
Get the root id with the proper logic: for the root contract, it returns its
getId() , for the child
contracts - the origin id (state.origin field value). |
java.util.Set<com.icodici.crypto.PublicKey> |
getSealedByKeys() |
Get set of public keys contract binary signed with
|
java.util.Set<Contract> |
getSiblings() |
If the contract is creating siblings, e.g.
|
Contract.State |
getState() |
Get state of a contract
|
net.sergeych.tools.Binder |
getStateData() |
Get data section of contract state
|
static int |
getTestQuantaLimit() |
|
Contract.Transactional |
getTransactional() |
|
net.sergeych.tools.Binder |
getTransactionalData() |
Binder to hold any data client might want to keep per one transaction.
|
TransactionPack |
getTransactionPack() |
Get transaction pack of the contract
|
java.util.Set<java.lang.String> |
getValidRoleReferences() |
|
protected Contract |
initializeWithDsl(net.sergeych.tools.Binder root) |
|
boolean |
isInWhiteList(java.util.List<com.icodici.crypto.PublicKey> whiteList) |
|
boolean |
isLimitedForTestnet() |
|
boolean |
isOk() |
Important.
|
boolean |
isPermitted(java.lang.String permissionName,
com.icodici.crypto.PublicKey key) |
Checks if permission of given type that is allowed for given key exists
|
boolean |
isPermitted(java.lang.String permissionName,
KeyRecord keyRecord) |
Checks if permission of given type exists and is allowed for given key record
|
boolean |
isPermitted(java.lang.String permissionName,
java.util.Collection<com.icodici.crypto.PublicKey> keys) |
Checks if permission of given type that is allowed for given keys exists
|
boolean |
isRoleReference(Reference reference) |
|
boolean |
isSuitableForTestnet() |
Use after check().
|
boolean |
isU(java.util.Set<com.icodici.crypto.KeyAddress> issuerKeys,
java.lang.String issuerName) |
Special check for item to pass or not U contract criteria: allowed issuer keys and issuer name
|
boolean |
isUnlimitKeyContract(Config config) |
Checks contract is set unlimited requests for a key.
|
boolean |
paymentCheck(java.util.Set<com.icodici.crypto.KeyAddress> issuerKeys) |
Check contract to be a valid "U" payment.
|
void |
prepareForReferenceMatching() |
|
Role |
registerRole(Role role) |
Deprecated.
use
addRole(Role) instead |
void |
removeAllReferencedItems() |
|
void |
removeAllSignatures() |
Remove all signatures from sealed binary
|
void |
removeReference(Reference reference) |
Remove reference to the references list of the contract
|
void |
removeReferencedItem(Contract removed) |
|
byte[] |
seal() |
Seal contract to binary.
|
byte[] |
sealAsV2() |
|
net.sergeych.tools.Binder |
serialize(net.sergeych.biserializer.BiSerializer s) |
|
void |
set(java.lang.String name,
net.sergeych.tools.Binder value) |
Set the named field in 'dotted' notation, e.g.
|
void |
setApiLevel(int apiLevel) |
Set api level of the contract
|
Role |
setCreator(Role role) |
Deprecated.
|
Role |
setCreator(java.util.Collection<KeyRecord> records) |
Set "creator" role to given key records
|
@NonNull Role |
setCreatorKeys(java.lang.Object... keys) |
Set "creator" role to given keys
|
@NonNull Role |
setCreatorKeys(java.util.Collection<?> keys) |
Set "creator" role to given keys
|
void |
setExpiresAt(java.time.ZonedDateTime dateTime) |
Set expiration date of contract
|
Role |
setIssuerKeys(java.lang.Object... keys) |
Set "issuer" role to given keys
|
Role |
setIssuerKeys(java.util.Collection<?> keys) |
Set "issuer" role to given keys
|
void |
setKeysToSignWith(java.util.Set<com.icodici.crypto.PrivateKey> keysToSignWith) |
Set private keys contract binary to be signed with when sealed next time.
|
void |
setLimitedForTestnet(boolean limitedForTestnet) |
|
@NonNull Role |
setOwnerKey(java.lang.Object keyOrRecord) |
Set "owner" role to given key or key record
|
@NonNull Role |
setOwnerKeys(java.lang.Object... keys) |
Set "owner" role to given keys
|
@NonNull Role |
setOwnerKeys(java.util.Collection<?> keys) |
Set "owner" role to given keys
|
void |
setReferenceContextKeys(java.util.Set<com.icodici.crypto.PublicKey> effectiveKeys) |
|
Role |
setRoleKeys(java.lang.String roleName,
java.lang.Object... keys) |
Set given role to given keys
|
Role |
setRoleKeys(java.lang.String roleName,
java.util.Collection<?> keys) |
Set given role to given keys
|
void |
setShouldBeU(boolean shouldBeU) |
|
static void |
setTestQuantaLimit(int testQuantaLimit) |
|
void |
setTransactionPack(TransactionPack transactionPack) |
Set transaction pack for the contract
|
void |
setVotedByKeys(java.util.Set<com.icodici.crypto.PublicKey> votedByKeys) |
|
boolean |
shouldBeU() |
Getter for the node that shows for the node if item should be U contract and should check with special payment check.
|
Contract[] |
split(int count) |
Split one or more siblings from this revision.
|
Contract |
splitValue(java.lang.String fieldName,
Decimal valueToExtract) |
Split this contract extracting specified value from a named field.
|
KeyRecord |
testGetOwner() |
Deprecated.
|
void |
traceErrors() |
|
void |
verifySealedKeys(boolean isQuantise) |
Verify signatures in sealed contract (if needed) and forms a map of sealed keys.
|
protected void |
verifySignatureQuantized(com.icodici.crypto.PublicKey key) |
Verify signature, but before quantize this operation.
|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
check
public Contract(byte[] sealed, @NonNull TransactionPack pack) throws java.io.IOException
It is recommended to call Approvable.check()
after construction to see the errors.
sealed
- binary sealed contract.pack
- the transaction pack to resolve dependeincise agains.java.io.IOException
- on the various format errorspublic Contract(net.sergeych.tools.Binder data, @NonNull TransactionPack pack) throws java.io.IOException
java.io.IOException
public Contract(byte[] data) throws java.io.IOException
It is recommended to call Approvable.check()
after construction to see the errors.
data
- binary sealed contract.java.io.IOException
- on the various format errorspublic Contract(byte[] sealed, net.sergeych.tools.Binder data, TransactionPack pack) throws java.io.IOException
TransactionPack
, and fill the
transaction pack with its contents. This contsructor also fills transaction pack instance with the new and
revoking items included in its body in v2.sealed
- binary sealed contractdata
- unpacked sealed data (it is ready by the time of calling it)pack
- is TransactionPack
for contract was sent withjava.io.IOException
- on the various format errorspublic Contract()
public Contract(com.icodici.crypto.PrivateKey key)
This constructor adds key as sealing signature so it is ready to seal()
just after construction, thought
it is necessary to put real data to it first. It is allowed to change owner, expiration and data fields after
creation (but before sealing).
Change owner permission is added by default
key
- is PrivateKey
for creating roles "issuer", "owner", "creator" and sign contractpublic void setVotedByKeys(java.util.Set<com.icodici.crypto.PublicKey> votedByKeys)
public void prepareForReferenceMatching() throws Quantiser.QuantiserException
Quantiser.QuantiserException
public Quantiser getQuantiser()
public static int getTestQuantaLimit()
public static void setTestQuantaLimit(int testQuantaLimit)
public java.util.List<ErrorRecord> getErrors()
getErrors
in interface Approvable
ErrorRecord
containg errors foundprotected Contract initializeWithDsl(net.sergeych.tools.Binder root) throws com.icodici.crypto.EncryptionError
com.icodici.crypto.EncryptionError
public static Contract fromDslFile(java.lang.String fileName) throws java.io.IOException
fileName
- path to file containing Yaml representation of contract.java.io.IOException
public static Contract fromDslString(java.lang.String dslString) throws java.io.IOException
dslString
- containing Yaml representation of contractjava.io.IOException
public static Contract fromDslStream(java.io.InputStream dslStream) throws java.io.IOException
dslStream
- containing Yaml representation of contractjava.io.IOException
public Contract.State getState()
public Contract.Transactional getTransactional()
Contract.Transactional
object containing contract transacitonal.public int getApiLevel()
public void setApiLevel(int apiLevel)
apiLevel
- api level to be setpublic java.util.HashMap<java.lang.String,Reference> getReferences()
getReferences
in interface Approvable
public java.util.Set<Approvable> getReferencedItems()
getReferencedItems
in interface Approvable
public void removeReferencedItem(Contract removed)
public void removeAllReferencedItems()
public java.util.Set<Approvable> getRevokingItems()
RevokePermission
that is allowed for keys contract is signed withgetRevokingItems
in interface Approvable
public java.util.Set<Approvable> getNewItems()
getNewItems
in interface Approvable
public java.util.List<Contract> getAllContractInTree()
public boolean isUnlimitKeyContract(Config config)
getErrors()
()}.config
- is current node configurationpublic void verifySealedKeys(boolean isQuantise) throws Quantiser.QuantiserException
getErrors()
isQuantise
- if needed quantisation verifying signaturesQuantiser.QuantiserException
- when quantas limit was reached during checkpublic boolean check(java.lang.String prefix) throws Quantiser.QuantiserException
getErrors()
()}check
in interface Approvable
prefix
- is included in errors text. Used to differ errors found in contract from errors of subcontracts (revoking,new)Quantiser.QuantiserException
- when quantas limit was reached during checkpublic void setReferenceContextKeys(java.util.Set<com.icodici.crypto.PublicKey> effectiveKeys)
public boolean isRoleReference(Reference reference)
public java.util.Set<java.lang.String> checkReferencedItems(java.util.Set<java.lang.String> roleRefsToResolve) throws Quantiser.QuantiserException
Quantiser.QuantiserException
public boolean paymentCheck(java.util.Set<com.icodici.crypto.KeyAddress> issuerKeys) throws Quantiser.QuantiserException
paymentCheck
in interface Approvable
issuerKeys
- addresses of keys used by the network to issue "U"Quantiser.QuantiserException
- when quantas limit was reached during checkpublic int getProcessedCost()
Approvable.check()
method to check contract and calculate cost.public int getProcessedCostU()
Approvable.check()
method to check contract and calculate cost.@Deprecated public int getProcessedCostTU()
getProcessedCostU()
instead.public java.lang.String getRevisionId()
public void addError(Errors code, java.lang.String field, java.lang.String text)
addError
in interface Approvable
code
- error codefield
- path to contract field error found intext
- error messagepublic void addError(ErrorRecord er)
addError
in interface Approvable
er
- error record containing code, erroneous object and messageprotected HashId getRootId()
getId()
, for the child
contracts - the origin id (state.origin field value). Note that all contract states in the chain share same
origin - it is an id of the root contract, whose id is always null.protected Contract getRevokingItem(HashId id)
Contract
instance, it
will not be found, null will be returned.id
- to findpublic void addRevokingItems(Contract... toRevoke)
seal()
on them as resealing discards network approval by changing the id!toRevoke
- is comma-separated contract to revoke@Deprecated public @NonNull Role createRole(java.lang.String roleName, java.lang.Object roleObject)
Role
then return it.roleName
- is name of the roleroleObject
- is object for role creatingRole
public @NonNull Role addRole(java.lang.String roleName, java.lang.Object roleObject)
roleName
- is name of the roleroleObject
- is object for role creatingRole
public Role createRole(java.lang.String roleName, java.lang.Object roleObject, boolean addToContract)
roleName
- is name of the roleroleObject
- is object for role creatingaddToContract
- flag indicating if constructed role should also be added to a contract as persistent named roleRole
public Role getRole(java.lang.String roleName)
roleName
- name of the role to get@Deprecated public java.util.List<java.lang.String> getRoleAddresses(java.lang.String roleName)
public HashId getId(boolean sealAsNeed)
sealAsNeed
- true to seal the contract if there is no getLastSealedBinary()
.public HashId getId()
getId
in interface HashIdentifiable
public Role getIssuer()
public java.time.ZonedDateTime getCreatedAt()
getCreatedAt
in interface Approvable
public java.time.ZonedDateTime getExpiresAt()
getExpiresAt
in interface Approvable
public java.util.Map<java.lang.String,Role> getRoles()
public java.util.Map<java.lang.String,Role> getPredefinedRoles()
public java.util.Map<java.lang.String,Role> getCustomRoles()
public Contract.Definition getDefinition()
@Deprecated public KeyRecord testGetOwner()
@Deprecated public Role registerRole(Role role)
addRole(Role)
insteadrole
- public Role addRole(Role role)
get(String)
method by passing "state.roles.$ROLE_NAME"
Note: this method creates persistent named role within contract. Do not use this method for permission roles
as these roles should only be present inside of permission. It you want this role to be persistent named AND
be present within permission it is better to make a RoleLink
within permission to persistent role by its name.role
- public void anonymizeRole(java.lang.String roleName)
PublicKey
it will be replaced with AnonymousId
roleName
- name of the role to anonymizepublic boolean isPermitted(java.lang.String permissionName, KeyRecord keyRecord) throws Quantiser.QuantiserException
permissionName
- type of permission to check forkeyRecord
- key record to check permission withQuantiser.QuantiserException
- if quantas limit was reached during checkpublic void addPermission(Permission perm)
public boolean isPermitted(java.lang.String permissionName, com.icodici.crypto.PublicKey key) throws Quantiser.QuantiserException
permissionName
- type of permission to check forkey
- public key to check permission withQuantiser.QuantiserException
- if quantas limit was reached during checkpublic boolean isPermitted(java.lang.String permissionName, java.util.Collection<com.icodici.crypto.PublicKey> keys) throws Quantiser.QuantiserException
permissionName
- type of permission to check forkeys
- collection of keys to check withQuantiser.QuantiserException
- if quantas limit was reached during checkprotected void addError(Errors code, java.lang.String field)
code
- error codefield
- path to contract field error found inpublic java.time.chrono.ChronoZonedDateTime<?> getEarliestCreationTime()
public java.util.Set<com.icodici.crypto.PublicKey> getSealedByKeys()
public java.util.Set<com.icodici.crypto.PrivateKey> getKeysToSignWith()
public void setKeysToSignWith(java.util.Set<com.icodici.crypto.PrivateKey> keysToSignWith)
keysToSignWith
- key contract binary to be signed withpublic void addSignerKeyFromFile(java.lang.String fileName) throws java.io.IOException
fileName
- path to file containing private keyjava.io.IOException
public void addSignerKey(com.icodici.crypto.PrivateKey privateKey)
privateKey
- key to sign withpublic void addSignerKeys(java.util.Collection<com.icodici.crypto.PrivateKey> keys)
keys
- key to sign withpublic void addReference(Reference reference)
Reference.type
reference
- reference to addpublic void removeReference(Reference reference)
reference
- reference to removepublic boolean isOk()
Approvable.check()
.public byte[] sealAsV2()
public byte[] seal()
getKeysToSignWith()
public void addSignatureToSeal(com.icodici.crypto.PrivateKey privateKey)
privateKey
- - key to sign contract will withpublic void addSignatureToSeal(com.icodici.crypto.PrivateKey... privateKeys)
privateKeys
- - key to sign contract will withpublic void addSignatureToSeal(java.util.Set<com.icodici.crypto.PrivateKey> privateKeys)
privateKeys
- - key to sign contract will withpublic void addSignatureToSeal(byte[] signature, com.icodici.crypto.PublicKey publicKey)
signature
- - signature to addpublicKey
- - key signed withpublic byte[] getContractBytes()
addSignatureToSeal(byte[], PublicKey)
.ExtendedSignature.createTargetSignature(PublicKey, byte[], boolean)
public void removeAllSignatures()
public boolean findSignatureInSeal(com.icodici.crypto.PublicKey publicKey) throws Quantiser.QuantiserException
publicKey
- public key to check signature ofQuantiser.QuantiserException
- if quantas limit was reached during checkpublic byte[] extractTheContract()
public byte[] getLastSealedBinary()
Contract(byte[])
or was explicitly sealed seal()
.
Caution. This method could return out of date binary, if the contract was changed after the seal()
call.
Before we will add track of changes, use it only if you are sure that seal()
was called and contract was
not changed since then.
seal()
call, or the binary from which was constructed.public Contract createRevision()
public Contract createRevision(Contract.Transactional transactional)
transactional
- is Contract.Transactional
section to create new revision withpublic int getRevision()
public HashId getParent()
public HashId getRawOrigin()
public HashId getOrigin()
public Contract createRevision(com.icodici.crypto.PrivateKey... keys)
keys
- initially added and signer keys. Role "creator" is set to these keys for new revisionpublic Contract createRevision(Contract.Transactional transactional, com.icodici.crypto.PrivateKey... keys)
keys
- initially added and signer keys. Role "creator" is set to these keys for new revisiontransactional
- is Contract.Transactional
section to create new revision withpublic Contract createRevision(java.util.Collection<com.icodici.crypto.PrivateKey> keys)
keys
- initially added and signer keys. Role "creator" is set to these keys for new revisionpublic Contract createRevision(java.util.Collection<com.icodici.crypto.PrivateKey> keys, Contract.Transactional transactional)
keys
- initially added and signer keys. Role "creator" is set to these keys for new revisiontransactional
- is Contract.Transactional
section to create new revision withpublic Contract createRevisionAnonymously(java.util.Collection<?> keys)
keys
- initially added and signer keys. Role "creator" is set to anonymous ids of these keyspublic Contract createRevisionAnonymously(java.util.Collection<?> keys, Contract.Transactional transactional)
keys
- initially added and signer keys. Role "creator" is set to anonymous ids of these keystransactional
- is Contract.Transactional
section to create new revision withpublic Contract createRevisionWithAddress(java.util.Collection<?> keys)
keys
- initially added and signer keys. Role "creator" is set to addresses of these keyspublic Contract createRevisionWithAddress(java.util.Collection<?> keys, Contract.Transactional transactional)
keys
- initially added and signer keys. Role "creator" is set to addresses of these keystransactional
- is Contract.Transactional
section to create new revision withpublic Role setCreator(java.util.Collection<KeyRecord> records)
records
- key records to set "creator" role topublic @NonNull Role setCreatorKeys(java.lang.Object... keys)
keys
- keys to set "creator" role topublic @NonNull Role setCreatorKeys(java.util.Collection<?> keys)
keys
- keys to set "creator" role topublic Role getOwner()
public @NonNull Role setOwnerKey(java.lang.Object keyOrRecord)
keyOrRecord
- key or key record to set "creator" role topublic @NonNull Role setOwnerKeys(java.util.Collection<?> keys)
keys
- keys to set "owner" role topublic Role setRoleKeys(java.lang.String roleName, java.lang.Object... keys)
roleName
- name of a rolekeys
- keys to set "owner" role topublic Role setRoleKeys(java.lang.String roleName, java.util.Collection<?> keys)
roleName
- name of a rolekeys
- keys to set "owner" role topublic @NonNull Role setOwnerKeys(java.lang.Object... keys)
keys
- keys to set "owner" role topublic Role getCreator()
public net.sergeych.collections.Multimap<java.lang.String,Permission> getPermissions()
public net.sergeych.tools.Binder getStateData()
public Role setIssuerKeys(java.util.Collection<?> keys)
keys
- keys to set "issuer" role topublic Role setIssuerKeys(java.lang.Object... keys)
keys
- keys to set "issuer" role topublic void setExpiresAt(java.time.ZonedDateTime dateTime)
dateTime
- expiration date to setpublic void deserialize(net.sergeych.tools.Binder data, net.sergeych.biserializer.BiDeserializer deserializer)
deserialize
in interface net.sergeych.biserializer.BiSerializable
public net.sergeych.tools.Binder serialize(net.sergeych.biserializer.BiSerializer s)
serialize
in interface net.sergeych.biserializer.BiSerializable
public Contract[] split(int count)
createRevision(PrivateKey...)
first. We recommend setting up signing keys before calling split, otherwise
caller must explicitly set signing keys on each contract.
It the new revision is already split, it can't be split again.
It is important to understand that this revision become a contract that has to be registered with Universa service, which will automatically register all requested siblings in a transaction. Do not register siblings themselves: registering this contract will do all the work.
count
- number of siblings to splitpublic Contract splitValue(java.lang.String fieldName, Decimal valueToExtract)
SplitJoinPermission
and be signed with proper keys to pass checks.
Important. This contract must be a new revision: call createRevision(PrivateKey...)
first.
fieldName
- field to extract fromvalueToExtract
- how much to extractpublic java.util.Set<Contract> getSiblings()
public void addNewItems(Contract... newContracts)
seal()
or getPackedTransaction()
. Do not reseal as it changes the id!newContracts
- is comma-separated contractspublic <T> T get(java.lang.String name)
T
- type for valuename
- of field to got value frompublic void set(java.lang.String name, net.sergeych.tools.Binder value)
name
- of field to be setvalue
- to be setpublic static Contract fromSealedFile(java.lang.String contractFileName) throws java.io.IOException
contractFileName
- file name to get binary fromjava.io.IOException
public java.time.ZonedDateTime getIssuedAt()
public byte[] getLastSealedBinary(boolean sealAsNeed)
sealAsNeed
- seal()
it if there is no cached binarypublic byte[] getPackedTransaction()
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.public net.sergeych.tools.Binder getTransactionalData()
Binder
from transactional sectionpublic static Contract fromPackedTransaction(@org.checkerframework.checker.nullness.qual.NonNull byte[] packedItem) throws java.io.IOException
TransactionPack
instance to pack it to store or send to
approval.
The supported file variants are:
- v2 legacy unicon. Is loaded with packed counterparts if any. Only for compatibility, avoid using it.
- v3 compacted unicon. Is loaded without counterparts, should be added later if need with addNewItems(Contract...)
and addRevokingItems(Contract...)
. This is a good way to keep the long
contract chain.
- packed TransactionPack
. This is a preferred way to keep current contract state.
To pack and write corresponding .unicon file use getPackedTransaction()
.
packedItem
- some packed from of the universa contractContract
java.io.IOException
- if the packedItem is brokenpublic void setTransactionPack(TransactionPack transactionPack)
transactionPack
- transaction pack to setpublic TransactionPack getTransactionPack()
public Contract createRevocation(com.icodici.crypto.PrivateKey... keys)
So, to revoke some contract:
- call createRevocation(PrivateKey...)
with key or keys that can play the role for "revoke" permission
- register it in the Universa network, see Client.register(byte[], long)
.
Upon the successful registration the source contract will be revoked. Use transaction contract's getPackedTransaction()
to obtain a binary to submit to the client.
keys
- one or more keys that together can play the role assigned to the revoke permission.public java.util.List<Contract> getRevoking()
public java.util.List<? extends Contract> getNew()
public java.util.List<? extends Contract> getReferenced()
Reference
.public boolean canBeRevoked(java.util.Set<com.icodici.crypto.PublicKey> keys) throws Quantiser.QuantiserException
keys
- that should be testedQuantiser.QuantiserException
- if processing cost limit is gotpublic Contract.Transactional createTransactionalSection()
protected void verifySignatureQuantized(com.icodici.crypto.PublicKey key) throws Quantiser.QuantiserException
key
- that will be quantizedQuantiser.QuantiserException
- if processing cost limit is gotpublic void checkApplicablePermissionQuantized(Permission permission) throws Quantiser.QuantiserException
permission
- that will be quantizedQuantiser.QuantiserException
- if processing cost limit is gotprotected void checkSubItemQuantized(Contract contract, java.lang.String prefix) throws Quantiser.QuantiserException
Quantiser.QuantiserException
public Reference findReferenceByName(java.lang.String name)
name
- name of the referencepublic Reference findReferenceByName(java.lang.String name, java.lang.String section)
name
- name of the referencesection
- section to search inpublic java.util.Set<java.lang.String> getValidRoleReferences()
public java.util.Set<com.icodici.crypto.PublicKey> getEffectiveKeys()
public java.util.Set<com.icodici.crypto.PublicKey> getReferenceContextKeys()
public Contract getContract()
public void traceErrors()
public java.lang.String getErrorsString()
protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
protected Contract.Context getContext()
public boolean isU(java.util.Set<com.icodici.crypto.KeyAddress> issuerKeys, java.lang.String issuerName)
Approvable
isU
in interface Approvable
issuerKeys
- is set of allowed by node keys for U issuingissuerName
- is allowed issuer namepublic boolean shouldBeU()
Approvable
shouldBeU
in interface Approvable
public void setShouldBeU(boolean shouldBeU)
public void setLimitedForTestnet(boolean limitedForTestnet)
public boolean isLimitedForTestnet()
public boolean isSuitableForTestnet()
public boolean isInWhiteList(java.util.List<com.icodici.crypto.PublicKey> whiteList)
isInWhiteList
in interface Approvable
public static java.time.ZonedDateTime decodeDslTime(java.lang.Object t)
public java.lang.Object execJS(JSApiExecOptions execOptions, byte[] jsFileContent, java.lang.String... params) throws java.lang.Exception
Contract.Definition.setJS(byte[], String, JSApiScriptParameters)
or Contract.State.setJS(byte[], String, JSApiScriptParameters)
.
Provides instance of JSApi
to this script, as 'jsApi' global var.params
- list of strings, will be passed to javascriptjavax.script.ScriptException
- if javascript throws some errorsjava.lang.IllegalArgumentException
- if javascript is not defined in contract's definitionjava.lang.Exception
public java.lang.Object execJS(byte[] jsFileContent, java.lang.String... params) throws java.lang.Exception
java.lang.Exception
public java.lang.Object execJSByScriptHash(JSApiExecOptions execOptions, HashId scriptHash, java.lang.String... params) throws java.lang.Exception
execJS(JSApiExecOptions, byte[], String...)
,
but searches script body in contract. It should be saved previously with Contract.Definition.setJS(byte[], String, JSApiScriptParameters, boolean)
or Contract.State.setJS(byte[], String, JSApiScriptParameters, boolean)
with putContentIntoContract == true.scriptHash
- is HashId
from js-file content.java.lang.Exception
public java.lang.Object execJSByScriptHash(HashId scriptHash, java.lang.String... params) throws java.lang.Exception
java.lang.Exception
public java.lang.Object execJSByName(JSApiExecOptions execOptions, java.lang.String jsFileName, java.lang.String... params) throws java.lang.Exception
java.lang.Exception
public java.lang.Object execJSByName(java.lang.String jsFileName, java.lang.String... params) throws java.lang.Exception
java.lang.Exception
public java.util.List<java.lang.String> extractJSNames()
public static Contract fromSealedBinary(byte[] sealedBinary) throws java.io.IOException
java.io.IOException
public static Contract fromSealedBinary(byte[] sealedBinary, TransactionPack tp) throws java.io.IOException
java.io.IOException
public void attachToNetwork(Client client) throws ClientError
NSmartContract
for local calculations
match the ones connected network is using.client
- connection to an instance of Universa network.ClientError