Example #1
0
func StoreCredWithAuthor(cred *credence.Cred, author models.User) (bool, string) {
	credBytes, _ := proto.Marshal(cred)

	db := models.DB()
	var credRecord models.CredRecord
	credHash := CredHash(cred)

	db.FirstOrInit(&credRecord, models.CredRecord{CredHash: credHash})
	newCred := db.NewRecord(credRecord)

	if newCred {
		credRecord.Author = author
		credRecord.StatementHash = StatementHash(cred)
		credRecord.CredBytes = credBytes
		credRecord.SourceUri = cred.SourceUri
		credRecord.ReceivedAt = time.Now()

		credRecord.NoComment = cred.Assertion == credence.Cred_NO_COMMENT
		credRecord.IsTrue = cred.Assertion == credence.Cred_IS_TRUE
		credRecord.IsFalse = cred.Assertion == credence.Cred_IS_FALSE
		credRecord.IsAmbiguous = cred.Assertion == credence.Cred_IS_AMBIGUOUS

		db.Save(&credRecord)
	}

	return newCred, credHash
}
Example #2
0
func RetrieveCredRecord(credRecord *models.CredRecord) CredRecordProps {
	cred := credRecord.Cred()
	sourceUri, _ := url.Parse(cred.SourceUri)
	props := CredRecordProps{
		Assertion: cred.Assertion.String(),
		Statement: cred.GetHumanReadable().Statement,
		ProofUri:  cred.ProofUri,
		Source: DisplayedUri{
			String: sourceUri.Host,
			Url:    cred.SourceUri,
		},
		Author:   credRecord.Author,
		CredHash: credRecord.CredHash,
	}
	return props
}