feat: merge

main
cyl19970726 2 years ago
commit 6859c07b90

4
.gitignore vendored

@ -1,3 +1,5 @@
.DS_Store
Thumbs.db
node_modules
.env
coverage
@ -8,4 +10,6 @@ typechain-types
# Hardhat files
cache
artifacts
.vscode/
local.config.ts

@ -1,8 +1,13 @@
# Contract Info
- RPC : https://galileo.web3q.io:8545
<<<<<<< HEAD
- ChainId : 3334
- Git3 Contract Address: 0x981cf56258Af8B6470642cBf1f991980cAa5DBf3
=======
- ChainId : 3334
- Git3 Contract Address: 0x680336910D9357F6aDf26c0d61eAB8e65998Ab2d
>>>>>>> b6a009f8d3f2189aa198e4cb55d6ad28c8b8e155
# Sample Hardhat Project

@ -9,6 +9,7 @@ import "git3-evm-large-storage/contracts/LargeStorageManager.sol";
// import "evm-large-storage/contracts/W3RC3.sol";
contract Git3 is LargeStorageManager {
struct refInfo {
bytes20 hash;
uint96 index;
@ -19,6 +20,7 @@ contract Git3 is LargeStorageManager {
string name;
}
mapping(bytes => address) public repoNameToOwner;
mapping(string => refInfo) public nameToRefInfo; // dev => {hash: 0x1234..., index: 1 }
string[] public refs; // [main, dev, test, staging]
@ -31,35 +33,52 @@ contract Git3 is LargeStorageManager {
constructor() LargeStorageManager(0) {}
modifier onlyOwner(bytes memory repoName) {
require(repoNameToOwner[repoName] == msg.sender);
_;
}
function download(
bytes memory repoName,
bytes memory path
) external view returns (bytes memory, bool) {
return _get(keccak256(path));
// call flat directory(FD)
return _get(keccak256(bytes.concat(repoName, '/', path)));
}
function createRepo(bytes memory repoName)
external payable
{
require(repoNameToOwner[repoName] == address(0));
repoNameToOwner[repoName] = msg.sender;
}
function upload(bytes memory path, bytes calldata data) external payable {
_putChunkFromCalldata(keccak256(path), 0, data, msg.value);
function upload(bytes memory repoName, bytes memory path, bytes calldata data)
external payable onlyOwner(repoName)
{
_putChunkFromCalldata(keccak256(bytes.concat(repoName, '/', path)), 0, data,msg.value);
}
function uploadChunk(
bytes memory repoName,
bytes memory path,
uint256 chunkId,
bytes calldata data
) external payable {
_putChunkFromCalldata(keccak256(path), chunkId, data, msg.value);
) external payable onlyOwner(repoName) {
_putChunkFromCalldata(keccak256(bytes.concat(repoName, '/', path)), chunkId, data,msg.value);
}
function remove(bytes memory path) external {
function remove(bytes memory repoName, bytes memory path) external onlyOwner(repoName) {
// The actually process of remove will remove all the chunks
_remove(keccak256(path), 0);
_remove(keccak256(bytes.concat(repoName, '/', path)),0);
}
function size(bytes memory name) external view returns (uint256, uint256) {
return _size(keccak256(name));
}
function countChunks(bytes memory path) external view returns (uint256) {
return _countChunks(keccak256(path));
function countChunks(bytes memory name) external view returns (uint256) {
return _countChunks(keccak256(name));
}
function listRefs() public view returns (refData[] memory list) {
@ -69,7 +88,8 @@ contract Git3 is LargeStorageManager {
}
}
function setRef(string memory name, bytes20 refHash) public {
function setRef(bytes memory repoName, string memory name, bytes20 refHash) public onlyOwner(repoName) {
// only execute `sload` once to reduce gas consumption
refInfo memory srs;
srs = nameToRefInfo[name];
@ -92,13 +112,17 @@ contract Git3 is LargeStorageManager {
}
}
function delRef(string memory name) public {
function delRef(bytes memory repoName, string memory name) public onlyOwner(repoName) {
// only execute `sload` once to reduce gas consumption
refInfo memory srs;
srs = nameToRefInfo[name];
uint256 refsLen = refs.length;
require(srs.hash != bytes20(0), "The name of reference does not exist");
require(
srs.hash != bytes20(0),
"Reference of this name does not exist"
);
require(srs.index < refsLen, "System Error: Invalid index");
if (srs.index < refsLen - 1) {
@ -109,3 +133,4 @@ contract Git3 is LargeStorageManager {
delete nameToRefInfo[name];
}
}

@ -0,0 +1,20 @@
const NetworkDefinition = {
rinkeby: {
url: "https://rinkeby.infura.io/v3/*******your-api-key*******",
accounts: {
mnemonic: "test test test test test test test test test test test junk"
}
},
polygon: {
url: "https://polygon.infura.io/v3/*******your-api-key*******",
accounts: {
mnemonic: "test test test test test test test test test test test junk"
}
}
}
const EtherscanConfig = {
apiKey: "YOUR_ETHERSCAN_API_KEY"
}
export { NetworkDefinition, EtherscanConfig }

@ -2,15 +2,30 @@ require("dotenv").config();
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import { NetworkDefinition, EtherscanConfig } from './local.config';
const config: HardhatUserConfig = {
solidity: "0.8.17",
solidity: {
compilers: [
{
version: "0.8.17",
settings: {
optimizer: {
enabled: true,
runs: 1000
}
}
}
],
},
networks: {
w3qGalileo: {
url: "https://galileo.web3q.io:8545",
accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
},
...NetworkDefinition
},
etherscan: EtherscanConfig,
};
export default config;

2182
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -18,15 +18,25 @@
"homepage": "https://github.com/cyl19970726/dGithub#readme",
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
"@typechain/ethers-v5": "^10.2.0",
"@typechain/hardhat": "^6.1.5",
"dotenv": "^16.0.3",
"hardhat": "^2.12.4",
"prettier": "2.8.1",
"prettier-check": "^2.0.0",
"prettier-plugin-solidity": "^1.0.0-beta.18"
"prettier-plugin-solidity": "^1.0.0-beta.18",
"hardhat-gas-reporter": "^1.0.9",
"solidity-coverage": "^0.8.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
},
"dependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^1.0.5",
"@nomiclabs/hardhat-ethers": "^2.2.1",
"@nomiclabs/hardhat-etherscan": "^3.1.3",
"@openzeppelin/contracts": "^4.8.0",
"evm-large-storage": "^1.0.0",
"git3-evm-large-storage": "^1.0.0"
"git3-evm-large-storage": "^1.0.0",
"chai": "^4.3.7",
"typechain": "^8.1.1"
}
}

@ -4,7 +4,9 @@ async function main() {
const Git3 = await ethers.getContractFactory("Git3");
const git3 = await Git3.deploy();
let receipt = await git3.deployed();
console.log(receipt);
console.log(git3.address);
}
// We recommend this pattern to be able to use async/await everywhere

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

@ -0,0 +1,39 @@
import hre from 'hardhat'
const { ethers } = hre;
import fs from 'fs'
async function main() {
const accounts = await ethers.getSigners();
console.log(accounts[0].address);
const Git3 = await hre.ethers.getContractAt("Git3", "0xa709975Bc01e745432f8898499E7b9a60f420117")
let storageManager = await Git3.storageManager()
console.log("storageManager", storageManager)
const flat = await hre.ethers.getContractAt("FlatDirectory", storageManager)
let owner = await flat.owner()
console.log("owner", owner)
return
let file = fs.readFileSync("test/git3.png")
let buffer = Array.from(file).slice(0, 24576)
let fileSize = buffer.length
console.log("buffer", buffer.length)
let cost = 0
if (fileSize > 24 * 1024 - 326) {
cost = Math.floor((fileSize + 326) / 1024 / 24)
}
let key = ethers.utils.toUtf8Bytes("aaa")
let rept = await Git3.upload(key, buffer, { value: ethers.utils.parseEther(cost.toString()) })
console.log("rept", "https://explorer.galileo.web3q.io/tx/" + rept.hash)
}
main().catch((error) => {
console.error(error);
process.exit(1);
});
Loading…
Cancel
Save