| 237 | } |
| 238 | |
| 239 | func ProofChainCreateFromValidator(validator *validator.Base) (pc *ProofChain, err error) { |
| 240 | pc = &ProofChain{ |
| 241 | Action: validator.Action, |
| 242 | Persona: MarshalPersona(validator.Pubkey), |
| 243 | Identity: validator.Identity, // TODO: exception may occur |
| 244 | AltID: validator.AltID, |
| 245 | Platform: validator.Platform, |
| 246 | Location: validator.ProofLocation, |
| 247 | Signature: MarshalSignature(validator.Signature), |
| 248 | SignaturePayload: validator.SignaturePayload, |
| 249 | CreatedAt: validator.CreatedAt, |
| 250 | Uuid: validator.Uuid.String(), |
| 251 | Previous: nil, |
| 252 | ArweaveID: "", |
| 253 | } |
| 254 | |
| 255 | if validator.Previous != "" { |
| 256 | previous, err := ProofChainFindBySignature(validator.Previous) |
| 257 | if err != nil { |
| 258 | return nil, xerrors.Errorf("%w", err) |
| 259 | } |
| 260 | |
| 261 | pc.Previous = previous |
| 262 | } |
| 263 | |
| 264 | if len(validator.Extra) != 0 { |
| 265 | extra_json, err := json.Marshal(validator.Extra) |
| 266 | if err != nil { |
| 267 | return nil, xerrors.Errorf("%w", err) |
| 268 | } |
| 269 | pc.Extra = datatypes.JSON(extra_json) |
| 270 | } |
| 271 | |
| 272 | tx := DB.Create(pc) |
| 273 | if tx.Error != nil { |
| 274 | return nil, xerrors.Errorf("%w", err) |
| 275 | } |
| 276 | |
| 277 | return pc, nil |
| 278 | } |
| 279 | |
| 280 | func ProofChainFindByPersona(persona string, all_data bool, from int, limit int) (total int64, rs []ProofChainItem, err error) { |
| 281 | rs = make([]ProofChainItem, 0, 0) |