new API validateTangle()

This commit is contained in:
Andre Staltz 2023-04-18 18:41:28 +03:00
parent 3ab7d98550
commit f1e313461e
1 changed files with 11 additions and 0 deletions

View File

@ -324,6 +324,16 @@ exports.init = function initDB(peer, config) {
return new DBTangle(tangleId, records()) return new DBTangle(tangleId, records())
} }
function validateTangle(tangleId, msgs) {
let err
const tangle = new FeedV1.Tangle(tangleId)
for (const msg of msgs) {
const msgHash = FeedV1.getMsgHash(msg)
if ((err = FeedV1.validate(msg, tangle, msgHash, tangleId))) return err
tangle.add(msgHash, msg)
}
}
function* msgs() { function* msgs() {
for (let i = 0; i < recs.length; i++) { for (let i = 0; i < recs.length; i++) {
const rec = recs[i] const rec = recs[i]
@ -351,6 +361,7 @@ exports.init = function initDB(peer, config) {
erase, erase,
onRecordAdded, onRecordAdded,
getTangle, getTangle,
validateTangle,
msgs, msgs,
records, records,