Validate check the OpBase for errors
(op Operation, opType OperationType)
| 166 | |
| 167 | // Validate check the OpBase for errors |
| 168 | func (base *OpBase) Validate(op Operation, opType OperationType) error { |
| 169 | if base.OperationType == 0 { |
| 170 | return fmt.Errorf("operation type unset") |
| 171 | } |
| 172 | if base.OperationType != opType { |
| 173 | return fmt.Errorf("incorrect operation type (expected: %v, actual: %v)", opType, base.OperationType) |
| 174 | } |
| 175 | |
| 176 | if op.Time().Unix() == 0 { |
| 177 | return fmt.Errorf("time not set") |
| 178 | } |
| 179 | |
| 180 | if base.author == nil { |
| 181 | return fmt.Errorf("author not set") |
| 182 | } |
| 183 | |
| 184 | if err := op.Author().Validate(); err != nil { |
| 185 | return errors.Wrap(err, "author") |
| 186 | } |
| 187 | |
| 188 | if op, ok := op.(OperationWithFiles); ok { |
| 189 | for _, hash := range op.GetFiles() { |
| 190 | if !hash.IsValid() { |
| 191 | return fmt.Errorf("file with invalid hash %v", hash) |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if len(base.Nonce) > 64 { |
| 197 | return fmt.Errorf("nonce is too big") |
| 198 | } |
| 199 | if len(base.Nonce) < 20 { |
| 200 | return fmt.Errorf("nonce is too small") |
| 201 | } |
| 202 | |
| 203 | return nil |
| 204 | } |
| 205 | |
| 206 | // IsAuthored is a sign post method for gqlgen |
| 207 | func (base *OpBase) IsAuthored() {} |