IPcl.createAddressList

createAddressList() external returns (uint64 listId)

새로운 공유 주소 리스트를 할당하고 호출자를 관리자로 지정합니다. 권한 검사가 없으므로 어떤 계정이나 컨트랙트든 호출할 수 있습니다. 반환값인 0이 아닌 listId는 ALLOW_LIST_POLICY와 DENY_LIST_POLICY가 listId 필드로 참조합니다. 반환된 리스트는 상태가 Active이고 멤버십은 비어 있으므로, 이 리스트를 참조하는 정책을 바인딩하기 전에 updateAddressList로 멤버를 채웁니다. PCL 프리컴파일에는 EVM 바이트코드가 없지만, 반환값이 있는 함수는 Solidity의 고수준 호출로도 동작합니다. ABI 형태 없이 레지스트리를 호출하려는 경우에는 저수준 호출로 보낸 뒤 반환된 uint64를 디코드합니다.

파라미터

이 메서드는 파라미터가 없습니다.

반환값

타입: uint64

새로 할당된 리스트 ID입니다. ID는 0이 아니고 단조 증가하며, 재사용되지 않습니다.

에러

코드 이름 설명
InvalidAddressListConfig InvalidAddressListConfig 호출자가 0 주소이거나 레지스트리에 저장된 ID 카운터나 ID 시퀀스가 어긋났을 때 revert됩니다. InvalidAddressListConfig(uint64 listId) 형태로 인코딩되며, 할당 실패의 경우 listId는 0입니다.
AddressListStorageError AddressListStorageError 하부 레지스트리 저장소를 읽거나 쓸 수 없을 때 revert됩니다. AddressListStorageError(uint64 listId) 형태로 인코딩되며, 흔히 발생하지 않습니다. 노드 수준 저장소 결함을 의미합니다.
ABISetupFailed ABISetupFailed IPrecompile에서 상속됩니다. calldata를 프리컴파일 ABI로 디코딩할 수 없을 때 revert되며, 보통 ABI가 오래되었거나 일치하지 않는 경우입니다.

예제

viem으로 TypeScript에서 공유 리스트 생성

writeContract는 트랜잭션 해시를 반환하므로, 할당된 listId는 AddressListCreated 이벤트(인덱싱된 listId, 인덱싱된 admin)에서 읽습니다. 호출 자체는 uint64를 반환하지만 온체인 트랜잭션 반환값은 JSON-RPC로 노출되지 않으므로, 이벤트가 올바른 조회 경로입니다.

import { createWalletClient, createPublicClient, http, parseEventLogs } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { iPclAbi } from "@maroo-chain/contracts/abi/precompiles/pcl/IPcl";

const PCL = "0x1000000000000000000000000000000000000005" as const;

const admin = privateKeyToAccount(process.env.LIST_ADMIN_KEY as `0x${string}`);
const wallet = createWalletClient({
  account: admin,
  transport: http(process.env.MAROO_RPC_URL),
});
const publicClient = createPublicClient({ transport: http(process.env.MAROO_RPC_URL) });

const hash = await wallet.writeContract({
  address: PCL,
  abi: iPclAbi,
  functionName: "createAddressList",
  args: [],
});
const receipt = await publicClient.waitForTransactionReceipt({ hash });
const [created] = parseEventLogs({
  abi: iPclAbi,
  eventName: "AddressListCreated",
  logs: receipt.logs,
});
if (!created) throw new Error("AddressListCreated event not emitted");
const listId = created.args.listId;
console.log("new listId:", listId);

Solidity에서 공유 리스트 생성 (저수준 호출)

createAddressList를 호출한 컨트랙트가 리스트의 관리자가 되므로, 팩토리는 반환하기 전에 changeAddressListAdmin으로 리스트를 호출자에게 넘깁니다. 이 인계는 현재 관리자만 할 수 있으므로, 호출자가 나중에 별도 트랜잭션으로 가져올 수는 없습니다.

// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.28;

import { IPcl } from "@maroo-chain/contracts/precompiles/pcl/IPcl.sol";

contract ListFactory {
    address constant PCL = 0x1000000000000000000000000000000000000005;

    /// @notice Allocate a new address list, hand its admin to the caller, and return its id.
    ///         PCL makes THIS contract the admin (it called createAddressList), so the
    ///         hand-over has to happen here — the caller cannot do it afterwards.
    function createList() external returns (uint64 listId) {
        // createAddressList returns a value, so a high-level call works on the
        // bytecode-less precompile; we keep it low-level here only to show the
        // explicit decode. The alternative is: listId = IPcl(PCL).createAddressList();
        (bool ok, bytes memory ret) = PCL.call(
            abi.encodeCall(IPcl.createAddressList, ())
        );
        if (!ok) {
            assembly { revert(add(ret, 32), mload(ret)) }
        }
        listId = abi.decode(ret, (uint64));

        // changeAddressListAdmin returns nothing → low-level call (PCL has no bytecode).
        (ok, ret) = PCL.call(
            abi.encodeCall(IPcl.changeAddressListAdmin, (listId, msg.sender))
        );
        if (!ok) {
            assembly { revert(add(ret, 32), mload(ret)) }
        }
    }
}
ESC
검색어를 입력하세요