Skip to content
Open

V203 #104

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ckb-md5-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- rel_pkg: "x86_64-unknown-linux-gnu-portable"
build_target: "prod_portable"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.ckb_version }}
repository: nervosnetwork/ckb
Expand All @@ -51,15 +51,15 @@ jobs:
exit 1
fi
env:
BUILDER_IMAGE: nervos/ckb-docker-builder:bionic-rust-1.71.1-openssl-3.1.3
BUILDER_IMAGE: nervos/ckb-docker-builder:bionic-rust-1.85.0
REL_PKG: ${{ matrix.rel_pkg }}
CKB_VERSION: ${{ github.event.inputs.ckb_version }}

package-for-linux-aarch64:
name: package-for-linux-aarch64
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.ckb_version }}
repository: nervosnetwork/ckb
Expand Down Expand Up @@ -131,13 +131,13 @@ jobs:
# exit 1
fi
env:
BUILDER_IMAGE: nervos/ckb-docker-builder:centos-7-rust-1.71.1-openssl-3.1.3
BUILDER_IMAGE: nervos/ckb-docker-builder:centos-7-rust-1.85.0
REL_PKG: ${{ matrix.rel_pkg }}
CKB_VERSION: ${{ github.event.inputs.ckb_version }}

package-for-mac:
name: package-for-mac
runs-on: macos-11
runs-on: macos-13
strategy:
matrix:
include:
Expand All @@ -146,7 +146,7 @@ jobs:
- rel_pkg: "x86_64-apple-darwin-portable"
build_target: "prod_portable"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.ckb_version }}
repository: nervosnetwork/ckb
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ tmp
download
pytest.ini
reprot
__pycache__
pid.txt
.idea
venv
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ prepare:
python3 -m download_ckb_light_client
echo "install ckb cli"
sh prepare.sh

develop_prepare:
python3 -m venv venv
. venv/bin/activate
Expand All @@ -25,7 +26,6 @@ develop_prepare:
# test_cases/ckb2023 \

test_cases := \
test_cases/replace_rpc \
test_cases/ckb_cli \
test_cases/contracts \
test_cases/example \
Expand Down
14 changes: 1 addition & 13 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,10 @@
from tqdm import tqdm

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",
"0.117.0",
"0.118.0",
"0.119.0",
"0.120.0",
"0.121.0",
"0.200.0",
"0.201.0",
"0.202.0",
"0.203.0-rc1",
] # Replace with your versions

DOWNLOAD_DIR = "download"
Expand Down
10 changes: 1 addition & 9 deletions download_ckb_light_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@


versions = [
"0.2.4",
"0.3.0",
"0.3.1",
"0.3.2",
"0.3.3",
"0.3.4",
"0.3.5",
"0.3.6",
"0.4.1",
"0.5.0",
"0.5.3",
] # Replace with your versions

Expand Down
131 changes: 102 additions & 29 deletions framework/helper/ckb_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,6 @@
cli_path = f"cd {get_project_root()}/source && ./ckb-cli"


def exception_use_old_ckb():
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
if "SoftFork" in str(e):
global cli_path
cli_path = f"cd {get_project_root()}/source && ./ckb-cli-old"
print("------ change use old ckb-cli -------")
try:
ret = func(*args, **kwargs)
cli_path = f"cd {get_project_root()}/source && ./ckb-cli"
return ret
except Exception as e:
cli_path = f"cd {get_project_root()}/source && ./ckb-cli"
raise e
else:
raise e

return wrapper

return decorator


@exception_use_old_ckb()
def wallet_get_capacity(ckb_address, api_url="http://127.0.0.1:8114"):
"""
MacBook-Pro-4 0.111.0 % ./ckb-cli wallet get-capacity
Expand Down Expand Up @@ -67,7 +40,6 @@ def wallet_get_capacity(ckb_address, api_url="http://127.0.0.1:8114"):
Exception(f"Number not found :{capacity_response}")


@exception_use_old_ckb()
def wallet_get_live_cells(ckb_address, api_url="http://127.0.0.1:8114"):
"""
./ckb-cli wallet get-live-cells --address
Expand Down Expand Up @@ -132,7 +104,6 @@ def wallet_get_live_cells(ckb_address, api_url="http://127.0.0.1:8114"):
return json.loads(run_command(cmd))


@exception_use_old_ckb()
def wallet_transfer_by_private_key(
private_key,
to_ckb_address,
Expand Down Expand Up @@ -181,6 +152,54 @@ def version():
return output


def tx_build_multisig_address(
addresses,
threshold=None,
multisig_code_hash="legacy",
api_url="http://127.0.0.1:8114",
):
"""
Build a multisig address using ckb-cli tx build-multisig-address command.

Args:
addresses (list): List of sighash addresses, at least two addresses required (e.g., ["ckt1qz...", "ckt1qz..."]).
threshold (int, optional): Number of signatures required. Defaults to len(addresses).
multisig_code_hash (str, optional): Multisig code hash. Defaults to "legacy".
cli_path (str): Path to ckb-cli executable. Defaults to "ckb-cli".

Returns:
str: Output of the ckb-cli command.

Example:
addresses = [
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvm4mmpqw7vp4alvjuls8lxqz0jtvd47mqg0estw",
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqtmcfut7hfzcpcjx5m2c6ylrnfkckyvldcu8d67f"
]
output = build_multisig_address(addresses, threshold=2, multisig_code_hash="legacy")
"""
if threshold is None:
threshold = len(addresses)

if len(addresses) < 2:
raise ValueError("At least two addresses are required.")
if threshold < 2 or threshold > len(addresses):
raise ValueError(f"Threshold must be between 2 and {len(addresses)}.")

cmd = f"export API_URL={api_url} && {cli_path} tx build-multisig-address"
for addr in addresses:
cmd += f" --sighash-address {addr}"
cmd += f" --threshold {threshold} --multisig-code-hash {multisig_code_hash}"
cmd += f" --output-format json"

output = run_command(cmd)

# print("\n=============== Multisig Address Output ===============")
# print(output.strip())
# print("=======================================================\n")

return json.loads(output)


def deploy_gen_txs(
from_address, deployment_config_path, tx_info_path, api_url="http://127.0.0.1:8114"
):
Expand Down Expand Up @@ -386,6 +405,34 @@ def tx_add_input(tx_hash, index, tx_file, api_url="http://127.0.0.1:8114"):
return run_command(cmd)


def tx_add_output_multisig(
address, capacity, tx_file, is_multisig=False, api_url="http://127.0.0.1:8114"
):
"""
Add output to transaction.
Args:
address: recipient CKB address
capacity: capacity in CKB (1 CKB = 10^8 shannons)
tx_file: transaction file path
is_multisig: whether the address is a short multisig address
api_url: CKB node RPC URL
Returns:
command execution result
"""
address_flag = (
"--to-short-multisig-address" if is_multisig else "--to-sighash-address"
)

cmd = (
f"export API_URL={api_url} && "
f"{cli_path} tx add-output "
f"{address_flag} {address} "
f"--capacity {capacity} "
f"--tx-file {tx_file}"
)
return run_command(cmd)


def tx_add_multisig_config(ckb_address, tx_file, api_url="http://127.0.0.1:8114"):
"""
./ckb-cli tx add-multisig-config --multisig-code-hash legacy --sighash-address ckt1qyqdfjzl8ju2vfwjtl4mttx6me09hayzfldq8m3a0y --tx-file tx.txt
Expand Down Expand Up @@ -427,6 +474,31 @@ def tx_add_multisig_config(ckb_address, tx_file, api_url="http://127.0.0.1:8114"
return run_command(cmd)


def tx_add_multisig_config_for_addr_list(
addresses,
tx_file,
threshold=None,
multisig_code_hash="legacy",
api_url="http://127.0.0.1:8114",
):
if not addresses:
raise ValueError("At least two addresses are required.")

threshold = threshold or len(addresses)
sighash_addresses = " ".join(f"--sighash-address {addr}" for addr in addresses)

cmd = (
f"export API_URL={api_url} && "
f"{cli_path} tx add-multisig-config "
f"{sighash_addresses} "
f"--threshold {threshold} "
f"--multisig-code-hash {multisig_code_hash} "
f"--tx-file {tx_file}"
)

return run_command(cmd)


def tx_info(tx_file_path, api_url="http://127.0.0.1:8114"):
cmd = f"export API_URL={api_url} && {cli_path} tx info --tx-file {tx_file_path}"
return run_command(cmd)
Expand Down Expand Up @@ -541,6 +613,7 @@ def get_deploy_toml_config(account_private, contract_bin_path, enable_type_id):

[[dep_groups]]
name = "my_dep_group"
enable_type_id = {str(enable_type_id).lower()}
cells = []

[lock]
Expand Down
4 changes: 0 additions & 4 deletions framework/helper/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def get_arg_and_data(self, key) -> (str, str):
pass


@exception_use_old_ckb()
def deploy_ckb_contract(
private_key,
contract_path,
Expand Down Expand Up @@ -79,7 +78,6 @@ def deploy_ckb_contract(
return run_command(cmd).replace("\n", "")


@exception_use_old_ckb()
def get_ckb_contract_codehash(
tx_hash, tx_index, enable_type_id=True, api_url="http://127.0.0.1:8114"
):
Expand Down Expand Up @@ -110,7 +108,6 @@ def get_ckb_contract_codehash(
return f"0x{hex_digest}"


@exception_use_old_ckb()
def invoke_ckb_contract(
account_private,
contract_out_point_tx_hash,
Expand Down Expand Up @@ -260,7 +257,6 @@ def invoke_ckb_contract(
return tx_send(tmp_tx_file, api_url).strip()


@exception_use_old_ckb()
def build_invoke_ckb_contract(
account_private,
contract_out_point_tx_hash,
Expand Down
Loading
Loading