如何将状态更新存储在链下数据库中?
How to store the updates of state in an offchain database?
我想将所有区块链数据存储在链外数据库中。
rpc 有一个名为 EXPERIMENTAL_changes 的函数,有人告诉我可以通过此方法的 http 轮询来做到这一点,但我无法找到如何使用它。
http post https://rpc.testnet.near.org jsonrpc=2.0 id=dontcare method=EXPERIMENTAL_changes \ params:='{ "changes_type": "data_changes", "account_ids": ["guest-book.testnet"], "key_prefix_base64": "", "block_id": 19450732 }'
例如这里的结果为:
"change": { "account_id": "guest-book.testnet", "key_base64": "bTo6Mzk=", "value_base64": "eyJwcmVtaXVtIjpmYWxzZSwic2VuZGVyIjoiZmhyLnRlc3RuZXQiLCJ0ZXh0IjoiSGkifQ==" }
什么是 key_base64?
将其解码为字符串给出 m::39
什么是 m::39?
比如我在rust结构体中有如下状态数据
pub struct Demo {
user_profile_map: TreeMap<u128, User>,
user_products_map: TreeMap<u128, UnorderedSet<u128>>, // (user_id, set<product_id>)
product_reviews_map: TreeMap<u128, UnorderedSet<u128>>, // (product_id, set<review_id>)
product_check_bounty: LookupMap<u128, Vector<u64>>
}
如何知道这些变量发生了什么变化?
我是否必须检查合约部署点的每个区块 ID,以了解哪里有变化?
I want to store all the blockchain data in offchain database.
如果是这样,我建议你看一下 Indexer Framework, which allows you to get a stream of blocks and handle them. We use it to build Indexer for Wallet (keeps track of every added and deleted access key, and stores those into Postgres) and Indexer for Explorer(跟踪每个块、块、交易、收据、执行结果、状态更改、帐户和访问密钥,并存储所有在 Postgres 中)
What is m::39?
NEAR 协议中的合约可以访问键值存储(状态),因此在最低级别,您使用键值操作进行操作(NEAR SDK for AssemblyScript 定义了 Storage class with get
and set
operations, and NEAR SDK for Rust has storage_read
and storage_write
保存数据的调用).
留言簿示例使用称为 PersistentVector
的高级抽象,它自动读取和写入其记录 from/to NEAR 键值存储(状态)。 As you can see:
export const messages = new PersistentVector<PostedMessage>("m");
Guest Book定义要存储在m
前缀存储中的消息,然后你看到m::39
,这基本上意味着它是messages[39]
存储在键值存储中.
What is key_base64?
顾名思义就是key-value存储,数据是通过key来存储和访问的,key可以是二进制的,所以使用base64编码来实现JSON-RPC API users with a查询这些二进制键的方法(无法在 JSON 中传递原始二进制 blob)。
How to know anything gets changed in these variables? Will I have to check every block id for the point the contract is deployed, to know where there is the change?
正确,您需要跟踪每个块,并检查更改。这就是我们构建 Indexer Framework 以便在此基础上启用社区构建服务的原因(我们选择构建应用程序 Indexer for Wallet 和 Indexer for Explorer,但其他人可能决定构建 GraphQL 服务,如 TheGraph)
我想将所有区块链数据存储在链外数据库中。 rpc 有一个名为 EXPERIMENTAL_changes 的函数,有人告诉我可以通过此方法的 http 轮询来做到这一点,但我无法找到如何使用它。
http post https://rpc.testnet.near.org jsonrpc=2.0 id=dontcare method=EXPERIMENTAL_changes \ params:='{ "changes_type": "data_changes", "account_ids": ["guest-book.testnet"], "key_prefix_base64": "", "block_id": 19450732 }'
例如这里的结果为:
"change": { "account_id": "guest-book.testnet", "key_base64": "bTo6Mzk=", "value_base64": "eyJwcmVtaXVtIjpmYWxzZSwic2VuZGVyIjoiZmhyLnRlc3RuZXQiLCJ0ZXh0IjoiSGkifQ==" }
什么是 key_base64?
将其解码为字符串给出 m::39
什么是 m::39?
比如我在rust结构体中有如下状态数据
pub struct Demo {
user_profile_map: TreeMap<u128, User>,
user_products_map: TreeMap<u128, UnorderedSet<u128>>, // (user_id, set<product_id>)
product_reviews_map: TreeMap<u128, UnorderedSet<u128>>, // (product_id, set<review_id>)
product_check_bounty: LookupMap<u128, Vector<u64>>
}
如何知道这些变量发生了什么变化?
我是否必须检查合约部署点的每个区块 ID,以了解哪里有变化?
I want to store all the blockchain data in offchain database.
如果是这样,我建议你看一下 Indexer Framework, which allows you to get a stream of blocks and handle them. We use it to build Indexer for Wallet (keeps track of every added and deleted access key, and stores those into Postgres) and Indexer for Explorer(跟踪每个块、块、交易、收据、执行结果、状态更改、帐户和访问密钥,并存储所有在 Postgres 中)
What is m::39?
NEAR 协议中的合约可以访问键值存储(状态),因此在最低级别,您使用键值操作进行操作(NEAR SDK for AssemblyScript 定义了 Storage class with get
and set
operations, and NEAR SDK for Rust has storage_read
and storage_write
保存数据的调用).
留言簿示例使用称为 PersistentVector
的高级抽象,它自动读取和写入其记录 from/to NEAR 键值存储(状态)。 As you can see:
export const messages = new PersistentVector<PostedMessage>("m");
Guest Book定义要存储在m
前缀存储中的消息,然后你看到m::39
,这基本上意味着它是messages[39]
存储在键值存储中.
What is key_base64?
顾名思义就是key-value存储,数据是通过key来存储和访问的,key可以是二进制的,所以使用base64编码来实现JSON-RPC API users with a查询这些二进制键的方法(无法在 JSON 中传递原始二进制 blob)。
How to know anything gets changed in these variables? Will I have to check every block id for the point the contract is deployed, to know where there is the change?
正确,您需要跟踪每个块,并检查更改。这就是我们构建 Indexer Framework 以便在此基础上启用社区构建服务的原因(我们选择构建应用程序 Indexer for Wallet 和 Indexer for Explorer,但其他人可能决定构建 GraphQL 服务,如 TheGraph)