buckyos / dcrm Goto Github PK
View Code? Open in Web Editor NEWDecentralized Compute Resource Marketplace
License: MIT License
Decentralized Compute Resource Marketplace
License: MIT License
Please use GitHub Actions to create test case with performance recording / gas for function usage
{ "hash": "0x39c767e230f1cc4d8fa7baa4ef8c39bc2e4add8680d09bfe086e1efdaa0d6437", "score": 290 }, // 10
{ "hash": "0x39c767e230f1cc4d8fa7baa4ef8c39bc2e4add8680d09bfe086e1efdaa0d6438", "score": 290 }, // 10
看那个先进
Current version is not upgradable meaning when we realize there is a caveat, we can't make change. I suggest we consider upgradability
https://docs.openzeppelin.com/upgrades-plugins/1.x/proxies
This new API is more efficient assuming update
is run more often than ranking
.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// todo: getDataSize 必须不要回答0(现在可以回答0)
library TopN {
// stores the top N scores, order is undefined, except that any zero scores are at the end
struct List {
uint256 maxLength;
mapping(uint256 => bytes32) public keys;
mapping(uint256 => uint256) public values;
}
error InvalidKey(bytes32 key);
error ValueTooSmall(uint256 value);
error MaxLengthCannotShrink();
/// @notice 获取一个值
/// @param self TopN数据结构
/// @param maxLength 最大长度, 必须不小于当前最大长度
function setMaxLength(List storage self, uint256 maxLength) public {
if (maxLength < self.maxLength) {
revert MaxLengthCannotShrink();
}
self.maxLength = maxLength;
}
/// @notice 更新一个值
/// @param self TopN数据结构
/// @param key 键,必须部位0
/// @param value 值,必须大于当前这个key的值
function updateValue(List storage self, bytes32 key, uint256 value) public {
if (key == bytes32(0)) {
revert InvalidKey(key);
}
if (value == 0) {
revert ValueTooSmall(value);
}
// 找最小的值,如果比最小的值还小,就不用更新了
uint256 replaceAt = 0;
uint256 replaceValue = 0;
bool found = false;
for (uint256 i = 0; i < self.maxLength; i++) {
uint256 v = self.values[i];
if (v == 0) {
// insert
self.keys[i] = key;
self.values[i] = value;
return;
}
if (self.keys[i] == key) {
if (value <= v) {
revert InvalidValue(value);
}
self.values[i] = value;
return;
}
if (value > v && (v < replaceValue || !found)) {
replaceValue = v;
replaceAt = i;
found = true;
}
}
if (found) {
self.keys[replaceAt] = key;
self.values[replaceAt] = value;
}
}
// todo: 如果不同的key有相同的value,他们每一个ranking一样。这个好吗?
/// @notice 考虑一个key的排名
/// @param self TopN数据结构
/// @param key 键,必须部位0
/// @return 最大为1,第二大为2。。。。。。,如果不存在,返回0
function getRanking(List storage self, bytes32 key) public view returns (uint256) {
// 找key和value
uint256 keyValue = 0;
for (uint256 i = 0; i < self.maxLength; i++) {
if (self.keys[i] == key) {
keyValue = self.values[i];
break;
}
if (self.keys[i] == bytes32(0)) {
return 0;
}
}
if (keyValue == 0) {
return 0;
}
// 找比这个值大的值
uint256 ranking = 1;
for (uint256 i = 0; i < self.maxLength; i++) {
if (self.values[i] > keyValue) {
ranking += 1;
}
if (self.values[i] == 0) {
break;
}
}
return ranking;
}
}
I am preparing for the "public data gameplay" ,Can have some interaction with communities based on ERC721 NFTs.
a. Qualified storage suppliers: Only suppliers meeting certain criteria (time, a certain amount of data delivery size) are eligible to participate in the public data storage reward program.
b. Qualified suppliers actively store public data in a certain NFT contract.
c. In specific blocks under certain conditions, SHOW the designated Merkle path of public data is considered a successful storage, and successful storage SHOW will be rewarded. The reward comes from the system, and the owner of the public data can also contribute addition rewards.
d. In a settlement period (usually including multiple eligible reward blocks), the most showed public data (Top n? and possibly exceeding a certain base amount) will earn additional rewards for the author/owner and the suppliers of the public data.
Following our recent discussions, I have officially submitted ERC 7585 to the Ethereum Foundation. For discussions on the core design and the first demonstrative implementation, we can asynchronously refer to the relevant link on the ERC.
Thank you once again for everyone's support!
https://ethereum-magicians.org/t/erc-7585-mixhash-and-public-data-storage-proofs/17707
ethereum/ERCs#177
All codes, docs, tests for PublicDataProof ERC draft have been moved to a separate repository PublicDataProof.
All subsequent discussions on ERC draft and proof algorithms will in that repository.
old ERC draft related files(doc/erc) should be seen as archived.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.