Approvable
, NContract
, HashIdentifiable
, java.lang.Cloneable
, net.sergeych.biserializer.BiSerializable
FollowerContract
, SlotContract
, UnsContract
public class NSmartContract extends Contract implements NContract
Modifier and Type | Class | Description |
---|---|---|
static interface |
NSmartContract.NodeInfoProvider |
Instance of this provider should be passed into setNodeInfoProvider of smart contract.
|
static class |
NSmartContract.SmartContractType |
Contract.Context, Contract.ContractDev, Contract.Definition, Contract.State, Contract.Transactional, Contract.UnicapsuleExpectedException
Modifier and Type | Field | Description |
---|---|---|
static java.lang.String |
PAID_U_FIELD_NAME |
JSAPI_SCRIPT_FIELD
Constructor | Description |
---|---|
NSmartContract() |
|
NSmartContract(byte[] sealed,
@NonNull TransactionPack pack) |
Extract contract from v2 or v3 sealed form, getting revokein and new items from the transaction pack supplied.
|
NSmartContract(com.icodici.crypto.PrivateKey key) |
Create a default empty new contract using a provided key as issuer and owner and sealer.
|
NSmartContract(net.sergeych.tools.Binder unpacked,
@NonNull TransactionPack pack) |
Modifier and Type | Method | Description |
---|---|---|
void |
addError(ErrorRecord r) |
Add error to contract
|
void |
attachToNetwork(Client client) |
Attach current contract to an instance of Universa network.
|
boolean |
beforeCreate(ImmutableEnvironment c) |
Check the smart contract could be created
|
boolean |
beforeRevoke(ImmutableEnvironment c) |
Check the smart contract could be revoked
|
boolean |
beforeUpdate(ImmutableEnvironment c) |
Check the smart contract could be updated (e.g.
|
boolean |
canFollowContract(Contract contract) |
|
boolean |
check() |
|
static NSmartContract |
fromDslFile(java.lang.String fileName) |
Method creates smart contract from dsl file where contract is described.
|
protected java.util.Collection<com.icodici.crypto.KeyAddress> |
getAdditionalKeysAddressesToSignWith() |
|
java.util.Map<java.lang.String,com.icodici.crypto.PublicKey> |
getCallbackKeys() |
|
@NonNull java.lang.String |
getExtendedType() |
This is a string tag which is used to find the proper
NContract
implementation. |
net.sergeych.tools.Binder |
getExtraResultForApprove() |
Creates
Binder that will be returned to client after smart contract have been approved. |
int |
getMinPayment() |
Get minimum possible payment for this type of
NSmartContract |
NSmartContract.NodeInfoProvider |
getNodeInfoProvider() |
|
protected int |
getPaidU() |
|
protected int |
getPaidU(boolean allowTestPayments) |
|
protected java.math.BigDecimal |
getRate() |
|
protected java.math.BigDecimal |
getRate(java.lang.String key) |
|
java.util.Map<HashId,java.lang.String> |
getTrackingOrigins() |
|
protected NSmartContract |
initializeWithDsl(net.sergeych.tools.Binder root) |
Method calls from
fromDslFile(String) and initialize contract from given binder. |
void |
onContractSubscriptionEvent(ContractSubscription.Event event) |
For the
ContractSubscription the instance will receive event notifications with this callback |
@Nullable net.sergeych.tools.Binder |
onCreated(MutableEnvironment c) |
Called after the new contract is approved by the network.
|
void |
onRevoked(ImmutableEnvironment c) |
Called when the contract is just revoked by the network
|
net.sergeych.tools.Binder |
onUpdated(MutableEnvironment c) |
Called after the new contract revision is approved by the network.
|
@NonNull net.sergeych.tools.Binder |
query(ImmutableEnvironment e,
java.lang.String methodName,
net.sergeych.tools.Binder params) |
Call the readonly method (query) that does not change the contract inner state (neither the contract nor
any associated data) and return the result
|
void |
setNodeInfoProvider(NSmartContract.NodeInfoProvider nodeInfoProvider) |
Provide info about payment rates, "U" issuer and some other data required by smart contract.
|
net.sergeych.tools.Binder |
toBinder() |
addError, addError, addNewItems, addPermission, addReference, addRevokingItems, addRole, addRole, addSignatureToSeal, addSignatureToSeal, addSignatureToSeal, addSignatureToSeal, addSignerKey, addSignerKeyFromFile, addSignerKeys, anonymizeRole, canBeRevoked, check, checkApplicablePermissionQuantized, checkReferencedItems, checkSubItemQuantized, clone, copy, createRevision, createRevision, createRevision, createRevision, createRevision, createRevision, createRevisionAnonymously, createRevisionAnonymously, createRevisionWithAddress, createRevisionWithAddress, createRevocation, createRole, createRole, createTransactionalSection, decodeDslTime, deserialize, execJS, execJS, execJSByName, execJSByName, execJSByScriptHash, execJSByScriptHash, extractJSNames, extractTheContract, findReferenceByName, findReferenceByName, findSignatureInSeal, fromDslStream, fromDslString, fromPackedTransaction, fromSealedBinary, fromSealedBinary, fromSealedFile, get, getAllContractInTree, getApiLevel, getContext, getContract, getContractBytes, getCreatedAt, getCreator, getCustomRoles, getDefinition, getEarliestCreationTime, getEffectiveKeys, getErrors, getErrorsString, getExpiresAt, getId, getId, getIssuedAt, getIssuer, getKeysToSignWith, getLastSealedBinary, getLastSealedBinary, getNew, getNewItems, getOrigin, getOwner, getPackedTransaction, getParent, getPermissions, getPredefinedRoles, getProcessedCost, getProcessedCostTU, getProcessedCostU, getQuantiser, getRawOrigin, getReferenceContextKeys, getReferenced, getReferencedItems, getReferences, getRevision, getRevisionId, getRevoking, getRevokingItem, getRevokingItems, getRole, getRoleAddresses, getRoles, getRootId, getSealedByKeys, getSiblings, getState, getStateData, getTestQuantaLimit, getTransactional, getTransactionalData, getTransactionPack, getValidRoleReferences, isInWhiteList, isLimitedForTestnet, isOk, isPermitted, isPermitted, isPermitted, isRoleReference, isSuitableForTestnet, isU, isUnlimitKeyContract, paymentCheck, prepareForReferenceMatching, registerRole, removeAllReferencedItems, removeAllSignatures, removeReference, removeReferencedItem, seal, sealAsV2, serialize, set, setApiLevel, setCreator, setCreator, setCreatorKeys, setCreatorKeys, setExpiresAt, setIssuerKeys, setIssuerKeys, setKeysToSignWith, setLimitedForTestnet, setOwnerKey, setOwnerKeys, setOwnerKeys, setReferenceContextKeys, setRoleKeys, setRoleKeys, setShouldBeU, setTestQuantaLimit, setTransactionPack, setVotedByKeys, shouldBeU, split, splitValue, testGetOwner, traceErrors, verifySealedKeys, verifySignatureQuantized
public static final java.lang.String PAID_U_FIELD_NAME
public NSmartContract(byte[] sealed, @NonNull TransactionPack pack) throws java.io.IOException
It is recommended to call 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 NSmartContract(net.sergeych.tools.Binder unpacked, @NonNull TransactionPack pack) throws java.io.IOException
java.io.IOException
public NSmartContract()
public NSmartContract(com.icodici.crypto.PrivateKey key)
This constructor adds key as sealing signature so it is ready to Contract.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).
key
- is PrivateKey
for creating roles "issuer", "owner", "creator" and sign contractpublic void setNodeInfoProvider(NSmartContract.NodeInfoProvider nodeInfoProvider)
nodeInfoProvider
- instance of NSmartContract.NodeInfoProvider
public NSmartContract.NodeInfoProvider getNodeInfoProvider()
public @NonNull java.lang.String getExtendedType()
NContract
NContract
implementation.getExtendedType
in interface NContract
public boolean beforeCreate(ImmutableEnvironment c)
NContract
beforeCreate
in interface NContract
public boolean beforeUpdate(ImmutableEnvironment c)
NContract
beforeUpdate
in interface NContract
public boolean beforeRevoke(ImmutableEnvironment c)
NContract
beforeRevoke
in interface NContract
public @Nullable net.sergeych.tools.Binder onCreated(MutableEnvironment c)
NContract
public net.sergeych.tools.Binder onUpdated(MutableEnvironment c)
NContract
public void onRevoked(ImmutableEnvironment c)
NContract
public @NonNull net.sergeych.tools.Binder query(ImmutableEnvironment e, java.lang.String methodName, net.sergeych.tools.Binder params)
NContract
public void addError(ErrorRecord r)
Contract
addError
in interface Approvable
addError
in class Contract
r
- error record containing code, erroneous object and messagepublic net.sergeych.tools.Binder toBinder()
toBinder
in interface net.sergeych.biserializer.BiSerializable
public boolean check() throws Quantiser.QuantiserException
check
in interface Approvable
Quantiser.QuantiserException
public void onContractSubscriptionEvent(ContractSubscription.Event event)
NContract
ContractSubscription
the instance will receive event notifications with this callbackonContractSubscriptionEvent
in interface NContract
protected NSmartContract initializeWithDsl(net.sergeych.tools.Binder root) throws com.icodici.crypto.EncryptionError
fromDslFile(String)
and initialize contract from given binder.initializeWithDsl
in class Contract
root
- id binder with initialized dataNSmartContract
contract.com.icodici.crypto.EncryptionError
- if something went wrongpublic static NSmartContract fromDslFile(java.lang.String fileName) throws java.io.IOException
fileName
- is path to dsl file with yaml structure of data for contract.java.io.IOException
public int getMinPayment()
NSmartContract
protected int getPaidU()
protected int getPaidU(boolean allowTestPayments)
protected java.math.BigDecimal getRate()
protected java.math.BigDecimal getRate(java.lang.String key)
protected java.util.Collection<com.icodici.crypto.KeyAddress> getAdditionalKeysAddressesToSignWith()
public net.sergeych.tools.Binder getExtraResultForApprove()
Binder
that will be returned to client after smart contract have been approved.public java.util.Map<HashId,java.lang.String> getTrackingOrigins()
public java.util.Map<java.lang.String,com.icodici.crypto.PublicKey> getCallbackKeys()
public boolean canFollowContract(Contract contract)
public void attachToNetwork(Client client) throws ClientError
NSmartContract
for local calculations
match the ones connected network is using.attachToNetwork
in class Contract
client
- connection to an instance of Universa network.ClientError