forked from RetricSu/nostr-binding
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
74 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,42 @@ | ||
import { ccc, CellDepInfoLike, KnownScript, Script } from "@ckb-ccc/ccc"; | ||
import offCKBConfig, { Network } from "offckb.config"; | ||
|
||
export const DEVNET_SCRIPTS: Record< | ||
string, | ||
Pick<Script, "codeHash" | "hashType"> & { cellDeps: CellDepInfoLike[] } | ||
> = { | ||
[KnownScript.Secp256k1Blake160]: | ||
offCKBConfig.systemScripts.secp256k1_blake160_sighash_all!.script, | ||
[KnownScript.Secp256k1Multisig]: | ||
offCKBConfig.systemScripts.secp256k1_blake160_multisig_all!.script, | ||
[KnownScript.AnyoneCanPay]: offCKBConfig.systemScripts.anyone_can_pay!.script, | ||
[KnownScript.OmniLock]: offCKBConfig.systemScripts.omnilock!.script, | ||
[KnownScript.TypeId]: { | ||
codeHash: | ||
"0x00000000000000000000000000000000000000000000000000545950455f4944", | ||
hashType: "type", | ||
cellDeps: [], | ||
}, | ||
[KnownScript.XUdt]: offCKBConfig.systemScripts.xudt!.script, | ||
[KnownScript.NostrLock]: offCKBConfig.myScripts["nostr-lock"]!, | ||
}; | ||
|
||
export function buildCccClient(network: Network) { | ||
const client = | ||
network === "mainnet" | ||
? new ccc.ClientPublicMainnet() | ||
: network === "testnet" | ||
? new ccc.ClientPublicTestnet() | ||
: new ccc.ClientPublicTestnet( | ||
offCKBConfig.rpcUrl, | ||
undefined, | ||
DEVNET_SCRIPTS, | ||
); | ||
if (network === "devnet") { | ||
const DEVNET_SCRIPTS: Record< | ||
string, | ||
Pick<Script, "codeHash" | "hashType"> & { cellDeps: CellDepInfoLike[] } | ||
> = { | ||
[KnownScript.Secp256k1Blake160]: | ||
offCKBConfig.systemScripts.secp256k1_blake160_sighash_all!.script, | ||
[KnownScript.Secp256k1Multisig]: | ||
offCKBConfig.systemScripts.secp256k1_blake160_multisig_all!.script, | ||
[KnownScript.AnyoneCanPay]: | ||
offCKBConfig.systemScripts.anyone_can_pay!.script, | ||
[KnownScript.OmniLock]: offCKBConfig.systemScripts.omnilock!.script, | ||
[KnownScript.TypeId]: { | ||
codeHash: | ||
"0x00000000000000000000000000000000000000000000000000545950455f4944", | ||
hashType: "type", | ||
cellDeps: [], | ||
}, | ||
[KnownScript.XUdt]: offCKBConfig.systemScripts.xudt!.script, | ||
[KnownScript.NostrLock]: offCKBConfig.myScripts["nostr-lock"]!, | ||
}; | ||
return new ccc.ClientPublicTestnet( | ||
offCKBConfig.rpcUrl, | ||
undefined, | ||
DEVNET_SCRIPTS, | ||
); | ||
} | ||
|
||
if (network === "testnet") { | ||
return new ccc.ClientPublicTestnet(); | ||
} | ||
|
||
if (network === "mainnet") { | ||
return new ccc.ClientPublicMainnet(); | ||
} | ||
|
||
return client; | ||
throw new Error("invalid network"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters