mirror of git3://git3.w3q/git3-cli
parent
1c59e0cf28
commit
f4da12ac27
@ -1,260 +0,0 @@
|
||||
export default [
|
||||
{
|
||||
"inputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "constructor"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "bytes",
|
||||
"name": "name",
|
||||
"type": "bytes"
|
||||
}
|
||||
],
|
||||
"name": "countChunks",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "name",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "delRef",
|
||||
"outputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "bytes",
|
||||
"name": "path",
|
||||
"type": "bytes"
|
||||
}
|
||||
],
|
||||
"name": "download",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bytes",
|
||||
"name": "",
|
||||
"type": "bytes"
|
||||
},
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "listRefs",
|
||||
"outputs": [
|
||||
{
|
||||
"components": [
|
||||
{
|
||||
"internalType": "bytes20",
|
||||
"name": "hash",
|
||||
"type": "bytes20"
|
||||
},
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "name",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"internalType": "struct Git3.refData[]",
|
||||
"name": "list",
|
||||
"type": "tuple[]"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "nameToRefInfo",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bytes20",
|
||||
"name": "hash",
|
||||
"type": "bytes20"
|
||||
},
|
||||
{
|
||||
"internalType": "uint96",
|
||||
"name": "index",
|
||||
"type": "uint96"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "refs",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "val",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "refund",
|
||||
"outputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "refund1",
|
||||
"outputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "bytes",
|
||||
"name": "path",
|
||||
"type": "bytes"
|
||||
}
|
||||
],
|
||||
"name": "remove",
|
||||
"outputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "name",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"internalType": "bytes20",
|
||||
"name": "refHash",
|
||||
"type": "bytes20"
|
||||
}
|
||||
],
|
||||
"name": "setRef",
|
||||
"outputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "bytes",
|
||||
"name": "name",
|
||||
"type": "bytes"
|
||||
}
|
||||
],
|
||||
"name": "size",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "storageManager",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "contract IFileOperator",
|
||||
"name": "",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "bytes",
|
||||
"name": "path",
|
||||
"type": "bytes"
|
||||
},
|
||||
{
|
||||
"internalType": "bytes",
|
||||
"name": "data",
|
||||
"type": "bytes"
|
||||
}
|
||||
],
|
||||
"name": "upload",
|
||||
"outputs": [],
|
||||
"stateMutability": "payable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "bytes",
|
||||
"name": "path",
|
||||
"type": "bytes"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "chunkId",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "bytes",
|
||||
"name": "data",
|
||||
"type": "bytes"
|
||||
}
|
||||
],
|
||||
"name": "uploadChunk",
|
||||
"outputs": [],
|
||||
"stateMutability": "payable",
|
||||
"type": "function"
|
||||
}
|
||||
]
|
@ -1,58 +0,0 @@
|
||||
import { mkdirSync, readFileSync, existsSync, statSync } from "fs"
|
||||
import { ethers } from 'ethers'
|
||||
import parse from 'parse-git-config'
|
||||
import abi from './abi.js'
|
||||
|
||||
// path -> /ab/123ab3123
|
||||
export async function callContractMethod({
|
||||
method = 'upload',
|
||||
path,
|
||||
file,
|
||||
sha
|
||||
}) {
|
||||
const wallet = 'default'
|
||||
const keyPath = process.env.HOME + "/.git3/keys"
|
||||
mkdirSync(keyPath, { recursive: true })
|
||||
|
||||
const content = readFileSync(`${keyPath}/${wallet}`).toString()
|
||||
const [walletType, key] = content.split('\n')
|
||||
const provider = new ethers.providers.JsonRpcProvider('https://galileo.web3q.io:8545');
|
||||
|
||||
let etherWallet = walletType === 'privateKey'
|
||||
? new ethers.Wallet(key)
|
||||
: ethers.Wallet.fromMnemonic(key)
|
||||
|
||||
etherWallet = etherWallet.connect(provider)
|
||||
const contract = new ethers.Contract('0xb940B75947F64C9fe0b4B2b6c56Fc9DEF03bBb5F', abi, etherWallet);
|
||||
const pathBuffer = path ? Buffer.from(path) : ''
|
||||
|
||||
if (method === 'upload') {
|
||||
const uploadResult = await contract.upload(pathBuffer, file)
|
||||
console.error(`=== upload file ${path} result ===`)
|
||||
console.error(uploadResult)
|
||||
}
|
||||
|
||||
if (method === 'download') {
|
||||
const res = await contract.download(pathBuffer)
|
||||
const buf = Buffer.from(res[0].slice(2), 'hex')
|
||||
|
||||
console.error(`=== download file ${path} result ===`)
|
||||
console.error(buf.toString('utf-8'))
|
||||
return buf
|
||||
}
|
||||
|
||||
if (method === 'setRef') {
|
||||
const res = await contract.setRef(path, '0x' + sha)
|
||||
}
|
||||
|
||||
if (method === 'listRefs') {
|
||||
const res = await contract.listRefs()
|
||||
let refs = res.map(i => ({
|
||||
ref: i[1],
|
||||
sha: i[0].slice(2)
|
||||
}))
|
||||
|
||||
// refs = refs.concat([{ ref: 'HEAD', sha: 'refs/heads/main' }])
|
||||
return refs
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
import { mkdirSync, readFileSync } from "fs"
|
||||
import { ethers } from 'ethers'
|
||||
|
||||
export function getWallet(): ethers.Wallet {
|
||||
const wallet = 'default'
|
||||
const keyPath = process.env.HOME + "/.git3/keys"
|
||||
mkdirSync(keyPath, { recursive: true })
|
||||
|
||||
const content = readFileSync(`${keyPath}/${wallet}`).toString()
|
||||
const [walletType, key] = content.split('\n')
|
||||
|
||||
let etherWallet = walletType === 'privateKey'
|
||||
? new ethers.Wallet(key)
|
||||
: ethers.Wallet.fromMnemonic(key)
|
||||
|
||||
return etherWallet
|
||||
}
|
Loading…
Reference in new issue