Skip to content

Commit

Permalink
refactor(demo): use offckb v3 for demo
Browse files Browse the repository at this point in the history
  • Loading branch information
RetricSu committed Sep 3, 2024
1 parent d3ff76a commit 7181814
Show file tree
Hide file tree
Showing 7 changed files with 816 additions and 323 deletions.
2 changes: 2 additions & 0 deletions contracts/nostr-lock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub fn entry() -> Result<(), Error> {
return Err(Error::InvalidScriptArgs);
}

debug!("hello, this is new add!");

let sighash_all = generate_sighash_all()?;
let sighash_all_hex = hex::encode(&sighash_all);
debug!("sighash_all = {}", sighash_all_hex);
Expand Down
114 changes: 6 additions & 108 deletions packages/demo/app/lib/ccc.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,120 +5,18 @@ export const DEVNET_SCRIPTS: Record<
string,
Pick<Script, "codeHash" | "hashType"> & { cellDeps: CellDepInfoLike[] }
> = {
[KnownScript.Secp256k1Blake160]: {
codeHash: offCKBConfig.lumosConfig.SCRIPTS["SECP256K1_BLAKE160"]!
.CODE_HASH as `0x${string}`,
hashType: offCKBConfig.lumosConfig.SCRIPTS["SECP256K1_BLAKE160"]!.HASH_TYPE,
cellDeps: [
{
cellDep: {
outPoint: {
txHash:
offCKBConfig.lumosConfig.SCRIPTS["SECP256K1_BLAKE160"]!.TX_HASH,
index:
offCKBConfig.lumosConfig.SCRIPTS["SECP256K1_BLAKE160"]!.INDEX,
},
depType:
offCKBConfig.lumosConfig.SCRIPTS["SECP256K1_BLAKE160"]!.DEP_TYPE,
},
},
],
},
[KnownScript.Secp256k1Multisig]: {
codeHash: offCKBConfig.lumosConfig.SCRIPTS["SECP256K1_BLAKE160_MULTISIG"]!
.CODE_HASH as `0x{string}`,
hashType:
offCKBConfig.lumosConfig.SCRIPTS["SECP256K1_BLAKE160_MULTISIG"]!
.HASH_TYPE,
cellDeps: [
{
cellDep: {
outPoint: {
txHash:
offCKBConfig.lumosConfig.SCRIPTS["SECP256K1_BLAKE160_MULTISIG"]!
.TX_HASH,
index:
offCKBConfig.lumosConfig.SCRIPTS["SECP256K1_BLAKE160_MULTISIG"]!
.INDEX,
},
depType:
offCKBConfig.lumosConfig.SCRIPTS["SECP256K1_BLAKE160_MULTISIG"]!
.DEP_TYPE,
},
},
],
},
[KnownScript.AnyoneCanPay]: {
codeHash: offCKBConfig.lumosConfig.SCRIPTS["ANYONE_CAN_PAY"]!
.CODE_HASH as `0x{string}`,
hashType: offCKBConfig.lumosConfig.SCRIPTS["ANYONE_CAN_PAY"]!.HASH_TYPE,
cellDeps: [
{
cellDep: {
outPoint: {
txHash: offCKBConfig.lumosConfig.SCRIPTS["ANYONE_CAN_PAY"]!.TX_HASH,
index: offCKBConfig.lumosConfig.SCRIPTS["ANYONE_CAN_PAY"]!.INDEX,
},
depType: offCKBConfig.lumosConfig.SCRIPTS["ANYONE_CAN_PAY"]!.DEP_TYPE,
},
},
],
},
[KnownScript.OmniLock]: {
codeHash: offCKBConfig.lumosConfig.SCRIPTS["OMNILOCK"]!
.CODE_HASH as `0x{string}`,
hashType: offCKBConfig.lumosConfig.SCRIPTS["OMNILOCK"]!.HASH_TYPE,
cellDeps: [
{
cellDep: {
outPoint: {
txHash: offCKBConfig.lumosConfig.SCRIPTS["OMNILOCK"]!.TX_HASH,
index: offCKBConfig.lumosConfig.SCRIPTS["OMNILOCK"]!.INDEX,
},
depType: offCKBConfig.lumosConfig.SCRIPTS["OMNILOCK"]!.DEP_TYPE,
},
},
],
},
[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]: {
codeHash: offCKBConfig.lumosConfig.SCRIPTS["XUDT"]!
.CODE_HASH as `0x{string}`,
hashType: offCKBConfig.lumosConfig.SCRIPTS["XUDT"]!.HASH_TYPE,
cellDeps: [
{
cellDep: {
outPoint: {
txHash: offCKBConfig.lumosConfig.SCRIPTS["XUDT"]!.TX_HASH,
index: offCKBConfig.lumosConfig.SCRIPTS["XUDT"]!.INDEX,
},
depType: offCKBConfig.lumosConfig.SCRIPTS["XUDT"]!.DEP_TYPE,
},
},
],
},

[KnownScript.NostrLock]: {
codeHash: offCKBConfig.lumosConfig.SCRIPTS["NOSTR_LOCK"]!
.CODE_HASH as `0x{string}`,
hashType: offCKBConfig.lumosConfig.SCRIPTS["NOSTR_LOCK"]!.HASH_TYPE,
cellDeps: [
{
cellDep: {
outPoint: {
txHash: offCKBConfig.lumosConfig.SCRIPTS["NOSTR_LOCK"]!.TX_HASH,
index: offCKBConfig.lumosConfig.SCRIPTS["NOSTR_LOCK"]!.INDEX,
},
depType: offCKBConfig.lumosConfig.SCRIPTS["NOSTR_LOCK"]!.DEP_TYPE,
},
},
],
},
[KnownScript.XUdt]: offCKBConfig.systemScripts.xudt!.script,
[KnownScript.NostrLock]: offCKBConfig.myScripts['nostr-lock']!,
};

export function buildCccClient(network: Network) {
Expand Down
2 changes: 0 additions & 2 deletions packages/demo/app/lib/ckb.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { sdk } from "./sdk.client";
import { EventToBind } from "@nostr-binding/sdk";
import { ccc } from "@ckb-ccc/ccc";

offCKB.initializeLumosConfig();

export async function buildUnlockCKBTransaction(
signer: ccc.Signer,
toLock: ccc.ScriptLike,
Expand Down
41 changes: 36 additions & 5 deletions packages/demo/app/lib/sdk.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,41 @@ import {
import offCKBConfig, { readEnvNetwork } from "offckb.config";

export const DEVNET_CONFIGS: SDKConfig = {
prefix: offCKBConfig.lumosConfig.PREFIX as "ckt" | "ckb",
rpcUrl: offCKBConfig.indexer.ckbIndexerUrl,
NOSTR_LOCK: offCKBConfig.lumosConfig.SCRIPTS["NOSTR_LOCK"]!,
NOSTR_BINDING: offCKBConfig.lumosConfig.SCRIPTS["NOSTR_BINDING"]!,
prefix: offCKBConfig.addressPrefix,
rpcUrl: offCKBConfig.rpcUrl,
NOSTR_LOCK: {
CODE_HASH: offCKBConfig.myScripts["nostr-lock"]!.codeHash,
HASH_TYPE: offCKBConfig.myScripts["nostr-lock"]!.hashType,
TX_HASH:
offCKBConfig.myScripts["nostr-lock"]!.cellDeps[0].cellDep.outPoint.txHash,
INDEX:
"0x" +
offCKBConfig.myScripts[
"nostr-lock"
]!.cellDeps[0].cellDep.outPoint.index.toString(16),
DEP_TYPE:
offCKBConfig.myScripts["nostr-lock"]!.cellDeps[0].cellDep.depType ===
"code"
? "code"
: "depGroup",
},
NOSTR_BINDING: {
CODE_HASH: offCKBConfig.myScripts["nostr-binding"]!.codeHash,
HASH_TYPE: offCKBConfig.myScripts["nostr-binding"]!.hashType,
TX_HASH:
offCKBConfig.myScripts["nostr-binding"]!.cellDeps[0].cellDep.outPoint
.txHash,
INDEX:
"0x" +
offCKBConfig.myScripts[
"nostr-binding"
]!.cellDeps[0].cellDep.outPoint.index.toString(16),
DEP_TYPE:
offCKBConfig.myScripts["nostr-binding"]!.cellDeps[0].cellDep.depType ===
"code"
? "code"
: "depGroup",
},
};

const network = readEnvNetwork();
Expand All @@ -20,5 +51,5 @@ export const sdk = new NostrBindingSDK(
? DEVNET_CONFIGS
: network === "testnet"
? TESTNET_CONFIGS
: MAINNET_CONFIGS,
: MAINNET_CONFIGS
);
Loading

0 comments on commit 7181814

Please sign in to comment.