Skip to content

Commit 8c82f62

Browse files
authored
Merge pull request #45 from cryptape/v116
V116 merge main
2 parents 968c9a1 + 7916107 commit 8c82f62

18 files changed

+1192
-56
lines changed

download.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import requests
1212
from tqdm import tqdm
1313

14-
versions = ['0.109.0', '0.110.2', '0.111.0', '0.112.1', '0.113.1', "0.114.0", "0.115.0"] # Replace with your versions
15-
14+
versions = ['0.109.0', '0.110.2', '0.111.0', '0.112.1', '0.113.1', "0.114.0", "0.115.0", "0.116.1"] # Replace with your versions
1615

1716
DOWNLOAD_DIR = "download"
1817
SYSTEMS = {

framework/helper/tx.py

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,108 @@ def build_tx_info(tmp_tx_file):
9595
witness = "0x5500000010000000550000005500000041000000" + tx['signatures'][sign_keys][0][2:]
9696
tx_msg = tx['transaction']
9797
tx_msg['witnesses'] = [witness]
98-
return tx_msg
98+
return tx_msg
99+
100+
def build_tx_info_err(tmp_tx_file):
101+
with open(tmp_tx_file, "r") as file:
102+
tx_info_str = file.read()
103+
tx = json.loads(tx_info_str)
104+
sign_keys = list(tx['signatures'].keys())[0]
105+
witness = "0x0500000010000000550000005500000041000000" + tx['signatures'][sign_keys][0][2:]
106+
tx_msg = tx['transaction']
107+
tx_msg['witnesses'] = [witness]
108+
return tx_msg
109+
110+
def build_tx_info_err2(tmp_tx_file):
111+
with open(tmp_tx_file, "r") as file:
112+
tx_info_str = file.read()
113+
tx = json.loads(tx_info_str)
114+
tx['transaction']['cell_deps'][0]['out_point']['index'] = '0x11'
115+
sign_keys = list(tx['signatures'].keys())[0]
116+
witness = "0x5500000010000000550000005500000041000000" + tx['signatures'][sign_keys][0][2:]
117+
tx_msg = tx['transaction']
118+
tx_msg['witnesses'] = [witness]
119+
return tx_msg
120+
121+
def build_send_transfer_self_tx_with_input_err(input_tx_hash_list, input_tx_index_list, sign_private, data="0x",
122+
123+
fee=5000, output_count=1,
124+
api_url="http://127.0.0.1:8114", dep_cells=[]):
125+
# tx file init
126+
127+
tmp_tx_file = f"/tmp/demo{time.time()}-{random.randint(0, 100000000)}.json"
128+
tx_init(tmp_tx_file, api_url)
129+
account = util_key_info_by_private_key(sign_private)
130+
account_address = account["address"]["testnet"]
131+
tx_add_multisig_config(account_address, tmp_tx_file, api_url)
132+
# add input
133+
output_cell_capacity_total = 0
134+
input_cell_template: any
135+
for i in range(len(input_tx_hash_list)):
136+
input_tx_index = input_tx_index_list[i]
137+
input_tx_hash = input_tx_hash_list[i]
138+
print(f"input_tx_index:{input_tx_index}")
139+
tx_add_input(input_tx_hash, int(input_tx_index, 16), tmp_tx_file, api_url)
140+
# add output
141+
input_cell = RPCClient(api_url).get_transaction(input_tx_hash)["transaction"]["outputs"][
142+
int(input_tx_index, 16)]
143+
output_cell_capacity = int(int(input_cell["capacity"], 16) - fee)
144+
output_cell_capacity_total += output_cell_capacity
145+
input_cell_template = input_cell
146+
min_output_count = min(int(output_cell_capacity_total / (100 * 100000000)), output_count)
147+
min_output_count = max(min_output_count, 1)
148+
output_cell_capacity = int(output_cell_capacity_total / min_output_count)
149+
for i in range(min_output_count):
150+
tx_add_type_out_put(input_cell_template["lock"]["code_hash"], input_cell_template["lock"]["hash_type"],
151+
input_cell_template["lock"]["args"],
152+
hex(output_cell_capacity), data, tmp_tx_file, False)
153+
for i in range(len(dep_cells)):
154+
tx_add_cell_dep(dep_cells[i]['tx_hash'],dep_cells[i]['index_hex'],tmp_tx_file)
155+
156+
# sign
157+
sign_data = tx_sign_inputs(sign_private, tmp_tx_file, api_url)
158+
tx_add_signature(sign_data[0]['lock-arg'], sign_data[0]['signature'], tmp_tx_file, api_url)
159+
tx_info(tmp_tx_file, api_url)
160+
# send tx return hash
161+
return build_tx_info_err(tmp_tx_file)
162+
163+
def build_send_transfer_self_tx_with_input_err2(input_tx_hash_list, input_tx_index_list, sign_private, data="0x",
164+
fee=5000, output_count=1,
165+
api_url="http://127.0.0.1:8114", dep_cells=[]):
166+
# tx file init
167+
168+
tmp_tx_file = f"/tmp/demo{time.time()}-{random.randint(0, 100000000)}.json"
169+
tx_init(tmp_tx_file, api_url)
170+
account = util_key_info_by_private_key(sign_private)
171+
account_address = account["address"]["testnet"]
172+
tx_add_multisig_config(account_address, tmp_tx_file, api_url)
173+
# add input
174+
output_cell_capacity_total = 0
175+
input_cell_template: any
176+
for i in range(len(input_tx_hash_list)):
177+
input_tx_index = input_tx_index_list[i]
178+
input_tx_hash = input_tx_hash_list[i]
179+
print(f"input_tx_index:{input_tx_index}")
180+
tx_add_input(input_tx_hash, int(input_tx_index, 16), tmp_tx_file, api_url)
181+
# add output
182+
input_cell = RPCClient(api_url).get_transaction(input_tx_hash)["transaction"]["outputs"][
183+
int(input_tx_index, 16)]
184+
output_cell_capacity = int(int(input_cell["capacity"], 16) - fee)
185+
output_cell_capacity_total += output_cell_capacity
186+
input_cell_template = input_cell
187+
min_output_count = min(int(output_cell_capacity_total / (100 * 100000000)), output_count)
188+
min_output_count = max(min_output_count, 1)
189+
output_cell_capacity = int(output_cell_capacity_total / min_output_count)
190+
for i in range(min_output_count):
191+
tx_add_type_out_put(input_cell_template["lock"]["code_hash"], input_cell_template["lock"]["hash_type"],
192+
input_cell_template["lock"]["args"],
193+
hex(output_cell_capacity), data, tmp_tx_file, False)
194+
for i in range(len(dep_cells)):
195+
tx_add_cell_dep(dep_cells[i]['tx_hash'],dep_cells[i]['index_hex'],tmp_tx_file)
196+
197+
# sign
198+
sign_data = tx_sign_inputs(sign_private, tmp_tx_file, api_url)
199+
tx_add_signature(sign_data[0]['lock-arg'], sign_data[0]['signature'], tmp_tx_file, api_url)
200+
tx_info(tmp_tx_file, api_url)
201+
# send tx return hash
202+
return build_tx_info_err2(tmp_tx_file)

framework/rpc.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
from typing import Union
23

34
import requests
45

@@ -177,7 +178,33 @@ def set_network_active(self, state):
177178
def remove_transaction(self, tx_hash):
178179
return self.call("remove_transaction", [tx_hash])
179180

181+
def get_live_cell_with_include_tx_pool(self, index, tx_hash, with_data=True, include_tx_pool: Union[bool, None] = None):
182+
"""
183+
over ckb v116.1 version
184+
https://github.com/nervosnetwork/ckb/blob/bb677558efdc3e5f0759556720b62169469b555d/rpc/README.md#chain-get_live_cell
185+
Args:
186+
index:
187+
tx_hash:
188+
with_data:boolean
189+
include_tx_pool:boolean | null
190+
191+
Returns:CellWithStatus
192+
193+
"""
194+
return self.call("get_live_cell", [{"index": index, "tx_hash": tx_hash}, with_data, include_tx_pool])
195+
180196
def get_live_cell(self, index, tx_hash, with_data=True):
197+
"""
198+
under ckb v116.1 version
199+
https://github.com/nervosnetwork/ckb/blob/bb677558efdc3e5f0759556720b62169469b555d/rpc/README.md#chain-get_live_cell
200+
Args:
201+
index:
202+
tx_hash:
203+
with_data:boolean
204+
205+
Returns:CellWithStatus
206+
207+
"""
181208
return self.call("get_live_cell", [{"index": index, "tx_hash": tx_hash}, with_data])
182209

183210
def submit_block(self, work_id, block):
@@ -192,6 +219,9 @@ def get_cells_capacity(self, script):
192219
def get_current_epoch(self):
193220
return self.call("get_current_epoch", [])
194221

222+
def test_tx_pool_accept(self,tx, outputs_validator):
223+
return self.call("test_tx_pool_accept",[tx, outputs_validator])
224+
195225
def call(self, method, params, try_count=15):
196226

197227
headers = {'content-type': 'application/json'}

framework/test_node.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,22 @@
1111
class CkbNodeConfigPath(Enum):
1212

1313
CURRENT_TEST = (
14-
"source/template/ckb/v115/ckb.toml.j2",
15-
"source/template/ckb/v115/ckb-miner.toml.j2",
16-
"source/template/ckb/v115/specs/dev.toml",
17-
"download/0.115.0"
14+
"source/template/ckb/v116/ckb.toml.j2",
15+
"source/template/ckb/v116/ckb-miner.toml.j2",
16+
"source/template/ckb/v116/specs/dev.toml",
17+
"download/0.116.1"
1818
)
1919

20-
CURRENT_MAIN = ("source/template/ckb/v115/ckb.toml.j2",
21-
"source/template/ckb/v115/ckb-miner.toml.j2",
20+
CURRENT_MAIN = ("source/template/ckb/v116/ckb.toml.j2",
21+
"source/template/ckb/v116/ckb-miner.toml.j2",
2222
"source/template/specs/mainnet.toml.j2",
23-
"download/0.115.0")
23+
"download/0.116.1")
2424

25+
v116 = ( "source/template/ckb/v116/ckb.toml.j2",
26+
"source/template/ckb/v116/ckb-miner.toml.j2",
27+
"source/template/ckb/v116/specs/dev.toml",
28+
"download/0.116.1"
29+
)
2530
v115 = (
2631
"source/template/ckb/v115/ckb.toml.j2",
2732
"source/template/ckb/v115/ckb-miner.toml.j2",

source/template/ckb/v114/ckb.toml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ block_uncles_cache_size = {{ ckb_store_block_uncles_cache_size | default("
187187
# init_tip_hash = "0x8fbd0ec887159d2814cee475911600e3589849670f5ee1ed9798b38fdeef4e44"
188188
#
189189
# # CKB rich-indexer has its unique configuration.
190-
[indexer_v2.rich_indexer]
190+
#[indexer_v2.rich_indexer]
191191
# # By default, it uses an embedded SQLite database.
192192
# # Alternatively, you can set up a PostgreSQL database service and provide the connection parameters.
193193
# db_type = "postgres"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Config generated by `ckb init --chain dev`
2+
3+
data_dir = "{{ ckb_miner_data_dir | default(ckb_data_dir) }}"
4+
5+
[chain]
6+
{# Choose the kind of chains to run, possible values: #}
7+
{# - { file = "specs/dev.toml" } #}
8+
{# - { bundled = "specs/testnet.toml" } #}
9+
{# - { bundled = "specs/mainnet.toml" } #}
10+
spec = {{ ckb_chain_spec }}
11+
12+
13+
[logger]
14+
filter = "{{ ckb_miner_logger_filter | default("info") }}"
15+
color = {{ ckb_miner_logger_color | default("true") }}
16+
log_to_file = {{ ckb_miner_logger_log_to_file | default("true") }}
17+
log_to_stdout = {{ ckb_miner_logger_log_to_stdout | default("true") }}
18+
19+
[sentry]
20+
# set to blank to disable sentry error collection
21+
dsn = "{{ ckb_miner_sentry_dsn | default("") }}"
22+
# if you are willing to help us to improve,
23+
# please leave a way to contact you when we have troubles to reproduce the errors.
24+
# org_contact = "{{ ckb_miner_sentry_org_contact | default() }}"
25+
26+
[miner.client]
27+
rpc_url = "http://{{ ckb_miner_rpc_url | default("127.0.0.1:8114") }}"
28+
block_on_submit = {{ ckb_miner_block_on_submit | default("true") }}
29+
30+
# block template polling interval in milliseconds
31+
poll_interval = {{ ckb_miner_poll_interval | default("1000") }}
32+
33+
#{% if ckb_miner_workers is defined %}
34+
# {% for worker in ckb_miner_workers %}
35+
# [[miner.workers]]
36+
# worker_type = "{{ worker.worker_type }}"
37+
# delay_type = "{{ worker.delay_type }}"
38+
# value = {{ worker.value }}
39+
# {% endfor %}
40+
#{% else %}
41+
[[miner.workers]]
42+
worker_type = "Dummy"
43+
delay_type = "Constant"
44+
value = 1000
45+
#{% endif %}

0 commit comments

Comments
 (0)