github.com/braveheart12/just@v0.8.7/core/message/ledger.go (about)

     1  /*
     2   *    Copyright 2019 Insolar Technologies
     3   *
     4   *    Licensed under the Apache License, Version 2.0 (the "License");
     5   *    you may not use this file except in compliance with the License.
     6   *    You may obtain a copy of the License at
     7   *
     8   *        http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   *    Unless required by applicable law or agreed to in writing, software
    11   *    distributed under the License is distributed on an "AS IS" BASIS,
    12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   *    See the License for the specific language governing permissions and
    14   *    limitations under the License.
    15   */
    16  
    17  package message
    18  
    19  import (
    20  	"github.com/insolar/insolar/core"
    21  	"github.com/insolar/insolar/ledger/recentstorage"
    22  	"github.com/insolar/insolar/ledger/storage/jet"
    23  )
    24  
    25  // FIXME: @andreyromancev. 21.12.18. Remove this and create 'LogicRunnerMessage' interface to get rid of 'GetCaller' in ledger.
    26  type ledgerMessage struct {
    27  }
    28  
    29  // GetCaller implementation of Message interface.
    30  func (ledgerMessage) GetCaller() *core.RecordRef {
    31  	return nil
    32  }
    33  
    34  // SetRecord saves record in storage.
    35  type SetRecord struct {
    36  	ledgerMessage
    37  
    38  	Record    []byte
    39  	TargetRef core.RecordRef
    40  }
    41  
    42  // AllowedSenderObjectAndRole implements interface method
    43  func (m *SetRecord) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
    44  	return &m.TargetRef, core.DynamicRoleVirtualExecutor
    45  }
    46  
    47  // DefaultRole returns role for this event
    48  func (*SetRecord) DefaultRole() core.DynamicRole {
    49  	return core.DynamicRoleLightExecutor
    50  }
    51  
    52  // DefaultTarget returns of target of this event.
    53  func (m *SetRecord) DefaultTarget() *core.RecordRef {
    54  	return &m.TargetRef
    55  }
    56  
    57  // Type implementation of Message interface.
    58  func (m *SetRecord) Type() core.MessageType {
    59  	return core.TypeSetRecord
    60  }
    61  
    62  // GetCode retrieves code From storage.
    63  type GetCode struct {
    64  	ledgerMessage
    65  	Code core.RecordRef
    66  }
    67  
    68  // AllowedSenderObjectAndRole implements interface method
    69  func (m *GetCode) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
    70  	return &m.Code, core.DynamicRoleVirtualExecutor
    71  }
    72  
    73  // DefaultRole returns role for this event
    74  func (*GetCode) DefaultRole() core.DynamicRole {
    75  	return core.DynamicRoleLightExecutor
    76  }
    77  
    78  // DefaultTarget returns of target of this event.
    79  func (m *GetCode) DefaultTarget() *core.RecordRef {
    80  	return &m.Code
    81  }
    82  
    83  // Type implementation of Message interface.
    84  func (*GetCode) Type() core.MessageType {
    85  	return core.TypeGetCode
    86  }
    87  
    88  // GetObject retrieves object From storage.
    89  type GetObject struct {
    90  	ledgerMessage
    91  	Head     core.RecordRef
    92  	State    *core.RecordID // If nil, will fetch the latest state.
    93  	Approved bool
    94  }
    95  
    96  // AllowedSenderObjectAndRole implements interface method
    97  func (m *GetObject) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
    98  	return &m.Head, core.DynamicRoleVirtualExecutor
    99  }
   100  
   101  // DefaultRole returns role for this event
   102  func (*GetObject) DefaultRole() core.DynamicRole {
   103  	return core.DynamicRoleLightExecutor
   104  }
   105  
   106  // DefaultTarget returns of target of this event.
   107  func (m *GetObject) DefaultTarget() *core.RecordRef {
   108  	return &m.Head
   109  }
   110  
   111  // Type implementation of Message interface.
   112  func (*GetObject) Type() core.MessageType {
   113  	return core.TypeGetObject
   114  }
   115  
   116  // GetDelegate retrieves object represented as provided type.
   117  type GetDelegate struct {
   118  	ledgerMessage
   119  	Head   core.RecordRef
   120  	AsType core.RecordRef
   121  }
   122  
   123  // AllowedSenderObjectAndRole implements interface method
   124  func (m *GetDelegate) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   125  	return &m.Head, core.DynamicRoleVirtualExecutor
   126  }
   127  
   128  // DefaultRole returns role for this event
   129  func (*GetDelegate) DefaultRole() core.DynamicRole {
   130  	return core.DynamicRoleLightExecutor
   131  }
   132  
   133  // DefaultTarget returns of target of this event.
   134  func (m *GetDelegate) DefaultTarget() *core.RecordRef {
   135  	return &m.Head
   136  }
   137  
   138  // Type implementation of Message interface.
   139  func (*GetDelegate) Type() core.MessageType {
   140  	return core.TypeGetDelegate
   141  }
   142  
   143  // UpdateObject amends object.
   144  type UpdateObject struct {
   145  	ledgerMessage
   146  
   147  	Record []byte
   148  	Object core.RecordRef
   149  	Memory []byte
   150  }
   151  
   152  // AllowedSenderObjectAndRole implements interface method
   153  func (m *UpdateObject) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   154  	return &m.Object, core.DynamicRoleVirtualExecutor
   155  }
   156  
   157  // DefaultRole returns role for this event
   158  func (*UpdateObject) DefaultRole() core.DynamicRole {
   159  	return core.DynamicRoleLightExecutor
   160  }
   161  
   162  // DefaultTarget returns of target of this event.
   163  func (m *UpdateObject) DefaultTarget() *core.RecordRef {
   164  	return &m.Object
   165  }
   166  
   167  // Type implementation of Message interface.
   168  func (*UpdateObject) Type() core.MessageType {
   169  	return core.TypeUpdateObject
   170  }
   171  
   172  // RegisterChild amends object.
   173  type RegisterChild struct {
   174  	ledgerMessage
   175  	Record []byte
   176  	Parent core.RecordRef
   177  	Child  core.RecordRef
   178  	AsType *core.RecordRef // If not nil, considered as delegate.
   179  }
   180  
   181  // AllowedSenderObjectAndRole implements interface method
   182  func (m *RegisterChild) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   183  	return &m.Child, core.DynamicRoleVirtualExecutor
   184  }
   185  
   186  // DefaultRole returns role for this event
   187  func (*RegisterChild) DefaultRole() core.DynamicRole {
   188  	return core.DynamicRoleLightExecutor
   189  }
   190  
   191  // DefaultTarget returns of target of this event.
   192  func (m *RegisterChild) DefaultTarget() *core.RecordRef {
   193  	return &m.Parent
   194  }
   195  
   196  // Type implementation of Message interface.
   197  func (*RegisterChild) Type() core.MessageType {
   198  	return core.TypeRegisterChild
   199  }
   200  
   201  // GetChildren retrieves a chunk of children references.
   202  type GetChildren struct {
   203  	ledgerMessage
   204  	Parent    core.RecordRef
   205  	FromChild *core.RecordID
   206  	FromPulse *core.PulseNumber
   207  	Amount    int
   208  }
   209  
   210  // AllowedSenderObjectAndRole implements interface method
   211  func (m *GetChildren) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   212  	return &m.Parent, core.DynamicRoleVirtualExecutor
   213  }
   214  
   215  // DefaultRole returns role for this event
   216  func (*GetChildren) DefaultRole() core.DynamicRole {
   217  	return core.DynamicRoleLightExecutor
   218  }
   219  
   220  // DefaultTarget returns of target of this event.
   221  func (m *GetChildren) DefaultTarget() *core.RecordRef {
   222  	return &m.Parent
   223  }
   224  
   225  // Type implementation of Message interface.
   226  func (*GetChildren) Type() core.MessageType {
   227  	return core.TypeGetChildren
   228  }
   229  
   230  // JetDrop spreads jet drop
   231  type JetDrop struct {
   232  	ledgerMessage
   233  
   234  	JetID core.RecordID
   235  
   236  	Drop        []byte
   237  	Messages    [][]byte
   238  	PulseNumber core.PulseNumber
   239  }
   240  
   241  // AllowedSenderObjectAndRole implements interface method
   242  func (m *JetDrop) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   243  	// This check is not needed, because JetDrop sender is explicitly checked in handler.
   244  	return nil, core.DynamicRoleUndefined
   245  }
   246  
   247  // DefaultRole returns role for this event
   248  func (*JetDrop) DefaultRole() core.DynamicRole {
   249  	return core.DynamicRoleLightExecutor
   250  }
   251  
   252  // DefaultTarget returns of target of this event.
   253  func (m *JetDrop) DefaultTarget() *core.RecordRef {
   254  	return core.NewRecordRef(core.RecordID{}, m.JetID)
   255  }
   256  
   257  // Type implementation of Message interface.
   258  func (*JetDrop) Type() core.MessageType {
   259  	return core.TypeJetDrop
   260  }
   261  
   262  // ValidateRecord creates VM validation for specific object record.
   263  type ValidateRecord struct {
   264  	ledgerMessage
   265  
   266  	Object             core.RecordRef
   267  	State              core.RecordID
   268  	IsValid            bool
   269  	ValidationMessages []core.Message
   270  }
   271  
   272  // AllowedSenderObjectAndRole implements interface method
   273  func (m *ValidateRecord) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   274  	return &m.Object, core.DynamicRoleVirtualExecutor
   275  }
   276  
   277  // DefaultRole returns role for this event
   278  func (*ValidateRecord) DefaultRole() core.DynamicRole {
   279  	return core.DynamicRoleLightExecutor
   280  }
   281  
   282  // DefaultTarget returns of target of this event.
   283  func (m *ValidateRecord) DefaultTarget() *core.RecordRef {
   284  	return &m.Object
   285  }
   286  
   287  // Type implementation of Message interface.
   288  func (*ValidateRecord) Type() core.MessageType {
   289  	return core.TypeValidateRecord
   290  }
   291  
   292  // SetBlob saves blob in storage.
   293  type SetBlob struct {
   294  	ledgerMessage
   295  
   296  	TargetRef core.RecordRef
   297  	Memory    []byte
   298  }
   299  
   300  // AllowedSenderObjectAndRole implements interface method
   301  func (m *SetBlob) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   302  	return &m.TargetRef, core.DynamicRoleVirtualExecutor
   303  }
   304  
   305  // DefaultRole returns role for this event
   306  func (*SetBlob) DefaultRole() core.DynamicRole {
   307  	return core.DynamicRoleLightExecutor
   308  }
   309  
   310  // DefaultTarget returns of target of this event.
   311  func (m *SetBlob) DefaultTarget() *core.RecordRef {
   312  	return &m.TargetRef
   313  }
   314  
   315  // Type implementation of Message interface.
   316  func (*SetBlob) Type() core.MessageType {
   317  	return core.TypeSetBlob
   318  }
   319  
   320  // GetObjectIndex fetches objects index.
   321  type GetObjectIndex struct {
   322  	ledgerMessage
   323  
   324  	Object core.RecordRef
   325  }
   326  
   327  // AllowedSenderObjectAndRole implements interface method
   328  func (m *GetObjectIndex) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   329  	return &m.Object, core.DynamicRoleLightExecutor
   330  }
   331  
   332  // DefaultRole returns role for this event
   333  func (*GetObjectIndex) DefaultRole() core.DynamicRole {
   334  	return core.DynamicRoleHeavyExecutor
   335  }
   336  
   337  // DefaultTarget returns of target of this event.
   338  func (m *GetObjectIndex) DefaultTarget() *core.RecordRef {
   339  	return &m.Object
   340  }
   341  
   342  // Type implementation of Message interface.
   343  func (*GetObjectIndex) Type() core.MessageType {
   344  	return core.TypeGetObjectIndex
   345  }
   346  
   347  // ValidationCheck checks if validation of a particular record can be performed.
   348  type ValidationCheck struct {
   349  	ledgerMessage
   350  
   351  	Object              core.RecordRef
   352  	ValidatedState      core.RecordID
   353  	LatestStateApproved *core.RecordID
   354  }
   355  
   356  // DefaultTarget returns of target of this event.
   357  func (m *ValidationCheck) DefaultTarget() *core.RecordRef {
   358  	return &m.Object
   359  }
   360  
   361  // DefaultRole returns role for this event
   362  func (m *ValidationCheck) DefaultRole() core.DynamicRole {
   363  	return core.DynamicRoleLightExecutor
   364  }
   365  
   366  // AllowedSenderObjectAndRole implements interface method
   367  func (m *ValidationCheck) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   368  	// TODO: return smth real
   369  	return nil, 0
   370  }
   371  
   372  // Type implementation of Message interface.
   373  func (*ValidationCheck) Type() core.MessageType {
   374  	return core.TypeValidationCheck
   375  }
   376  
   377  // HotData contains hot-data
   378  type HotData struct {
   379  	ledgerMessage
   380  	Jet                core.RecordRef
   381  	DropJet            core.RecordID // If will be different in case of split.
   382  	Drop               jet.JetDrop
   383  	RecentObjects      map[core.RecordID]HotIndex
   384  	PendingRequests    map[core.RecordID]recentstorage.PendingObjectContext
   385  	PulseNumber        core.PulseNumber
   386  	JetDropSizeHistory jet.DropSizeHistory
   387  }
   388  
   389  // AllowedSenderObjectAndRole implements interface method
   390  func (m *HotData) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   391  	return nil, core.DynamicRoleUndefined
   392  }
   393  
   394  // DefaultRole returns role for this event
   395  func (*HotData) DefaultRole() core.DynamicRole {
   396  	return core.DynamicRoleLightExecutor
   397  }
   398  
   399  // DefaultTarget returns of target of this event.
   400  func (m *HotData) DefaultTarget() *core.RecordRef {
   401  	return &m.Jet
   402  }
   403  
   404  // Type implementation of Message interface.
   405  func (*HotData) Type() core.MessageType {
   406  	return core.TypeHotRecords
   407  }
   408  
   409  // HotIndex contains meat about hot-data
   410  type HotIndex struct {
   411  	TTL   int
   412  	Index []byte
   413  }
   414  
   415  // GetPendingRequests fetches pending requests for object.
   416  type GetPendingRequests struct {
   417  	ledgerMessage
   418  
   419  	Object core.RecordRef
   420  }
   421  
   422  // Type implementation of Message interface.
   423  func (*GetPendingRequests) Type() core.MessageType {
   424  	return core.TypeGetPendingRequests
   425  }
   426  
   427  // AllowedSenderObjectAndRole implements interface method
   428  func (m *GetPendingRequests) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   429  	return &m.Object, core.DynamicRoleVirtualExecutor
   430  }
   431  
   432  // DefaultRole returns role for this event
   433  func (*GetPendingRequests) DefaultRole() core.DynamicRole {
   434  	return core.DynamicRoleLightExecutor
   435  }
   436  
   437  // DefaultTarget returns of target of this event.
   438  func (m *GetPendingRequests) DefaultTarget() *core.RecordRef {
   439  	return &m.Object
   440  }
   441  
   442  // GetJet requests to calculate a jet for provided object.
   443  type GetJet struct {
   444  	ledgerMessage
   445  
   446  	Object core.RecordID
   447  	Pulse  core.PulseNumber
   448  }
   449  
   450  // Type implementation of Message interface.
   451  func (*GetJet) Type() core.MessageType {
   452  	return core.TypeGetJet
   453  }
   454  
   455  // AllowedSenderObjectAndRole implements interface method
   456  func (m *GetJet) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   457  	return core.NewRecordRef(core.DomainID, m.Object), core.DynamicRoleLightExecutor
   458  }
   459  
   460  // DefaultRole returns role for this event
   461  func (*GetJet) DefaultRole() core.DynamicRole {
   462  	return core.DynamicRoleLightExecutor
   463  }
   464  
   465  // DefaultTarget returns of target of this event.
   466  func (m *GetJet) DefaultTarget() *core.RecordRef {
   467  	return core.NewRecordRef(core.DomainID, m.Object)
   468  }
   469  
   470  // AbandonedRequestsNotification informs virtual node about unclosed requests.
   471  type AbandonedRequestsNotification struct {
   472  	ledgerMessage
   473  
   474  	Object core.RecordID
   475  }
   476  
   477  // Type implementation of Message interface.
   478  func (*AbandonedRequestsNotification) Type() core.MessageType {
   479  	return core.TypeAbandonedRequestsNotification
   480  }
   481  
   482  // AllowedSenderObjectAndRole implements interface method
   483  func (m *AbandonedRequestsNotification) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   484  	return nil, core.DynamicRoleUndefined
   485  }
   486  
   487  // DefaultRole returns role for this event
   488  func (*AbandonedRequestsNotification) DefaultRole() core.DynamicRole {
   489  	return core.DynamicRoleVirtualExecutor
   490  }
   491  
   492  // DefaultTarget returns of target of this event.
   493  func (m *AbandonedRequestsNotification) DefaultTarget() *core.RecordRef {
   494  	return core.NewRecordRef(core.DomainID, m.Object)
   495  }
   496  
   497  // GetRequest fetches request from ledger.
   498  type GetRequest struct {
   499  	ledgerMessage
   500  
   501  	Request core.RecordID
   502  }
   503  
   504  // Type implementation of Message interface.
   505  func (*GetRequest) Type() core.MessageType {
   506  	return core.TypeGetRequest
   507  }
   508  
   509  // AllowedSenderObjectAndRole implements interface method
   510  func (m *GetRequest) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   511  	return nil, core.DynamicRoleUndefined
   512  }
   513  
   514  // DefaultRole returns role for this event
   515  func (*GetRequest) DefaultRole() core.DynamicRole {
   516  	return core.DynamicRoleLightExecutor
   517  }
   518  
   519  // DefaultTarget returns of target of this event.
   520  func (m *GetRequest) DefaultTarget() *core.RecordRef {
   521  	return core.NewRecordRef(core.DomainID, m.Request)
   522  }
   523  
   524  // GetPendingRequestID fetches a pending request id for an object from current LME
   525  type GetPendingRequestID struct {
   526  	ledgerMessage
   527  
   528  	ObjectID core.RecordID
   529  }
   530  
   531  // Type implementation of Message interface.
   532  func (*GetPendingRequestID) Type() core.MessageType {
   533  	return core.TypeGetPendingRequestID
   534  }
   535  
   536  // AllowedSenderObjectAndRole implements interface method
   537  func (m *GetPendingRequestID) AllowedSenderObjectAndRole() (*core.RecordRef, core.DynamicRole) {
   538  	return nil, core.DynamicRoleUndefined
   539  }
   540  
   541  // DefaultRole returns role for this event
   542  func (*GetPendingRequestID) DefaultRole() core.DynamicRole {
   543  	return core.DynamicRoleLightExecutor
   544  }
   545  
   546  // DefaultTarget returns of target of this event.
   547  func (m *GetPendingRequestID) DefaultTarget() *core.RecordRef {
   548  	return core.NewRecordRef(core.DomainID, m.ObjectID)
   549  }