-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ckb|example): Dynamic fetching cell deps deployed by TypeID #191
Conversation
May need a CDN for the static JSON content and test the speed comparing to fetching TypeID script cell deps through ckb-indexer directly. |
We can try using https://www.jsdelivr.com/?docs=gh, they provide a free, fast CDN. |
# RGB++ Lock deployment type script
➜ rgbpp echo '{
"id": 2,
"jsonrpc": "2.0",
"method": "get_cells",
"params": [
{
"script": {
"code_hash": "0x00000000000000000000000000000000000000000000000000545950455f4944",
"hash_type": "type",
"args": "0xa3bc8441df149def76cfe15fec7b1e51d949548bc27fb7a75e9d4b3ef1c12c7f"
},
"script_type": "type"
},
"asc",
"0x64"
]
}' \
| curl -o /dev/null -s -w 'Total: %{time_total}s\n' -H 'content-type: application/json' -d @- \
https://testnet.ckb.dev/indexer
Total: 0.710650s
# CDN
➜ rgbpp curl -o /dev/null -s -w 'Total: %{time_total}s\n' https://cdn.jsdelivr.net/gh/ckb-cell/typeid-contract-cell-deps@main/deployment/cell-deps.json
Total: 0.197599s
# raw github url
➜ rgbpp curl -o /dev/null -s -w 'Total: %{time_total}s\n' https://raw.githubusercontent.com/ckb-cell/typeid-contract-cell-deps/main/deployment/cell-deps.json
Total: 0.559571s
➜ rgbpp curl -o /dev/null -s -w 'Total: %{time_total}s\n' https://raw.githubusercontent.com/ckb-cell/typeid-contract-cell-deps/main/deployment/cell-deps.json
Total: 0.279097s
|
const request = (url: string) => axios.get(url, { timeout: 2000 });
const fetchCellDepsJson = async () => {
try {
const response = await Promise.any([request(GITHUB_CELL_DEPS_JSON_URL), request(CDN_GITHUB_CELL_DEPS_JSON_URL)]);
return response.data as CellDepsObject;
} catch (error) {
// console.error('Error fetching cell deps:', error);
}
}; The CDN and timeout have been added to make the |
I think the update of the |
The task of updating latest cell deps has been triggering and the update time is not strictly 5 minutes. |
Problem
Although Lumos provides a function
refreshTypeIdCellDeps
to refresh the cell deps of a upgraded TypeID script, it requires the dApp developers themselves to handle it manually.But usually a dApp developer doesn't know when a TypeID script is updated.
This PR introduces a mechanism to automatically get the TypeID scripts' latest cell deps, trying to make things easier.
Design Goal and Main Changes
fetchTypeIdCellDeps
function to fetchcellDeps
from the GitHub JSON filecellDepsSelected
parameter to select thecellDeps
which are neededcellDeps
for all the RGB++ transactionsfetchCellDepsJson
fails due to a network error, the constants are used as a fallback mechanism.The speed of fetching
cell-deps.json
should be faster than fetching TypeID script cell deps through ckb-indexer directly.Example: https://cdn.jsdelivr.net/gh/ckb-cell/typeid-contract-cell-deps@main/deployment/cell-deps.json
test: feat(ckb|example): Dynamic fetching cell deps deployed by TypeID #191 (comment)
https://github.com/ckb-cell/typeid-contract-cell-deps/actions/workflows/update.yml
Those that need to be optimized
Fetching the GitHub JSON file is not stable or slow for some users, we should do something to optimize it.
The GitHub JSON file path is https://github.com/ckb-cell/rgbpp-sdk/pull/191/files#diff-3039d7f71cfd89a5a23296b2cccdb966bc9132c2bf938a39a08bf0aeceed5d58R21
The tests that need to be run
I have tested the examples of
xudt-on-ckb
and using the integration tests of #169 to test more examples is needed. cc @Dawn-githup