【问题标题】:Orbitdb + IPFS in nodejsnodejs中的Orbitdb + IPFS
【发布时间】:2020-10-13 18:51:28
【问题描述】:

我正在尝试将 orbit-db 与 IPFS 一起使用,并且正在阅读 OrbitDB 的官方文档。 ATM,我只是想创建一个数据库(特别是键值存储),我现在有以下代码


const IPFS = require('ipfs')
const OrbitDB = require('orbit-db')

createDb = async() => {

        try {
            const ipfsOptions = {
                config: {
                  my-config-options
                },
                EXPERIMENTAL: {
                  pubsub: true
                }
            }

            const ipfs = await IPFS.create(ipfsOptions)            
            const orbitdb = await OrbitDB.createInstance(ipfs)
            const db = await orbitdb.create('test', 'keyvalue', {
                overwrite: false,
                replicate: true,
                accessController: {
                    admin: ['*'],
                    write: ['*']
                }
            })
            console.log(db)
            await db.put('hello', { name: 'world' })
            console.log(db.all)
        } catch (error) {
            console.trace(error)

        }
    }

但无论我尝试什么,我都会遇到同样的错误

Trace: Error: Could not append entry, key "..." is not allowed to write to the log

因此,我们将不胜感激任何帮助。如果缺少任何信息,也请发表评论,我会根据要求添加它

【问题讨论】:

    标签: node.js ipfs orbitdb


    【解决方案1】:

    我认为您的accessController 存在小问题。 admin 属性的存在表明你想像这样使用orbitdb 类型:

                    accessController: {
                        type: 'orbitdb',
                        admin: ['*'],
                        write: ['*']
                    }
    

    否则,如果您希望使用默认的 ipfs 类型,请删除 admin 属性,如下所示:

                    accessController: {
                        type: 'ipfs',
                        write: ['*']
                    }
    

    【讨论】:

    • 两者的主要区别是什么?
    • 错误输出到Database '...' is type 'keyvalue' but was opened as 'ipfs'Database '...' is type 'keyvalue' but was opened as 'orbitdb'
    • 似乎可以在沙盒 io 上工作,但不能在我的机器上工作(Windows)
    • > 两者的主要区别是什么? orbitdb 访问控制器允许动态添加对其他身份的写入访问权限,ipfs 类型不允许
    • 那么如果我用ipfs类型初始化orbitdb,其他用户将无法向数据库添加数据?
    猜你喜欢
    • 2020-07-18
    • 2018-10-03
    • 2019-08-23
    • 2022-08-17
    • 1970-01-01
    • 2021-02-19
    • 2019-04-29
    • 1970-01-01
    • 2019-03-13
    相关资源
    最近更新 更多