Skip to content

Commit 32429fa

Browse files
committed
feat: use dep group
1 parent 90c46af commit 32429fa

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/ckb/api.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module CKB
1010
class API
1111
attr_reader :rpc
1212
attr_reader :system_script_out_point
13+
attr_reader :system_script_group_out_point
1314
attr_reader :system_script_code_hash
1415
attr_reader :dao_out_point
1516
attr_reader :dao_code_hash
@@ -18,10 +19,12 @@ def initialize(host: CKB::RPC::DEFAULT_URL, mode: MODE::TESTNET)
1819
@rpc = CKB::RPC.new(host: host)
1920
if mode == MODE::TESTNET
2021
# Testnet system script code_hash
21-
expected_code_hash = "0xa76801d09a0eabbfa545f1577084b6f3bafb0b6250e7f5c89efcfd4e3499fb55"
22+
expected_code_hash = "0x664b03c55410dd7d694a73779fa86edd7f069ee17fd79b0fef4c4fec0377b9a6"
2223
# For testnet chain, we can assume the second cell of the first transaction
2324
# in the genesis block contains default lock script we can use here.
2425
system_cell_transaction = genesis_block.transactions.first
26+
27+
system_scipt_group_transaction = genesis_block.transactions[1]
2528
out_point = Types::OutPoint.new(
2629
tx_hash: system_cell_transaction.hash,
2730
index: "1"
@@ -32,6 +35,11 @@ def initialize(host: CKB::RPC::DEFAULT_URL, mode: MODE::TESTNET)
3235
raise "System script code_hash error!" unless code_hash == expected_code_hash
3336

3437
set_system_script_cell(out_point, code_hash)
38+
group_out_point = Types::OutPoint.new(
39+
tx_hash: system_scipt_group_transaction.hash,
40+
index: "0"
41+
)
42+
set_system_script_group_cell(group_out_point)
3543

3644
dao_out_point = Types::OutPoint.new(
3745
tx_hash: system_cell_transaction.hash,
@@ -51,6 +59,11 @@ def set_system_script_cell(out_point, code_hash)
5159
@system_script_code_hash = code_hash
5260
end
5361

62+
# @param out_point [CKB::Types::OutPoint]
63+
def set_system_script_group_cell(out_point)
64+
@system_script_group_out_point = out_point
65+
end
66+
5467
def set_dao_cell(out_point, code_hash)
5568
@dao_out_point = out_point
5669
@dao_code_hash = code_hash
@@ -140,6 +153,10 @@ def compute_transaction_hash(transaction)
140153
rpc.compute_transaction_hash(transaction.to_h)
141154
end
142155

156+
def compute_script_hash(script_h)
157+
rpc.compute_script_hash(script_h)
158+
end
159+
143160
# @return [CKB::Type::Peer]
144161
def local_node_info
145162
Types::Peer.from_h(

lib/ckb/wallet.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def generate_tx(target_address, capacity, data = "0x", key: nil, fee: 0)
9595
tx = Types::Transaction.new(
9696
version: 0,
9797
cell_deps: [
98-
Types::CellDep.new(out_point: api.system_script_out_point)
98+
Types::CellDep.new(out_point: api.system_script_group_out_point, is_dep_group: true)
9999
],
100100
inputs: i.inputs,
101101
outputs: outputs,
@@ -154,14 +154,15 @@ def deposit_to_dao(capacity, key: nil)
154154
tx = Types::Transaction.new(
155155
version: 0,
156156
cell_deps: [
157-
Types::CellDep.new(out_point: api.system_script_out_point),
157+
Types::CellDep.new(out_point: api.system_script_group_out_point, is_dep_group: true),
158158
Types::CellDep.new(out_point: api.dao_out_point)
159159
],
160160
inputs: i.inputs,
161161
outputs: outputs,
162162
outputs_data: outputs.map(&:data),
163163
witnesses: i.witnesses
164164
)
165+
165166
tx_hash = api.compute_transaction_hash(tx)
166167
send_transaction(tx.sign(key, tx_hash))
167168

@@ -211,7 +212,7 @@ def generate_withdraw_from_dao_transaction(out_point, key: nil)
211212
version: 0,
212213
cell_deps: [
213214
Types::CellDep.new(out_point: api.dao_out_point),
214-
Types::CellDep.new(out_point: api.system_script_out_point)
215+
Types::CellDep.new(out_point: api.system_script_group_out_point, is_dep_group: true)
215216
],
216217
header_deps: [
217218
current_block.hash,
@@ -246,7 +247,7 @@ def block_assembler_config
246247
end
247248

248249
def lock_hash
249-
@lock_hash ||= lock.to_hash
250+
@lock_hash ||= lock.to_hash(api)
250251
end
251252

252253
private

0 commit comments

Comments
 (0)