github.com/braveheart12/just@v0.8.7/ledger/storage/record/result.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 record 18 19 import ( 20 "io" 21 22 "github.com/insolar/insolar/core" 23 ) 24 25 // State is a state of lifeline records. 26 type State int 27 28 const ( 29 // StateUndefined is used for special cases. 30 StateUndefined = State(iota) 31 // StateActivation means it's an activation record. 32 StateActivation 33 // StateAmend means it's an amend record. 34 StateAmend 35 // StateDeactivation means it's a deactivation record. 36 StateDeactivation 37 ) 38 39 // ObjectState is common object state record. 40 type ObjectState interface { 41 // State returns state id. 42 State() State 43 // GetImage returns state code. 44 GetImage() *core.RecordRef 45 // GetIsPrototype returns state code. 46 GetIsPrototype() bool 47 // GetMemory returns state memory. 48 GetMemory() *core.RecordID 49 // PrevStateID returns previous state id. 50 PrevStateID() *core.RecordID 51 } 52 53 // ResultRecord represents result of a VM method. 54 type ResultRecord struct { 55 Object core.RecordID 56 Request core.RecordRef 57 Payload []byte 58 } 59 60 // WriteHashData writes record data to provided writer. This data is used to calculate record's hash. 61 func (r *ResultRecord) WriteHashData(w io.Writer) (int, error) { 62 return w.Write(SerializeRecord(r)) 63 } 64 65 // SideEffectRecord is a record which is created in response to a request. 66 type SideEffectRecord struct { 67 Domain core.RecordRef 68 Request core.RecordRef 69 } 70 71 // TypeRecord is a code interface declaration. 72 type TypeRecord struct { 73 SideEffectRecord 74 75 TypeDeclaration []byte 76 } 77 78 // WriteHashData writes record data to provided writer. This data is used to calculate record's hash. 79 func (r *TypeRecord) WriteHashData(w io.Writer) (int, error) { 80 return w.Write(SerializeRecord(r)) 81 } 82 83 // CodeRecord is a code storage record. 84 type CodeRecord struct { 85 SideEffectRecord 86 87 Code *core.RecordID 88 MachineType core.MachineType 89 } 90 91 // WriteHashData writes record data to provided writer. This data is used to calculate record's hash. 92 func (r *CodeRecord) WriteHashData(w io.Writer) (int, error) { 93 return w.Write(SerializeRecord(r)) 94 } 95 96 // ObjectStateRecord is a record containing data for an object state. 97 type ObjectStateRecord struct { 98 Memory *core.RecordID 99 Image core.RecordRef // If code or prototype object reference. 100 IsPrototype bool // If true, Image should point to a prototype object. Otherwise to a code. 101 } 102 103 // GetMemory returns state memory. 104 func (r *ObjectStateRecord) GetMemory() *core.RecordID { 105 return r.Memory 106 } 107 108 // GetImage returns state code. 109 func (r *ObjectStateRecord) GetImage() *core.RecordRef { 110 return &r.Image 111 } 112 113 // GetIsPrototype returns state code. 114 func (r *ObjectStateRecord) GetIsPrototype() bool { 115 return r.IsPrototype 116 } 117 118 // ObjectActivateRecord is produced when we instantiate new object from an available prototype. 119 type ObjectActivateRecord struct { 120 SideEffectRecord 121 ObjectStateRecord 122 123 Parent core.RecordRef 124 IsDelegate bool 125 } 126 127 // PrevStateID returns previous state id. 128 func (r *ObjectActivateRecord) PrevStateID() *core.RecordID { 129 return nil 130 } 131 132 // State returns state id. 133 func (r *ObjectActivateRecord) State() State { 134 return StateActivation 135 } 136 137 // WriteHashData writes record data to provided writer. This data is used to calculate record's hash. 138 func (r *ObjectActivateRecord) WriteHashData(w io.Writer) (int, error) { 139 return w.Write(SerializeRecord(r)) 140 } 141 142 // ObjectAmendRecord is an amendment record for objects. 143 type ObjectAmendRecord struct { 144 SideEffectRecord 145 ObjectStateRecord 146 147 PrevState core.RecordID 148 } 149 150 // PrevStateID returns previous state id. 151 func (r *ObjectAmendRecord) PrevStateID() *core.RecordID { 152 return &r.PrevState 153 } 154 155 // State returns state id. 156 func (r *ObjectAmendRecord) State() State { 157 return StateAmend 158 } 159 160 // WriteHashData writes record data to provided writer. This data is used to calculate record's hash. 161 func (r *ObjectAmendRecord) WriteHashData(w io.Writer) (int, error) { 162 return w.Write(SerializeRecord(r)) 163 } 164 165 // DeactivationRecord marks targeted object as disabled. 166 type DeactivationRecord struct { 167 SideEffectRecord 168 PrevState core.RecordID 169 } 170 171 // PrevStateID returns previous state id. 172 func (r *DeactivationRecord) PrevStateID() *core.RecordID { 173 return &r.PrevState 174 } 175 176 // State returns state id. 177 func (r *DeactivationRecord) State() State { 178 return StateDeactivation 179 } 180 181 // WriteHashData writes record data to provided writer. This data is used to calculate record's hash. 182 func (r *DeactivationRecord) WriteHashData(w io.Writer) (int, error) { 183 return w.Write(SerializeRecord(r)) 184 } 185 186 // GetMachineType returns state code machine type. 187 func (*DeactivationRecord) GetMachineType() core.MachineType { 188 return core.MachineTypeNotExist 189 } 190 191 // GetMemory returns state memory. 192 func (*DeactivationRecord) GetMemory() *core.RecordID { 193 return nil 194 } 195 196 // GetImage returns state code. 197 func (r *DeactivationRecord) GetImage() *core.RecordRef { 198 return nil 199 } 200 201 // GetIsPrototype returns state code. 202 func (r *DeactivationRecord) GetIsPrototype() bool { 203 return false 204 }