cyhhao 2 years ago
parent 707d58869c
commit aebbbf1a8d

@ -25,10 +25,10 @@ type Option = {
skipRepoName: boolean
}
export function parseGit3URI(
export async function parseGit3URI(
uri: string,
option: Option = { skipRepoName: false }
): Git3Protocol {
): Promise<Git3Protocol> {
const url = new URL(uri)
let sender = url.username || "default"
let chainId = url.port ? parseInt(url.port) : null
@ -37,8 +37,7 @@ export function parseGit3URI(
let nsName, nsDomain, ns
if (!hub) throw new Error("invalid git3 uri, no hub address")
let repoName = url.pathname.slice(1)
if (!option.skipRepoName && !repoName)
throw new Error("invalid git3 uri, no repo name")
if (!option.skipRepoName && !repoName) throw new Error("invalid git3 uri, no repo name")
if (hub.indexOf(".") < 0) {
if (url.hostname.startsWith("0x")) {
@ -51,8 +50,17 @@ export function parseGit3URI(
ns = nameServices[nsDomain]
if (!ns) throw new Error("invalid name service")
chainId = chainId || ns.chainId
// Todo: resolve name service
// hubAddress = ns.resolver()
// Todo: temporary resolve name service
let resolverAddress = ns["resolver"]
let nsContract = setupContract(
new ethers.providers.JsonRpcProvider("https://goerli-rollup.arbitrum.io/rpc"),
resolverAddress,
abis.NameService
)
hubAddress = await nsContract.NameHub([nsName, nsDomain].join("."))
if (hubAddress == "0x0000000000000000000000000000000000000000")
throw new Error(`${nsName} not found`)
}
if (!chainId) throw new Error("invalid git3 uri, no chainId")

@ -12,9 +12,7 @@ export function getWallet(wallet: string | null = "default"): ethers.Wallet {
const [walletType, key] = content.split("\n")
let etherWallet =
walletType === "privateKey"
? new ethers.Wallet(key)
: ethers.Wallet.fromMnemonic(key)
walletType === "privateKey" ? new ethers.Wallet(key) : ethers.Wallet.fromMnemonic(key)
return etherWallet
}
@ -23,13 +21,13 @@ export function setupContract(
provider: ethers.providers.JsonRpcProvider,
hubAddress: string,
abi: string,
wallet: ethers.Wallet
wallet: ethers.Wallet | null = null
): ethers.Contract {
let contract = new ethers.Contract(hubAddress, abi, provider)
wallet = wallet.connect(provider)
contract = contract.connect(wallet)
if (wallet) {
wallet = wallet.connect(provider)
contract = contract.connect(wallet)
}
return contract
}

File diff suppressed because one or more lines are too long

@ -1,23 +1,15 @@
const ns: Record<string, any> = {
eth: {
chainId: 1,
resolver: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
},
w3q: {
chainId: 3334,
resolver: "0x076B3e04dd300De7db95Ba3F5db1eD31f3139aE0",
},
fvm: {
chainId: 3141,
resolver: "",
},
goerli: {
chainId: 5,
resolver: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
resolver: "0xF56A1dd941667911896B9B872AC79E56cfc6a3dB",
},
arb: {
chainId: 42170,
resolver: "0xF56A1dd941667911896B9B872AC79E56cfc6a3dB",
},
arbg: {
chainId: 421613,
resolver: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
resolver: "0xF56A1dd941667911896B9B872AC79E56cfc6a3dB",
},
}

@ -10,7 +10,7 @@ GitRemoteHelper({
stdout: process.stdout,
api: {
init: async (p: ApiBaseParams) => {
const protocol = parseGit3URI(p.remoteUrl)
const protocol = await parseGit3URI(p.remoteUrl)
const storage = new protocol.storageClass(protocol)
git = new Git(p, storage)
return

@ -143,7 +143,7 @@ program
if (!uri.startsWith("git3://")) {
uri = "git3://" + uri
}
const protocol = parseGit3URI(uri)
const protocol = await parseGit3URI(uri)
let owner = await protocol.contract.repoNameToOwner(
Buffer.from(protocol.repoName)
)
@ -215,7 +215,7 @@ program
if (!uri.startsWith("git3://")) {
uri = "git3://" + uri
}
const protocol = parseGit3URI(uri, { skipRepoName: true })
const protocol = await parseGit3URI(uri, { skipRepoName: true })
const txManager = new TxManager(
protocol.contract,
protocol.chainId,

Loading…
Cancel
Save