-
Notifications
You must be signed in to change notification settings - Fork 194
Description
Since users will need to reindex their nodes to apply #2210 fixes, it would be a good opportunity to introduce a new and useful index for boxes: the ErgoTree template index.
Motivation
Let's take the Babel Fees contracts as an example, the only difference between the SigUSD to the RSN contracts is the _tokenID constant (see Contract Template section). Therefore, if a user wants to query both the SigUSD and RSN tokens he needs to do one query for each token, leading to inefficiencies. We need an efficient way to fetch boxes protected by contracts that shares the same logic (template), regardless of the constants.
Solution
Constant-segregated ErgoTrees are roughly divided in three parts: header, constants, and expression tree. The expression tree, commonly called template, can be used to produce a common identifier for these contracts.
So I propose a new endpoint: blockchain/box/unspent/byTemplateHash/{templateHash} GET, where templateHash is a blake2b256 hash of the box's ergoTree.template encoded as a base16 string.
Optimization
- I suggest skipping non-constant-segregated contracts at indexing time, since the expression tree will include constants in it, so they would be useless.
- I suggest using a hash instead of the template itself so we can save disk space.