master
cyhhao 2 years ago
parent aebbbf1a8d
commit 90a5a9b6ae

@ -53,10 +53,13 @@ export class QueueTask {
setTimeout(() => {
resolve(true)
}, delta)
// console.error("wait delta", delta, "ms")
this.lastTaskScheduled = now + delta
return
} else {
setTimeout(() => {
resolve(true)
}, 0)
this.lastTaskScheduled = now
resolve(true)
return

@ -4,5 +4,5 @@ export default {
SLIStorage:
'[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"repoName","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"ref","type":"bytes"}],"name":"PushRef","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"repoName","type":"bytes"},{"indexed":false,"internalType":"address","name":"owner","type":"address"}],"name":"RepoCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"repoName","type":"bytes"},{"indexed":false,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"RepoOwnerTransfer","type":"event"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes[]","name":"path","type":"bytes[]"},{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"batchUpload","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"}],"name":"createRepo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"ref","type":"bytes"}],"name":"delRef","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"path","type":"bytes"}],"name":"download","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"}],"name":"listRefs","outputs":[{"components":[{"internalType":"bytes20","name":"hash","type":"bytes20"},{"internalType":"bytes","name":"name","type":"bytes"}],"internalType":"struct Git3HubStorage_SLI.refData[]","name":"list","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"}],"name":"nameToRefInfo","outputs":[{"internalType":"bytes20","name":"hash","type":"bytes20"},{"internalType":"uint96","name":"index","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"pathToHash","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"path","type":"bytes"}],"name":"remove","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"}],"name":"repoNameToOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"repoNameToRefs","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"ref","type":"bytes"},{"internalType":"bytes20","name":"refHash","type":"bytes20"}],"name":"setRef","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"repoName","type":"bytes"},{"internalType":"bytes","name":"path","type":"bytes"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upload","outputs":[],"stateMutability":"payable","type":"function"}]',
NameService:
'[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"string","name":"","type":"string"}],"name":"HubRecords","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"NameHub","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"NameOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"address","name":"hub","type":"address"}],"name":"rebindHubAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"address","name":"hub","type":"address"}],"name":"registerHub","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferNameOwner","outputs":[],"stateMutability":"nonpayable","type":"function"}]',
'[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"string","name":"","type":"string"}],"name":"HubRecords","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"nameHub","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"nameList","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nameListLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"nameOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"address","name":"hub","type":"address"}],"name":"rebindHubAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"address","name":"hub","type":"address"}],"name":"registerHub","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferNameOwner","outputs":[],"stateMutability":"nonpayable","type":"function"}]',
}

@ -47,26 +47,6 @@ const evmNetworks: Record<number, any> = {
// },
// contracts: { git3: "0x51bb7F23193b88696D25EAec7E3293a2C96e55Ee" },
// },
3334: {
name: "Web3Q Galileo",
nativeCurrency: {
name: "Web3Q",
symbol: "W3Q",
decimals: 18,
},
rpc: ["https://galileo.web3q.io:8545"],
explorers: [
{
name: "w3q-galileo",
url: "https://explorer.galileo.web3q.io",
standard: "EIP3091",
},
],
txConst: {
blockTimeSec: 7,
},
contracts: { git3: "0x59ef6b2dbfE86CcAaD84E2d8e78177f528521Da9" },
},
// 3141: {
// name: "Filecoin - Hyperspace testnet",
// nativeCurrency: {
@ -91,6 +71,26 @@ const evmNetworks: Record<number, any> = {
// },
// contracts: { git3: "0xF56A1dd941667911896B9B872AC79E56cfc6a3dB" },
// },
3334: {
name: "Web3Q Galileo",
nativeCurrency: {
name: "Web3Q",
symbol: "W3Q",
decimals: 18,
},
rpc: ["https://galileo.web3q.io:8545"],
explorers: [
{
name: "w3q-galileo",
url: "https://explorer.galileo.web3q.io",
standard: "EIP3091",
},
],
txConst: {
blockTimeSec: 7,
},
contracts: { git3: "0x59ef6b2dbfE86CcAaD84E2d8e78177f528521Da9" },
},
421613: {
name: "Arbitrum - Goerli",
nativeCurrency: {

@ -1,15 +1,15 @@
const ns: Record<string, any> = {
w3q: {
chainId: 3334,
resolver: "0xF56A1dd941667911896B9B872AC79E56cfc6a3dB",
resolver: "0x3144d2EF1ac2fD651a250c9B5EfC095330ED9C05",
},
arb: {
chainId: 42170,
resolver: "0xF56A1dd941667911896B9B872AC79E56cfc6a3dB",
resolver: "0x3144d2EF1ac2fD651a250c9B5EfC095330ED9C05",
},
arbg: {
chainId: 421613,
resolver: "0xF56A1dd941667911896B9B872AC79E56cfc6a3dB",
resolver: "0x3144d2EF1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
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkaWQ6ZXRocjoweDhmOTY1ZjAyRWY1MzkxODBlNDNiQ0M5M0FkZDJDZDI1RjU5RjRiMzIiLCJpc3MiOiJuZnQtc3RvcmFnZSIsImlhdCI6MTY3Njg4ODM4NjkxMiwibmFtZSI6ImdpdDYifQ.C4vSfG_sSSwnOzAMfy2ccvvoh4iiFiiC1-ejU5Vo4ek",
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkaWQ6ZXRocjoweDhmOTY1ZjAyRWY1MzkxODBlNDNiQ0M5M0FkZDJDZDI1RjU5RjRiMzIiLCJpc3MiOiJuZnQtc3RvcmFnZSIsImlhdCI6MTY3Njg5MjQ2NDk3MywibmFtZSI6ImdpdDcifQ.4tXjPZxG99LVqhqCklSfSDTxBDeY2dCSsatcLbmrt0o",
]
this.txManager = new TxManager(this.contract, protocol.chainId, protocol.netConfig.txConst)
@ -208,39 +212,35 @@ export class SLIStorage implements Storage {
const TIMEOUT = 15
try {
let cid = await this.storageTask.run(async () => {
let response = await axios.post("https://api.nft.storage/upload", data, {
headers: {
"Content-Type": "application/octet-stream",
Authorization: this.auth[Math.floor(Math.random() * this.auth.length)],
},
timeout: TIMEOUT * 1000,
})
if (response.status == 200) {
return response.data.value.cid
} else {
throw new Error(`response code: ${response.status}`)
// let start = Date.now().valueOf()
let index = Math.floor(Math.random() * this.auth.length)
try {
let response = await axios.post("https://api.nft.storage/upload", data, {
headers: {
"Content-Type": "application/octet-stream",
Authorization: this.auth[index],
},
timeout: TIMEOUT * 1000,
})
// let end = Date.now().valueOf()
if (response.status == 200) {
// console.error(`nft.storage success ${end - start}ms ${index}`)
return response.data.value.cid
} else {
// console.error(
// `nft.storage status ${response.status} ${end - start}ms ${index}`
// )
throw new Error(`response code: ${response.status}`)
}
} catch (e) {
// let end = Date.now().valueOf()
// console.error(`nft.storage failed ${end - start}ms ${e} ${index}`)
throw new Error(`nft.storage failed: ${e}`)
}
})
return cid
} catch (e) {
throw new Error(`store ipfs failed: ${e}`)
}
// for (let i = 0; i < RETRY_TIMES; i++) {
// try {
// while (
// Date.now().valueOf() - this.storageCallLastTime <
// this.storageIntervalLimit
// ) {
// await new Promise((r) => setTimeout(r, this.storageIntervalLimit / 2))
// }
// this.storageCallLastTime = Date.now().valueOf()
// } catch (e) {
// //pass
// lastError = e
// new Promise((r) => setTimeout(r, 1000))
// }
// }
}
}

Loading…
Cancel
Save