Skip to content

Commit

Permalink
Merge pull request #6 from libraries/update
Browse files Browse the repository at this point in the history
Use ckb development network for src/tm... scripts
  • Loading branch information
mohanson authored Nov 23, 2023
2 parents d01be6e + ce7e6ff commit 96b51b6
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 5 deletions.
3 changes: 3 additions & 0 deletions dapp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

src/info.json
src/migrations
Binary file added dapp/src/binCluster
Binary file not shown.
Binary file added dapp/src/binSpore
Binary file not shown.
17 changes: 17 additions & 0 deletions dapp/src/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
URL="http://18.162.168.78:8114"

rm -rf migrations
mkdir migrations
ckb-cli --url ${URL} deploy gen-txs \
--deployment-config ./deploy.toml \
--migration-dir ./migrations \
--from-address ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt4z78ng4yutl5u6xsv27ht6q08mhujf8s2r0n40 \
--sign-now \
--info-file info.json
ckb-cli --url ${URL} deploy sign-txs \
--from-account ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt4z78ng4yutl5u6xsv27ht6q08mhujf8s2r0n40 \
--add-signatures \
--info-file info.json
ckb-cli --url ${URL} deploy apply-txs --migration-dir ./migrations --info-file info.json
rm -rf info.json
rm -rf migrations
15 changes: 15 additions & 0 deletions dapp/src/deploy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[cells]]
name = "spore"
enable_type_id = false
location = { file = "binSpore" }

[[cells]]
name = "cluster"
enable_type_id = false
location = { file = "binCluster" }

# The lock script set to output cells
[lock]
code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
args = "0x75178f34549c5fe9cd1a0c57aebd01e7ddf9249e"
hash_type = "type"
154 changes: 154 additions & 0 deletions dapp/src/tmConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import { createConfig } from '@ckb-lumos/config-manager';
import { SporeConfig, PredefinedSporeConfigScriptName } from '@spore-sdk/core';

// export const config: SporeConfig<PredefinedSporeConfigScriptName> = {
// lumos: createConfig(createConfig({
// PREFIX: "ckt",
// SCRIPTS: {
// SECP256K1_BLAKE160: {
// CODE_HASH:
// "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
// HASH_TYPE: "type",
// TX_HASH:
// "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37",
// INDEX: "0x0",
// DEP_TYPE: "depGroup",
// SHORT_ID: 0,
// },
// SECP256K1_BLAKE160_MULTISIG: {
// CODE_HASH:
// "0x5c5069eb0857efc65e1bca0c07df34c31663b3622fd3876c876320fc9634e2a8",
// HASH_TYPE: "type",
// TX_HASH:
// "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37",
// INDEX: "0x1",
// DEP_TYPE: "depGroup",
// SHORT_ID: 1,
// },
// DAO: {
// CODE_HASH:
// "0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e",
// HASH_TYPE: "type",
// TX_HASH:
// "0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f",
// INDEX: "0x2",
// DEP_TYPE: "code",
// },
// SUDT: {
// CODE_HASH:
// "0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4",
// HASH_TYPE: "type",
// TX_HASH:
// "0xe12877ebd2c3c364dc46c5c992bcfaf4fee33fa13eebdf82c591fc9825aab769",
// INDEX: "0x0",
// DEP_TYPE: "code",
// },
// ANYONE_CAN_PAY: {
// CODE_HASH:
// "0x3419a1c09eb2567f6552ee7a8ecffd64155cffe0f1796e6e61ec088d740c1356",
// HASH_TYPE: "type",
// TX_HASH:
// "0xec26b0f85ed839ece5f11c4c4e837ec359f5adc4420410f6453b1f6b60fb96a6",
// INDEX: "0x0",
// DEP_TYPE: "depGroup",
// SHORT_ID: 2,
// },
// OMNILOCK: {
// CODE_HASH:
// "0xf329effd1c475a2978453c8600e1eaf0bc2087ee093c3ee64cc96ec6847752cb",
// HASH_TYPE: "type",
// TX_HASH:
// "0x27b62d8be8ed80b9f56ee0fe41355becdb6f6a40aeba82d3900434f43b1c8b60",
// INDEX: "0x0",
// DEP_TYPE: "code",
// },
// },
// })),
// ckbNodeUrl: 'https://testnet.ckb.dev/rpc',
// ckbIndexerUrl: 'https://testnet.ckb.dev/indexer',
// maxTransactionSize: 500 * 1024,
// scripts: {
// Spore: {
// script: {
// codeHash: '0xbbad126377d45f90a8ee120da988a2d7332c78ba8fd679aab478a19d6c133494',
// hashType: 'data1',
// },
// cellDep: {
// outPoint: {
// txHash: '0xfd694382e621f175ddf81ce91ce2ecf8bfc027d53d7d31b8438f7d26fc37fd19',
// index: '0x0',
// },
// depType: 'code',
// },
// versions: [],
// },
// Cluster: {
// script: {
// codeHash: '0x598d793defef36e2eeba54a9b45130e4ca92822e1d193671f490950c3b856080',
// hashType: 'data1',
// },
// cellDep: {
// outPoint: {
// txHash: '0x49551a20dfe39231e7db49431d26c9c08ceec96a29024eef3acc936deeb2ca76',
// index: '0x0',
// },
// depType: 'code',
// },
// versions: [],
// },
// },
// extensions: [],
// };


export const config: SporeConfig<PredefinedSporeConfigScriptName> = {
lumos: createConfig(createConfig({
PREFIX: "ckt",
SCRIPTS: {
SECP256K1_BLAKE160: {
CODE_HASH:
"0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8",
HASH_TYPE: "type",
TX_HASH:
"0x94dfbac7f4ccb5b1f41b1cc314abae9df3f85108af214c5aaff569c8ada0885e",
INDEX: "0x0",
DEP_TYPE: "depGroup",
SHORT_ID: 0,
},
},
})),
ckbNodeUrl: 'http://18.162.168.78:8114/rpc',
ckbIndexerUrl: 'http://18.162.168.78:8114/indexer',
maxTransactionSize: 500 * 1024,
scripts: {
Spore: {
script: {
codeHash: '0xbbad126377d45f90a8ee120da988a2d7332c78ba8fd679aab478a19d6c133494',
hashType: 'data1',
},
cellDep: {
outPoint: {
txHash: '0x769d127f11d81e8f6e8aefd45ea4fe8a32e9d84e70ec1267170c6db82b9796f0',
index: '0x0',
},
depType: 'code',
},
versions: [],
},
Cluster: {
script: {
codeHash: '0x598d793defef36e2eeba54a9b45130e4ca92822e1d193671f490950c3b856080',
hashType: 'data1',
},
cellDep: {
outPoint: {
txHash: '0x769d127f11d81e8f6e8aefd45ea4fe8a32e9d84e70ec1267170c6db82b9796f0',
index: '0x0',
},
depType: 'code',
},
versions: [],
},
},
extensions: [],
};
2 changes: 2 additions & 0 deletions dapp/src/tmCreateSpore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createSpore } from '@spore-sdk/core';
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { config } from './tmConfig';
import { accounts } from './tmWallet';

export async function fetchLocalFile(src: string) {
Expand All @@ -16,6 +17,7 @@ export async function main() {
},
toLock: accounts.alice.lock,
fromInfos: [accounts.alice.address],
config: config,
});
const hash = await accounts.alice.signAndSendTransaction(txSkeleton);
console.log(`Spore created at: https://pudge.explorer.nervos.org/transaction/${hash}`);
Expand Down
18 changes: 18 additions & 0 deletions dapp/src/tmTransferSpore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { transferSpore } from '@spore-sdk/core';
import { config } from './tmConfig';
import { accounts } from './tmWallet';

async function main() {
let { txSkeleton } = await transferSpore({
outPoint: {
txHash: '0xb83fa0529c76fede0531b211ddf61a689f52470584d9f487cd6c40a7df7cec53',
index: '0x0',
},
toLock: accounts.bob.lock,
config: config,
});
let hash = await accounts.alice.signAndSendTransaction(txSkeleton);
console.log(`Spore transfered at: https://pudge.explorer.nervos.org/transaction/${hash}`);
}

main()
9 changes: 4 additions & 5 deletions dapp/src/tmWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { bytes } from "@ckb-lumos/codec";
import { Config } from "@ckb-lumos/config-manager";
import { TransactionSkeletonType, createTransactionFromSkeleton } from "@ckb-lumos/helpers";
import { RPC, hd, helpers } from '@ckb-lumos/lumos';
import { defaultEmptyWitnessArgs, getSporeConfig, isScriptValueEquals, updateWitnessArgs } from '@spore-sdk/core';
import { defaultEmptyWitnessArgs, isScriptValueEquals, updateWitnessArgs } from '@spore-sdk/core';
import { Set } from "immutable";
import { config } from './tmConfig';

const { CKBHasher, ckbHash } = utils;

Expand Down Expand Up @@ -105,8 +106,6 @@ export interface Wallet {
* providing lock/address, and functions to sign message/transaction and send the transaction on-chain.
*/
export function createDefaultLockWallet(privateKey: HexString): Wallet {
const config = getSporeConfig();

// Generate a lock script from the private key
const Secp256k1Blake160 = config.lumos.SCRIPTS['SECP256K1_BLAKE160']!;
const lock: Script = {
Expand Down Expand Up @@ -182,6 +181,6 @@ export function createDefaultLockWallet(privateKey: HexString): Wallet {
}

export const accounts = {
alice: createDefaultLockWallet('0x49aa6d595ac46cc8e1a31b511754dd58f241a7d8a6ad29e83d6b0c1a82399f3d'),
bob: createDefaultLockWallet('0xc153ee57dc8ae3dac3495c828d6f8c3fef6b1d0c74fc31101c064137b3269d6d'),
alice: createDefaultLockWallet('0x0000000000000000000000000000000000000000000000000000000000000001'),
bob: createDefaultLockWallet('0x0000000000000000000000000000000000000000000000000000000000000002'),
};

0 comments on commit 96b51b6

Please sign in to comment.